chore: adding better bootstrap support for react sdk#1194
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
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
Changes provider startup behavior by merging a new
bootstrapoption intoclient.start()options, which can affect initialization semantics for existing consumers. Risk is moderate but localized to React provider creation and documented/tested.Overview
Adds a top-level
bootstrapoption tocreateLDReactProviderso apps can pre-seed flags from server-provided data without deferring initialization.When auto-starting, the factory now builds an
effectiveStartOptionsthat mergesbootstrapintostartOptions(withbootstraptaking precedence) and updates tests and migration docs to cover the new API and merge behavior.Written by Cursor Bugbot for commit 3cf06dc. This will update automatically on new commits. Configure here.