mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1080] [MERGED] refactor(config): dedupe regex cache and destination param chain #1077
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#1077
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/1080
Author: @james-elicx
Created: 5/5/2026
Status: ✅ Merged
Merged: 5/5/2026
Merged by: @james-elicx
Base:
main← Head:refactor/dedupe-config-matchers-internals📝 Commits (1)
20c404erefactor(config): dedupe regex cache and destination param chain📊 Changes
1 file changed (+49 additions, -29 deletions)
View changed files
📝
packages/vinext/src/config/config-matchers.ts(+49 -29)📄 Description
Summary
Two related cleanups inside
packages/vinext/src/config/config-matchers.ts. Pure refactor — no behavior change. Follow-up to #1058.A.
getCachedRegexhelper (collapses 3 near-identical caches)The file had three separate
Map-based regex compilation caches, each repeating the sameif (cache.get(key) === undefined) { compile + safeRegExp; cache.set(...) }pattern:_compiledPatternCache(inmatchConfigPattern)_compiledHeaderSourceCache(inmatchHeaders)_compiledConditionCache(in_cachedConditionRegex)These are now consumed via a single generic helper:
The helper is generic over the cached value type (the pattern cache stores
{ re, paramNames } | nullwhile the others storeRegExp | null), and only handles caching —compile()is still responsible for invokingsafeRegExp(), so the ReDoS-rejection path is untouched.nullcontinues to mark "seen and rejected" so we never re-runisSafeRegexon a known-bad pattern.The per-cache documentation comments at the declaration sites (explaining why each cache exists) are preserved verbatim.
B.
substituteAndSanitizeDestinationwrapper (collapses 4 call sites)substituteDestinationParams(dest, params)followed immediately bysanitizeDestination(...)appeared in four places — locale-static redirect, locale-prefix redirect, linear redirect fallback, and rewrite. All four sites passed exactly the same arguments and used the result the same way (assign todest, then return / store on alocaleMatch). They are now wrapped in a single file-private helper.The "collapse protocol-relative URLs" comment is kept at the redirect-fallback and rewrite call sites.
Files changed
packages/vinext/src/config/config-matchers.ts(+49 / -29)Test plan
pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts— 508/508 pass; one unrelatedallowedDevOriginsafterAllteardown timeout in pages-router (pre-existing flake, no production code path touched by this PR)pnpm vp test run tests/next-config.test.ts tests/features.test.ts tests/pages-i18n.test.ts— 379/379 pass (covers redirects, rewrites, headers, has/missing conditions)pnpm fmt --writepnpm knip— clean🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.