mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1049] [MERGED] fix(routing): decode matched params with decodeURIComponent #1049
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#1049
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?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/1049
Author: @NathanDrake2406
Created: 5/4/2026
Status: ✅ Merged
Merged: 5/4/2026
Merged by: @james-elicx
Base:
main← Head:fix/decode-dynamic-params📝 Commits (2)
5e88c1bfix(routing): decode matched params with decodeURIComponent3c18dddtest(app-rsc-route-matching): update param decode assertion to match new behavior📊 Changes
5 files changed (+125 additions, -4 deletions)
View changed files
📝
packages/vinext/src/routing/route-pattern.ts(+22 -1)📝
packages/vinext/src/routing/route-trie.ts(+32 -1)📝
tests/app-rsc-route-matching.test.ts(+4 -2)📝
tests/route-pattern.test.ts(+28 -0)📝
tests/route-trie.test.ts(+39 -0)📄 Description
Summary
decodeURIComponent, matching Next.js behavior%2F→/,%23→#,%3F→?in param values (pages, route handlers, metadata,useParams)Problem
Vinext's segment-safe normalization preserves encoded delimiters for correct route matching (so
/files/a%2Fbmatches/files/[name]instead of splitting on the encoded slash). However, the captured param values were returned undecoded: the trie would correctly match but returnname = "a%2Fb"instead ofname = "a/b".Next.js applies
decodeURIComponentat the route-matcher level:https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/router/utils/route-matcher.ts#L25-L27
This divergence affects every consumer of matched params: page components,
generateMetadata, route handlers, anduseParams.Fix
Add
decodeURIComponentwrappers at the two route matching entry points:trieMatchinpackages/vinext/src/routing/route-trie.ts— used by the App Router and Pages Router trie-based matchersmatchRoutePatterninpackages/vinext/src/routing/route-pattern.ts— used for slot-specific param extraction, route handlers, and metadata routesThe decode helpers handle both string and
string[](catch-all) param values and gracefully preserve malformed percent escapes (the normalization layer already validates encoding in the strict request path).Tests
%2F,%23,%3Fin dynamic segment%GG%252F%2F)Verification
vp test run tests/route-trie.test.ts— 64 tests passvp test run tests/route-pattern.test.ts— 9 tests passvp test run tests/routing.test.ts tests/route-sorting.test.ts— 143 tests passvp test run tests/app-router.test.ts— 300 tests passvp test run tests/pages-router.test.ts— 200 tests passvp lint— 0 warnings, 0 errorsReferences
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.