Skip to content

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Dec 3, 2025

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

  • feat: adding waitForInitialize to browser 4.x
  • test: adding unit tests for waitForInitilization

Describe the solution you've provided

Added waitForInitialization function to browser 4.x implementation.

Additional context

  • I kept the method signiture the same as 3.x but am open to updating it to align with what we have in the server sdks f({timeout: 5}) instead of f(5)
  • I "simplified" the way we are tracking for the initialization state to a boolean. It looks like our new identification would not be throwing which minimizes the reject conditions... I can add those back in case we get an error status returned? At that point we might want to just wait for the timeout to throw.
  • I put in a default 5 seconds timeout on the wait
  • I also added in an initialized event that a successful identify will emit, I figured that would be a way for developers to know if LDClient initialized even if the initialization goes past timeout.

Note

Adds waitForInitialization({ timeout }) to the browser SDK, resolves on identify success/failure or timeout, and emits an initialized event; includes comprehensive tests.

  • Browser SDK 4.x
    • New API: LDClient.waitForInitialization(options?: { timeout: number }) returning LDWaitForInitializationResult (complete | failed | timeout).
    • Initialization flow:
      • Tracks init state via internal promise and result cache in BrowserClientImpl.
      • Resolves to complete on successful identify, failed on identify error, or timeout via cancelableTimedPromise.
      • Exposes waitForInitialization on returned client from makeClient.
    • Types: Adds LDWaitForInitializationOptions, LDWaitForInitializationComplete|Failed|Timeout and union LDWaitForInitializationResult in packages/sdk/browser/src/LDClient.ts.
  • Events
    • Emits initialized on successful identify in shared LDClientImpl.
    • Expands emitter EventName to include initialized.
  • Compat
    • compat/LDClientCompat omits waitForInitialization from its interface to preserve 3.x surface.
  • Tests
    • Adds unit tests covering: blocking until ready, timeout behavior, immediate failure resolution, and failure-before-wait handling.

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

@joker23 joker23 requested a review from a team as a code owner December 3, 2025 22:18
@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

@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 Dec 3, 2025

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

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

@joker23 joker23 requested a review from kinyoklion December 5, 2025 17:20
@joker23 joker23 force-pushed the skz/sdk-1360/browser-4.x-waitforinit branch from d324724 to acf1ac7 Compare December 5, 2025 17:24
unit tests broke because we introduced retries on initial polls which timed out of initial wait tests (since those tests were using fake timers). This change would simply advance the fake timer so all retries would have been triggered.
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