chore: adding better bootstrap support for react sdk#1194
Conversation
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
|
@launchdarkly/browser size report |
|
@launchdarkly/js-client-sdk-common size report |
2c0361a to
e2f975f
Compare
|
@cursor review |
| * `bootstrap` and `startOptions.bootstrap` are provided, this top-level value takes | ||
| * precedence. | ||
| */ | ||
| bootstrap?: unknown; |
There was a problem hiding this comment.
|
|
||
| const client = createClient(clientSideID, context, ldOptions); | ||
|
|
||
| if (!deferInitialization) { |
There was a problem hiding this comment.
I figured if users are deferring start then they will need to provide their own start options. We may need to call this out in docs somewhere.
| if (!deferInitialization) { | ||
| client.start(startOptions); | ||
| const effectiveStartOptions = bootstrap ? { ...startOptions, bootstrap } : startOptions; | ||
| client.start(effectiveStartOptions); | ||
| } |
There was a problem hiding this comment.
🟡 Bootstrap data is silently discarded when deferInitialization: true
When a user passes { bootstrap: myData, deferInitialization: true } to createLDReactProvider, the bootstrap value is destructured from options at line 119 but never used because the if (!deferInitialization) block (lines 123-126) is skipped entirely. Since createLDReactProvider returns a React.FC (not the client), the user has no way to recover the lost bootstrap data. The only way to later call start() is through the useLDClient() hook (packages/sdk/react/src/client/hooks/useLDClient.ts:14), but the bootstrap data from the original options is inaccessible at that point. The API happily accepts this combination without any warning, silently discarding the user's bootstrap data.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
I think this is fine as we should have it documented that if developers decide to defer initialization then they are responsible for starting the client however they want.
631cb11 to
3cf06dc
Compare
3cf06dc to
da8201d
Compare
This PR will allow developers to directly set bootstrap data on the sdk provider.
I think this is helpful in order to reasonably preserve the non-deferred start case.
Note
Medium Risk
Touches provider initialization behavior by altering the
client.start()options, which could affect startup/flag hydration if callers relied on previousstartOptionssemantics.Overview
Adds a first-class
bootstrapoption tocreateLDReactProvider, and when auto-starting it now merges that value into theclient.start()options (overriding anystartOptions.bootstrap).Updates unit coverage to assert the new merge/precedence behavior, and extends the migration docs to explain how to pass bootstrap data in the new SDK.
Written by Cursor Bugbot for commit da8201d. This will update automatically on new commits. Configure here.