Skip to content

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Jan 2, 2026

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

sdk-1680

Describe the solution you've provided

  • refactors the waitForInitialization function to client common, which exposes this capability for react native sdk
  • added unit tests to test the common capabilities
  • adds back ready event to be compatible with previous versions

Additional context

  • For React Native SDK, waitForInitialization is not, and is still not, part of the documented initialization flow. While this capability works, it will ONLY work if users are using the identifyResults function
  • There is a separate piece of work that will consolidate the identify and 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

  • Implements waitForInitialization in LDClientImpl with timeout handling (promiseWithTimeout), init state tracking (initializedPromise, initializeResult), and emits ready/initialized events; adds shared types in api/LDWaitForInitialization and exports
  • Refactors Browser client to rely on common initialization flow (removes local wait/timeout logic); start() now uses common promiseWithTimeout and shared init state; imports updated
  • Extends LDEmitter with ready event; updates LDClient API to include waitForInitialization
  • Adds unit tests validating waitForInitialization complete/timeout/failure paths
  • Updates RN Jest tooling to mock waitForInitialization

Written by Cursor Bugbot for commit 25f2444. This will update automatically on new commits. Configure here.

- refactors the `waitForInitialization` function to client common
- exposes `waitForInitialization` to react native SDK
@joker23 joker23 requested a review from a team as a code owner January 2, 2026 21:43
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25394 bytes
Compressed size limit: 26000
Uncompressed size: 124693 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

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

@joker23 joker23 force-pushed the skz/sdk-1680/wait-for-init-common branch from c0519a4 to 1c46a53 Compare January 2, 2026 21:51
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 });
Copy link
Member

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;
Copy link

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.

Fix in Cursor Fix in Web

@joker23 joker23 force-pushed the skz/sdk-1680/wait-for-init-common branch from 39f5e85 to 25f2444 Compare January 6, 2026 23:33
this.initResolve(result);
this.initResolve = undefined;
}
}
Copy link

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)

Fix in Cursor Fix in Web

@joker23 joker23 merged commit 13ce456 into main Jan 6, 2026
37 checks passed
@joker23 joker23 deleted the skz/sdk-1680/wait-for-init-common branch January 6, 2026 23:51
@github-actions github-actions bot mentioned this pull request Jan 6, 2026
joker23 pushed a commit that referenced this pull request Jan 7, 2026
🤖 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>
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.

3 participants