Resolve variants in a proxy and read them during a render
A proxy is where a variant is resolved, because the decision has to be made before anything decides what to serve. This change adds the wrapper that runs it. For each request the wrapper finds the variants that the target route reads, invokes their `decide` functions, rejects a value that is not a string, and passes the values on. A project wires the wrapper into its own `proxy.ts` for now, and the bundler will inject it once the variants transform exists. No route declares yet which combinations to prerender against, so nothing is prerendered per combination. Every value is therefore resolved per request, and every read of one happens at request time. The values reach the origin in `x-next-internal-variants`. That prefix is reserved for the routing layer of a deployment, and `filterInternalHeaders` strips such a header when self-hosting, so a client cannot supply the values itself. The route module reads the header, and not the router server. The router server sees the header when self-hosting, but a deployed request reaches no Next.js code before the route module runs. Which variants apply follows from the route that renders, and a rewrite changes that route, so the wrapper resolves against the rewrite target and not the incoming path. A base path belongs to a request and not to a route, so it comes off the target before the route table is consulted. A resolved value reaches a render through the request store, and it resolves at the runtime stage. No cache key includes a variant, so nothing a render caches may hold a variant value. A route that the `config.matcher` of the proxy omits resolves nothing, and a read of a variant there fails.
Showing
Please
register
or
sign in
to comment