Skip to content

fix: Pages prod config headers and redirects after middleware rewrites#448

Open
JaredStowell wants to merge 5 commits intocloudflare:mainfrom
JaredStowell:jstowell/fix-pages-prod-config-matchers-before-middleware-rewrite
Open

fix: Pages prod config headers and redirects after middleware rewrites#448
JaredStowell wants to merge 5 commits intocloudflare:mainfrom
JaredStowell:jstowell/fix-pages-prod-config-matchers-before-middleware-rewrite

Conversation

@JaredStowell
Copy link
Contributor

Fix Pages Router production ordering so next.config.js headers() and redirects() still match against the original request pathname even when middleware rewrites the downstream render target.

Previously, Pages prod wrote the middleware rewrite into resolvedUrl, derived resolvedPathname from that rewritten URL, and then fed that rewritten pathname into matchHeaders() and matchRedirect(). That caused config headers/redirects to run against the middleware target instead of the pre-middleware request path.

This change updates both Pages production paths to preserve the original normalized pathname for config header/redirect matching while continuing to use resolvedUrl/resolvedPathname for downstream rewrites, API routing, and page rendering.

Changes

  • Update Pages prod server to use pre-middleware pathname for:
    • matchHeaders()
    • matchRedirect()
  • Mirror the same fix in the Cloudflare worker/deploy template
  • Add Pages Router regression coverage for:
    • config headers() still applying after a middleware rewrite
    • config redirects() still winning before a middleware rewrite target
  • Update worker entry generator tests and snapshots

Testing

  • pnpm test tests/pages-router.test.ts tests/deploy.test.ts tests/entry-templates.test.ts
  • pnpm run fmt
  • pnpm run typecheck

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@448

commit: a3a51f9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant