Skip to content

Next 16 (forced nodejs proxy runtime) broke relative URL redirects deployed on vercel (with matching deployment URLs) #87950

@mlstubblefield

Description

@mlstubblefield

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    MiddlewareRelated to Next.js Middleware.RedirectsRelated to redirecting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions