Skip to content

chore: adding better bootstrap support for react sdk#1194

Open
joker23 wants to merge 1 commit intomainfrom
skz/sdk-1992/react-bootstrapping
Open

chore: adding better bootstrap support for react sdk#1194
joker23 wants to merge 1 commit intomainfrom
skz/sdk-1992/react-bootstrapping

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Mar 18, 2026

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.


Open with Devin

Note

Medium Risk
Changes provider startup behavior by merging a new bootstrap option into client.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 bootstrap option to createLDReactProvider so apps can pre-seed flags from server-provided data without deferring initialization.

When auto-starting, the factory now builds an effectiveStartOptions that merges bootstrap into startOptions (with bootstrap taking 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.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25661 bytes
Compressed size limit: 29000
Uncompressed size: 126143 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 24981 bytes
Compressed size limit: 25000
Uncompressed size: 86916 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 172978 bytes
Compressed size limit: 200000
Uncompressed size: 804043 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 29156 bytes
Compressed size limit: 38000
Uncompressed size: 156220 bytes

devin-ai-integration[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-1992/react-bootstrapping branch from 2c0361a to e2f975f Compare March 18, 2026 15:33
@joker23
Copy link
Contributor Author

joker23 commented Mar 18, 2026

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@joker23 joker23 marked this pull request as ready for review March 18, 2026 19:02
@joker23 joker23 requested a review from a team as a code owner March 18, 2026 19:02
* `bootstrap` and `startOptions.bootstrap` are provided, this top-level value takes
* precedence.
*/
bootstrap?: unknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const client = createClient(clientSideID, context, ldOptions);

if (!deferInitialization) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines 123 to 126
if (!deferInitialization) {
client.start(startOptions);
const effectiveStartOptions = bootstrap ? { ...startOptions, bootstrap } : startOptions;
client.start(effectiveStartOptions);
}
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@joker23 joker23 force-pushed the skz/sdk-1992/react-bootstrapping branch from 631cb11 to 3cf06dc Compare March 20, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant