Skip to content

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Dec 12, 2025

Related issues

sdk-1653
sdk-1376
sdk-1663
sdk-1681

Describe the solution you've provided

  • 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.
  • Added a new presetFlags function in client sdk common that allow flagstore to take in contexless data before initialization
  • Bootstrapped data will first preset the flag store so they can be evaluated before a full context is made
  • Added logic to suppress event creation if context is not validated (while the client only has preset data)

Additional context

  • eventually I would like to consolidate the context tracker with the tracking logic we have for waitForInitialization and have a general state tracker for client sdk common.
  • I am also open to suggestions on distinguishing between "no context" state and "pre initialized" state. Though, it seems like, at the moment, those 2 states are handled in the same way.

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.

  • Core (sdk-client)
    • ActiveContextTracker: New internal utility to store pristine/validated context and manage identify promises; replaces direct _uncheckedContext/_checkedContext usage across LDClientImpl.
    • Evaluation/Event behavior: variation* now allows evaluation without a set context (logs warning) and suppresses event creation when context is absent; track requires a valid context.
    • Flag management:
      • Add FlagManager.presetFlags and LDClientImpl.presetFlags to initialize in-memory flags without context/persistence.
      • FlagUpdater tracks the active Context (not just canonical key); emits change callbacks with the active context.
    • Misc: ensureKey now uses namespaceForGeneratedContextKey.
  • Browser SDK
    • Bootstrap support: BrowserClientImpl.identifyResult reads bootstrap data once and calls presetFlags so flags can be evaluated before identify completes; sets initialization results for waitForInitialization.
  • Tests
    • Add test ensuring flags can be evaluated from bootstrap data prior to identify completion.
  • Tooling
    • Update lint:fix script to use npx eslint.

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

- 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.
@github-actions
Copy link
Contributor

@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

@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

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

@github-actions
Copy link
Contributor

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

@joker23 joker23 marked this pull request as ready for review December 12, 2025 22:59
@joker23 joker23 requested a review from a team as a code owner December 12, 2025 22:59

import { getOrGenerateKey } from '../storage/getOrGenerateKey';
import { namespaceForAnonymousGeneratedContextKey } from '../storage/namespaceUtils';
import { namespaceForGeneratedContextKey } from '../storage/namespaceUtils';
Copy link

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.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

2 participants