Repository navigation
Description
Which project does this relate to?
Router
Describe the bug
We have been noticing hydration errors in a real world application, both in development and production. However, the issue is much easier to reproduce in development.
It's occurring when a client-side navigation is triggered by a parent route that has already hydrated, while a nested route is still hydrating.
The reproduction repo is very minimal, and renders 10,000 span elements in the page/$name route. To reproduce we navigate from /page/origin to /page/destination. The idea is to click the link (which is in __root) quickly after hydration, while the nested route is still hydrating, as in this screen recording:
2026-09-09.14-36-46.mp4
The hydrated flag comes from the useHydrated() hook. As you can see from the logs:
__root__ hydrated=true
page/origin hydrated=false
page/destination hydrated=false
page/destination hydrated=true
The nested route flipped from page/origin hydrated=false to page/destination hydrated=false, and hydrated with the destination content, causing the hydration mismatch.
The page/$name route also renders a <title>, which is causing duplicate <title> elements after the client-side navigation.
If this proves difficult to reproduce manually, I have included a playwright script in repro.mjs, which you can run through npm run repro (this relies on the dev server being up at port 7112). The script runs the same scenario as above, and should output:
{
"routeName": "destination",
"titles": [
"destination",
"origin"
],
"hydrationErrors": 1
}This might be related to #8233, but it does not appear the PR there (#8292) addresses this specific scenario.
Complete minimal reproducer
Steps to Reproduce the Bug
- Clone the repo and run
npm install npm run dev
Then either:
- Open
localhost:7112/page/originin your browser - Click the link to navigate to
page/destination. This requires timing the click quickly after "(hydrated)" appears next to the link - Notice the hydration error in the console
Or:
-
In another terminal, run the automated reproduction:
npx playwright install chromium npm run repro
-
Observe the result:
{ "routeName": "destination", "titles": [ "destination", "origin" ], "hydrationErrors": 1 }
Expected behavior
No hydration error should occur.
Screenshots or Videos
No response
Platform
- Router:
1.170.33 - Start:
1.168.50 - OS: Linux
- Browser: Chrome
- Browser Version:
153.0 - Bundler: Vite
- Bundler Version:
8.2.2
Additional context
No response
Activity
dasjideepak commentedon Oct 6, 2026
I can reproduce this on the latest versions (react-router 1.170.41, react-start 1.168.60): 3/3 runs of
npm run reprogivehydrationErrors: 1and two<title>s.I think the cause is in
useSelectorfrom@tanstack/react-store. It passesgetSnapshotas both the client and the server snapshot:React uses the server snapshot while a component is still hydrating. When the navigation updates the router stores before
page/$namehas hydrated, that component reads the new match (destination) and hydrates it against theoriginHTML.As a check, I patched
useSelectorlocally so the server snapshot returns the store's first value (the hydration-time state). With that, 5/5 runs givehydrationErrors: 0, the page still lands ondestination, and there's only one<title>.That patch is only a proof. A real fix probably needs
useSelectorto accept agetServerSnapshotoption (TanStack/store), with the router passing its hydration-time state. Happy to open the PRs if that direction sounds right, or a different one if you prefer.