mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #1099] App Router: client-side dynamic param parsing should canonicalize URL pathname parts to match server encoding #235
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#235
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @github-actions[bot] on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/1099
Tracking Next.js fix vercel/next.js#93491 (commit 47bcfa0).
Summary
When deriving segment cache keys for dynamic params on the client, Next.js's
parseDynamicParamFromURLPartwas applyingencodeURIComponentto pathname parts that come fromURL.pathname.split('/'). Those parts are already in the percent-encoded form the URL parser produces, so the call double-encoded — turning%2Finto%252Fand so on. The server-side equivalent (get-dynamic-param.ts) starts from a decoded param value and appliesencodeURIComponentonce, so the two encodings only matched for inputs without any percent sequences.The fix introduces a
canonicalizeURLParthelper that decodes first and re-encodes:The decode step also handles characters like
,,:, and+that the URL parser leaves untouched butencodeURIComponentpercent-encodes; simply droppingencodeURIComponentwould silently mismatch on those.Impact in Next.js
When client and server param encodings disagreed:
writeDynamicDataIntoNavigationTaskreturneddidReceiveUnknownParallelRoutefinishNavigationTaskfell through todispatchRetryDueToTreeMismatchinvalidateRouteCacheEntries, bumping the route cache version and invalidating every entrynext-router-segment-prefetchrequest — visible regression on encoded URLs (e.g./foo%2Fbar) during back navigation after a<Link>re-mountRelevance to vinext
vinext implements App Router client navigation and its own route param plumbing. Audit our equivalent of
parseDynamicParamFromURLPart(or wherever we derive params fromURL.pathname.split('/')parts on the client) and confirm:%xxsequences (especially%2F),,,:,+Test case to port
The PR adds
test/e2e/app-dir/segment-cache/encoded-slash-params/exercising prefetch → click → back against/fooand/foo%2Fbar. With the bug, the encoded variant fires a route-tree request on the back-nav<Link>reveal while the unencoded variant does not. Port an equivalent fixture + assertion once we audit the param parsing path.References
github.com/vercel/next.js@47bcfa0956packages/next/src/client/route-params.tstest/e2e/app-dir/segment-cache/encoded-slash-params/