Skip to content

Commit 7cce22d

Browse files
committed
docs: addressing PR comments
1 parent 897cece commit 7cce22d

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

packages/sdk/browser/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import { AutoEnvAttributes, LDContext } from '@launchdarkly/js-client-sdk-common';
1414

1515
import { makeClient } from './BrowserClient';
16-
import { LDClient } from './LDClient';
16+
import { LDClient, LDStartOptions } from './LDClient';
1717
import { BrowserOptions as LDOptions } from './options';
1818

1919
export * from './common';
20-
export type { LDClient, LDOptions };
20+
export type { LDClient, LDOptions, LDStartOptions };
2121
export type { LDPlugin } from './LDPlugin';
2222

2323
/**

packages/sdk/browser/upgrade/v4.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ successfully upgrade.
1313

1414
## Key changes
1515

16-
### Client creation
16+
### Client initialization
1717

1818
**Key differences:**
1919
- Initialization is now split into 2 parts `createClient` and `start`
20+
- We split the original `LDOptions` that was passed into the `initialize()` function into
21+
2 types `LDStartOptions` and `LDOptions`. [more here](#ldoptions)
2022
- Removed the use of `initialize` method
2123

2224
**Before (v3.x):**
@@ -43,6 +45,21 @@ perform any necessary setup before the client begins connecting to LaunchDarkly.
4345
This eliminates race conditions where events might be missed if listeners were
4446
registered after the client had already started initializing.
4547

48+
### LDOptions
49+
50+
We moved a few things around in `LDOptions` to support the changes that are discussed in
51+
other parts of this doc. Please visit the following docs to see how to interact with our SDK:
52+
- [LDOptions](https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/interfaces/LDOptions.html) that is passed into `createClient()`
53+
- [LDStartOptions](https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/interfaces/LDStartOptions.html) that is passed into `start()`
54+
- [LDIdentifyOptions](https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/interfaces/LDIdentifyOptions.html) that is passed into `identify()`
55+
56+
**Key differences:**
57+
- `bootstrap` option is moved from `LDOptions` to `LDStartOptions` and `Identify`. The reason for this is that bootstrapping data is
58+
now part of the initialization of a client instance.
59+
> NOTE: that `identify` is a key part of the client initialization process required to associate the instance with an initial context.
60+
- The SDK now defaults to use local storage based caching.
61+
> Previously, in order enable local storage caching, you will need to set this as a special value for the `bootstrap` property.
62+
4663
### Client initialization flow
4764

4865
The new SDK uses `waitForInitialization()` which returns a result object instead of rejecting promises.
@@ -111,11 +128,15 @@ The `identify()` method now always returns a result object and never throws erro
111128
This provides more predictable error handling.
112129

113130
**Key differences:**
114-
- `identify()` now takes an options object as the second parameter: `{ hash: '...' }` instead of a direct hash string
131+
- `identify()` now takes an options object as the second parameter: `LDIdentifyOptions` instead of a direct hash string
115132
- The method always returns a promise that resolves to a result object (never rejects)
116133
- You must check the `status` field to determine success or failure
117134
- The `hash` parameter is now part of the options object
135+
- `IdentifyOptions` now have a `sheddable` property that is `true` by default. Which means the default behavior for
136+
multiple identify calls is different
137+
[more info here](https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/interfaces/LDIdentifyOptions.html#sheddable)
118138
- Callback support has been removed - use async/await or `.then()` instead
139+
> See [options section](#ldoptions) for more information about changes to the options.
119140
120141
**Before (v3.x):**
121142
```javascript
@@ -154,7 +175,7 @@ if (result.status === 'completed') {
154175
}
155176
```
156177

157-
### Flag change event
178+
### Flag change event payload
158179

159180
The `change` event now receives the context and an array of changed flag keys as parameters.
160181
> NOTE: we will no longer return the flag value object along with this event
@@ -192,3 +213,28 @@ client.on('change:my-flag', (context) => {
192213
const flagValue = client.variation('my-flag', false);
193214
});
194215
```
216+
217+
### Error event handling changes
218+
219+
The new SDK has changed how errors are logged when error event listeners are present.
220+
221+
**Key difference:**
222+
223+
**Before (v3.x):**
224+
In the old SDK, the `maybeReportError` function would check if there was an error listener:
225+
- If an error listener was registered: the error event was emitted but **not logged** to the console
226+
- If no error listener was registered: the error was logged to the console
227+
228+
> This meant that if you wanted to handle errors yourself, you wouldn't get duplicate error logs.
229+
230+
**After (v4.x):**
231+
In the new SDK, the client always registers a default error listener that logs errors via the logger. This means:
232+
- Errors are **always logged** via the logger, even if you have your own error listeners
233+
- Your error listeners will still receive the error events
234+
- You may see duplicate error logs if you're also logging errors in your error handler
235+
236+
**Why this change?**
237+
The new error handling process allows for more robust control over what errors are ignored. The specific case
238+
that we want to avoid is not logging/informing end users when an unhandled error happens.
239+
240+
Our recommendation is to implement `LDLogger` for your client to suppress errors that are handled

0 commit comments

Comments
 (0)