Vercel preset: ISR URL restoration has no fallback — a failed restoration renders a cacheable 404 for the internal `-isr` path
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 64/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
Direzione di ricerca
Inizia da presets/vercel/runtime/isr.ts e segui come la funzione Vercel ripristina l’URL originale dall’header della richiesta e dalla stringa di query. Esegui la riproduzione con bun install, NITRO_PRESET=vercel bun run build e node scripts/local-repro.mjs; il lavoro è completato quando il ripristino tramite fallback funziona e le invocazioni interne non recuperabili restituiscono 503 invece di un 404 memorizzabile nella cache.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- nitropack
2.13.4(lockfile-resolved, latest release) — the gap also exists in v3main(presets/vercel/runtime/isr.ts, introduced via #3851) - Nuxt
4.4.8/@nuxt/[email protected] - Node
v25.9.0(repro script needs ≥ 20.11 forimport.meta.dirname), Bun1.3.14for install/build - Preset:
vercel(Build Output API v3)
Relevant config — any single isr route rule is enough:
routeRules: {
'/schedule': { isr: 300 },
}
Reproduction
https://github.com/MichaelDickBasecom/nuxt-vercel-isr-404-repro
bun install
NITRO_PRESET=vercel bun run build
node scripts/local-repro.mjs # exits non-zero if any case diverges
The StackBlitz/CodeSandbox starters can't exercise this bug: it lives in the built Vercel function's runtime URL restoration, and reproducing it means invoking .vercel/output/functions/__fallback.func with the exact request shapes Vercel's router/prerender cache produces. scripts/local-repro.mjs does precisely that — it serves the built function locally and sends it each invocation shape, so the failure is deterministic with no deployment needed. The repo's CI runs this script on every push against the frozen lockfile: https://github.com/MichaelDickBasecom/nuxt-vercel-isr-404-repro/actions/workflows/local-repro.yml
A live deployment with all route-rule shape variants (static / dynamic param / catch-all / nested / passQuery) plus self-monitoring is linked from the README: https://nuxt-vercel-isr-404-repro.vercel.app
Describe the bug
On Vercel, Nitro implements isr route rules by rewriting the request to an internal prerender function (/schedule → /schedule-isr?__isr_route=/schedule) and reconstructing the original URL inside the function. Reconstruction is mandatory: Vercel invokes the function with req.url set to the rewritten dest path, and with a default isr: <seconds> rule the query string is stripped, so the URL-encoded groups in the undocumented x-now-route-matches header are the only carrier of the original URL.
The restoration in 2.13.4 (presets/vercel/runtime/vercel.mjs, decompiled for clarity) trusts that single carrier and gives up silently:
const isrRoute = req.headers["x-now-route-matches"];
if (isrRoute) {
const { __isr_route: url } = parseQuery(isrRoute);
if (url && typeof url === "string") {
if (getRouteRulesForPath(url).isr) req.url = url;
}
// gap 1: header present but no `__isr_route` → the query string is never
// consulted, even when it carries the correct value
} else {
// (query-string branch — only reached when the header is absent entirely)
}
// gap 2: bare invocation (no header, no query) → no recovery at all
When restoration fails, the app renders its 404 page for the internal path (Page not found: /schedule-isr). On Vercel, 404 is a valid, storable ISR outcome (ISR docs, "On failure") — so the 404 is cached and served with x-vercel-cache: HIT until expiration (forever under isr: true). Verified live: revalidation of a poisoned entry re-invokes the function bare, re-caching the 404 indefinitely — a poisoned route does not heal until redeploy.
Behavior of the built function per invocation shape (this is what scripts/local-repro.mjs asserts):
| Invocation shape | Result |
|---|---|
header carries __isr_route (normal) |
200, correct page |
no header, __isr_route in query (passQuery shape) |
200, correct page |
header present without __isr_route — correct query param also present |
404 "Page not found: /schedule-isr" |
| bare invocation (no header, no query) | 404 "Page not found: /schedule-isr" |
Why this matters despite being hard to trigger today
This is the third time the same single-carrier weakness has shipped:
| nitropack | What happened | Status |
|---|---|---|
| 2.12.6 | -isr rename exposed a missing capture group for non-wildcard rules → internal path leaked |
fixed in 2.12.7 (#3595) |
| 2.12.6–2.12.9 | with passQuery/allowQuery, Vercel stops sending x-now-route-matches — these runtimes had no other carrier → every direct hit fails |
fixed in 2.13.0 (#3539) |
2.13.4 & v3 main |
single-carrier dependency, no fallback chain (gaps above) | open — this issue |
The header contract is undocumented and has demonstrably changed before (that change created the 2.12.x variant, and Vercel still omits the header entirely under passQuery today — verified live). Current versions survive only because the named group happens to be present in every carrier Vercel currently sends; a serialization variant emitting only positional groups (e.g. 1=schedule) is exactly the poisonous third row above.
Proposed fix, in priority order
- Fail safe (highest value): respond
503when the original URL cannot be recovered, instead of rendering the app's 404 for the internal path. Measured on a live deployment: 404/410 are stored by the ISR cache; 401/5xx are never stored and any existing good copy keeps serving (x-vercel-cache: STALE). A 503 turns an unrecognized future carrier shape into a transient miss instead of permanent cache poisoning — the only measure that defends against invocation shapes nobody has enumerated yet. - Consult the query string when the header lacks
__isr_route. Strictly additive — the rewrite writes the identical value into the dest query — and fixes the exact failing case in the repro without touching working paths. - (weakest) Strip the
-isrsuffix as a last resort — only works for static routes; a dynamic dest (/users/[id]-isr) strips to a route pattern, not a URL.
Prior art for a hardened design: Astro faced the same class of failure and hardened its ISR rewrite with a per-build token + internal-param stripping (withastro/astro#17370).
I'm happy to submit a PR for (1) + (2) against v3 main (and a 2.x backport if wanted) — scripts/local-repro.mjs in the repro repo is effectively the test for it.
Additional context
- Field reports with this symptom keep recurring and get misdiagnosed because
-isris just the internal function/cache-key name leaking into logs and error bodies. The repro repo's README separates three independent causes behind the identical user-visible symptom (404+x-vercel-cache: HITnaming-isr); this issue is the only one of the three that is a Nitro bug. Earlier reports in the lineage: #1287, #1880, nuxt#33316 → #3595, #3594/#3651 → #3539. - Adjacent open items (narrower than this issue, not duplicates): #4408 / PR #4409 (header branch drops the query string — the PR does not add a fallback chain), #4047 (
_payload.json-isrvariant; the bare-invocation payload case reproduces in the repro script as well). - How often the trigger fires today: the live deployment was monitored for ~2 days across ~318 revalidation boundaries, cold-cache races (8-way concurrent first hits), purge cycles, and Bun/Node runtimes — Vercel delivered a well-formed carrier every time. So on ≥ 2.13.0 this is a latent single point of failure on an undocumented contract, not a daily deterministic failure; on 2.12.6–2.12.9 (which lockfiles from ~Sept 2025–Jan 2026 still resolve) it fails deterministically with
passQuery/allowQuery— see branchdemo/p1-deterministicfor a browser-visible repro of that variant. - No external poisoning vector: outside requests to
/schedule-isr(even with a byte-identical?__isr_route=query) land on separate cache keys — the prerender cache is keyed on the original request path. Poisoning requires a malformed population/revalidation invocation, which is why the fail-safe (503) matters. - Only the Vercel preset is affected: it is the only preset that splits functions, rewrites paths, and reconstructs URLs at runtime (Netlify implements
isras SWR headers on one function; Cloudflare/AWS ignore the rule).
Logs
`node scripts/local-repro.mjs` against a fresh `NITRO_PRESET=vercel` build of nitropack 2.13.4 (2026-07-18):
as-expected status=200 control: /schedule via catch-all (trailing-slash workaround path)
as-expected status=200 header carries __isr_route (normal prerender invocation)
as-expected status=200 no header, query carries __isr_route (passQuery-style invocation)
as-expected status=404 BUG: header present WITHOUT __isr_route (query fallback shadowed)
→ server rendered "Page not found: /schedule-isr?__isr_route=/schedule"
as-expected status=404 BUG: no header, no query (bare prerender invocation)
→ server rendered "Page not found: /schedule-isr"
as-expected status=404 BUG: payload fn, bare invocation
→ server rendered "Page not found: /schedule/_payload.json-isr"
Mechanism confirmed: when the function cannot recover the original URL it renders
a 404 for the internal /…-isr path. On Vercel, 404 is a *valid, cacheable* ISR
outcome → it is stored and replayed with x-vercel-cache: HIT until expiration.
- Lingua principale
- TypeScript
- Stelle
- 11.5k
- Fork
- 968
- Merge medio
- 4g 9h
- PR unite (30g)
- 64
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nitrojs/nitro
-
pending triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 2 giorni
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configForse già presa @draarivpatel-ui l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
I maintainer di solito rispondono entro 2 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
pending triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
nitrojs/nitro#5205 · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di nitrojs/nitro
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno