Skip to content

Commit 31b94e6

Browse files
authored
Merge pull request #88244 from Expensify/claude-fixHybridAppSessionCallbackRace
Skip module-level reset on initial SESSION load in HybridApp
2 parents 053ec53 + 3705687 commit 31b94e6

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/libs/actions/HybridApp/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ Onyx.connectWithoutView({
5959
return;
6060
}
6161

62+
const isInitialSessionLoad = currentSessionAccountID === undefined;
6263
currentSessionAccountID = nextSessionAccountID;
64+
65+
if (isInitialSessionLoad) {
66+
return;
67+
}
68+
6369
currentTryNewDot = undefined;
6470
hasReceivedTryNewDotUpdate = false;
6571
isLoadingTryNewDot = nextSessionAccountID !== undefined || isLoadingApp !== false;

tests/unit/HybridAppActionsTest.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,31 @@ describe('HybridApp actions', () => {
197197
expect(closeNativeAppSpy).toHaveBeenCalledWith({shouldSetNVP: true});
198198
});
199199

200+
it('allows shouldSetNVP exits when NVP_TRY_NEW_DOT arrives before SESSION on initial app start', async () => {
201+
await Onyx.set(ONYXKEYS.IS_LOADING_APP, false);
202+
await waitForBatchedUpdatesWithAct();
203+
204+
// Simulate mobile ordering: NVP fires before SESSION
205+
await Onyx.set(ONYXKEYS.NVP_TRY_NEW_DOT, {
206+
classicRedirect: {
207+
dismissed: false,
208+
},
209+
});
210+
await waitForBatchedUpdatesWithAct();
211+
212+
// SESSION fires after NVP — this is the initial undefined → accountID transition
213+
await Onyx.set(ONYXKEYS.SESSION, {
214+
accountID: 1,
215+
authToken: 'auth-token',
216+
});
217+
await waitForBatchedUpdatesWithAct();
218+
219+
// closeReactNativeApp should still work because the initial session load
220+
// must not blank the already-populated currentTryNewDot
221+
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: false});
222+
expect(closeNativeAppSpy).toHaveBeenCalledWith({shouldSetNVP: true});
223+
});
224+
200225
it('preserves shouldSetNVP exits when the auth token rotates for the same session', async () => {
201226
await Onyx.multiSet({
202227
[ONYXKEYS.IS_LOADING_APP]: false,

0 commit comments

Comments
 (0)