-
Notifications
You must be signed in to change notification settings - Fork 31
feat: add waitForInitialization to RN SDK #1048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- refactors the `waitForInitialization` function to client common - exposes `waitForInitialization` to react native SDK
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
c0519a4 to
1c46a53
Compare
| return { status: 'error', error: res.error } as LDIdentifyError; | ||
| const errorResult = { status: 'error', error: res.error } as LDIdentifyError; | ||
| // Track initialization state for waitForInitialization | ||
| this.setInitializationResult({ status: 'failed', error: res.error }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only want to actually set the initialization result when initializing.
| const errorResult = { status: 'error', error: res.error } as LDIdentifyError; | ||
| // Track initialization state for waitForInitialization | ||
| this.setInitializationResult({ status: 'failed', error: res.error }); | ||
| return errorResult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing initialization result when identify is shed
Low Severity
When identifyResult completes with status: 'shed', the code returns immediately without calling setInitializationResult. This means initializeResult remains undefined and initializedPromise never resolves. If a user calls waitForInitialization alongside a sheddable identifyResult that gets shed, waitForInitialization will timeout rather than returning a meaningful status. While the browser SDK mitigates this by using sheddable: false for initial identifies, and waitForInitialization is not the documented flow for React Native, this could cause unexpected behavior if users rely on both features together.
39f5e85 to
25f2444
Compare
| this.initResolve(result); | ||
| this.initResolve = undefined; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialized event now fires only once instead of every identify
Medium Severity
The initialized event behavior has changed. Previously, this.emitter.emit('initialized') was called in the .then() callback on every successful identifyResult call. Now it's called inside maybeSetInitializationResult, which only emits the event when this.initializeResult === undefined (the first successful identify). Code listening to initialized to detect each identify completion will no longer work as expected for subsequent identify calls. While semantically "initialized" may only need to fire once, this is a breaking change from the previous behavior.
Additional Locations (1)
🤖 I have created a release *beep* *boop* --- <details><summary>browser-telemetry: 1.0.16</summary> ## [1.0.16](browser-telemetry-v1.0.15...browser-telemetry-v1.0.16) (2026-01-06) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/js-client-sdk bumped from 0.11.0 to 0.12.0 </details> <details><summary>jest: 0.2.0</summary> ## [0.2.0](jest-v0.1.15...jest-v0.2.0) (2026-01-06) ### Features * add waitForInitialization to RN SDK ([#1048](#1048)) ([13ce456](13ce456)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/react-native-client-sdk bumped from ~10.12.3 to ~10.12.4 </details> <details><summary>js-client-sdk: 0.12.0</summary> ## [0.12.0](js-client-sdk-v0.11.0...js-client-sdk-v0.12.0) (2026-01-06) ### Features * add legacy storage key cleanup functionality ([#1043](#1043)) ([fe4725e](fe4725e)) * add waitForInitialization to RN SDK ([#1048](#1048)) ([13ce456](13ce456)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-client-sdk-common bumped from 1.16.0 to 1.17.0 </details> <details><summary>js-client-sdk-common: 1.17.0</summary> ## [1.17.0](js-client-sdk-common-v1.16.0...js-client-sdk-common-v1.17.0) (2026-01-06) ### Features * add legacy storage key cleanup functionality ([#1043](#1043)) ([fe4725e](fe4725e)) * add waitForInitialization to RN SDK ([#1048](#1048)) ([13ce456](13ce456)) </details> <details><summary>react-native-client-sdk: 10.12.4</summary> ## [10.12.4](react-native-client-sdk-v10.12.3...react-native-client-sdk-v10.12.4) (2026-01-06) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-client-sdk-common bumped from 1.16.0 to 1.17.0 </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Releases multiple packages and aligns versions/dependencies across the workspace. > > - Publish `@launchdarkly/js-client-sdk` 0.12.0 (adds legacy storage key cleanup); `@launchdarkly/js-client-sdk-common` 1.17.0; `@launchdarkly/react-native-client-sdk` 10.12.4; `@launchdarkly/browser-telemetry` 1.0.16; `@launchdarkly/jest` 0.2.0 (notes RN waitForInitialization) > - Bump deps to `@launchdarkly/js-client-sdk-common@1.17.0` in browser/RN SDKs and devDep `@launchdarkly/js-client-sdk@0.12.0` in telemetry; update `@launchdarkly/react-native-client-sdk` dep in `@launchdarkly/jest` > - Update version metadata in code (`BrowserInfo.ts`, `PlatformInfo.ts`) and `.release-please-manifest.json` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2d4e276. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Requirements
Related issues
sdk-1680
Describe the solution you've provided
waitForInitializationfunction to client common, which exposes this capability for react native sdkreadyevent to be compatible with previous versionsAdditional context
waitForInitializationis not, and is still not, part of the documented initialization flow. While this capability works, it will ONLY work if users are using theidentifyResultsfunctionidentifyand identifyResults` function in the common code (eg make both resolve to a result).Note
Centralizes initialization waiting in shared client and exposes it to platforms
waitForInitializationinLDClientImplwith timeout handling (promiseWithTimeout), init state tracking (initializedPromise,initializeResult), and emitsready/initializedevents; adds shared types inapi/LDWaitForInitializationand exportsstart()now uses commonpromiseWithTimeoutand shared init state; imports updatedLDEmitterwithreadyevent; updatesLDClientAPI to includewaitForInitializationwaitForInitializationcomplete/timeout/failure pathswaitForInitializationWritten by Cursor Bugbot for commit 25f2444. This will update automatically on new commits. Configure here.