-
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
base: main
Are you sure you want to change the base?
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
| if (res.status === 'completed') { | ||
| this._isInitialized = true; | ||
| this._initResolve?.({ status: 'complete' }); | ||
| } |
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: Initialization failure returns timeout instead of failed status
The identifyResult method only calls _initResolve when res.status === 'completed'. If identify fails with 'error', 'timeout', or 'shed' status, _initResolve is never called. This means waitForInitialization will always return { status: 'timeout' } for failed identifications, even though LDWaitForInitializationFailed type with status: 'failed' exists. Users cannot distinguish between an actual timeout and a genuine initialization failure.
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.
I think this is fine... if there is an error on one of the identifies then we will timeout here. Identification errors can be handled in the identify().catch() in case developers would want to try something else on error that could ultimately yield a successful identify within the waitForInitialization timeout.
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
Adds browser
waitForInitializationwith timeout handling and aninitializedevent, plus tests and supporting types.waitForInitialization(options)returningLDWaitForInitializationResult(complete | timeout | failed), implemented with a cancelable timeout and internal init state tracking.identifyResult; exposewaitForInitializationon the PIMPL client.src/LDClient.tsfor wait results/options."initialized"on successful identify (LDClientImpl), and add"initialized"toLDEmitterevent names.waitForInitializationfromcompat/LDClientCompatinterface.waitForInitializationblocks until ready and resolves withtimeoutwhen initialization exceeds the timeout.Written by Cursor Bugbot for commit ed10b6f. This will update automatically on new commits. Configure here.