[expo-router] Web URL is briefly rewritten to a group's first screen while a nested navigator mounts
Minimal reproducible example
https://github.com/nerioramirez17/expo-router-group-url-blink-repro
Steps to reproduce
Platform: web (Metro dev server, npx expo start --web). Package manager: npm. Four files total — two layouts and two screens, no other app code.
git clone https://github.com/nerioramirez17/expo-router-group-url-blink-repro
cd expo-router-group-url-blink-repro
npm install
npx expo start --web- Open
http://localhost:8081/b. - Refresh the page.
- Watch the address bar.
Expected: the URL stays at /b.
Actual: the URL goes /b → /a → /b. /a is never navigated to and never renders — only the URL is written. It is a history.replace, so no history entry is added. The blink is cosmetic, but it is visible, and any code that reads location during that window sees the wrong path.
To measure it rather than eyeball it, patch the history API in a page init script before loading:
const _r = history.replaceState.bind(history);
history.replaceState = function (s, t, u) { console.log('replace ->', String(u)); return _r(s, t, u); };Measured in the repro (Playwright + chrome-headless-shell):
+ 100ms replace -> /b ← initial linking sync
+ 405ms replace -> /a ← bogus
+1214ms replace -> /b ← corrected once (group)'s Stack commitsThe same sequence in our production app, refreshing /sign-in, writes /change-password in the middle.
Two conditions, both ordinary app shapes
- The group has no
indexroute.app/(group)/contains onlya.tsxandb.tsx. - Two layout gates resolve in different ticks. The root layout renders nothing until app initialisation finishes — the
useFonts+SplashScreen.preventAutoHideAsync()shape thatcreate-expo-appships with — and the group layout returns early until it is ready, the shape from the authentication guide.
The stagger is load-bearing, not cosmetic. If both gates flip in the same effect flush React batches them, the two navigators commit together, and the bug does not occur. One tick of separation is enough: a microtask in the root gate and a setTimeout(…, 0) in the group gate still reproduces it, in a ~7 ms window. The repro uses 300 ms / 800 ms only so the blink is visible to the naked eye — in a real app the same stagger comes for free from asset loading finishing before a session query resolves.
Cause
While gate #1 has opened and gate #2 has not, the root navigator has committed and emitted a state event, but the group's own <Stack> has not mounted. Instrumenting onStateChange shows the store state at that moment:
__root > (group) > <no nested state>useLinking's onStateChange (packages/expo-router/src/fork/useLinking.ts) computes a path from the store state on every state event:
const route = findFocusedRoute(state);
const path = getPathForRoute(route, state);findFocusedRoute returns the bare group (group), with route.state === undefined. getPathFromState's expo-router fork then applies its "navigated to a group without a target screen" rule (packages/expo-router/src/fork/getPathFromState.ts, the START FORK block):
const targetScreen = route.params?.screen ?? 'index';
const screen = screens[targetScreen] ? targetScreen : Object.keys(screens)[0];There is no index in the group, so it falls back to Object.keys(screens)[0] — a — and that path is written to history. When the nested navigator commits, the real state is known and the URL is rewritten correctly.
The rule itself is correct for an explicit router.push('/(group)'). The defect is applying it to a transient, partially-mounted state during the history sync.
Relationship to #34668
#34668 added the index check quoted above, and its description already describes this mechanism:
This issue only surfaces on components that call getPathFromState to generate a URL. The location bar URL does not demonstrate this issue, but thats because during partial navigation a second navigation event occurs. When you navigate to a partial state, it will load the navigator which will "fix" the remaining state - and cause the location URL to correct itself. Hence this issue only occurs in places where the URL is "snapshotted", like the TabBar
That reasoning scoped the fix to snapshotted URLs and left useLinking untouched. This report is that self-correction, measured: the correction is real, but it is not instant — 809 ms in the repro, 56–300 ms in our production app — so the wrong URL is visible in the address bar for the duration.
Suggested fix
While the focused route is a group whose nested navigator has not mounted, the URL sync should be skipped. The next state event carries the real route and writes the correct URL.
const pendingPath = pendingPopStatePathRef.current;
const route = findFocusedRoute(state);
+// A focused route named `(group)` means its nested navigator has not mounted yet, so the
+// state is still partial. Resolving a path from it falls back to the group's first screen,
+// which then gets rewritten again once the child navigator mounts.
+if (route && /^\([^/]+\)$/.test(route.name)) {
+ return;
+}
const path = getPathForRoute(route, state);previousStateRefis intentionally left untouched, so the next real event still computes push/replace/pop correctly relative to the last synced state.- Web only — native resolves
useLinking.native.ts. - We have been running this as a
yarn patchin production since 2026-07-30: no bogus write on refresh of any deep URL, while push navigation, browser back/forward, and deep links with query params keep working.
The guard belongs in useLinking rather than getPathFromState, because the group-fallback rule in getPathFromState has a legitimate use for an explicit router.push('/(group)'). A previous community attempt (#35178) patched getPathFromState and ran into that.
Verified non-fixes
| Attempt | Result |
|---|---|
Upgrade 56.2.9 → 57.0.9 |
No change. build/fork/useLinking.js and build/fork/getPathFromState.js are byte-identical between the two, and main's src/fork/useLinking.ts has no guard. |
Add an index route to the group |
Bogus write still happens, target changes from /a to /. In a real app the group that owns / already lives elsewhere, and the new index silently shadows it — no duplicate-route warning is emitted. |
unstable_settings.initialRouteName / anchor |
The group-fallback branch never consults it. |
Reordering Stack.Screen children |
The path comes from the filesystem-derived linking config. |
| Renaming routes so the intended one sorts first | Only changes the target of the bogus write. |
Moving the loading gate above the root <Stack> |
Shrinks the window but the bogus write remains — the nested navigator still commits after the root one. |
EXPO_NO_METRO_LAZY=1 |
No change, so this is not lazy-bundling related. |
Prior reports
- #33774 — same trigger. Closed by the stale bot, not by a fix.
- #34345 — same symptom. Closed as ambiguous, with the note that it "can also occur when there's no
/indexroute (including groups)" and an invitation to open new issues. This is exactly that configuration: the group has noindex, and there are no overlappingindexroutes. - #35178 — community fix to
getPathFromState, closed unmerged. - #48346 — my earlier report of this same bug, auto-closed for a missing reproduction link. Its repro was also incomplete: it had only the group-level gate, and I have since confirmed that version does not reproduce. This report supersedes it.
Environment
expo-env-info 2.1.0 environment info:
System:
OS: macOS 26.5.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.19.4 - /Users/admin/.nvm/versions/node/v20.19.4/bin/node
Yarn: 4.13.0 - /Users/admin/.nvm/versions/node/v20.19.4/bin/yarn
npm: 11.14.1 - /Users/admin/.nvm/versions/node/v20.19.4/bin/npm
Watchman: 2025.05.26.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.16.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 25.5, iOS 26.5, macOS 26.5, tvOS 26.5, visionOS 26.5, watchOS 26.5
IDEs:
Android Studio: 2024.3 AI-243.26053.27.2432.13536105
Xcode: 26.5/17F42 - /usr/bin/xcodebuild
npmPackages:
expo: ~57.0.9 => 57.0.9
expo-router: ~57.0.9 => 57.0.9
react: 19.2.3 => 19.2.3
react-dom: 19.2.3 => 19.2.3
react-native: 0.86.2 => 0.86.2
react-native-web: ^0.21.2 => 0.21.2
Expo Workflow: managedExpo Doctor Diagnostics
Running 20 checks on your project...
20/20 checks passed. No issues detected!Source: expo/expo