[PR #127] [CLOSED] fix(middleware-codegen): allow hyphens in path param names in generated matcher #334

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/127
Author: @SeolJaeHyeok
Created: 2/26/2026
Status: Closed

Base: mainHead: fix/middleware-codegen-hyphen-params


📝 Commits (1)

  • a3d9a9f fix(middleware-codegen): allow hyphens in path param names in generated matcher

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 packages/vinext/src/server/middleware-codegen.ts (+1 -1)

📄 Description

Summary

middleware-codegen.ts generates the matchMiddlewarePattern() function that
is inlined into the production RSC entry (worker/index.ts). The tokenRe
regex used [\w]+ for path parameter capture groups, which does not match
hyphens — so middleware matchers with hyphenated param names silently failed
in production.

- ${v} tokenRe = /\\/:([\\w]+)\\*|\\/:([\\w]+)\\+|:([\\w]+)|[.]|[^/:.]+|./g;
+ ${v} tokenRe = /\\/:([\\w-]+)\\*|\\/:([\\w-]+)\\+|:([\\w-]+)|[.]|[^/:.]+|./g;

Problem

A middleware config.matcher like "/:sign-in*" or "/auth/:reset-password"
would not be recognised as a param pattern and treated as a literal string,
causing the matcher to never fire in production.

This is a production-only gap. The dev path executes matchPattern() from
middleware.ts directly; the production RSC entry uses the generated string
from middleware-codegen.ts — and only the generated version had the bug.

Relation to PR #78

PR #78 fixes the same \w+ issue in middleware.ts (the dev path) and several
routing files, but middleware-codegen.ts was added to main after PR #78
was opened, so it was not included in that scope.

The file's own comment states:

The pattern matching logic must be identical to matchPattern() in
middleware.ts. Any changes here must be mirrored there and vice versa.

This PR applies that mirroring proactively, so dev and prod stay consistent
when PR #78 lands.


🔄 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/127 **Author:** [@SeolJaeHyeok](https://github.com/SeolJaeHyeok) **Created:** 2/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/middleware-codegen-hyphen-params` --- ### 📝 Commits (1) - [`a3d9a9f`](https://github.com/cloudflare/vinext/commit/a3d9a9fdef7f1d623ab8aedbd4f549c327cc6d1c) fix(middleware-codegen): allow hyphens in path param names in generated matcher ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/middleware-codegen.ts` (+1 -1) </details> ### 📄 Description ## Summary `middleware-codegen.ts` generates the `matchMiddlewarePattern()` function that is inlined into the production RSC entry (`worker/index.ts`). The `tokenRe` regex used `[\w]+` for path parameter capture groups, which does not match hyphens — so middleware matchers with hyphenated param names silently failed in production. ```diff - ${v} tokenRe = /\\/:([\\w]+)\\*|\\/:([\\w]+)\\+|:([\\w]+)|[.]|[^/:.]+|./g; + ${v} tokenRe = /\\/:([\\w-]+)\\*|\\/:([\\w-]+)\\+|:([\\w-]+)|[.]|[^/:.]+|./g; ``` ## Problem A middleware config.matcher like "/:sign-in*" or "/auth/:reset-password" would not be recognised as a param pattern and treated as a literal string, causing the matcher to never fire in production. This is a production-only gap. The dev path executes matchPattern() from middleware.ts directly; the production RSC entry uses the generated string from middleware-codegen.ts — and only the generated version had the bug. Relation to PR #78 PR #78 fixes the same \w+ issue in middleware.ts (the dev path) and several routing files, but middleware-codegen.ts was added to main after PR #78 was opened, so it was not included in that scope. The file's own comment states: The pattern matching logic must be identical to matchPattern() in middleware.ts. Any changes here must be mirrored there and vice versa. This PR applies that mirroring proactively, so dev and prod stay consistent when PR #78 lands. --- <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:15 +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#334
No description provided.