Vercel preset: ISR URL restoration has no fallback — a failed restoration renders a cacheable 404 for the internal `-isr` path
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 64/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
調査の方向性
presets/vercel/runtime/isr.ts から始め、Vercel 関数がリクエストヘッダーとクエリ文字列から元の URL を復元する仕組みを追跡します。bun install、NITRO_PRESET=vercel bun run build、node scripts/local-repro.mjs を使って再現を実行します。フォールバックによる復元が機能し、復元不能な内部呼び出しがキャッシュ可能な 404 ではなく 503 を返せば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 11.5k
- フォーク
- 968
- 平均マージ
- 4日 9時間
- マージ済み PR(30日)
- 64
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nitrojs/nitro のほかの issue
-
pending triage
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 2 日以内に返信
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler config対応中かも @draarivpatel-ui が 13 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 2 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
pending triage
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
nitrojs/nitro#5205 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
bug data-types
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
ClickHouse/clickhouse-js#1293 ·
メンテナーはふだん 1 日以内に返信
-
area: middleware enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
agent/quality testing
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
juspay/agent-distro#203 ·
メンテナーはふだん 1 日以内に返信