Skip to content

Conversation

@pi0
Copy link
Member

@pi0 pi0 commented Aug 19, 2025

Resolves #1880, #3594, #3651

Normally, with ISR matched routes, there is an (undocumented/legacy) x-now-route-matches header that contains the full pathname of the matched route. And Nitro vercel entry uses this header value to restore the original URL, but when passQuery isr route rule config is set, this header won't exist anymore, and the path is invalid (isr function name). We cannot always assume url query param is for ISR functions (it can be an actual query in normal routes!)

This PR changes the internal url query param to __isr_route and, if it exists, also attempts to rewrite without relying on legacy header but instead using a runtime protection check to make sure the requested route matches ISR route patterns.

We also make sure internal "__isr_route" is added to passQuery (if specified)


Beta testing:

package.json:

 "resolutions": {
    "nitropack": "https://pkg.pr.new/nitrojs/nitro/nitropack@3539"
  },

@vercel
Copy link

vercel bot commented Aug 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nitro.build Ready Ready Preview Comment Oct 14, 2025 10:58am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 13, 2025

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro/nitropack@3539

commit: 57d8f1f

@pi0 pi0 marked this pull request as ready for review October 14, 2025 10:46
@pi0 pi0 changed the title fix(vercel): workaround for isr route rule with passQuery: true fix(vercel): handle isr requests with passQuery: true Oct 14, 2025
@mkucmus
Copy link

mkucmus commented Nov 12, 2025

hey @pi0, do you plan to release the fix in upcoming version maybe?

@fmoessle
Copy link

Would love to see this merged. Using

  "resolutions": {
    "nitropack": "https://pkg.pr.new/nitrojs/nitro/nitropack@3539"
  }

works but is not ideal.

@fmoessle
Copy link

The problem I face with https://pkg.pr.new/nitrojs/nitro/nitropack@3539: Building and starting the application with node-presets causes an issue with the public folder resolution in .output

Reproduction: https://github.com/fmoessle/nitro-vercel-isr/tree/test-3539-fix

pnpm build
pnpm preview

results in errors like this:

request error] [unhandled] [GET] http://[::]:3000/favicon.ico
 H3Error: ENOENT: no such file or directory, open 'XXX/florian/projects/test/nitro-vercel-isr/.output/server/chunks/public/favicon.ico'
    at async open (node:internal/fs/promises:634:25)
    ... 2 lines matching cause stack trace ...
    at async Server.toNodeHandle (file:///XXX/.output/server/chunks/nitro/nitro.mjs:1917:7) {
  cause: Error: ENOENT: no such file or directory, open 'XXX/.output/server/chunks/public/favicon.ico'
      at async open (node:internal/fs/promises:634:25)
      at async Object.readFile (node:internal/fs/promises:1238:14)
      at async Object.handler (file:///XXX/.output/server/chunks/nitro/nitro.mjs:1646:19)
      at async Server.toNodeHandle (file:///XXX/.output/server/chunks/nitro/nitro.mjs:1917:7) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'open',
    path: 'XXX/.output/server/chunks/public/favicon.ico'
  },
  statusCode: 500,
  fatal: false,
  unhandled: true,
  statusMessage: undefined,
  data: undefined
}

There is no public folder in .output/server/chunks

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.

4 participants