nextjs - ✅(Solved) Fix Next 16 (forced nodejs proxy runtime) broke relative URL redirects deployed on vercel (with matching deployment URLs) [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87950Fetched 2026-04-08 02:05:42
View on GitHub
Comments
2
Participants
2
Timeline
16
Reactions
0
Timeline (top)
referenced ×4labeled ×3commented ×2cross-referenced ×2

Fix Action

Fixed

PR fix notes

PR #88253: Fix relative same host redirects in node middleware

Description (problem / solution / changelog)

This ensures we properly relativize URLs in node middleware when deployed and local. Tests weren't catching this previously as none were asserting the raw Location header value due to node-fetch auto-resolving the value.

Fixes: https://github.com/vercel/next.js/issues/87950 Closes: NEXT-4826

Changed files

  • packages/next/src/server/web/adapter.ts (modified, +4/-1)
  • test/e2e/middleware-redirects/app/middleware.js (modified, +1/-1)
  • test/e2e/middleware-redirects/test/index.test.ts (modified, +18/-1)
  • test/e2e/middleware-redirects/test/node-runtime.test.ts (added, +3/-0)

Code Example

const rel = getRelativeURL(value, initUrl)
resHeaders['location'] = rel

---

if (!process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE) {
    if (redirectURL.host === requestURL.host) {
        console.log('doing it')
        redirectURL.buildId = buildId || redirectURL.buildId;
        response.headers.set('Location', redirectURL.toString()); // rewrites the absolute URL
    }
}

---

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32094
  Available CPU cores: 16
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: 1.22.22
  pnpm: 9.11.0
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

NOTE: this is specific to deprecating the edge runtime for middleware and defaulting to nodejs breaking in v16 https://github.com/mlstubblefield/nextjs-proxy-redirect-absolute breaking in v15 https://github.com/mlstubblefield/nextjs-proxy-redirect-absolute/tree/v15-node-break-maybe

To Reproduce

  1. Browse to https://nextjs-proxy-redirect-absolute.vercel.app/redirect
  2. Note that the location header in the respones is absolute In past versions of next, this would have produced a relative URL

See the following code in resolve-routes.ts

const rel = getRelativeURL(value, initUrl)
resHeaders['location'] = rel

The following code in adapter.ts is also of note and only runs when isEdgeRendering is false (IE: nodejs runtime for middleware).

if (!process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE) {
    if (redirectURL.host === requestURL.host) {
        console.log('doing it')
        redirectURL.buildId = buildId || redirectURL.buildId;
        response.headers.set('Location', redirectURL.toString()); // rewrites the absolute URL
    }
}

Current vs. Expected behavior

When deployed on vercel The current behavior is producing an absolute URL In the past a relative URL (in this case to "/") would have been produced

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32094
  Available CPU cores: 16
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: 1.22.22
  pnpm: 9.11.0
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

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

Redirects, Middleware

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

Vercel (Deployed)

Additional context

This only happens on vercel (I can't reproduce it locally). Will try to pin down a canary.

I was able to narrow it down to v16.0.0-canary.18 having introduced the problem. The issue does not exist in v16.0.0-canary.17. As a bit of extra flavor, this is specifically b/c of the deprecation of the edge runtime. I was able to get this going on next 15 by using the nodejs runtime in middleare here https://github.com/mlstubblefield/nextjs-proxy-redirect-absolute/tree/v15-node-break-maybe

extent analysis

TL;DR

The issue can be fixed by conditionally handling the Location header in the adapter.ts file to produce a relative URL when deployed on Vercel.

Guidance

  • Review the adapter.ts file and modify the code to conditionally set the Location header to a relative URL when the isEdgeRendering flag is false (i.e., when using the Node.js runtime for middleware).
  • Verify that the getRelativeURL function in resolve-routes.ts is correctly generating a relative URL.
  • Test the changes on Vercel to ensure the Location header is being set to a relative URL.
  • Consider pinning the Next.js version to a specific canary version (e.g., v16.0.0-canary.17) that does not exhibit the issue, until a permanent fix is available.

Example

// adapter.ts
if (!process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE) {
  if (redirectURL.host === requestURL.host) {
    const rel = getRelativeURL(redirectURL, requestURL);
    response.headers.set('Location', rel);
  }
}

Notes

The issue is specific to Vercel deployments and is caused by the deprecation of the Edge runtime in Next.js v16. The provided code snippets and environment information suggest that the issue can be resolved by modifying the adapter.ts file to handle the Location header correctly.

Recommendation

Apply a workaround by modifying the adapter.ts file to conditionally set the Location header to a relative URL, as the issue is specific to Vercel deployments and the Edge runtime deprecation in Next.js v16.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - ✅(Solved) Fix Next 16 (forced nodejs proxy runtime) broke relative URL redirects deployed on vercel (with matching deployment URLs) [1 pull requests, 2 comments, 2 participants]