Skip to content

Avoid duplicate cached redirect headers#95913

Open
Austin1serb wants to merge 2 commits into
vercel:canaryfrom
Austin1serb:fix/duplicate-cached-redirect-headers
Open

Avoid duplicate cached redirect headers#95913
Austin1serb wants to merge 2 commits into
vercel:canaryfrom
Austin1serb:fix/duplicate-cached-redirect-headers

Conversation

@Austin1serb

Copy link
Copy Markdown

Summary*

Fix duplicate headers when a cached App Router redirect response is replayed.
Applies to routes using dynamic = 'force-static' with redirect() or permanentRedirect().

Root cause

Cached response headers were appended directly to the native Node response. This bypassed the duplicate-value protection already implemented by NodeNextResponse.appendHeader.
As a result, headers such as Location and x-nextjs-stale-time could appear twice.

Changes

  • Wrap the native response in NodeNextResponse.
  • Replay cached headers through its appendHeader method.
  • Identical values are no longer duplicated.
  • Distinct values for legitimate multi-value headers remain supported.

Regression test

  • Added a production App Router fixture with:

A catch-all route
dynamic = 'force-static'
permanentRedirect('/destination')
Inspected raw response headers.

  • Confirmed there is exactly one Location value and one x-nextjs-stale-time value.

Validation

  • Webpack production test passed.
  • Turbopack production test passed.
  • Next.js package build passed.
  • ESLint passed.
  • Prettier passed.

Fixes #82117

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.

Duplicate Location and x-nextjs-stale-time in Header using redirect/permanentRedirect alongside dynamic 'force-static'

1 participant