[PR #536] feat: precompile next.config matchers at build time #655

Open
opened 2026-05-06 13:09:21 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/536
Author: @SeolJaeHyeok
Created: 3/14/2026
Status: 🔄 Open

Base: mainHead: feat/issue-389-precompile-config-patterns


📝 Commits (7)

  • 711e283 refactor: extract reusable config pattern compilers
  • 893bf15 feat: emit precompiled config matchers in generated entries
  • d74e266 feat: use precompiled config matchers in request handlers
  • 37125bd fix: address precompiled config code review feedback
  • d057788 docs: clarify compileConfigPattern null return semantics
  • 3fa8cdf Merge branch 'main' into feat/issue-389-precompile-config-patterns
  • 94be940 PR approved, two minor formatting nits.

📊 Changes

16 files changed (+703 additions, -119 deletions)

View changed files

examples/fumadocs-docs-template/.source/browser.ts (+12 -0)
examples/fumadocs-docs-template/.source/dynamic.ts (+8 -0)
examples/fumadocs-docs-template/.source/server.ts (+12 -0)
examples/fumadocs-docs-template/.source/source.config.mjs (+24 -0)
📝 packages/vinext/src/config/config-matchers.ts (+112 -67)
packages/vinext/src/config/precompiled-config.ts (+76 -0)
📝 packages/vinext/src/deploy.ts (+30 -6)
📝 packages/vinext/src/entries/app-rsc-entry.ts (+20 -5)
📝 packages/vinext/src/entries/pages-server-entry.ts (+11 -0)
📝 packages/vinext/src/index.ts (+33 -5)
📝 packages/vinext/src/server/prod-server.ts (+19 -5)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+113 -30)
📝 tests/app-router.test.ts (+6 -1)
📝 tests/entry-templates.test.ts (+31 -0)
tests/precompiled-config.test.ts (+165 -0)
📝 tests/shims.test.ts (+31 -0)

📄 Description

Closes #389

summary

  • extract reusable compileConfigPattern and compileHeaderSourcePattern helpers from config-matchers
  • emit precompiled redirect, rewrite, and header matchers in generated App Router and Pages Router entries
  • use the precompiled matcher state in dev, prod, and deploy request handling paths instead of compiling on the first matching request

what changed

  • added packages/vinext/src/config/precompiled-config.ts to build and serialize precompiled config matcher state
  • updated packages/vinext/src/config/config-matchers.ts to expose reusable compile helpers and optional compiled matcher inputs for redirects, rewrites,
    and headers
  • updated generateRscEntry() to emit __compiledRedirects, __compiledRewrites, and __compiledHeaders alongside the existing config payloads
  • updated generateServerEntry() to export vinextCompiledConfig for Pages Router production and deploy paths
  • updated index.ts, server/prod-server.ts, and deploy.ts to thread the precompiled matcher state through the existing config matching flow
  • added regression coverage for matcher compilation and generated entry output

why

PR #387 removed the steady-state bottleneck by caching compiled config patterns per isolate. That keeps warm isolates fast, but low-traffic routes can still
pay the compilation cost on the first request after a cold start.

This PR moves that work out of the request path by compiling config patterns ahead of time for generated entries, and once during dev startup for the live
config path. Matching behavior stays the same, but the first matching request no longer needs to tokenize patterns, run the safe-regex check, and construct
RegExp instances.

test plan

  • pnpm test tests/shims.test.ts tests/app-router.test.ts tests/entry-templates.test.ts
  • pnpm run typecheck
  • pnpm run lint
  • `pnpm run build

🔄 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/536 **Author:** [@SeolJaeHyeok](https://github.com/SeolJaeHyeok) **Created:** 3/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/issue-389-precompile-config-patterns` --- ### 📝 Commits (7) - [`711e283`](https://github.com/cloudflare/vinext/commit/711e283f9676d5c8f3448e8f2b83fd0a3edba8b2) refactor: extract reusable config pattern compilers - [`893bf15`](https://github.com/cloudflare/vinext/commit/893bf15239d9c760db8f35b4194277b427bcd79a) feat: emit precompiled config matchers in generated entries - [`d74e266`](https://github.com/cloudflare/vinext/commit/d74e26610d1aebe38b6f21890d13ec5f4469764c) feat: use precompiled config matchers in request handlers - [`37125bd`](https://github.com/cloudflare/vinext/commit/37125bd65e05bd6e504441d9465c73ce473085c0) fix: address precompiled config code review feedback - [`d057788`](https://github.com/cloudflare/vinext/commit/d0577880c11ac33b374ed134775fb0fa75b12486) docs: clarify compileConfigPattern null return semantics - [`3fa8cdf`](https://github.com/cloudflare/vinext/commit/3fa8cdfe929d758daaef349a35aa57bc2830a6a0) Merge branch 'main' into feat/issue-389-precompile-config-patterns - [`94be940`](https://github.com/cloudflare/vinext/commit/94be9402a71a510305654412a1fda0d8771740c6) PR approved, two minor formatting nits. ### 📊 Changes **16 files changed** (+703 additions, -119 deletions) <details> <summary>View changed files</summary> ➕ `examples/fumadocs-docs-template/.source/browser.ts` (+12 -0) ➕ `examples/fumadocs-docs-template/.source/dynamic.ts` (+8 -0) ➕ `examples/fumadocs-docs-template/.source/server.ts` (+12 -0) ➕ `examples/fumadocs-docs-template/.source/source.config.mjs` (+24 -0) 📝 `packages/vinext/src/config/config-matchers.ts` (+112 -67) ➕ `packages/vinext/src/config/precompiled-config.ts` (+76 -0) 📝 `packages/vinext/src/deploy.ts` (+30 -6) 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+20 -5) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+11 -0) 📝 `packages/vinext/src/index.ts` (+33 -5) 📝 `packages/vinext/src/server/prod-server.ts` (+19 -5) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+113 -30) 📝 `tests/app-router.test.ts` (+6 -1) 📝 `tests/entry-templates.test.ts` (+31 -0) ➕ `tests/precompiled-config.test.ts` (+165 -0) 📝 `tests/shims.test.ts` (+31 -0) </details> ### 📄 Description Closes #389 ## summary - extract reusable `compileConfigPattern` and `compileHeaderSourcePattern` helpers from `config-matchers` - emit precompiled redirect, rewrite, and header matchers in generated App Router and Pages Router entries - use the precompiled matcher state in dev, prod, and deploy request handling paths instead of compiling on the first matching request ## what changed - added `packages/vinext/src/config/precompiled-config.ts` to build and serialize precompiled config matcher state - updated `packages/vinext/src/config/config-matchers.ts` to expose reusable compile helpers and optional compiled matcher inputs for redirects, rewrites, and headers - updated `generateRscEntry()` to emit `__compiledRedirects`, `__compiledRewrites`, and `__compiledHeaders` alongside the existing config payloads - updated `generateServerEntry()` to export `vinextCompiledConfig` for Pages Router production and deploy paths - updated `index.ts`, `server/prod-server.ts`, and `deploy.ts` to thread the precompiled matcher state through the existing config matching flow - added regression coverage for matcher compilation and generated entry output ## why PR #387 removed the steady-state bottleneck by caching compiled config patterns per isolate. That keeps warm isolates fast, but low-traffic routes can still pay the compilation cost on the first request after a cold start. This PR moves that work out of the request path by compiling config patterns ahead of time for generated entries, and once during dev startup for the live config path. Matching behavior stays the same, but the first matching request no longer needs to tokenize patterns, run the safe-regex check, and construct `RegExp` instances. ## test plan - [x] `pnpm test tests/shims.test.ts tests/app-router.test.ts tests/entry-templates.test.ts` - [x] `pnpm run typecheck` - [x] `pnpm run lint` - [x] `pnpm run build --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#655
No description provided.