mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #987] [MERGED] fix(routing): omit empty optional catch-all params #1004
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#1004
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/987
Author: @NathanDrake2406
Created: 4/30/2026
Status: ✅ Merged
Merged: 4/30/2026
Merged by: @james-elicx
Base:
main← Head:nathan/fix-optional-catchall-params📝 Commits (1)
f5c01d3fix(routing): omit empty optional catch-all params📊 Changes
5 files changed (+69 additions, -19 deletions)
View changed files
📝
packages/vinext/src/routing/route-trie.ts(+11 -6)📝
packages/vinext/src/server/app-rsc-route-matching.ts(+11 -4)📝
tests/app-rsc-route-matching.test.ts(+24 -3)📝
tests/route-trie.test.ts(+20 -3)📝
tests/routing.test.ts(+3 -3)📄 Description
What this changes
Optional catch-all routes now omit the param key when the route matches with zero remaining segments. For example,
/shopmatching/shop/[[...path]]now produces{}instead of{ path: [] }, while/shop/a/bstill produces{ path: ["a", "b"] }.Why
Next.js treats the zero-segment optional catch-all case as a missing capture, not as an empty captured array. The relevant source path is:
route-regex.tsemits an optional repeated capture for optional catch-all params.route-matcher.tsonly writes a param when the regex capture is defined.get-dynamic-param.test.tscovers the downstream app-router interpretation of an absent optional catch-all param as anulltree segment.vinext's route trie instead materialized the zero-segment optional catch-all as
[], which made app/pages route params observably diverge from Next.js.Approach
The fix keeps app shape in codegen and behavior in normal modules:
Validation
vp test run tests/route-trie.test.ts tests/app-rsc-route-matching.test.ts tests/routing.test.tsvp test run tests/pages-router.test.ts tests/app-router.test.ts -t "optional catch-all"vp check packages/vinext/src/routing/route-trie.ts packages/vinext/src/server/app-rsc-route-matching.ts tests/route-trie.test.ts tests/app-rsc-route-matching.test.ts tests/routing.test.tsRisks / follow-ups
This is a compatibility change for the zero-segment optional catch-all params shape. Code that depended on vinext's previous
[]value for missing optional catch-all params will need to use the sameparams.slug ?? []pattern that works in Next.js.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.