Repository navigation
Conversation
Every scenario ran twice, once below a Suspense-wrapped layout. That variant existed to cover the Activity/Suspense retry bug (#95848), which React has since fixed, and the search fixture still exercises a Suspense boundary directly. Run each scenario once against the plain routes and delete the /suspense fixtures.
Contributor
Stats from current PR🔴 1 regression
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
Build Cache
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (33 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffapp-route-ex..ntime.dev.jsDiff too large to display app-route-ex..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route.runtime.dev.jsDiff too large to display app-route.ru..time.prod.jsDiff too large to display dev-validati..ntime.dev.jsfailed to diffdev-validati..ntime.dev.jsfailed to diffdev-validati..ntime.dev.jsfailed to diffdev-validati..ntime.dev.jsfailed to diffpages-api-tu..ntime.dev.jsDiff too large to display pages-api-tu..time.prod.jsDiff too large to display pages-api.runtime.dev.jsDiff too large to display pages-api.ru..time.prod.jsDiff too large to display pages-turbo...ntime.dev.jsDiff too large to display pages-turbo...time.prod.jsDiff too large to display pages.runtime.dev.jsDiff too large to display pages.runtime.prod.jsDiff too large to display server.runtime.prod.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display 📎 Tarball URLCommit: 690aaad |
Contributor
Tests PassedCommit: 690aaad |
gaearon
marked this pull request as ready for review
August 21, 2026 03:03
The helpers returned as soon as the new document committed, so a scenario could act on history while the parser was still partway through the HTML. Wait for `document.readyState` to leave "loading" first. The stalled scripts are async, so this does not wait on them. This pins the tested window to "inline scripts have run, external scripts have not", which is the window the rest of the suite is about. No framework changes.
The scenarios checked the URL bar and the rendered heading. Neither one comes from the router: the browser owns the URL bar, and the heading is whatever React last rendered. `usePathname()` and `useSearchParams()` read the router's own `canonicalUrl`, which can disagree with both. Render it from the layout and assert it too. In the scenario where a third-party write lands during the recovery, the router never learns about the written entry. That is recorded with a TODO. No framework changes.
The suite had no control case. Add a reload with no history change and check that the server HTML is hydrated in place rather than re-rendered or reloaded, and that traversing away and back afterwards works. No framework changes.
gaearon
force-pushed
the
gaearon-history-prep
branch
2 times, most recently
from
August 21, 2026 17:04
9690fc9 to
c9e1114
Compare
The router initializes from window.location. After a Back press before hydration that is the traversed-to URL, while the server rendered the page for the entry the document started on. usePathname() rendered during hydration does not match the HTML, React reports a hydration error and regenerates the tree on the client. Render the pathname during hydration from the layout. Every scenario now checks that the page reported no errors, except the two that press Back before hydration, which record the mismatch with a TODO.
gaearon
added a commit
that referenced
this pull request
Aug 21, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, which only works in Chromium. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Record the URL the document was created for in an inline script that React emits with the shell, before anything else runs. Use the Navigation API's activation entry where available, since that is right even if history moved before the script ran, and location.href otherwise. Initialize the router from that URL. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on", which works in every browser and is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. A Back press before the inline script runs is handled only where the Navigation API exists, as before. The script is 150 bytes.
gaearon
force-pushed
the
gaearon-history-prep
branch
from
August 21, 2026 20:48
c9e1114 to
690aaad
Compare
gaearon
added a commit
that referenced
this pull request
Aug 21, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, which only works in Chromium. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Record the URL the document was created for in an inline script that React emits with the shell, before anything else runs. Use the Navigation API's activation entry where available, since that is right even if history moved before the script ran, and location.href otherwise. Initialize the router from that URL. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on", which works in every browser and is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. A Back press before the inline script runs is handled only where the Navigation API exists, as before. The script is 170 bytes. It is wrapped in try/catch and placed after the chunk bootstrap, since without the Navigation API `self.navigation` can resolve to a frame with that name and throw.
gaearon
added a commit
that referenced
this pull request
Aug 21, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, which only works in Chromium. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Record the URL the document was created for in an inline script that React emits with the shell, before anything else runs. Use the Navigation API's activation entry where available, since that is right even if history moved before the script ran, and location.href otherwise. Initialize the router from that URL. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on", which works in every browser and is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. A Back press before the inline script runs is handled only where the Navigation API exists, as before. The script is 200 bytes. It only reads from a real Navigation instance, since `self.navigation` may be a frame or an app object by that name, and nothing in it or in reading the value may throw, since hydration is bootstrapped in the same script and must not depend on this.
gaearon
added a commit
that referenced
this pull request
Aug 21, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, which only works in Chromium. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Record the URL the document was created for in an inline script that React emits with the shell, before anything else runs. Use the Navigation API's activation entry where available, since that is right even if history moved before the script ran, and location.href otherwise. Initialize the router from that URL. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on", which works in every browser and is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. A Back press before the inline script runs is handled only where the Navigation API exists, as before. The script is 200 bytes. It only reads from a real Navigation instance, since `self.navigation` may be a frame or an app object by that name, and nothing in it or in reading the value may throw, since hydration is bootstrapped in the same script and must not depend on this.
gaearon
added a commit
that referenced
this pull request
Aug 22, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, which only works in Chromium. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Record the URL the document was created for in an inline script that React emits with the shell, before anything else runs. Use the Navigation API's activation entry where available, since that is right even if history moved before the script ran, and location.href otherwise. Initialize the router from that URL. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on", which works in every browser and is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. A Back press before the inline script runs is handled only where the Navigation API exists, as before. The script is 200 bytes. It only reads from a real Navigation instance, since `self.navigation` may be a frame or an app object by that name, and nothing in it or in reading the value may throw, since hydration is bootstrapped in the same script and must not depend on this.
dianatofficial
left a comment
There was a problem hiding this comment.
Solid PR. Tests cover the important paths.
gaearon
added a commit
that referenced
this pull request
Aug 22, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, and only for entries the router wrote. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Initialize the router from the URL the document was created for instead: the Navigation API's activation entry where available, and window.location otherwise. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on". This is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. `window.navigation` is only read when it is a real Navigation instance, since a frame or a global by that name can take its place, and reading it must not break hydration.
gaearon
added a commit
that referenced
this pull request
Aug 22, 2026
The router only starts listening to history in an effect after hydration. #96252 handles a Back press before that by comparing Navigation API entry keys at hydration time, which only works in Chromium. It also initializes the router from window.location, which after such a Back press is the wrong URL: usePathname() disagrees with the server HTML and React regenerates the tree on the client. Record the URL the document was created for in an inline script that React emits with the shell, before anything else runs. Use the Navigation API's activation entry where available, since that is right even if history moved before the script ran, and location.href otherwise. Initialize the router from that URL. Then "history moved before the router was listening" is just "the current URL differs from the one the router started on", which works in every browser and is checked at the first history write and again when the listener is installed, so a traversal during hydration is seen too. The first write is skipped in that case and the Router effect catches up: a router-written entry is restored like a popstate, any other entry is adopted at its URL, as the first write used to do. The TODOs from #97651 are resolved: hydration matches the server HTML after a Back press, and a third-party write that lands during hydration is picked up. A Back press before the inline script runs is handled only where the Navigation API exists, as before. The script is 214 bytes. It only reads from a real Navigation instance, since `self.navigation` may be a frame or an app object by that name, and nothing in it or in reading the value may throw, since hydration is bootstrapped in the same script and must not depend on this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test-only changes.
back-before-hydrationtests. I added it to cover what turned out to be the Activity/Suspense retry bug (Blank page when pressing Back between a reload and hydration with cacheComponents (regression in 16.3.0-canary.87) #95848), which React has since fixed.usePathname()/useSearchParams()from the fixture layout and assert the router's URL in every scenario. One of these is wrong so there's a TODO for the future.