You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: allow clients to evaluate bootstrapped flags when not ready (#1036)
**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
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Enable flag evaluation from bootstrap data before identify completes
and refactor context handling via ActiveContextTracker with event
suppression when no valid context.
>
> - **Browser SDK**:
> - Read bootstrap data in `BrowserClient.identifyResult` and `preset`
flags for immediate evaluation; track first-identify via
`_identifyAttempted`.
> - Add test verifying flags evaluate from bootstrap before identify
completes in `packages/sdk/browser/__tests__/BrowserClient.test.ts`.
> - **Core SDK (shared)**:
> - Introduce `ActiveContextTracker`
(`src/context/createActiveContextTracker.ts`) and update `LDClientImpl`
to use it for getting/setting context and coordinating identify
promises.
> - Allow evaluations without an active context (log warning) and
suppress event creation when context is absent; add `presetFlags` to
`LDClientImpl`.
> - **Flag management**:
> - Add `presetFlags` to `FlagManager`/`DefaultFlagManager` to
initialize in-memory flags without persistence.
> - Update `FlagUpdater` to track active `Context` (not just key) and
adjust `init/initCached/upsert` and change callbacks accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b7b4bf8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
0 commit comments