Repository navigation
[No QA] Skip no-op onboarding resetRoot to stop Safari history.replaceState burst - #99314
Conversation
Co-authored-by: huult <huult@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. Heads up: I couldn't run |
… OnboardingFlowTest Co-authored-by: huult <huult@users.noreply.github.com>
|
Fixed the two failing checks — both were in the new What was failing:
Details
Note: |
🤖 Android test results —
|
| Check | Result |
|---|---|
| Advances Join → onboarding screens | ❌ crashed on tapping Join |
| Reaches Home/Inbox after onboarding | ❌ app blank, never reached |
| No runtime errors during flow | ❌ native Fabric crash |
Important caveat on attribution
I can't confirm whether this PR caused the crash. It fired inside the code path this PR modifies (src/libs/actions/Welcome/OnboardingFlow.ts — startOnboardingFlow, on the actual non-skipped resetRoot), which is a real signal. But addViewAt: failed to insert view is a generic Fabric view-mounting error that can also be flaky/pre-existing, and I only have one sample with no baseline against main. I couldn't run a same-session retry (relaunching the app/session is CI-owned, not something the in-session tester can self-authorize), so determinism is unconfirmed.
Recommended next step: re-run the Android test on a fresh CI session (and ideally against main) to establish whether this crash is deterministic and PR-related or a flaky RN mounting glitch. Given the PR's fix is Safari-specific (Chromium/Fabric coalesces the replaceState burst, so the original bug doesn't reproduce on Android anyway), a main-vs-branch comparison is the cleanest way to tell if this is a new regression.
Screenshots
Crash overlay right after tapping Join:
Blank screen after dismissing the crash (Home never reached):
🤖 Web test results —
|
| Check | Result |
|---|---|
| Flow advances without getting stuck / looping | ✅ single navigation, no replay |
| Reaches Home / Inbox | ✅ fully rendered Home tab |
| No visible errors or crashes in the UI | ✅ clean (only benign banners/tooltips) |
What I could not verify:
- JS console errors — the web tester tooling (
agent-device --platform web) has no console/log access, so I could not capture or rule out thehistory.replaceState() more than 100 times/SecurityErrorwarnings that this PR targets. Flagged as unverified, not a pass. - The onboarding transition itself — this run had onboarding skipped, so the account went straight from Join → Home. The specific
startOnboardingFlow→resetRootcode path this PR guards wasn't exercised as a fresh multi-screen onboarding.
Context that matters: this bug is Safari-only by design — the PR explanation notes Chromium coalesces the replaceState calls, so it never trips the limit on a Chromium web build in the first place. So a green web run wouldn't prove the fix; the meaningful signal here is only that the router change causes no regression (app still reaches Home cleanly), which held.
Recommended next step: the fix's actual effect can only be confirmed on Mobile Safari (or via the added unit test tests/unit/OnboardingFlowTest.ts, which asserts resetRoot is skipped on the no-op). Also worth noting: a parallel Android run of this flow hit a native crash on the same code path — see the Android comment on this PR — so I'd prioritize confirming that before merge.
Screenshot
Home reached after completing account setup (no visible errors):
…ot state) Co-authored-by: huult <huult@users.noreply.github.com>
|
Fixed the remaining What was failing (ESLint):
Fix: typed the mock via VerificationRan locally against the changed file: |
|
All the code checks are green now — The only remaining red is |
|
@MelvinBot Check all items on the author checklist, I will verify them later. |
| // can't actually change - but resetRoot({stale: true}) still re-runs react-navigation's useLinking.onStateChange, | ||
| // which calls history.replaceState(). A rapid burst of those no-op calls trips Safari's 100-per-10s replaceState | ||
| // cap and throws SecurityError. Skip resetRoot when the merged route list is identical to the current one, | ||
| // mirroring the idempotency guard linkTo already applies on the navigate side. |
There was a problem hiding this comment.
@MelvinBot Could you shorten this comment or remove it if it’s unnecessary?
There was a problem hiding this comment.
Shortened from 6 lines to 3 in OnboardingFlow.ts:103 — kept the essential "why" (the Safari replaceState cap) since it's non-obvious, and dropped the mechanics that the code already shows.
| }; | ||
|
|
||
| // startOnboardingFlow only reads `routes` off the root state, but getRootState's return type requires a full | ||
| // NavigationState, so build a minimal-but-complete one to avoid an unsafe type assertion. |
There was a problem hiding this comment.
@MelvinBot Could you shorten this comment or remove it if it’s unnecessary?
There was a problem hiding this comment.
Trimmed to a single line in OnboardingFlowTest.ts:305 — keeps the reason buildRootState exists without the extra detail.
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| // The onboarding modal navigator is already mounted; getAdaptedStateFromPath resolves to it. |
There was a problem hiding this comment.
@MelvinBot Could you shorten this comment or remove it if it’s unnecessary?
There was a problem hiding this comment.
Shortened to // Onboarding navigator already mounted. in OnboardingFlowTest.ts:317 — the mock line below makes the rest self-evident.
|
|
||
| it('should not call resetRoot when the merged route list is unchanged (no-op that would still fire replaceState)', () => { | ||
| mockedGetCurrentRoute.mockReturnValue({key: 'route-key', name: SCREENS.ONBOARDING.PRIVATE_DOMAIN, params: {}}); | ||
| // Resolved target focuses a different route name, so the name-only guard passes through to the merge check. |
There was a problem hiding this comment.
@MelvinBot Could you shorten this comment or remove it if it’s unnecessary?
There was a problem hiding this comment.
Trimmed in OnboardingFlowTest.ts:323 — kept the intent (name-only guard passes through to the merge check) in fewer words.
| it('should call resetRoot when the merged route list adds the onboarding navigator', () => { | ||
| mockedGetCurrentRoute.mockReturnValue({key: 'route-key', name: SCREENS.HOME}); | ||
| mockedFindFocusedRoute.mockReturnValue({key: 'focused-key', name: SCREENS.ONBOARDING.PERSONAL_DETAILS}); | ||
| // Root state does not yet contain the onboarding navigator, so the merge appends it and the route list changes. |
There was a problem hiding this comment.
@MelvinBot Could you shorten this comment or remove it if it’s unnecessary?
There was a problem hiding this comment.
Trimmed in OnboardingFlowTest.ts:335 — kept the intent (navigator absent, so the merge appends it and the route list changes) in fewer words.
🤖 I didn't blanket-check the author checklist — here's whyThe PR Author Checklist is the human author's attestation (co-author: What I verified
Bottom line on the checklistI'm not checking these boxes:
Web looks good and matches the fix's intent. But before this checklist is fully checked, the Android crash needs to be resolved or shown to be a pre-existing flake (ideally a branch-vs- Web screenshot attached below. Home/Inbox reached after the Join step on web: |
|
The code check failures are already resolved — my earlier push (
The only checks still red are |
Co-authored-by: huult <huult@users.noreply.github.com>
|
@MelvinBot Check all items on the author checklist, I will verify them later. |
🤖 Author checklist — updated (with honest gaps flagged)I went through the PR Author Checklist and ticked every item I could stand behind. I deliberately left some unchecked because ticking them would misrepresent what's actually been verified — you'll want to complete those yourself before marking the PR ready. ✅ Checked (objectively true or not applicable to this change):
❌ Left unchecked (need your verification — this is the "verify later" list):
Web verification — onboarding advanced to Home after Join: |
|
@MelvinBot ready for review |
🤖 Web test results — ✅ no regression,
|
| Check | Result |
|---|---|
| Onboarding advances to Home without getting stuck/looping | ✅ pass |
| Home + Inbox reachable, app shell stable | ✅ pass |
| No visible crash/error banners | ✅ pass |
JS console free of SecurityError/history.replaceState |
Two caveats worth flagging
- The exact bug can't be reproduced/confirmed on web. This PR fixes a Safari-only symptom — Chromium coalesces the
history.replaceStateburst, soSecurityErrornever fires here regardless of the fix. The web tooling also has no console/devtools inspection verb, so I can't directly assert the console was clean — only that nothing crashed or reloaded (indirect evidence). - The onboarding router path was likely short-circuited. The web session landed directly on Home with no purpose/name onboarding questions, consistent with the CI web config skipping onboarding — so
startOnboardingFlow(the function this PR modifies) wasn't fully exercised in this run.
Net: web shows no regression in reaching Home, but this platform can't validate the actual fix. The definitive verification is Mobile Safari (per the PR's own suggested manual steps) with the JS console open, watching for the absence of the SecurityError: history.replaceState() more than 100 times warning during onboarding.
Note: my earlier Android run on this PR hit a native Fabric crash on tapping Join (prior comment) — worth a fresh Android session + main baseline to rule out a regression there before merge.
Screenshot
|
@MelvinBot Please mark this PR as ready for review (not draft). |
|
@mountiny I'll take a look at it 👀 |
|
I've reviewed this PR and it looks good, but I think the check itself could be simpler. All we really need to know here is whether the onboarding modal navigator is already mounted, because function startOnboardingFlow(startOnboardingFlowParams: GetOnboardingInitialPathParamsType) {
- const currentRoute = navigationRef.getCurrentRoute();
- const onboardingPath = startOnboardingFlowParams.resumePath ?? getOnboardingInitialPath(startOnboardingFlowParams);
- const adaptedState = getAdaptedStateFromPath(onboardingPath as Route, undefined, false);
- const focusedRoute = findFocusedRoute(adaptedState as PartialState<NavigationState<RootNavigatorParamList>>);
- if (focusedRoute?.name === currentRoute?.name) {
+ const rootState = navigationRef.getRootState();
+
+ // resetRoot is only needed to MOUNT the onboarding navigator. The merge below appends routes by
+ // top-level name, so once it is mounted the merged route list cannot change - but resetRoot({stale: true})
+ // would still re-emit the state and fire history.replaceState, and a burst of those trips Safari's
+ // 100-per-10s cap (APP-HT5). Unlike the old payload this no longer re-asserts adaptedState's index.
+ if (rootState.routes.some((route) => route.name === NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR)) {
return;
}
- const rootState = navigationRef.getRootState();
+
+ const onboardingPath = startOnboardingFlowParams.resumePath ?? getOnboardingInitialPath(startOnboardingFlowParams);
+ const adaptedState = getAdaptedStateFromPath(onboardingPath as Route, undefined, false);
const rootStateRouteNamesSet = new Set(rootState.routes.map((route) => route.name));
- const mergedRoutes = [...rootState.routes, ...(adaptedState?.routes.filter((route) => !rootStateRouteNamesSet.has(route.name)) ?? [])];
- // Skip resetRoot when the merged route list is unchanged: resetRoot({stale: true}) still re-runs
- // react-navigation's history.replaceState() even for this no-op, and a burst of those trips Safari's
- // 100-per-10s replaceState cap (SecurityError). Mirrors the idempotency guard linkTo applies on navigate.
- const areRoutesUnchanged = mergedRoutes.length === rootState.routes.length && mergedRoutes.every((route, index) => route.name === rootState.routes.at(index)?.name);
- if (areRoutesUnchanged) {
- return;
- }
+
+ // resetRoot instead of navigate/replace because only replacing the whole root state can mount the target
+ // screen on top of the earlier onboarding steps that getAdaptedStateFromPath rebuilds, keeping Back working.
navigationRef.resetRoot({
...rootState,
...adaptedState,
stale: true,
- routes: mergedRoutes,
+ routes: [...rootState.routes, ...(adaptedState?.routes.filter((route) => !rootStateRouteNamesSet.has(route.name)) ?? [])],
} as PartialState<NavigationState>);
} |
|
@MelvinBot Could you please check this comment and implement the suggested changes? |
…mounted Co-authored-by: huult <huult@users.noreply.github.com>
|
Implemented What changed (
Tests ( I kept your note about the follow-up in mind — this still only stops the |
|
@MelvinBot could you sync with main? |
…tRootIdempotencyGuard Co-authored-by: huult <huult@users.noreply.github.com>
|
✅ Synced with |
|
MelvinBot has made 6 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
|
@WojtekBoman Updated based on your suggestion and re-tested it. Everything is working well. Could you review it again? Thanks! |
| // resetRoot is only needed to MOUNT the onboarding navigator. The merge below appends routes by | ||
| // top-level name, so once it is mounted the merged route list cannot change - but resetRoot({stale: true}) | ||
| // would still re-emit the state and fire history.replaceState, and a burst of those trips Safari's | ||
| // 100-per-10s cap (APP-HT5). Unlike the old payload this no longer re-asserts adaptedState's index. |
There was a problem hiding this comment.
| const rootStateRouteNamesSet = new Set(rootState.routes.map((route) => route.name)); | ||
|
|
||
| // resetRoot instead of navigate/replace because only replacing the whole root state can mount the target | ||
| // screen on top of the earlier onboarding steps that getAdaptedStateFromPath rebuilds, keeping Back working. |
There was a problem hiding this comment.
Co-authored-by: huult <huult@users.noreply.github.com>
|
@mountiny all yours |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.65-0 🚀
|
|
No help site changes are required. I did not create a docs PR. This PR changes only internal navigation plumbing. It adds an idempotency guard so Nothing user-facing changed:
The two files touched are I also checked @huult, there is no linked help site PR to review, since no article needs updating. Please confirm you agree that this change is not user-facing. If you think a specific article does need an update, tell me which one and I'll open the draft PR. |
|
🚀 Deployed to production by https://github.com/francoisl in version: 9.4.65-3 🚀
Bundle Size Analysis (Sentry): |






Explanation of Change
On Mobile Safari, onboarding users hit
SecurityError: Attempt to use history.replaceState() more than 100 times per 10 seconds. The rate limit is only the symptom — the real bug is that the always-mounted onboarding router (useOnboardingFlow→startOnboardingFlow) fires a rapid burst of no-ophistory.replaceStatecalls that don't change the visible route.startOnboardingFlowre-asserts the route viaresetRoot({stale: true}), but its idempotency guard was too weak:focusedRoute?.name === currentRoute?.name). The navigate side already has a full path+params guard inlinkTo; theresetRootside did not.resetRootmerge only appends routes whose top-level name isn't already present. Once theONBOARDING_MODAL_NAVIGATORis mounted, the computed target collapses onto the existing stack, so the visible route can't actually change — yetstale: trueunconditionally re-runs react-navigation'suseLinking.onStateChange, which callshistory.replaceState.So whenever a transient dependency flip (amplified by the stale, async read of
ONBOARDING_LAST_VISITED_PATH) made the computed route name differ from the current one, the guard passed through andresetRootfired a wastedreplaceStatethat didn't move the user. A burst of those exceeds Safari's 100/10s cap (Chromium coalesces them, which is why it's Safari-only).Fix: add a route-agnostic idempotency guard on the
resetRootside ofstartOnboardingFlow. Before callingresetRoot, compute the merged route list and skip the reset when it's identical to the current root state (same length + same route names in order) — mirroring the idempotency checklinkToalready applies on the navigate side. Because inter-screen onboarding moves go throughnavigate/forceReplace(notresetRoot) once inside the modal navigator, skipping a no-opresetRootchanges no observable behavior beyond dropping the wastedreplaceState. This neutralizes every onboarding route at once, rather than patching a single path.Fixed Issues
$ #97473
PROPOSAL: #97473 (comment)
Tests
// TODO: The human co-author must fill out the manual test steps and confirm them before marking this PR "ready for review".
Automated coverage added in this PR:
tests/unit/OnboardingFlowTest.tsgains astartOnboardingFlowsuite assertingresetRootis skipped when the merged route list is unchanged (the no-op that fired the extrareplaceState) and still runs when the onboarding navigator is actually added. Note: I was unable to execute the test suite / typecheck / lint locally because this environment does not permit runningnpm/node; CI and the human co-author should runnpm test -- tests/unit/OnboardingFlowTest.ts,npm run typecheck, andnpm run lintto confirm.Suggested manual verification (Mobile Safari): sign up with a private email domain, proceed through onboarding, and confirm the flow advances normally with no
SecurityError/history.replaceStatewarnings in the JS console.Offline tests
QA Steps
[No QA]
PR Author Checklist
Debug snippet — reproduce the repeated
startOnboardingFlow/history.replaceStateburstBecause this issue can't be reproduced through the normal flow, temporarily add the following debug code to
src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsxto simulate the repeatedstartOnboardingFlowcalls. Remove it before merging.On Mobile Safari (without this fix) this triggers
SecurityError: Attempt to use history.replaceState() more than 100 times per 10 seconds. With this fix the no-opresetRootcalls are skipped, so the burst no longer fires.### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari