Commit eff6a55
authored
refactor!: align browser v4 intialization flow to specs (#1040)
**Requirements**
- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [x] I have validated my changes against all supported platform
versions
**Related issues**
sdk-1667
**Describe the solution you've provided**
- Introduced `start` method in `BrowserClient` to handle client
initialization.
- Replaced direct calls to identify with `setInitialContext` and `start`
for better context management.
- Updated example app to reflect changes in client initialization and
context handling.
- Added tests to ensure proper functionality of new initialization flow.
**Additional context**
- The main motiviation behind this change is to present a more organized
front on when a client is starting.
- I'll be making a task to push this behavior down to the shared client
code as an optional start and start adding a deprecated message on the
old flow.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds an explicit client start() flow and new createClient API (with
required initial context), updates initialization/identify behavior, and
refreshes tests, examples, and compat layer accordingly.
>
> - **API/Initialization**:
> - Add `LDClient.start(options?)` returning
`LDWaitForInitializationResult`; cache promise; support `bootstrap` via
`start`/`identifyOptions`.
> - Replace `initialize(...)` with `createClient(clientSideId, context,
options)`; `makeClient` now requires an initial `LDContext`.
> - Disallow `identify` before `start` (returns `{ status: 'error' }`
and logs); initial `identify` is non-sheddable.
> - Normalize init statuses: `waitForInitialization` returns `{ status:
'complete' | 'failed' | 'timeout' }` (note: some tests updated from
`error`→`failed`).
> - Make `LDWaitForInitializationOptions.timeout` optional; add
`LDStartOptions`.
> - **BrowserClient**:
> - Track `_initialContext`, `_startPromise`, `_initializedPromise`;
preset flags from `bootstrap` before identify.
> - Update plugin registration/hook calls to run through new flow;
continue goal tracking logic, URL transformation for events.
> - **Compat (`/compat`)**:
> - `initialize(envKey, context, options)` now builds via
`makeClient(envKey, context, ...)`; immediately `start()` then perform
`identify` to mirror old behavior; re-export unchanged surface minus
`start`/`setInitialContext`.
> - **Examples/Contract Tests**:
> - Update example app and contract entity to use `createClient(...,
context)` and `client.start()` + `waitForInitialization()`.
> - **Tests**:
> - Revise unit tests to use `start()` and required initial context; add
cases for start idempotency, shedding order, bootstrap pre-eval, URL
filtering, waitForInitialization timing/failure.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
846ae61. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 17f5e7d commit eff6a55
File tree
11 files changed
+294
-75
lines changed- packages/sdk/browser
- __tests__
- compat
- contract-tests/entity/src
- example/src
- src
- compat
11 files changed
+294
-75
lines changedLines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 60 | + | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| |||
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
| 285 | + | |
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
| |||
0 commit comments