Repository navigation
fix(pages): report the requested URL in page data after a rewrite - #799
Conversation
A rewrite serves another route without changing the browser URL, but the page data's `url` was built from the rewritten request, so `useRouter()` reported the destination. Build it from `c.originalUrl()` when the request was rewritten, for loads and action re-renders alike. Closes voidzero-dev#798 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This needs a bit of work as rewrites can remove ordinary query parameters. A form submitted from |
The action key belongs to the query the rewritten request carries. Strip it from the original URL's query only when the rewrite kept that query, so a destination with its own query no longer drops the visitor's first parameter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@cpojer Thanks, fixed in a32774f. The action key comes from the query of the rewritten request. Page data now strips it from the original query only when the rewrite kept that query (the two queries are equal). A destination with its own query leaves the original query unchanged, so a form on The rewrite test now covers this for both |
Closes #798
Problem
A rewrite (
c.rewrite(),routing.rewrites,routing.fallbacks,_redirects200) serves another route without changing the browser URL. But the page data'surlwas built from the rewritten request, so the client router took the destination as the current URL. After a rewrite,useRouter().url,.pathand.querydescribed the destination,router.refresh()loaded the destination, and active-link matching treated the visitor as being on it.Change
requestPathWithSearch()inpackages/void/src/pages/protocol.tsnow builds the URL fromc.originalUrl()when the request was rewritten:decodePagePath(), so it is decoded the same wayc.req.pathis (/caf%C3%A9→/café). Requests that were not rewritten get the same URL as before.createStaticNotFound) run without the routing context middleware, so the helper falls back to the served request whenc.originalUrlis absent.The client already keeps the requested URL in history after a mutation rewrite (3c53034). One assertion in
pages-client.test.tschecked that the server sent the destination URL; it now expects the visible URL.Tests
routing-runtime.test.tscases cover middleware and rule rewrites for GET page loads, an encoded path, and named-action re-renders. All five fail without the fix (/maintenance?tab=1instead of/app/account?tab=1).vp run check,vp lintandvp fmt --checkpass.vp test run: 792 test files passed, 1 skipped.No docs change: the rewrites reference already says the browser URL does not change.
🤖 Generated with Claude Code