Files
Hendrik LiebauandGitHub e59eb73bbc Compute dev fallback params from the most-specific prerendered route (#95066)
When Cache Components is enabled, the development server threads a
`fallbackParams` request meta for dynamic app routes so the staged
render knows which params are not statically known and must be deferred
to a later stage. The previous computation walked the prerendered routes
from `getStaticPaths` and kept the one with the fewest fallback params,
without checking that the route actually matched the requested URL.
Consider `/mixed/[lang]/[id]` where `generateStaticParams` covers `lang:
'en'` but not `id`: the prerendered routes are the base
`/mixed/[lang]/[id]`, which defers `[lang, id]`, and the covered
`/mixed/en/[id]`, which defers only `[id]`. For the request
`/mixed/fr/123` the fewest-fallback route is `/mixed/en/[id]`, but `en`
does not match `fr`, so applying its `[id]` set left `lang` out of the
fallback set and `fr` was treated as a statically known value.

Because this meta decides which stage each param resolves in, and the
stage decides the environment a replayed `console.log` is attributed to,
treating `fr` as static resolved it in the prerender stage instead of
deferring it to the runtime stage. The computation now matches the
requested URL against each prerendered route with the canonical
`getRouteRegex` and, among the routes that match, picks the
most-specific one, the one with the fewest fallback params. For
`/mixed/fr/123` only the base route matches, so its `[lang, id]` set is
used and both params defer, while for `/mixed/en/123` the covered
`/mixed/en/[id]` still matches and wins, so `lang` resolves statically
and only `id` defers. This mirrors what a production build writes to the
prerender manifest, where the server matches the URL to the
most-specific prerendered route at request time. The change is
development-only, gated on the route module being in dev mode, and
production continues to read the manifest. A later change in this stack
reads the same `fallbackParams` meta for the Instant Navigation testing
API's on-demand shell render, so that path defers the identical per-URL
set a production prefetch would.
2026-06-23 23:55:51 +02:00

45 lines
1.1 KiB
TypeScript

import Link from 'next/link'
export default function Page() {
// NOTE: these links must be kept in sync with `path` variables used in the test
return (
<main>
<ul>
<li>
<Link href="/simple">/simple</Link>
</li>
<li>
<Link href="/private-cache">/private-cache</Link>
</li>
<li>
<Link href="/short-lived-cache">/short-lived-cache</Link>
</li>
<li>
<Link href="/short-stale-cache">/short-stale-cache</Link>
</li>
<li>
<Link href="/successive-caches">/successive-caches</Link>
</li>
<li>
<Link href="/apis/123">/apis/123</Link>
</li>
<li>
<Link href="/mixed/en/123">/mixed/en/123</Link>
</li>
<li>
<Link href="/mixed/fr/123">/mixed/fr/123</Link>
</li>
<li>
<Link href="/mixed/en/x">/mixed/en/x</Link>
</li>
<li>
<Link href="/sync-io/static">/sync-io/static</Link>
</li>
<li>
<Link href="/sync-io/runtime">/sync-io/runtime</Link>
</li>
</ul>
</main>
)
}