vercel / vercel/next.js

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

Open
#82,117 13 comments 18 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Headers linear: next
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/d-mon-/test-redirect

To Reproduce
  1. Build and run the server with npm run build && npm run start
  2. Go to http://localhost:3000/test with the network console opened
  3. You shall notice the Location header duplicated
Current vs. Expected behavior

Currently you will notice the Location and x-nextjs-stale-time fields to be duplicated in the header

screenshot Image

I'd expect to see only a single field for each of them. This is problematic as the user will be redirected to /redirect,/redirect instead of /redirect depending on how the Location value is processed in production

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 22.16.0
  npm: 11.4.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 15.4.4 // Latest available version is detected (15.4.4).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Headers

Which stage(s) are affected? (Select all that apply)

next start (local)

Additional context

The problem seems to happen since the 15.4.1 release (previous versions seem fine)

I identified these two blocks adding the headers:
the first call is doing a setHeader location (using NodeNextResponse)
https://github.com/vercel/next.js/blob/ad1e3f209b87b6cc4829b125a667e94f7193f62f/packages/next/src/server/app-render/action-handler.ts#L1061
the second call is doing an appendHeader of {location, x-nextjs-stale-time}, duplicating the value. This one seems to use the native function this time instead of NodeNextResponse which doesn't check for the existing values.
https://github.com/vercel/next.js/blob/ad1e3f209b87b6cc4829b125a667e94f7193f62f/packages/next/src/build/templates/app-page.ts#L1010-L1031

A potential candidate: https://github.com/vercel/next.js/pull/73431

NEXT-4749

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in the linked test repository with npm run build && npm run start, then inspect packages/next/src/server/app-render/action-handler.ts and packages/next/src/build/templates/app-page.ts, along with NodeNextResponse in packages/next/src/server/base-http/node.ts. The fix is complete when the /test response contains only one Location and one x-nextjs-stale-time header, with a single /redirect value.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.