Repository navigation
fix(react): keep the visitor's query in useRouter().url on static pages - #479
Merged
Merged
Conversation
With `output: 'static'`, the prerendered HTML and its page data hold the path without a query, and serve every query of that path. The React page router used the page data's URL whenever it differed from the browser URL, so `useRouter().url` dropped the query on load and after `Link` navigation, and kept a stale hash after a same-page hash link. When the page data has no query and belongs to the same page path, `router.url` now keeps the query of the visit. `/a`, `/a/`, `/a.html` and `/a/index.html` count as one page path, and paths are compared in encoded form. Hydration still renders with the prerendered URL, so the HTML matches. The commit then switches to the browser URL before effects run and re-renders in a transition, which keeps the server HTML of Suspense boundaries that have not hydrated yet. Fixes #449 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-react-static-query-void-cloud.voidzero-docs.workers.dev (commit 728fa09)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #449.
With
output: 'static', the prerendered HTML and_void/pages/<page>.jsonhold the page's path with no query, because one file serves every query of that path. In React,RouteResourceused the page data's URL whenever it differed from the browser URL, so:Vue, Svelte and Solid were not affected.
Change (React adapter only)
router.urlkeeps the visit's query. The hash comes from the browser after a same-page hash link, and from the visit during a reveal./a,/a/,/a.htmland/a/index.htmlcount as one page path, so the issue's localssg.html?foo=barrepro works too.router.urlkeeps the page path there, as before./café), so paths are compared in encoded form.Suspenseboundaries that have not hydrated yet.ssr = false) use the full URL from the first render. Server-rendered pages already have the query in their page data, so they take the existing exact-match branch.Tests
node-static.test.ts› "keeps the query string in router.url on a prerendered React page" uses newplayground/node-staticpages (router-url/[slug],router-url-client). It checks, with no page error and no hydration error:router.url/router-url/plain?foo=bar#bazafter hydration/router-url/plain?foo=bar#baz, and a mount-only effect sees?foo=bar<Link href="#details">/router-url/plain?foo=bar#details<Link href="…?foo=two">/router-url/plain?foo=two/router-url/a%20b?x=1#a, then the hash link/router-url/a%20b?x=1#a→…#details/router-url/plain.html?foo=bar#baz/router-url/plain?foo=bar#baz/router-url-client?foo=bar(ssr = false)?foo=barIt also checks that a lazy
Suspensechild keeps its server node through the switch.Mutation checks: each part fails the test when undone (the navigation branch, the initial
fetchUrl, the hydration start URL, the transition, encoding, the.htmlpath rule, thessr = falsecheck).Local runs used the installed Chrome, because the Playwright Chromium download is blocked here. These pass: all
packages/reacttests (536 with the deploy unit test), React and void typecheck, lint and format.Known limit
/a?x=1→/a) shows the old query for one render, until the navigation finishes. Fixing it would need the shared navigation engine to expose the redirect target, so it is left out.🤖 Generated with Claude Code