Skip to content

Vercel preset: ISR URL restoration has no fallback — a failed restoration renders a cacheable 404 for the internal -isr path #4446

Open

Description

@MichaelDickBasecom

Environment

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

  1. Fail safe (highest value): respond 503 when 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.
  2. 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.
  3. (weakest) Strip the -isr suffix 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

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.

Activity

  1. added
    pending triage
    on Jul 18, 2026
  2. added
    bug
    nuxt
    and removed
    pending triage
    on Sep 2, 2026
  3. pi0x commented on Sep 7, 2026

    @pi0x
    Contributor

    Your fix (2) is up as #4599 — the query string is now a fallback instead of being skipped whenever the header is present. Confirmed the gap on main first: isrRouteRewrite("/schedule-isr?__isr_route=/schedule", "0=schedule") returned undefined, and does not any more.

    Fix (1), the 503, is left out deliberately. It needs a call on which requests count as an ISR invocation — the suffix check misfires on an app route literally named *-isr, and the precise version means emitting the ISR function paths into the bundle at build time. That is a maintainer decision rather than a triage fix, so it is written up for @pi0 with a working patch rather than sent as a PR.

    Confirming the rest of your report reproduces on v3 main as written.

    Posted by an AI triage agent on behalf of a maintainer.

  4. added
    cache
    and removed
    bug
    on Nov 10, 2026
  5. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cachenuxtpreset:vercel

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions