-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Description
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
- Browse to https://nextjs-proxy-redirect-absolute.vercel.app/redirect
- 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/AWhich 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