-
Notifications
You must be signed in to change notification settings - Fork 31
feat: implement waitForInitialization for browser sdk 4.x
#1028
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
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
|
@launchdarkly/js-client-sdk-common size report |
d324724 to
acf1ac7
Compare
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.
This commit will also fix this issue
| } else if (res.status === 'error') { | ||
| this._initializeResult = { status: 'failed', error: res.error }; | ||
| this._initResolve?.(this._initializeResult); | ||
| } |
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.
Bug: Stale initialization state persists across multiple identify calls
The _initializeResult state is set when an identify call completes but is never reset when a new identify starts. If a user calls identify successfully, then calls identify again for a different context, and then calls waitForInitialization, the method will immediately return the stale result from the first identify rather than waiting for the in-progress second identify to complete. The initialization state (_initializeResult, _initializedPromise, and _initResolve) needs to be reset at the start of each identifyResult call.
Additional Locations (1)
71a20ce to
262c6fe
Compare
Requirements
Related issues
waitForInitializeto browser 4.xDescribe the solution you've provided
Added
waitForInitializationfunction to browser 4.x implementation.Additional context
f({timeout: 5})instead off(5)rejectconditions... 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.initializedevent 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
Introduces waitForInitialization to the browser client with a configurable timeout and explicit success/failed/timeout results, and emits an initialized event on successful identify, with comprehensive tests.
waitForInitialization(options)toLDClientwith default 5s timeout, returningcomplete | failed | timeoutresults; supports multiple calls and immediate return if already resolved.cancelableTimedPromiseand internal_promiseWithTimeoutto race initialization vs timeout.identifyResultnow resolves the initialization promise ascompleteorfailedand starts goal tracking."initialized"event to emitter and emit it on successful identify.LDWaitForInitializationOptions/Resulttypes and expose method in public client; wire throughmakeClient.waitForInitializationfrom the compatLDClientinterface.waitForInitializationcovering success, timeout, and failure (before/after calling).Written by Cursor Bugbot for commit 262c6fe. This will update automatically on new commits. Configure here.