-
Notifications
You must be signed in to change notification settings - Fork 31
feat: allow clients to evaluate bootstrapped flags when not ready #1036
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
- Introduced `ActiveContextTracker` to manage the current active context and its serialized state. - Updated `LDClientImpl` to utilize the new context tracker for identifying and evaluating flags. - Added logic in `BrowserClientImpl` to read flags from bootstrap data during the initial identification process. This change improves the SDK's ability to handle context and flag management, particularly during initialization.
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
|
|
||
| import { getOrGenerateKey } from '../storage/getOrGenerateKey'; | ||
| import { namespaceForAnonymousGeneratedContextKey } from '../storage/namespaceUtils'; | ||
| import { namespaceForGeneratedContextKey } from '../storage/namespaceUtils'; |
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: Anonymous context keys lost due to namespace change
The import was changed from namespaceForAnonymousGeneratedContextKey to namespaceForGeneratedContextKey, which changes the storage namespace from LaunchDarkly_AnonymousKeys_{kind} to LaunchDarkly_ContextKeys_{kind}. Existing anonymous contexts with auto-generated keys stored under the old namespace will not be found, causing the SDK to generate new keys. This breaks identity continuity for anonymous users, affecting targeting rules and analytics. The deprecation comment in namespaceUtils.ts notes this function should only be removed when data is migrated between namespaces, but no migration logic exists.
Related issues
sdk-1653
sdk-1376
sdk-1663
sdk-1681
Describe the solution you've provided
ActiveContextTrackerto manage the current active context and its serialized state.LDClientImplto utilize the new context tracker for identifying and evaluating flags.BrowserClientImplto read flags from bootstrap data during the initial identification process.presetFlagsfunction in client sdk common that allow flagstore to take in contexless data before initializationpresetthe flag store so they can be evaluated before a full context is madeAdditional context
Supersedes #1024
Note
Enables flag evaluations from bootstrap data before identify completes by presetting flags and introducing ActiveContextTracker, while suppressing events without a valid context.
_uncheckedContext/_checkedContextusage acrossLDClientImpl.variation*now allows evaluation without a set context (logs warning) and suppresses event creation when context is absent;trackrequires a valid context.FlagManager.presetFlagsandLDClientImpl.presetFlagsto initialize in-memory flags without context/persistence.FlagUpdatertracks the activeContext(not just canonical key); emits change callbacks with the active context.ensureKeynow usesnamespaceForGeneratedContextKey.BrowserClientImpl.identifyResultreads bootstrap data once and callspresetFlagsso flags can be evaluated before identify completes; sets initialization results forwaitForInitialization.lint:fixscript to usenpx eslint.Written by Cursor Bugbot for commit 158db3f. This will update automatically on new commits. Configure here.