Prerender each declared static variant combination
A page that exports `unstable_generateStaticVariants` declares the static variant combinations it wants prerendered. Until now the build read those declarations, validated them, and then discarded them. This change prerenders the route once per combination, and serves a request the prerender of the combination it resolved. The build prerenders every route a page produces once per combination. For a dynamic page that is each row of `generateStaticParams` and each fallback shell. For a page with no dynamic segments it is the page itself. The build writes each artifact under a path that carries the hash of the combination, for example `/__variants/1u0zqp3/blog/my-post`. The hash sits in the path because that is how a platform addresses a cached artifact today. It serves such a path straight from its filesystem before any function runs, and rebuilds the same path to revalidate the artifact, with no proxy in the loop. A platform that could pick a variant-specific prerender from request headers alone would need no prefix, so this shape is the one the current constraints leave rather than the one to keep. A proxy resolves the variants of a request, finds the combination they match, and rewrites to the prefixed path. Routing removes the prefix again before it matches a route, and puts the hash in `nxtV`, because route matching runs on route patterns and no prefixed path matches one. The origin recovers the combination from that hash rather than from the resolved values, because a request does not always arrive with them. A platform rebuilds the request from the artifact when it fills or revalidates a prerender, and the path is all it has to work from. The render then divides the values into two tiers. The matched combination assigns the static tier, and the artifact is keyed on those values, so a render may put them in its output. Everything else the request resolved is the runtime tier, which no artifact key mentions, so a read of one waits until request time. A request whose combination no page declared is served the one prerender that omits every variant. Such a prerender exists where the route is partially prerendered, and it keeps that request from taking a cache entry of its own, however many values it happens to carry. Two manifests hold the combinations, because two layers look them up differently. A proxy has a pathname and nothing else, so `variants-manifest.json` is keyed by pathname for a static route and holds a route regex for a dynamic one. The origin knows which route it renders, so the prerender manifest keys the same groups by page. Variants need a `proxy.ts` file, which always runs on the Node.js runtime, so `experimental.variants` together with a `middleware.ts` is now a build error. Serving a combination from a deployment needs routing rules that a later change adds.
Showing
This diff is collapsed.
This diff is collapsed.
Please
register
or
sign in
to comment