Skip to content

Commit 0fdbc25

Browse files
fix(mobile): a connect onboarding request stays cancelable until navigation is ready
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f981a73 commit 0fdbc25

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎apps/mobile/src/features/cloud/connectOnboarding.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22

3-
const navigation = vi.hoisted(() => ({ navigate: vi.fn() }));
3+
const navigation = vi.hoisted(() => ({
4+
navigate: vi.fn(),
5+
ready: true,
6+
queue: [] as Array<() => void>,
7+
}));
48
const optOut = vi.hoisted(() => ({ optedOut: new Set<string>() }));
59

610
vi.mock("../../lib/rootNavigation", () => ({
711
rootNavigationRef: navigation,
8-
whenRootNavigationReady: (navigate: () => void) => navigate(),
12+
whenRootNavigationReady: (navigate: () => void) =>
13+
navigation.ready ? navigate() : navigation.queue.push(navigate),
914
}));
1015
vi.mock("./connectOnboardingOptOut", () => ({
1116
isConnectOnboardingOptedOut: (accountId: string) =>
@@ -18,6 +23,8 @@ afterEach(() => {
1823
clearConnectOnboardingRequest();
1924
optOut.optedOut.clear();
2025
navigation.navigate.mockReset();
26+
navigation.ready = true;
27+
navigation.queue.length = 0;
2128
vi.useRealTimers();
2229
});
2330

@@ -54,4 +61,14 @@ describe("requestConnectOnboarding", () => {
5461
await vi.runAllTimersAsync();
5562
expect(navigation.navigate).toHaveBeenCalledOnce();
5663
});
64+
65+
it("drops a request cleared while it waits for navigation to be ready", async () => {
66+
vi.useFakeTimers();
67+
navigation.ready = false;
68+
requestConnectOnboarding("account-1");
69+
await vi.runAllTimersAsync();
70+
clearConnectOnboardingRequest();
71+
for (const navigate of navigation.queue.splice(0)) navigate();
72+
expect(navigation.navigate).not.toHaveBeenCalled();
73+
});
5774
});

‎apps/mobile/src/features/cloud/connectOnboarding.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ export function requestConnectOnboarding(accountId: string): void {
2323
// A sign-out or a newer sign-in may have replaced this request while
2424
// the opt-out read was in flight.
2525
if (pending !== request) return;
26-
pending = null;
27-
if (!optedOut) {
28-
whenRootNavigationReady(() => rootNavigationRef.navigate("ConnectOnboarding"));
26+
if (optedOut) {
27+
pending = null;
28+
return;
2929
}
30+
// Stays pending until navigation is ready, so a sign-out meanwhile still cancels it.
31+
whenRootNavigationReady(() => {
32+
if (pending !== request) return;
33+
pending = null;
34+
rootNavigationRef.navigate("ConnectOnboarding");
35+
});
3036
})();
3137
}, PRESENT_ONBOARDING_DELAY_MS),
3238
};

0 commit comments

Comments
 (0)