[PR #78] [MERGED] fix(routing): allow hyphens in dynamic segment param names #293

Closed
opened 2026-05-06 12:39:01 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/78
Author: @ask-bonk[bot]
Created: 2/25/2026
Status: Merged
Merged: 2/27/2026
Merged by: @FredKSchott

Base: mainHead: opencode/issue71-20260225213338


📝 Commits (2)

  • ddcd8e9 fix(routing): allow hyphens in dynamic segment param names
  • 3d567a0 fix(routing): allow hyphens in config matching and middleware-codegen param patterns

📊 Changes

14 files changed (+260 additions, -39 deletions)

View changed files

📝 packages/vinext/src/config/config-matchers.ts (+9 -6)
📝 packages/vinext/src/index.ts (+5 -3)
📝 packages/vinext/src/routing/app-router.ts (+12 -12)
📝 packages/vinext/src/routing/pages-router.ts (+9 -9)
📝 packages/vinext/src/server/app-dev-server.ts (+7 -7)
📝 packages/vinext/src/server/middleware-codegen.ts (+1 -1)
📝 packages/vinext/src/server/middleware.ts (+2 -1)
📝 tests/app-router.test.ts (+33 -0)
tests/fixtures/app-basic/app/auth/[auth-method]/page.tsx (+13 -0)
tests/fixtures/app-basic/app/sign-in/[[...sign-in]]/page.tsx (+15 -0)
tests/fixtures/pages-basic/pages/sign-up/[[...sign-up]]/index.tsx (+21 -0)
📝 tests/pages-router.test.ts (+22 -0)
📝 tests/route-sorting.test.ts (+12 -0)
📝 tests/routing.test.ts (+99 -0)

📄 Description

Summary

Fixes #71 — catch-all route params with hyphens (e.g. [[...sign-in]]) caused 404 because the regex used \w+ which doesn't match -. Next.js allows hyphens in param directory names, and this is the standard pattern scaffolded by Clerk ([[...sign-in]], [[...sign-up]]).

Changes

  • Changed all \w+ regex patterns to [\w-]+ across 4 source files (15 regex instances total):
    • app-router.tsfileToAppRoute(), discoverSlotSubRoutes(), computeInterceptTarget()
    • pages-router.tsfileToRoute(), patternToNextFormat()
    • app-dev-server.ts — middleware matcher regex, config pattern matching guard
    • middleware.tsmatchMiddlewarePath() pattern conversion
  • Added test fixtures: [[...sign-in]] and [auth-method] (App Router), [[...sign-up]] (Pages Router)
  • Added 16 new tests across 4 test files:
    • routing.test.ts — 10 unit tests for route discovery and URL matching with hyphenated params
    • route-sorting.test.ts — 3 tests for patternToNextFormat() with hyphenated params
    • app-router.test.ts — 3 integration tests (dev server renders hyphenated routes)
    • pages-router.test.ts — 2 integration tests (dev server renders hyphenated routes)

Dev/prod parity

The fix applies to both dev and production code paths. The matchPattern() functions in both routers use string slicing (not regex) to extract param names from the internal :param format, so they already handle hyphens correctly — no changes needed there.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/78 **Author:** [@ask-bonk[bot]](https://github.com/apps/ask-bonk) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 2/27/2026 **Merged by:** [@FredKSchott](https://github.com/FredKSchott) **Base:** `main` ← **Head:** `opencode/issue71-20260225213338` --- ### 📝 Commits (2) - [`ddcd8e9`](https://github.com/cloudflare/vinext/commit/ddcd8e9e64fb6f51c1647cf1789da69be24ebf47) fix(routing): allow hyphens in dynamic segment param names - [`3d567a0`](https://github.com/cloudflare/vinext/commit/3d567a0e9ad0c8c0efe0a87441863a7581641190) fix(routing): allow hyphens in config matching and middleware-codegen param patterns ### 📊 Changes **14 files changed** (+260 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/config/config-matchers.ts` (+9 -6) 📝 `packages/vinext/src/index.ts` (+5 -3) 📝 `packages/vinext/src/routing/app-router.ts` (+12 -12) 📝 `packages/vinext/src/routing/pages-router.ts` (+9 -9) 📝 `packages/vinext/src/server/app-dev-server.ts` (+7 -7) 📝 `packages/vinext/src/server/middleware-codegen.ts` (+1 -1) 📝 `packages/vinext/src/server/middleware.ts` (+2 -1) 📝 `tests/app-router.test.ts` (+33 -0) ➕ `tests/fixtures/app-basic/app/auth/[auth-method]/page.tsx` (+13 -0) ➕ `tests/fixtures/app-basic/app/sign-in/[[...sign-in]]/page.tsx` (+15 -0) ➕ `tests/fixtures/pages-basic/pages/sign-up/[[...sign-up]]/index.tsx` (+21 -0) 📝 `tests/pages-router.test.ts` (+22 -0) 📝 `tests/route-sorting.test.ts` (+12 -0) 📝 `tests/routing.test.ts` (+99 -0) </details> ### 📄 Description ## Summary Fixes #71 — catch-all route params with hyphens (e.g. `[[...sign-in]]`) caused 404 because the regex used `\w+` which doesn't match `-`. Next.js allows hyphens in param directory names, and this is the standard pattern scaffolded by Clerk (`[[...sign-in]]`, `[[...sign-up]]`). ## Changes - Changed all `\w+` regex patterns to `[\w-]+` across 4 source files (15 regex instances total): - `app-router.ts` — `fileToAppRoute()`, `discoverSlotSubRoutes()`, `computeInterceptTarget()` - `pages-router.ts` — `fileToRoute()`, `patternToNextFormat()` - `app-dev-server.ts` — middleware matcher regex, config pattern matching guard - `middleware.ts` — `matchMiddlewarePath()` pattern conversion - Added test fixtures: `[[...sign-in]]` and `[auth-method]` (App Router), `[[...sign-up]]` (Pages Router) - Added 16 new tests across 4 test files: - `routing.test.ts` — 10 unit tests for route discovery and URL matching with hyphenated params - `route-sorting.test.ts` — 3 tests for `patternToNextFormat()` with hyphenated params - `app-router.test.ts` — 3 integration tests (dev server renders hyphenated routes) - `pages-router.test.ts` — 2 integration tests (dev server renders hyphenated routes) ## Dev/prod parity The fix applies to both dev and production code paths. The `matchPattern()` functions in both routers use string slicing (not regex) to extract param names from the internal `:param` format, so they already handle hyphens correctly — no changes needed there. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:01 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#293
No description provided.