Commit 9b4542a
authored
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 -->1 parent b85e07b commit 9b4542a
File tree
7 files changed
+250
-66
lines changed- packages
- sdk/browser
- __tests__
- src
7 files changed
+250
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
192 | 229 | | |
193 | 230 | | |
194 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| |||
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
225 | 246 | | |
226 | 247 | | |
227 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| |||
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
58 | | - | |
59 | | - | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| |||
200 | 205 | | |
201 | 206 | | |
202 | 207 | | |
203 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
207 | | - | |
| 214 | + | |
208 | 215 | | |
209 | 216 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
311 | | - | |
| 310 | + | |
312 | 311 | | |
313 | 312 | | |
314 | | - | |
| 313 | + | |
315 | 314 | | |
316 | 315 | | |
317 | | - | |
318 | | - | |
| 316 | + | |
| 317 | + | |
319 | 318 | | |
320 | 319 | | |
321 | 320 | | |
| |||
370 | 369 | | |
371 | 370 | | |
372 | 371 | | |
373 | | - | |
| 372 | + | |
374 | 373 | | |
375 | 374 | | |
376 | 375 | | |
| |||
382 | 381 | | |
383 | 382 | | |
384 | 383 | | |
385 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
386 | 390 | | |
387 | 391 | | |
388 | 392 | | |
389 | 393 | | |
390 | 394 | | |
391 | 395 | | |
392 | | - | |
| 396 | + | |
393 | 397 | | |
394 | 398 | | |
395 | 399 | | |
| |||
401 | 405 | | |
402 | 406 | | |
403 | 407 | | |
404 | | - | |
405 | | - | |
406 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
407 | 419 | | |
408 | 420 | | |
409 | | - | |
| 421 | + | |
410 | 422 | | |
411 | 423 | | |
412 | 424 | | |
413 | 425 | | |
414 | 426 | | |
415 | 427 | | |
416 | 428 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
421 | 436 | | |
422 | 437 | | |
423 | 438 | | |
| |||
426 | 441 | | |
427 | 442 | | |
428 | 443 | | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
439 | 456 | | |
440 | 457 | | |
441 | 458 | | |
442 | | - | |
| 459 | + | |
443 | 460 | | |
444 | 461 | | |
445 | 462 | | |
| |||
453 | 470 | | |
454 | 471 | | |
455 | 472 | | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
466 | 485 | | |
467 | 486 | | |
468 | 487 | | |
469 | 488 | | |
470 | 489 | | |
471 | 490 | | |
472 | | - | |
| 491 | + | |
473 | 492 | | |
474 | 493 | | |
475 | 494 | | |
476 | 495 | | |
477 | 496 | | |
478 | 497 | | |
479 | | - | |
480 | | - | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
481 | 503 | | |
482 | 504 | | |
483 | 505 | | |
| |||
487 | 509 | | |
488 | 510 | | |
489 | 511 | | |
490 | | - | |
491 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
492 | 517 | | |
493 | 518 | | |
494 | 519 | | |
| |||
0 commit comments