Skip to content

Commit df7fa9e

Browse files
authored
feat: support waitForNetworkResults in FDv2 data manager (#1280)
The FDv2 data manager now respects the waitForNetworkResults identify option. When false (the default for mobile), identify resolves as soon as cached data is delivered rather than waiting for network. **Requirements** - [ ] I have added test coverage for new or changed functionality - [ ] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [ ] I have validated my changes against all supported platform versions **Related issues** Provide links to any issues in this repository or elsewhere relating to this pull request. **Describe the solution you've provided** Provide a clear and concise description of what you expect to happen. **Describe alternatives you've considered** Provide a clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context about the pull request here. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes when the `identify` promise resolves (cached-first vs network-fresh), which can alter initialization timing and app control flow across platforms. > > **Overview** > `FDv2DataManagerBase` now respects `LDIdentifyOptions.waitForNetworkResults` by tracking a `minimumDataAvailability` threshold for `identify` completion. > > When configured to not wait for network results, `identify` can resolve as soon as any initial data (e.g. cache) is delivered via `dataCallback`, while the data source continues initializing and applying subsequent updates as they arrive. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a2244e6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9a2b25a commit df7fa9e

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

packages/shared/sdk-client/src/datasource/FDv2DataManagerBase.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ export function createFDv2DataManagerBase(
157157
let closed = false;
158158
let flushCallback: (() => void) | undefined;
159159

160+
/**
161+
* The minimum data availability required before the identify promise
162+
* resolves. Maps from the public `waitForNetworkResults` option:
163+
* - `'cached'` -- resolve as soon as any data (e.g. from cache) is delivered
164+
* - `'fresh'` -- wait for network data with a selector (REFRESHED state)
165+
*/
166+
let minimumDataAvailability: 'cached' | 'fresh' = 'fresh';
167+
160168
// Explicit connection mode override — bypasses transition table entirely.
161169
let connectionModeOverride: FDv2ConnectionMode | undefined;
162170

@@ -331,11 +339,22 @@ export function createFDv2DataManagerBase(
331339

332340
const descriptors = flagEvalPayloadToItemDescriptors(payload.updates ?? []);
333341
// Flag updates and change events happen synchronously inside applyChanges.
334-
// The returned promise is only for async cache persistence we intentionally
342+
// The returned promise is only for async cache persistence -- we intentionally
335343
// do not await it so the data source pipeline is not blocked by storage I/O.
336344
flagManager.applyChanges(context, descriptors, payload.type).catch((e) => {
337345
logger.warn(`${logTag} Failed to persist flag cache: ${e}`);
338346
});
347+
348+
// When the minimum data availability is 'cached', resolve the identify
349+
// promise as soon as any data (e.g. from cache) has been delivered. The
350+
// data source continues its initialization pipeline normally --
351+
// subsequent changesets update flags and fire change events.
352+
if (minimumDataAvailability === 'cached' && !initialized && pendingIdentifyResolve) {
353+
initialized = true;
354+
pendingIdentifyResolve();
355+
pendingIdentifyResolve = undefined;
356+
pendingIdentifyReject = undefined;
357+
}
339358
}
340359

341360
/**
@@ -472,6 +491,7 @@ export function createFDv2DataManagerBase(
472491
selector = undefined;
473492
initialized = false;
474493
bootstrapped = false;
494+
minimumDataAvailability = identifyOptions?.waitForNetworkResults ? 'fresh' : 'cached';
475495
identifiedContext = context;
476496
pendingIdentifyResolve = identifyResolve;
477497
pendingIdentifyReject = identifyReject;

0 commit comments

Comments
 (0)