Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7da1b16
fix(app-router): enforce dynamicParams = false for route handlers
james-elicx Oct 20, 2026
a2c9ba7
fix(app-router): run route handler generateStaticParams in a scope of…
james-elicx Nov 9, 2026
7bea37b
fix(app-router): let fallback rewrites claim a route handler's dynami…
james-elicx Nov 9, 2026
8e8e250
test(app-router): cover a fallback rewrite claiming a route handler's…
james-elicx Nov 9, 2026
802a06e
fix(app-router): decide a route handler's draft mode at routing as it…
james-elicx Nov 9, 2026
c6a9409
docs: note that fallback rewrites check a dynamicParams route handler…
james-elicx Nov 9, 2026
b179e83
chore: trace the route handler dispatch module from generated entries…
james-elicx Nov 9, 2026
4d6016e
fix(app-router): run route handler generateStaticParams without reque…
james-elicx Nov 9, 2026
60a5ef0
fix(app-router): reject connection() and draftMode() in a route handl…
james-elicx Nov 9, 2026
cb9abbf
fix(app-router): run route handler generateStaticParams in its own wo…
james-elicx Nov 9, 2026
1f51249
chore: keep revalidateTag's doc comment on revalidateTag
james-elicx Nov 9, 2026
98bc59e
fix(app-router): keep route handler generateStaticParams' revalidatio…
james-elicx Nov 9, 2026
06abf36
docs: limit the routing dynamicParams note to routes the check applie…
james-elicx Nov 9, 2026
542ac48
fix(app-router): finish a route handler generateStaticParams' after()…
james-elicx Nov 9, 2026
8a450f7
fix(app-router): drop a failed route handler generateStaticParams' af…
james-elicx Nov 9, 2026
0b045bf
docs: limit the per-request dynamicParams note to routes the check ap…
james-elicx Nov 9, 2026
5e30408
fix(app-router): discard after() callbacks a failed route handler gen…
james-elicx Nov 9, 2026
c902e9b
fix(app-router): give a route handler generateStaticParams its own fe…
james-elicx Nov 9, 2026
c67c99c
fix(app-router): give a route handler generateStaticParams the route'…
james-elicx Nov 9, 2026
a6a18de
fix(app-router): keep cache-scope rules for a route handler generateS…
james-elicx Nov 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/differences.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ At request time, vinext decides whether a render is dynamic while it renders. (T

Next.js also treats an otherwise static route as SSG when a layout above its last dynamic segment returns every param from `generateStaticParams`. vinext doesn't run the generator to classify requests, so it renders such a route on every request unless it exports `dynamic = "force-static"` or `"error"`. Adding `generateStaticParams` to the last dynamic segment, even one that returns `[]`, makes the route static in both.

Under `dynamicParams = false`, Next.js checks a request against the params its build generated and runs no `generateStaticParams` per request. vinext runs the route's generators when the cache doesn't answer a request, including a request for params the route doesn't list. In an app with `fallback` rewrites, it runs a page's generators for every request to the page outside draft mode while routing, so a rewrite can claim a param the page doesn't list, as in Next.js. A child segment's generator runs only for the parent params that match the request, but a generator in a parallel route slot runs for every combination its parents generate. If a child's generator returns a different value for a parent param, vinext runs it for every parent combination once it sees that change. If the generator changes a parent param only for parent values that don't match the request, vinext can miss the change and answer 404 where Next.js renders the page. A cached image metadata response is served without this check, and so is a cached page in an app without `fallback` rewrites, so with a pinned `generateBuildId` and a cache that persists across deploys, an entry an earlier deploy stored can outlive the removal of its params. Keep generators cheap, for example by caching the data they fetch.
Under `dynamicParams = false`, Next.js checks a request against the params its build generated and runs no `generateStaticParams` per request. For a route the check applies to, vinext runs the route's generators when the cache doesn't answer a request, including a request for params the route doesn't list. In an app with `fallback` rewrites, it runs them while routing for every request to such a route, outside draft mode, so a rewrite can claim a param the route doesn't list, as in Next.js. A child segment's generator runs only for the parent params that match the request, but a generator in a parallel route slot runs for every combination its parents generate. If a child's generator returns a different value for a parent param, vinext runs it for every parent combination once it sees that change. If the generator changes a parent param only for parent values that don't match the request, vinext can miss the change and answer 404 where Next.js renders the page. A cached image metadata response is served without this check, and so is a cached page or route handler response in an app without `fallback` rewrites, so with a pinned `generateBuildId` and a cache that persists across deploys, an entry an earlier deploy stored can outlive the removal of its params. Keep generators cheap, for example by caching the data they fetch.

Like Next.js, a client navigation renders only below the layouts the client already holds, so a shared layout's server code doesn't run again. vinext does this only for renders it never stores: every render in development, and in production draft-mode requests and routes with `runtime = "edge"`, `dynamic = "force-dynamic"`, `revalidate = 0`, or a dynamic segment without `generateStaticParams`. A route that reads `cookies()` or `headers()` without route config renders every layout on each navigation in production, because vinext learns that it's dynamic only while rendering it, where Next.js knows from its build. In development the same route skips the held layouts. To skip them in production too, export `dynamic = "force-dynamic"` from the route's `layout.tsx`.

Expand Down
1 change: 1 addition & 0 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default {
"src/server/app-page-head.ts",
"src/server/app-page-ppr-runtime.ts",
"src/server/app-prerender-static-params.ts",
"src/server/app-route-handler-dispatch.ts",
"src/server/app-route-module-loader.ts",
"src/server/nitro-public-files.ts",
"src/server/nitro-public-files-plugin.ts",
Expand Down
15 changes: 15 additions & 0 deletions packages/vinext/src/entries/app-rsc-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,17 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
ensureRouteLoaded: __ensureRouteLoaded,
async isDynamicParamsMiss(route, params) {
if (!route.isDynamic) return false;
if (route.routeHandler) {
const { isAppRouteHandlerParamsMiss: __isAppRouteHandlerParamsMiss } =
await __loadAppRouteHandlerDispatch();
return __isAppRouteHandlerParamsMiss({
handler: route.routeHandler,
isProduction: process.env.NODE_ENV === "production",
params,
pattern: route.pattern,
routeSegments: route.routeSegments,
});
}
const __segmentConfig = __resolveRouteSegmentConfig(route, __resolveRouteSegmentConfigBranches(route));
if (__segmentConfig.dynamicParamsConfig !== false) return false;
return (await __validateAppPageRouteDynamicParams({
Expand Down Expand Up @@ -1732,9 +1743,11 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
cleanPathname,
middlewareContext,
params,
renderNotFound,
request,
route,
searchParams,
skipStaticParamsValidation,
}) {
const { dispatchAppRouteHandler: __dispatchAppRouteHandler } =
await __loadAppRouteHandlerDispatch();
Expand All @@ -1758,6 +1771,7 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
middlewareContext,
middlewareRequestHeaders: middlewareContext.requestHeaders,
params,
renderNotFound,
request,
route: {
pattern: route.pattern,
Expand All @@ -1766,6 +1780,7 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
},
scheduleBackgroundRegeneration: __triggerBackgroundRegeneration,
searchParams,
skipStaticParamsValidation,
});
},
${
Expand Down
36 changes: 4 additions & 32 deletions packages/vinext/src/server/app-page-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ import {
VINEXT_MOUNTED_LAYOUTS_HEADER,
VINEXT_PARAMS_HEADER,
VINEXT_PRERENDER_SPECULATIVE_HEADER,
VINEXT_ROUTE_MISS_HEADER,
} from "./headers.js";
import { parseMountedLayoutsHeader } from "./app-mounted-layouts.js";
import { applyCdnResponseHeaders, NEVER_CACHE_CONTROL } from "./cache-control.js";
import { preserveFullyBufferedBodyMetadata } from "./fully-buffered-response.js";
import { markRouteMissResponse } from "./route-miss-response.js";
import { buildAppPageTags } from "./implicit-tags.js";
import { resolveAppPageTraceOperation } from "./app-page-tracing.js";
import {
Expand All @@ -123,7 +121,6 @@ import {
beginRouteCacheability,
isRouteCacheabilityIdentityProbe,
isRouteCacheabilityProbe,
markRouteCacheabilityFinalResponseUncacheable,
markRouteCacheabilityPatternDynamic,
readRouteCacheabilityState,
} from "vinext/shims/cacheability-classification";
Expand All @@ -134,10 +131,7 @@ import {
} from "./cacheability-manifest.js";
import type { AppRenderErrorContextOverrides } from "./app-rsc-error-handler.js";
import { traceResponseStart } from "./response-start-tracing.js";
import {
copyLinkHeaderProvenance,
getFrameworkLinkHeader,
} from "./app-response-header-provenance.js";
import { getFrameworkLinkHeader } from "./app-response-header-provenance.js";

type AppPageParams = Record<string, string | string[]>;
type AppPageElement = ReactNode | Readonly<Record<string, ReactNode>>;
Expand Down Expand Up @@ -623,28 +617,6 @@ async function runAppPageRevalidationContext<
}
}

/**
* Next.js sends a routing-level 404 with its never-cache policy, which neither
* middleware nor next.config headers can replace. The request stage reasserts
* it after config headers, and shared-cache admission never stores it.
*/
function markAppPageRouteMissResponse(response: Response): Response {
markRouteCacheabilityFinalResponseUncacheable("routing-level not-found");
const headers = new Headers(response.headers);
applyCdnResponseHeaders(headers, { cacheControl: NEVER_CACHE_CONTROL });
headers.set(VINEXT_ROUTE_MISS_HEADER, "1");
const marked = preserveFullyBufferedBodyMetadata(
response,
new Response(response.body, {
headers,
status: response.status,
statusText: response.statusText,
}),
);
copyLinkHeaderProvenance(response.headers, marked.headers);
return marked;
}

function toInterceptOptions(
interceptionContext: string | null,
intercept: AppPageDispatchIntercept,
Expand Down Expand Up @@ -1329,12 +1301,12 @@ async function dispatchAppPageInner<TRoute extends AppPageDispatchRoute>(
scriptNonce: options.scriptNonce,
};
if (renderedNotFound) {
return markAppPageRouteMissResponse(
return markRouteMissResponse(
applyIneligibleRouteCachePolicy(renderedNotFound, cachePolicy),
);
}
options.clearRequestContext();
return markAppPageRouteMissResponse(
return markRouteMissResponse(
applyIneligibleRouteCachePolicy(dynamicParamsResponse, cachePolicy),
);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/vinext/src/server/app-page-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,19 @@ function normalizeGenerateStaticParams(
});
}

export function routePatternParamNames(patternParts: readonly string[]): string[] {
return patternParts.flatMap((part) => {
if (!part.startsWith(":")) return [];
return [part.slice(1, part.endsWith("+") || part.endsWith("*") ? -1 : undefined)];
});
}

export function routePatternOptionalCatchAllParamNames(patternParts: readonly string[]): string[] {
return patternParts.flatMap((part) =>
part.startsWith(":") && part.endsWith("*") ? [part.slice(1, -1)] : [],
);
}

export async function validateAppPageDynamicParams(
options: ValidateAppPageDynamicParamsOptions,
): Promise<Response | null> {
Expand Down
4 changes: 3 additions & 1 deletion packages/vinext/src/server/app-route-handler-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
assertSupportedAppRouteHandlerResponse,
buildAppRouteCacheValue,
buildRouteHandlerCachedResponse,
stripAppRouteHandlerRouteMissMarker,
} from "./app-route-handler-response.js";
import { markKnownDynamicAppRoute } from "./app-route-handler-runtime.js";
import { resolveAppRouteHandlerSpecialError } from "./app-route-handler-policy.js";
Expand Down Expand Up @@ -171,8 +172,9 @@ export async function readAppRouteHandlerCacheResponse(
options.cleanPathname,
options.getCollectedFetchTags(),
);
// The body's producer may have set headers while completing.
const routeCacheValue = await buildAppRouteCacheValue(
completed.response,
stripAppRouteHandlerRouteMissMarker(completed.response),
response.headers.get("Cache-Control") ?? undefined,
);
await options.isrSet(routeKey, routeCacheValue, {
Expand Down
Loading
Loading