vinext 0.0.47 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build/layout-classification.js +3 -1
- package/dist/build/layout-classification.js.map +1 -1
- package/dist/build/prerender.js +10 -10
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/report.d.ts +8 -4
- package/dist/build/report.js +17 -7
- package/dist/build/report.js.map +1 -1
- package/dist/build/run-prerender.d.ts +5 -0
- package/dist/build/run-prerender.js +4 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/server-manifest.js +2 -7
- package/dist/build/server-manifest.js.map +1 -1
- package/dist/build/standalone.js +3 -5
- package/dist/build/standalone.js.map +1 -1
- package/dist/check.js +45 -29
- package/dist/check.js.map +1 -1
- package/dist/cli-args.d.ts +3 -1
- package/dist/cli-args.js +18 -1
- package/dist/cli-args.js.map +1 -1
- package/dist/cli.js +9 -1
- package/dist/cli.js.map +1 -1
- package/dist/config/config-matchers.js +46 -37
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/deploy.d.ts +18 -2
- package/dist/deploy.js +47 -4
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +11 -9
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.js +4 -1
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/pages-client-entry.js +3 -2
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +21 -62
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +12 -3
- package/dist/entries/runtime-entry-module.js +15 -4
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js +2 -2
- package/dist/init.js.map +1 -1
- package/dist/plugins/og-assets.js +15 -16
- package/dist/plugins/og-assets.js.map +1 -1
- package/dist/plugins/rsc-client-shim-excludes.d.ts +2 -1
- package/dist/plugins/rsc-client-shim-excludes.js +10 -1
- package/dist/plugins/rsc-client-shim-excludes.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +90 -4
- package/dist/routing/app-route-graph.js +210 -7
- package/dist/routing/app-route-graph.js.map +1 -1
- package/dist/routing/app-router.d.ts +15 -3
- package/dist/routing/app-router.js +20 -23
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +3 -1
- package/dist/routing/file-matcher.js +6 -1
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.js +10 -19
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-matching.d.ts +28 -0
- package/dist/routing/route-matching.js +44 -0
- package/dist/routing/route-matching.js.map +1 -0
- package/dist/routing/route-pattern.js +4 -1
- package/dist/routing/route-pattern.js.map +1 -1
- package/dist/routing/route-trie.d.ts +8 -0
- package/dist/routing/route-trie.js +12 -1
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.js +3 -4
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +8 -1
- package/dist/routing/utils.js +25 -2
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +2 -8
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-entry.js +66 -49
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-navigation-controller.d.ts +7 -5
- package/dist/server/app-browser-navigation-controller.js +43 -35
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +33 -15
- package/dist/server/app-browser-state.js +52 -59
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +68 -0
- package/dist/server/app-browser-visible-commit.js +182 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -0
- package/dist/server/app-client-reference-preloader.d.ts +15 -0
- package/dist/server/app-client-reference-preloader.js +46 -0
- package/dist/server/app-client-reference-preloader.js.map +1 -0
- package/dist/server/app-elements-wire.d.ts +130 -0
- package/dist/server/app-elements-wire.js +205 -0
- package/dist/server/app-elements-wire.js.map +1 -0
- package/dist/server/app-elements.d.ts +2 -84
- package/dist/server/app-elements.js +3 -102
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +1 -1
- package/dist/server/app-middleware.d.ts +2 -1
- package/dist/server/app-middleware.js +34 -11
- package/dist/server/app-middleware.js.map +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -1
- package/dist/server/app-page-boundary-render.js +8 -5
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +8 -13
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +2 -1
- package/dist/server/app-page-dispatch.js +18 -10
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +1 -1
- package/dist/server/app-page-element-builder.js +8 -5
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +23 -5
- package/dist/server/app-page-execution.js +39 -24
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.js +2 -1
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-method.js +2 -5
- package/dist/server/app-page-method.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +1 -1
- package/dist/server/app-page-probe.js +5 -1
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render.d.ts +1 -1
- package/dist/server/app-page-render.js +38 -3
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +0 -1
- package/dist/server/app-page-request.js +7 -10
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.js +3 -2
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +5 -2
- package/dist/server/app-page-route-wiring.js +15 -12
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +7 -0
- package/dist/server/app-page-stream.js +9 -2
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-prerender-endpoints.js +3 -2
- package/dist/server/app-prerender-endpoints.js.map +1 -1
- package/dist/server/app-route-handler-cache.js +2 -1
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.js +6 -5
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-policy.js +13 -13
- package/dist/server/app-route-handler-policy.js.map +1 -1
- package/dist/server/app-route-handler-response.js +2 -1
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +9 -1
- package/dist/server/app-route-handler-runtime.js +11 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-router-entry.js +9 -4
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +34 -0
- package/dist/server/app-rsc-cache-busting.js +137 -0
- package/dist/server/app-rsc-cache-busting.js.map +1 -0
- package/dist/server/app-rsc-handler.js +22 -11
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.d.ts +4 -2
- package/dist/server/app-rsc-request-normalization.js +10 -6
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.js +8 -4
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-segment-config.js +4 -0
- package/dist/server/app-segment-config.js.map +1 -1
- package/dist/server/app-server-action-execution.js +43 -51
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.js +21 -20
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +44 -0
- package/dist/server/artifact-compatibility.js +82 -0
- package/dist/server/artifact-compatibility.js.map +1 -0
- package/dist/server/cache-proof.d.ts +200 -0
- package/dist/server/cache-proof.js +342 -0
- package/dist/server/cache-proof.js.map +1 -0
- package/dist/server/dev-origin-check.js +8 -4
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.js +6 -16
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +67 -0
- package/dist/server/http-error-responses.js +77 -0
- package/dist/server/http-error-responses.js.map +1 -0
- package/dist/server/image-optimization.js +2 -1
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/metadata-route-response.js +6 -5
- package/dist/server/metadata-route-response.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +1 -0
- package/dist/server/metadata-routes.js +6 -0
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-matcher.js +2 -2
- package/dist/server/middleware-matcher.js.map +1 -1
- package/dist/server/middleware-response-headers.js +21 -0
- package/dist/server/middleware-response-headers.js.map +1 -1
- package/dist/server/middleware-runtime.js +3 -3
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +33 -0
- package/dist/server/navigation-trace.js +35 -0
- package/dist/server/navigation-trace.js.map +1 -0
- package/dist/server/next-error-digest.d.ts +44 -0
- package/dist/server/next-error-digest.js +40 -0
- package/dist/server/next-error-digest.js.map +1 -0
- package/dist/server/pages-api-route.js +4 -7
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-node-compat.js +4 -16
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +2 -8
- package/dist/server/pages-page-response.js +44 -14
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prod-server.d.ts +6 -0
- package/dist/server/prod-server.js +28 -21
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +42 -1
- package/dist/server/request-pipeline.js +97 -17
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +3 -6
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.js +3 -5
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/fetch-cache.js +2 -3
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/head-state.js +2 -3
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/headers.js +4 -44
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-state.js +2 -3
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/internal/als-registry.d.ts +15 -0
- package/dist/shims/internal/als-registry.js +55 -0
- package/dist/shims/internal/als-registry.js.map +1 -0
- package/dist/shims/internal/cookie-serialize.d.ts +46 -0
- package/dist/shims/internal/cookie-serialize.js +51 -0
- package/dist/shims/internal/cookie-serialize.js.map +1 -0
- package/dist/shims/link.js +31 -26
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +26 -1
- package/dist/shims/metadata.js +94 -4
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.js +2 -3
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +2 -7
- package/dist/shims/navigation.js +44 -36
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/request-context.js +2 -4
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/router-state.js +2 -3
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.js +2 -2
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/server.js +5 -30
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.d.ts +1 -1
- package/dist/shims/slot.js +5 -4
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/thenable-params.d.ts +5 -2
- package/dist/shims/thenable-params.js +26 -6
- package/dist/shims/thenable-params.js.map +1 -1
- package/dist/shims/unified-request-context.js +2 -14
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/utils/base-path.d.ts +7 -1
- package/dist/utils/base-path.js +12 -1
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/query.d.ts +8 -1
- package/dist/utils/query.js +12 -1
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/safe-json-file.d.ts +18 -0
- package/dist/utils/safe-json-file.js +25 -0
- package/dist/utils/safe-json-file.js.map +1 -0
- package/dist/utils/text-stream.d.ts +29 -0
- package/dist/utils/text-stream.js +66 -0
- package/dist/utils/text-stream.js.map +1 -0
- package/package.json +5 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { methodNotAllowedResponse } from "./http-error-responses.js";
|
|
1
2
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
2
3
|
import { isPossibleAppRouteActionRequest } from "./app-route-handler-policy.js";
|
|
3
4
|
//#region src/server/app-page-method.ts
|
|
@@ -18,11 +19,7 @@ function resolveAppPageMethodResponse(options) {
|
|
|
18
19
|
if (!isStaticOrSsgAppPageCandidate(options)) return null;
|
|
19
20
|
const headers = new Headers();
|
|
20
21
|
mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);
|
|
21
|
-
|
|
22
|
-
return new Response("Method Not Allowed", {
|
|
23
|
-
headers,
|
|
24
|
-
status: 405
|
|
25
|
-
});
|
|
22
|
+
return methodNotAllowedResponse("GET, HEAD", { headers });
|
|
26
23
|
}
|
|
27
24
|
//#endregion
|
|
28
25
|
export { isStaticOrSsgAppPageCandidate, resolveAppPageMethodResponse };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-method.js","names":[],"sources":["../../src/server/app-page-method.ts"],"sourcesContent":["import { isPossibleAppRouteActionRequest } from \"./app-route-handler-policy.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\ntype AppPageMethodPolicyOptions = {\n dynamicConfig?: string;\n hasGenerateStaticParams: boolean;\n isDynamicRoute: boolean;\n revalidateSeconds: number | null;\n};\n\ntype ResolveAppPageMethodResponseOptions = {\n middlewareHeaders?: Headers | null;\n request: Pick<Request, \"headers\" | \"method\">;\n} & AppPageMethodPolicyOptions;\n\nfunction isNonGetOrHead(method: string): boolean {\n const normalizedMethod = method.toUpperCase();\n return normalizedMethod !== \"GET\" && normalizedMethod !== \"HEAD\";\n}\n\nexport function isStaticOrSsgAppPageCandidate(options: AppPageMethodPolicyOptions): boolean {\n if (options.dynamicConfig === \"force-dynamic\" || options.revalidateSeconds === 0) {\n return false;\n }\n\n if (options.dynamicConfig === \"force-static\" || options.dynamicConfig === \"error\") {\n return true;\n }\n\n if (options.revalidateSeconds !== null && options.revalidateSeconds > 0) {\n return true;\n }\n\n if (options.hasGenerateStaticParams) {\n return true;\n }\n\n return !options.isDynamicRoute;\n}\n\nexport function resolveAppPageMethodResponse(\n options: ResolveAppPageMethodResponseOptions,\n): Response | null {\n if (!isNonGetOrHead(options.request.method)) {\n return null;\n }\n\n if (isPossibleAppRouteActionRequest(options.request)) {\n return null;\n }\n\n if (!isStaticOrSsgAppPageCandidate(options)) {\n return null;\n }\n\n const headers = new Headers();\n mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);\n
|
|
1
|
+
{"version":3,"file":"app-page-method.js","names":[],"sources":["../../src/server/app-page-method.ts"],"sourcesContent":["import { isPossibleAppRouteActionRequest } from \"./app-route-handler-policy.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\nimport { methodNotAllowedResponse } from \"./http-error-responses.js\";\n\ntype AppPageMethodPolicyOptions = {\n dynamicConfig?: string;\n hasGenerateStaticParams: boolean;\n isDynamicRoute: boolean;\n revalidateSeconds: number | null;\n};\n\ntype ResolveAppPageMethodResponseOptions = {\n middlewareHeaders?: Headers | null;\n request: Pick<Request, \"headers\" | \"method\">;\n} & AppPageMethodPolicyOptions;\n\nfunction isNonGetOrHead(method: string): boolean {\n const normalizedMethod = method.toUpperCase();\n return normalizedMethod !== \"GET\" && normalizedMethod !== \"HEAD\";\n}\n\nexport function isStaticOrSsgAppPageCandidate(options: AppPageMethodPolicyOptions): boolean {\n if (options.dynamicConfig === \"force-dynamic\" || options.revalidateSeconds === 0) {\n return false;\n }\n\n if (options.dynamicConfig === \"force-static\" || options.dynamicConfig === \"error\") {\n return true;\n }\n\n if (options.revalidateSeconds !== null && options.revalidateSeconds > 0) {\n return true;\n }\n\n if (options.hasGenerateStaticParams) {\n return true;\n }\n\n return !options.isDynamicRoute;\n}\n\nexport function resolveAppPageMethodResponse(\n options: ResolveAppPageMethodResponseOptions,\n): Response | null {\n if (!isNonGetOrHead(options.request.method)) {\n return null;\n }\n\n if (isPossibleAppRouteActionRequest(options.request)) {\n return null;\n }\n\n if (!isStaticOrSsgAppPageCandidate(options)) {\n return null;\n }\n\n const headers = new Headers();\n mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);\n\n return methodNotAllowedResponse(\"GET, HEAD\", { headers });\n}\n"],"mappings":";;;;AAgBA,SAAS,eAAe,QAAyB;CAC/C,MAAM,mBAAmB,OAAO,aAAa;AAC7C,QAAO,qBAAqB,SAAS,qBAAqB;;AAG5D,SAAgB,8BAA8B,SAA8C;AAC1F,KAAI,QAAQ,kBAAkB,mBAAmB,QAAQ,sBAAsB,EAC7E,QAAO;AAGT,KAAI,QAAQ,kBAAkB,kBAAkB,QAAQ,kBAAkB,QACxE,QAAO;AAGT,KAAI,QAAQ,sBAAsB,QAAQ,QAAQ,oBAAoB,EACpE,QAAO;AAGT,KAAI,QAAQ,wBACV,QAAO;AAGT,QAAO,CAAC,QAAQ;;AAGlB,SAAgB,6BACd,SACiB;AACjB,KAAI,CAAC,eAAe,QAAQ,QAAQ,OAAO,CACzC,QAAO;AAGT,KAAI,gCAAgC,QAAQ,QAAQ,CAClD,QAAO;AAGT,KAAI,CAAC,8BAA8B,QAAQ,CACzC,QAAO;CAGT,MAAM,UAAU,IAAI,SAAS;AAC7B,gCAA+B,SAAS,QAAQ,qBAAqB,KAAK;AAE1E,QAAO,yBAAyB,aAAa,EAAE,SAAS,CAAC"}
|
|
@@ -22,9 +22,13 @@ async function probeAppPageBeforeRender(options) {
|
|
|
22
22
|
layoutFlags
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
+
if (options.hasLoadingBoundary) return {
|
|
26
|
+
response: null,
|
|
27
|
+
layoutFlags
|
|
28
|
+
};
|
|
25
29
|
return {
|
|
26
30
|
response: await probeAppPageComponent({
|
|
27
|
-
awaitAsyncResult:
|
|
31
|
+
awaitAsyncResult: true,
|
|
28
32
|
async onError(pageError) {
|
|
29
33
|
const specialError = options.resolveSpecialError(pageError);
|
|
30
34
|
if (specialError) return options.renderPageSpecialError(specialError);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-probe.js","names":[],"sources":["../../src/server/app-page-probe.ts"],"sourcesContent":["import {\n probeAppPageComponent,\n probeAppPageLayouts,\n type AppPageSpecialError,\n type LayoutClassificationOptions,\n type LayoutFlags,\n} from \"./app-page-execution.js\";\n\ntype ProbeAppPageBeforeRenderResult = {\n response: Response | null;\n layoutFlags: LayoutFlags;\n};\n\ntype ProbeAppPageBeforeRenderOptions = {\n hasLoadingBoundary: boolean;\n layoutCount: number;\n probeLayoutAt: (layoutIndex: number) => unknown;\n probePage: () => unknown;\n renderLayoutSpecialError: (\n specialError: AppPageSpecialError,\n layoutIndex: number,\n ) => Promise<Response>;\n renderPageSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => AppPageSpecialError | null;\n runWithSuppressedHookWarning<T>(probe: () => Promise<T>): Promise<T>;\n /** When provided, enables per-layout static/dynamic classification. */\n classification?: LayoutClassificationOptions | null;\n};\n\nexport async function probeAppPageBeforeRender(\n options: ProbeAppPageBeforeRenderOptions,\n): Promise<ProbeAppPageBeforeRenderResult> {\n let layoutFlags: LayoutFlags = {};\n\n // Layouts render before their children in Next.js, so layout-level special\n // errors must be handled before probing the page component itself.\n if (options.layoutCount > 0) {\n const layoutProbeResult = await probeAppPageLayouts({\n layoutCount: options.layoutCount,\n async onLayoutError(layoutError, layoutIndex) {\n const specialError = options.resolveSpecialError(layoutError);\n if (!specialError) {\n return null;\n }\n\n return options.renderLayoutSpecialError(specialError, layoutIndex);\n },\n probeLayoutAt: options.probeLayoutAt,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n classification: options.classification,\n });\n\n layoutFlags = layoutProbeResult.layoutFlags;\n\n if (layoutProbeResult.response) {\n return { response: layoutProbeResult.response, layoutFlags };\n }\n }\n\n // Server Components are functions, so we can probe the page ahead of stream\n // creation and only turn special throws into immediate responses.\n const pageResponse = await probeAppPageComponent({\n awaitAsyncResult:
|
|
1
|
+
{"version":3,"file":"app-page-probe.js","names":[],"sources":["../../src/server/app-page-probe.ts"],"sourcesContent":["import {\n probeAppPageComponent,\n probeAppPageLayouts,\n type AppPageSpecialError,\n type LayoutClassificationOptions,\n type LayoutFlags,\n} from \"./app-page-execution.js\";\n\ntype ProbeAppPageBeforeRenderResult = {\n response: Response | null;\n layoutFlags: LayoutFlags;\n};\n\ntype ProbeAppPageBeforeRenderOptions = {\n hasLoadingBoundary: boolean;\n layoutCount: number;\n probeLayoutAt: (layoutIndex: number) => unknown;\n probePage: () => unknown;\n renderLayoutSpecialError: (\n specialError: AppPageSpecialError,\n layoutIndex: number,\n ) => Promise<Response>;\n renderPageSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => AppPageSpecialError | null;\n runWithSuppressedHookWarning<T>(probe: () => Promise<T>): Promise<T>;\n /** When provided, enables per-layout static/dynamic classification. */\n classification?: LayoutClassificationOptions | null;\n};\n\nexport async function probeAppPageBeforeRender(\n options: ProbeAppPageBeforeRenderOptions,\n): Promise<ProbeAppPageBeforeRenderResult> {\n let layoutFlags: LayoutFlags = {};\n\n // Layouts render before their children in Next.js, so layout-level special\n // errors must be handled before probing the page component itself.\n if (options.layoutCount > 0) {\n const layoutProbeResult = await probeAppPageLayouts({\n layoutCount: options.layoutCount,\n async onLayoutError(layoutError, layoutIndex) {\n const specialError = options.resolveSpecialError(layoutError);\n if (!specialError) {\n return null;\n }\n\n return options.renderLayoutSpecialError(specialError, layoutIndex);\n },\n probeLayoutAt: options.probeLayoutAt,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n classification: options.classification,\n });\n\n layoutFlags = layoutProbeResult.layoutFlags;\n\n if (layoutProbeResult.response) {\n return { response: layoutProbeResult.response, layoutFlags };\n }\n }\n\n // When a route-level loading.tsx is present, the page renders inside a\n // route-level Suspense boundary, so a thrown redirect()/notFound() during\n // page render becomes an error inside that boundary. We can't catch it\n // here without serializing on the page promise — which would defeat the\n // streaming benefit of loading.tsx for slow non-redirecting pages.\n //\n // Recovery for the redirect/notFound case happens later in\n // renderAppPageLifecycle: rscErrorTracker captures the digest from React's\n // onError callback, and a short race window after shell-ready lets the\n // lifecycle swap the response to a 307/404 before bytes are flushed.\n // This mirrors Next.js's \"until-first-byte-is-flushed\" swap behavior.\n if (options.hasLoadingBoundary) {\n return { response: null, layoutFlags };\n }\n\n // Server Components are functions, so we can probe the page ahead of stream\n // creation and only turn special throws into immediate responses.\n const pageResponse = await probeAppPageComponent({\n awaitAsyncResult: true,\n async onError(pageError) {\n const specialError = options.resolveSpecialError(pageError);\n if (specialError) {\n return options.renderPageSpecialError(specialError);\n }\n\n // Non-special probe failures (for example use() outside React's render\n // cycle or client references executing on the server) are expected here.\n // The real RSC/SSR render path will surface those properly below.\n return null;\n },\n probePage: options.probePage,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n });\n\n return { response: pageResponse, layoutFlags };\n}\n"],"mappings":";;AA6BA,eAAsB,yBACpB,SACyC;CACzC,IAAI,cAA2B,EAAE;AAIjC,KAAI,QAAQ,cAAc,GAAG;EAC3B,MAAM,oBAAoB,MAAM,oBAAoB;GAClD,aAAa,QAAQ;GACrB,MAAM,cAAc,aAAa,aAAa;IAC5C,MAAM,eAAe,QAAQ,oBAAoB,YAAY;AAC7D,QAAI,CAAC,aACH,QAAO;AAGT,WAAO,QAAQ,yBAAyB,cAAc,YAAY;;GAEpE,eAAe,QAAQ;GACvB,6BAA6B,OAAO;AAClC,WAAO,QAAQ,6BAA6B,MAAM;;GAEpD,gBAAgB,QAAQ;GACzB,CAAC;AAEF,gBAAc,kBAAkB;AAEhC,MAAI,kBAAkB,SACpB,QAAO;GAAE,UAAU,kBAAkB;GAAU;GAAa;;AAehE,KAAI,QAAQ,mBACV,QAAO;EAAE,UAAU;EAAM;EAAa;AAwBxC,QAAO;EAAE,UAnBY,MAAM,sBAAsB;GAC/C,kBAAkB;GAClB,MAAM,QAAQ,WAAW;IACvB,MAAM,eAAe,QAAQ,oBAAoB,UAAU;AAC3D,QAAI,aACF,QAAO,QAAQ,uBAAuB,aAAa;AAMrD,WAAO;;GAET,WAAW,QAAQ;GACnB,6BAA6B,OAAO;AAClC,WAAO,QAAQ,6BAA6B,MAAM;;GAErD,CAAC;EAE+B;EAAa"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CachedAppPageValue } from "../shims/cache.js";
|
|
2
|
-
import { AppOutgoingElements } from "./app-elements.js";
|
|
2
|
+
import { AppOutgoingElements } from "./app-elements-wire.js";
|
|
3
3
|
import { AppPageFontPreload, AppPageSpecialError, LayoutClassificationOptions } from "./app-page-execution.js";
|
|
4
4
|
import { AppPageMiddlewareContext } from "./app-page-response.js";
|
|
5
5
|
import { AppPageSsrHandler } from "./app-page-stream.js";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createArtifactCompatibilityEnvelope, createArtifactCompatibilityGraphVersion } from "./artifact-compatibility.js";
|
|
2
|
+
import { AppElementsWire, isAppElementsRecord } from "./app-elements-wire.js";
|
|
3
|
+
import "./app-elements.js";
|
|
2
4
|
import { createAppPageFontData, createAppPageRscErrorTracker, deferUntilStreamConsumed, renderAppPageHtmlStream, renderAppPageHtmlStreamWithRecovery, shouldRerenderAppPageWithGlobalError } from "./app-page-stream.js";
|
|
3
5
|
import { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse } from "./app-page-cache.js";
|
|
4
6
|
import { buildAppPageFontLinkHeader, readAppPageBinaryStream, resolveAppPageSpecialError, teeAppPageRscStreamForCapture } from "./app-page-execution.js";
|
|
@@ -28,6 +30,22 @@ function applyRequestCacheLife(options) {
|
|
|
28
30
|
revalidateSeconds
|
|
29
31
|
};
|
|
30
32
|
}
|
|
33
|
+
function readRootBoundaryId(element) {
|
|
34
|
+
const rootLayoutTreePath = element[AppElementsWire.keys.rootLayout];
|
|
35
|
+
return typeof rootLayoutTreePath === "string" ? rootLayoutTreePath : null;
|
|
36
|
+
}
|
|
37
|
+
function createAppPageArtifactCompatibility(element, routePattern) {
|
|
38
|
+
if (!isAppElementsRecord(element)) return;
|
|
39
|
+
const rootBoundaryId = readRootBoundaryId(element);
|
|
40
|
+
return createArtifactCompatibilityEnvelope({
|
|
41
|
+
graphVersion: createArtifactCompatibilityGraphVersion({
|
|
42
|
+
routePattern,
|
|
43
|
+
rootBoundaryId
|
|
44
|
+
}),
|
|
45
|
+
deploymentVersion: process.env.__VINEXT_BUILD_ID ?? null,
|
|
46
|
+
rootBoundaryId
|
|
47
|
+
});
|
|
48
|
+
}
|
|
31
49
|
/**
|
|
32
50
|
* Wraps an RSC response body to report invalid dynamic usage errors after the
|
|
33
51
|
* stream is fully consumed. In dev mode, errors from cookies()/headers() inside
|
|
@@ -95,9 +113,11 @@ async function renderAppPageLifecycle(options) {
|
|
|
95
113
|
});
|
|
96
114
|
if (preRenderResult.response) return preRenderResult.response;
|
|
97
115
|
const layoutFlags = preRenderResult.layoutFlags;
|
|
98
|
-
const
|
|
116
|
+
const artifactCompatibility = createAppPageArtifactCompatibility(options.element, options.routePattern);
|
|
117
|
+
const outgoingElement = AppElementsWire.encodeOutgoingPayload({
|
|
99
118
|
element: options.element,
|
|
100
|
-
layoutFlags
|
|
119
|
+
layoutFlags,
|
|
120
|
+
...artifactCompatibility ? { artifactCompatibility } : {}
|
|
101
121
|
});
|
|
102
122
|
const compileEnd = options.isProduction ? void 0 : performance.now();
|
|
103
123
|
const rscErrorTracker = createAppPageRscErrorTracker(options.createRscOnErrorHandler(options.cleanPathname, options.routePattern));
|
|
@@ -197,6 +217,16 @@ async function renderAppPageLifecycle(options) {
|
|
|
197
217
|
if (htmlRender.response) return htmlRender.response;
|
|
198
218
|
const htmlStream = htmlRender.htmlStream;
|
|
199
219
|
if (!htmlStream) throw new Error("[vinext] Expected an HTML stream when no fallback response was returned");
|
|
220
|
+
if (options.hasLoadingBoundary) {
|
|
221
|
+
const captured = rscErrorTracker.getCapturedSpecialError();
|
|
222
|
+
if (captured) {
|
|
223
|
+
const specialError = resolveAppPageSpecialError(captured);
|
|
224
|
+
if (specialError) {
|
|
225
|
+
htmlStream.cancel().catch(() => {});
|
|
226
|
+
return options.renderPageSpecialError(specialError);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
200
230
|
if (shouldRerenderAppPageWithGlobalError({
|
|
201
231
|
capturedError: rscErrorTracker.getCapturedError(),
|
|
202
232
|
hasLocalBoundary: options.routeHasLocalBoundary
|
|
@@ -214,7 +244,9 @@ async function renderAppPageLifecycle(options) {
|
|
|
214
244
|
}
|
|
215
245
|
const draftCookie = options.getDraftModeCookieHeader();
|
|
216
246
|
const dynamicUsedDuringRender = options.consumeDynamicUsage();
|
|
247
|
+
let dynamicUsedBeforeContextCleanup = dynamicUsedDuringRender;
|
|
217
248
|
const safeHtmlStream = deferUntilStreamConsumed(htmlStream, () => {
|
|
249
|
+
dynamicUsedBeforeContextCleanup = dynamicUsedBeforeContextCleanup || options.consumeDynamicUsage();
|
|
218
250
|
options.clearRequestContext();
|
|
219
251
|
});
|
|
220
252
|
const htmlResponsePolicy = resolveAppPageHtmlResponsePolicy({
|
|
@@ -245,6 +277,9 @@ async function renderAppPageLifecycle(options) {
|
|
|
245
277
|
});
|
|
246
278
|
if (options.isPrerender === true) return isrResponse;
|
|
247
279
|
return finalizeAppPageHtmlCacheResponse(isrResponse, {
|
|
280
|
+
capturedDynamicUsageBeforeContextCleanup() {
|
|
281
|
+
return dynamicUsedBeforeContextCleanup;
|
|
282
|
+
},
|
|
248
283
|
capturedRscDataPromise: capturedRscDataRef.value,
|
|
249
284
|
cleanPathname: options.cleanPathname,
|
|
250
285
|
consumeDynamicUsage: options.consumeDynamicUsage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-render.js","names":[],"sources":["../../src/server/app-page-render.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { CachedAppPageValue } from \"vinext/shims/cache\";\nimport { buildOutgoingAppPayload, type AppOutgoingElements } from \"./app-elements.js\";\nimport {\n finalizeAppPageHtmlCacheResponse,\n finalizeAppPageRscCacheResponse,\n} from \"./app-page-cache.js\";\nimport {\n buildAppPageFontLinkHeader,\n readAppPageBinaryStream,\n resolveAppPageSpecialError,\n teeAppPageRscStreamForCapture,\n type AppPageFontPreload,\n type AppPageSpecialError,\n type LayoutClassificationOptions,\n} from \"./app-page-execution.js\";\nimport { probeAppPageBeforeRender } from \"./app-page-probe.js\";\nimport {\n buildAppPageHtmlResponse,\n buildAppPageRscResponse,\n resolveAppPageHtmlResponsePolicy,\n resolveAppPageRscResponsePolicy,\n type AppPageMiddlewareContext,\n type AppPageResponseTiming,\n} from \"./app-page-response.js\";\nimport {\n createAppPageFontData,\n createAppPageRscErrorTracker,\n deferUntilStreamConsumed,\n renderAppPageHtmlStream,\n renderAppPageHtmlStreamWithRecovery,\n shouldRerenderAppPageWithGlobalError,\n type AppPageSsrHandler,\n} from \"./app-page-stream.js\";\n\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\ntype AppPageDebugLogger = (event: string, detail: string) => void;\ntype AppPageCacheSetter = (\n key: string,\n data: CachedAppPageValue,\n revalidateSeconds: number,\n tags: string[],\n expireSeconds?: number,\n) => Promise<void>;\n\ntype AppPageRequestCacheLife = {\n revalidate?: number;\n expire?: number;\n};\n\ntype RenderAppPageLifecycleOptions = {\n cleanPathname: string;\n clearRequestContext: () => void;\n consumeDynamicUsage: () => boolean;\n /** Read and clear any invalid dynamic usage error recorded during render (dev-only). */\n consumeInvalidDynamicUsageError?: () => unknown;\n createRscOnErrorHandler: (pathname: string, routePath: string) => AppPageBoundaryOnError;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n getNavigationContext: () => unknown;\n getPageTags: () => string[];\n getRequestCacheLife: () => AppPageRequestCacheLife | null;\n peekRequestCacheLife?: () => AppPageRequestCacheLife | null;\n getDraftModeCookieHeader: () => string | null | undefined;\n handlerStart: number;\n hasLoadingBoundary: boolean;\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isPrerender?: boolean;\n isProduction: boolean;\n isRscRequest: boolean;\n isrDebug?: AppPageDebugLogger;\n isrHtmlKey: (pathname: string) => string;\n isrRscKey: (pathname: string, mountedSlotsHeader?: string | null) => string;\n isrSet: AppPageCacheSetter;\n layoutCount: number;\n loadSsrHandler: () => Promise<AppPageSsrHandler>;\n middlewareContext: AppPageMiddlewareContext;\n params: Record<string, unknown>;\n probeLayoutAt: (layoutIndex: number) => unknown;\n probePage: () => unknown;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n renderErrorBoundaryResponse: (error: unknown) => Promise<Response | null>;\n renderLayoutSpecialError: (\n specialError: AppPageSpecialError,\n layoutIndex: number,\n ) => Promise<Response>;\n renderPageSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n renderToReadableStream: (\n element: ReactNode | AppOutgoingElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n routeHasLocalBoundary: boolean;\n routePattern: string;\n runWithSuppressedHookWarning<T>(probe: () => Promise<T>): Promise<T>;\n scriptNonce?: string;\n mountedSlotsHeader?: string | null;\n waitUntil?: (promise: Promise<void>) => void;\n element: ReactNode | Readonly<Record<string, ReactNode>>;\n classification?: LayoutClassificationOptions | null;\n};\n\nfunction buildResponseTiming(\n options: Pick<RenderAppPageLifecycleOptions, \"handlerStart\" | \"isProduction\"> & {\n compileEnd?: number;\n renderEnd?: number;\n responseKind: AppPageResponseTiming[\"responseKind\"];\n },\n): AppPageResponseTiming | undefined {\n if (options.isProduction) {\n return undefined;\n }\n\n return {\n compileEnd: options.compileEnd,\n handlerStart: options.handlerStart,\n renderEnd: options.renderEnd,\n responseKind: options.responseKind,\n };\n}\n\nfunction readRequestCacheLifeForPrerender(\n options: Pick<RenderAppPageLifecycleOptions, \"getRequestCacheLife\" | \"peekRequestCacheLife\">,\n): AppPageRequestCacheLife | null {\n // Prefer the non-destructive reader so prerender.ts can consume metadata\n // after the handler returns. The consume fallback supports older entry glue\n // and is only safe because this path reads at most once per prerender.\n return options.peekRequestCacheLife?.() ?? options.getRequestCacheLife();\n}\n\nfunction applyRequestCacheLife(options: {\n expireSeconds?: number;\n requestCacheLife: AppPageRequestCacheLife | null;\n revalidateSeconds: number | null;\n}): { expireSeconds?: number; revalidateSeconds: number | null } {\n let revalidateSeconds = options.revalidateSeconds;\n let expireSeconds = options.expireSeconds;\n const requestCacheLife = options.requestCacheLife;\n\n if (requestCacheLife?.revalidate !== undefined) {\n revalidateSeconds =\n revalidateSeconds === null\n ? requestCacheLife.revalidate\n : Math.min(revalidateSeconds, requestCacheLife.revalidate);\n }\n if (requestCacheLife?.expire !== undefined) {\n // cacheLife() supplies the effective hard-expire ceiling for this render,\n // so it replaces the config fallback instead of min-merging with it.\n expireSeconds = requestCacheLife.expire;\n }\n\n return { expireSeconds, revalidateSeconds };\n}\n\n/**\n * Wraps an RSC response body to report invalid dynamic usage errors after the\n * stream is fully consumed. In dev mode, errors from cookies()/headers() inside\n * \"use cache\" may be caught by user try/catch and silently swallowed — this\n * wrapper waits for the stream to drain and surfaces any recorded error to the\n * terminal (and, via HMR, the browser dev overlay).\n * Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n */\nfunction wrapRscResponseForDevErrorReporting(\n response: Response,\n consumeInvalidDynamicUsageError: () => unknown,\n): Response {\n const originalBody = response.body;\n if (!originalBody) return response;\n\n let consumed = false;\n const onConsumed = () => {\n if (consumed) return;\n consumed = true;\n const error = consumeInvalidDynamicUsageError();\n if (error) {\n console.error(\"[vinext] Invalid dynamic usage:\", error);\n }\n };\n\n const cleanup = new TransformStream<Uint8Array, Uint8Array>({\n flush() {\n onConsumed();\n },\n });\n\n const piped = originalBody.pipeThrough(cleanup);\n const reader = piped.getReader();\n const wrappedStream = new ReadableStream<Uint8Array>({\n pull(controller) {\n return reader.read().then(\n ({ done, value }) => {\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n },\n (streamError) => {\n onConsumed();\n controller.error(streamError);\n },\n );\n },\n cancel(reason) {\n onConsumed();\n return reader.cancel(reason);\n },\n });\n\n return new Response(wrappedStream, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n}\n\nexport async function renderAppPageLifecycle(\n options: RenderAppPageLifecycleOptions,\n): Promise<Response> {\n const preRenderResult = await probeAppPageBeforeRender({\n hasLoadingBoundary: options.hasLoadingBoundary,\n layoutCount: options.layoutCount,\n probeLayoutAt(layoutIndex) {\n return options.probeLayoutAt(layoutIndex);\n },\n probePage() {\n return options.probePage();\n },\n renderLayoutSpecialError(specialError, layoutIndex) {\n return options.renderLayoutSpecialError(specialError, layoutIndex);\n },\n renderPageSpecialError(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n classification: options.classification,\n });\n if (preRenderResult.response) {\n return preRenderResult.response;\n }\n\n const layoutFlags = preRenderResult.layoutFlags;\n\n // Render the CANONICAL element. The outgoing payload carries per-layout\n // static/dynamic flags under `__layoutFlags` so the client can later tell\n // which layouts are safe to skip on subsequent navigations.\n const outgoingElement = buildOutgoingAppPayload({\n element: options.element,\n layoutFlags,\n });\n\n const compileEnd = options.isProduction ? undefined : performance.now();\n const baseOnError = options.createRscOnErrorHandler(options.cleanPathname, options.routePattern);\n const rscErrorTracker = createAppPageRscErrorTracker(baseOnError);\n const rscStream = options.renderToReadableStream(outgoingElement, {\n onError: rscErrorTracker.onRenderError,\n });\n\n let revalidateSeconds = options.revalidateSeconds;\n let expireSeconds = options.expireSeconds;\n const shouldCaptureRscForCacheMetadata =\n (options.isProduction || options.isPrerender === true) &&\n (revalidateSeconds === null || (revalidateSeconds > 0 && revalidateSeconds !== Infinity)) &&\n !options.isForceDynamic;\n const rscCapture = teeAppPageRscStreamForCapture(rscStream, shouldCaptureRscForCacheMetadata);\n const rscForResponse = rscCapture.ssrStream;\n\n // When the fused tee (#981) is active, the sideStream carries both the embed\n // transform AND the raw RSC byte accumulation. For RSC requests, we consume\n // the sideStream directly. For HTML requests, handleSsr creates an embed\n // transform from it and fills capturedRscDataRef. The ref object is threaded\n // through so .value is read lazily after handleSsr completes.\n const capturedRscDataRef: { value: Promise<ArrayBuffer> | null } = { value: null };\n if (rscCapture.sideStream && options.isRscRequest) {\n capturedRscDataRef.value = readAppPageBinaryStream(rscCapture.sideStream);\n }\n\n if (options.isRscRequest) {\n if (options.isPrerender === true) {\n await settleCapturedRscRenderForCacheMetadata(capturedRscDataRef.value);\n ({ expireSeconds, revalidateSeconds } = applyRequestCacheLife({\n expireSeconds,\n requestCacheLife: readRequestCacheLifeForPrerender(options),\n revalidateSeconds,\n }));\n }\n\n const dynamicUsedDuringBuild = options.consumeDynamicUsage();\n const rscResponsePolicy = resolveAppPageRscResponsePolicy({\n dynamicUsedDuringBuild,\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n expireSeconds,\n revalidateSeconds,\n });\n const rscResponse = buildAppPageRscResponse(rscForResponse, {\n middlewareContext: options.middlewareContext,\n mountedSlotsHeader: options.mountedSlotsHeader,\n params: options.params,\n policy: rscResponsePolicy,\n timing: buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n responseKind: \"rsc\",\n }),\n });\n\n // In dev mode, wrap the RSC response body to forward invalid dynamic usage\n // errors after the stream is consumed. This mirrors Next.js behavior where\n // workStore.invalidDynamicUsageError is checked after the accumulated chunks\n // promise resolves (app-render.tsx generateDynamicFlightRenderResultWithStagesInDev).\n // Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n //\n // Note: This only covers RSC responses (client-side navigations). The HTML path\n // (initial page loads) intentionally defers this coverage — the error is still\n // thrown through the RSC pipeline and captured by rscErrorTracker.onRenderError\n // if uncaught by user code. Full parity with Next.js would require checking\n // invalidDynamicUsageError after SSR rendering, which is deferred as out of scope\n // for this PR focused on client-side navigations.\n const devRscResponse =\n !options.isProduction && rscResponse.body && options.consumeInvalidDynamicUsageError\n ? wrapRscResponseForDevErrorReporting(rscResponse, options.consumeInvalidDynamicUsageError)\n : rscResponse;\n\n return finalizeAppPageRscCacheResponse(devRscResponse, {\n capturedRscDataPromise:\n options.isProduction && shouldCaptureRscForCacheMetadata ? capturedRscDataRef.value : null,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n dynamicUsedDuringBuild,\n getPageTags() {\n return options.getPageTags();\n },\n getRequestCacheLife() {\n return options.getRequestCacheLife();\n },\n isrDebug: options.isrDebug,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n mountedSlotsHeader: options.mountedSlotsHeader,\n preserveClientResponseHeaders: rscResponsePolicy.cacheState !== \"MISS\",\n expireSeconds,\n revalidateSeconds,\n waitUntil(promise) {\n options.waitUntil?.(promise);\n },\n });\n }\n\n const fontData = createAppPageFontData({\n getLinks: options.getFontLinks,\n getPreloads: options.getFontPreloads,\n getStyles: options.getFontStyles,\n });\n const fontLinkHeader = buildAppPageFontLinkHeader(fontData.preloads);\n let renderEnd: number | undefined;\n\n const htmlRender = await renderAppPageHtmlStreamWithRecovery({\n onShellRendered() {\n if (!options.isProduction) {\n renderEnd = performance.now();\n }\n },\n renderErrorBoundaryResponse(error) {\n return options.renderErrorBoundaryResponse(error);\n },\n async renderHtmlStream() {\n const ssrHandler = await options.loadSsrHandler();\n return renderAppPageHtmlStream({\n capturedRscDataRef,\n fontData,\n navigationContext: options.getNavigationContext(),\n rscStream: rscForResponse,\n scriptNonce: options.scriptNonce,\n sideStream: rscCapture.sideStream,\n ssrHandler,\n });\n },\n renderSpecialErrorResponse(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n });\n if (htmlRender.response) {\n return htmlRender.response;\n }\n const htmlStream = htmlRender.htmlStream;\n if (!htmlStream) {\n throw new Error(\"[vinext] Expected an HTML stream when no fallback response was returned\");\n }\n\n if (\n shouldRerenderAppPageWithGlobalError({\n capturedError: rscErrorTracker.getCapturedError(),\n hasLocalBoundary: options.routeHasLocalBoundary,\n })\n ) {\n const cleanResponse = await options.renderErrorBoundaryResponse(\n rscErrorTracker.getCapturedError(),\n );\n if (cleanResponse) {\n return cleanResponse;\n }\n }\n\n // Eagerly read values that must be captured before the stream is consumed.\n if (options.isPrerender === true) {\n await settleCapturedRscRenderForCacheMetadata(capturedRscDataRef.value);\n ({ expireSeconds, revalidateSeconds } = applyRequestCacheLife({\n expireSeconds,\n requestCacheLife: readRequestCacheLifeForPrerender(options),\n revalidateSeconds,\n }));\n }\n const draftCookie = options.getDraftModeCookieHeader();\n const dynamicUsedDuringRender = options.consumeDynamicUsage();\n\n // Defer clearRequestContext() until the HTML stream is fully consumed by the\n // HTTP layer. The RSC/SSR pipeline is lazy — Server Components execute while\n // the response body is being pulled, not when the stream handle is returned.\n // Clearing the context synchronously here would race those executions, causing\n // headers()/cookies() to see a null context on warm (module-cached) requests.\n // See: https://github.com/cloudflare/vinext/issues/660\n const safeHtmlStream = deferUntilStreamConsumed(htmlStream, () => {\n options.clearRequestContext();\n });\n\n const htmlResponsePolicy = resolveAppPageHtmlResponsePolicy({\n dynamicUsedDuringRender,\n hasScriptNonce: Boolean(options.scriptNonce),\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n expireSeconds,\n revalidateSeconds,\n });\n const htmlResponseTiming = buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n renderEnd,\n responseKind: \"html\",\n });\n\n const shouldSpeculativelyWriteCache =\n options.isProduction &&\n shouldCaptureRscForCacheMetadata &&\n revalidateSeconds === null &&\n !options.isDynamicError &&\n !options.isForceStatic &&\n !options.scriptNonce &&\n !dynamicUsedDuringRender;\n\n if (htmlResponsePolicy.shouldWriteToCache || shouldSpeculativelyWriteCache) {\n const isrResponse = buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n\n if (options.isPrerender === true) {\n return isrResponse;\n }\n\n return finalizeAppPageHtmlCacheResponse(isrResponse, {\n capturedRscDataPromise: capturedRscDataRef.value,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n getPageTags() {\n return options.getPageTags();\n },\n getRequestCacheLife() {\n return options.getRequestCacheLife();\n },\n isrDebug: options.isrDebug,\n isrHtmlKey: options.isrHtmlKey,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n preserveClientResponseHeaders: !htmlResponsePolicy.shouldWriteToCache,\n expireSeconds,\n revalidateSeconds,\n waitUntil(cachePromise) {\n options.waitUntil?.(cachePromise);\n },\n });\n }\n\n return buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n}\n\nasync function settleCapturedRscRenderForCacheMetadata(\n capturedRscDataPromise: Promise<ArrayBuffer> | null,\n): Promise<void> {\n if (!capturedRscDataPromise) {\n return;\n }\n\n try {\n await capturedRscDataPromise;\n } catch {\n // The response stream and cache-write path own render error propagation.\n // This pre-read only makes \"use cache\" metadata available before headers\n // and ISR seed metadata are finalized.\n }\n}\n"],"mappings":";;;;;;;AA6GA,SAAS,oBACP,SAKmC;AACnC,KAAI,QAAQ,aACV;AAGF,QAAO;EACL,YAAY,QAAQ;EACpB,cAAc,QAAQ;EACtB,WAAW,QAAQ;EACnB,cAAc,QAAQ;EACvB;;AAGH,SAAS,iCACP,SACgC;AAIhC,QAAO,QAAQ,wBAAwB,IAAI,QAAQ,qBAAqB;;AAG1E,SAAS,sBAAsB,SAIkC;CAC/D,IAAI,oBAAoB,QAAQ;CAChC,IAAI,gBAAgB,QAAQ;CAC5B,MAAM,mBAAmB,QAAQ;AAEjC,KAAI,kBAAkB,eAAe,KAAA,EACnC,qBACE,sBAAsB,OAClB,iBAAiB,aACjB,KAAK,IAAI,mBAAmB,iBAAiB,WAAW;AAEhE,KAAI,kBAAkB,WAAW,KAAA,EAG/B,iBAAgB,iBAAiB;AAGnC,QAAO;EAAE;EAAe;EAAmB;;;;;;;;;;AAW7C,SAAS,oCACP,UACA,iCACU;CACV,MAAM,eAAe,SAAS;AAC9B,KAAI,CAAC,aAAc,QAAO;CAE1B,IAAI,WAAW;CACf,MAAM,mBAAmB;AACvB,MAAI,SAAU;AACd,aAAW;EACX,MAAM,QAAQ,iCAAiC;AAC/C,MAAI,MACF,SAAQ,MAAM,mCAAmC,MAAM;;CAI3D,MAAM,UAAU,IAAI,gBAAwC,EAC1D,QAAQ;AACN,cAAY;IAEf,CAAC;CAGF,MAAM,SADQ,aAAa,YAAY,QAAQ,CAC1B,WAAW;CAChC,MAAM,gBAAgB,IAAI,eAA2B;EACnD,KAAK,YAAY;AACf,UAAO,OAAO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1D;EACA,gBAAgB,QAAQ,QAAQ,YAAY;EAC5C,gBAAgB,QAAQ;EACxB,gBAAgB,QAAQ;EACxB,eAAe,QAAQ;EACvB,cAAc,QAAQ;EACtB;EACA;EACD,CAAC;CACF,MAAM,qBAAqB,oBAAoB;EAC7C;EACA,cAAc,QAAQ;EACtB,cAAc,QAAQ;EACtB;EACA,cAAc;EACf,CAAC;CAEF,MAAM,gCACJ,QAAQ,gBACR,oCACA,sBAAsB,QACtB,CAAC,QAAQ,kBACT,CAAC,QAAQ,iBACT,CAAC,QAAQ,eACT,CAAC;AAEH,KAAI,mBAAmB,sBAAsB,+BAA+B;EAC1E,MAAM,cAAc,yBAAyB,gBAAgB;GAC3D;GACA;GACA,mBAAmB,QAAQ;GAC3B,QAAQ;GACR,QAAQ;GACT,CAAC;AAEF,MAAI,QAAQ,gBAAgB,KAC1B,QAAO;AAGT,SAAO,iCAAiC,aAAa;GACnD,wBAAwB,mBAAmB;GAC3C,eAAe,QAAQ;GACvB,qBAAqB,QAAQ;GAC7B,cAAc;AACZ,WAAO,QAAQ,aAAa;;GAE9B,sBAAsB;AACpB,WAAO,QAAQ,qBAAqB;;GAEtC,UAAU,QAAQ;GAClB,YAAY,QAAQ;GACpB,WAAW,QAAQ;GACnB,QAAQ,QAAQ;GAChB,+BAA+B,CAAC,mBAAmB;GACnD;GACA;GACA,UAAU,cAAc;AACtB,YAAQ,YAAY,aAAa;;GAEpC,CAAC;;AAGJ,QAAO,yBAAyB,gBAAgB;EAC9C;EACA;EACA,mBAAmB,QAAQ;EAC3B,QAAQ;EACR,QAAQ;EACT,CAAC;;AAGJ,eAAe,wCACb,wBACe;AACf,KAAI,CAAC,uBACH;AAGF,KAAI;AACF,QAAM;SACA"}
|
|
1
|
+
{"version":3,"file":"app-page-render.js","names":[],"sources":["../../src/server/app-page-render.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { CachedAppPageValue } from \"vinext/shims/cache\";\nimport { AppElementsWire, isAppElementsRecord, type AppOutgoingElements } from \"./app-elements.js\";\nimport {\n finalizeAppPageHtmlCacheResponse,\n finalizeAppPageRscCacheResponse,\n} from \"./app-page-cache.js\";\nimport {\n buildAppPageFontLinkHeader,\n readAppPageBinaryStream,\n resolveAppPageSpecialError,\n teeAppPageRscStreamForCapture,\n type AppPageFontPreload,\n type AppPageSpecialError,\n type LayoutClassificationOptions,\n} from \"./app-page-execution.js\";\nimport { probeAppPageBeforeRender } from \"./app-page-probe.js\";\nimport {\n buildAppPageHtmlResponse,\n buildAppPageRscResponse,\n resolveAppPageHtmlResponsePolicy,\n resolveAppPageRscResponsePolicy,\n type AppPageMiddlewareContext,\n type AppPageResponseTiming,\n} from \"./app-page-response.js\";\nimport {\n createAppPageFontData,\n createAppPageRscErrorTracker,\n deferUntilStreamConsumed,\n renderAppPageHtmlStream,\n renderAppPageHtmlStreamWithRecovery,\n shouldRerenderAppPageWithGlobalError,\n type AppPageSsrHandler,\n} from \"./app-page-stream.js\";\nimport {\n createArtifactCompatibilityEnvelope,\n createArtifactCompatibilityGraphVersion,\n type ArtifactCompatibilityEnvelope,\n} from \"./artifact-compatibility.js\";\n\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\ntype AppPageDebugLogger = (event: string, detail: string) => void;\ntype AppPageCacheSetter = (\n key: string,\n data: CachedAppPageValue,\n revalidateSeconds: number,\n tags: string[],\n expireSeconds?: number,\n) => Promise<void>;\n\ntype AppPageRequestCacheLife = {\n revalidate?: number;\n expire?: number;\n};\n\ntype RenderAppPageLifecycleOptions = {\n cleanPathname: string;\n clearRequestContext: () => void;\n consumeDynamicUsage: () => boolean;\n /** Read and clear any invalid dynamic usage error recorded during render (dev-only). */\n consumeInvalidDynamicUsageError?: () => unknown;\n createRscOnErrorHandler: (pathname: string, routePath: string) => AppPageBoundaryOnError;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n getNavigationContext: () => unknown;\n getPageTags: () => string[];\n getRequestCacheLife: () => AppPageRequestCacheLife | null;\n peekRequestCacheLife?: () => AppPageRequestCacheLife | null;\n getDraftModeCookieHeader: () => string | null | undefined;\n handlerStart: number;\n hasLoadingBoundary: boolean;\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isPrerender?: boolean;\n isProduction: boolean;\n isRscRequest: boolean;\n isrDebug?: AppPageDebugLogger;\n isrHtmlKey: (pathname: string) => string;\n isrRscKey: (pathname: string, mountedSlotsHeader?: string | null) => string;\n isrSet: AppPageCacheSetter;\n layoutCount: number;\n loadSsrHandler: () => Promise<AppPageSsrHandler>;\n middlewareContext: AppPageMiddlewareContext;\n params: Record<string, unknown>;\n probeLayoutAt: (layoutIndex: number) => unknown;\n probePage: () => unknown;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n renderErrorBoundaryResponse: (error: unknown) => Promise<Response | null>;\n renderLayoutSpecialError: (\n specialError: AppPageSpecialError,\n layoutIndex: number,\n ) => Promise<Response>;\n renderPageSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n renderToReadableStream: (\n element: ReactNode | AppOutgoingElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n routeHasLocalBoundary: boolean;\n routePattern: string;\n runWithSuppressedHookWarning<T>(probe: () => Promise<T>): Promise<T>;\n scriptNonce?: string;\n mountedSlotsHeader?: string | null;\n waitUntil?: (promise: Promise<void>) => void;\n element: ReactNode | Readonly<Record<string, ReactNode>>;\n classification?: LayoutClassificationOptions | null;\n};\n\nfunction buildResponseTiming(\n options: Pick<RenderAppPageLifecycleOptions, \"handlerStart\" | \"isProduction\"> & {\n compileEnd?: number;\n renderEnd?: number;\n responseKind: AppPageResponseTiming[\"responseKind\"];\n },\n): AppPageResponseTiming | undefined {\n if (options.isProduction) {\n return undefined;\n }\n\n return {\n compileEnd: options.compileEnd,\n handlerStart: options.handlerStart,\n renderEnd: options.renderEnd,\n responseKind: options.responseKind,\n };\n}\n\nfunction readRequestCacheLifeForPrerender(\n options: Pick<RenderAppPageLifecycleOptions, \"getRequestCacheLife\" | \"peekRequestCacheLife\">,\n): AppPageRequestCacheLife | null {\n // Prefer the non-destructive reader so prerender.ts can consume metadata\n // after the handler returns. The consume fallback supports older entry glue\n // and is only safe because this path reads at most once per prerender.\n return options.peekRequestCacheLife?.() ?? options.getRequestCacheLife();\n}\n\nfunction applyRequestCacheLife(options: {\n expireSeconds?: number;\n requestCacheLife: AppPageRequestCacheLife | null;\n revalidateSeconds: number | null;\n}): { expireSeconds?: number; revalidateSeconds: number | null } {\n let revalidateSeconds = options.revalidateSeconds;\n let expireSeconds = options.expireSeconds;\n const requestCacheLife = options.requestCacheLife;\n\n if (requestCacheLife?.revalidate !== undefined) {\n revalidateSeconds =\n revalidateSeconds === null\n ? requestCacheLife.revalidate\n : Math.min(revalidateSeconds, requestCacheLife.revalidate);\n }\n if (requestCacheLife?.expire !== undefined) {\n // cacheLife() supplies the effective hard-expire ceiling for this render,\n // so it replaces the config fallback instead of min-merging with it.\n expireSeconds = requestCacheLife.expire;\n }\n\n return { expireSeconds, revalidateSeconds };\n}\n\nfunction readRootBoundaryId(element: Readonly<Record<string, unknown>>): string | null {\n const rootLayoutTreePath = element[AppElementsWire.keys.rootLayout];\n return typeof rootLayoutTreePath === \"string\" ? rootLayoutTreePath : null;\n}\n\nfunction createAppPageArtifactCompatibility(\n element: ReactNode | Readonly<Record<string, ReactNode>>,\n routePattern: string,\n): ArtifactCompatibilityEnvelope | undefined {\n if (!isAppElementsRecord(element)) {\n return undefined;\n }\n\n const rootBoundaryId = readRootBoundaryId(element);\n return createArtifactCompatibilityEnvelope({\n graphVersion: createArtifactCompatibilityGraphVersion({\n routePattern,\n rootBoundaryId,\n }),\n deploymentVersion: process.env.__VINEXT_BUILD_ID ?? null,\n rootBoundaryId,\n });\n}\n\n/**\n * Wraps an RSC response body to report invalid dynamic usage errors after the\n * stream is fully consumed. In dev mode, errors from cookies()/headers() inside\n * \"use cache\" may be caught by user try/catch and silently swallowed — this\n * wrapper waits for the stream to drain and surfaces any recorded error to the\n * terminal (and, via HMR, the browser dev overlay).\n * Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n */\nfunction wrapRscResponseForDevErrorReporting(\n response: Response,\n consumeInvalidDynamicUsageError: () => unknown,\n): Response {\n const originalBody = response.body;\n if (!originalBody) return response;\n\n let consumed = false;\n const onConsumed = () => {\n if (consumed) return;\n consumed = true;\n const error = consumeInvalidDynamicUsageError();\n if (error) {\n console.error(\"[vinext] Invalid dynamic usage:\", error);\n }\n };\n\n const cleanup = new TransformStream<Uint8Array, Uint8Array>({\n flush() {\n onConsumed();\n },\n });\n\n const piped = originalBody.pipeThrough(cleanup);\n const reader = piped.getReader();\n const wrappedStream = new ReadableStream<Uint8Array>({\n pull(controller) {\n return reader.read().then(\n ({ done, value }) => {\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n },\n (streamError) => {\n onConsumed();\n controller.error(streamError);\n },\n );\n },\n cancel(reason) {\n onConsumed();\n return reader.cancel(reason);\n },\n });\n\n return new Response(wrappedStream, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n}\n\nexport async function renderAppPageLifecycle(\n options: RenderAppPageLifecycleOptions,\n): Promise<Response> {\n const preRenderResult = await probeAppPageBeforeRender({\n hasLoadingBoundary: options.hasLoadingBoundary,\n layoutCount: options.layoutCount,\n probeLayoutAt(layoutIndex) {\n return options.probeLayoutAt(layoutIndex);\n },\n probePage() {\n return options.probePage();\n },\n renderLayoutSpecialError(specialError, layoutIndex) {\n return options.renderLayoutSpecialError(specialError, layoutIndex);\n },\n renderPageSpecialError(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n classification: options.classification,\n });\n if (preRenderResult.response) {\n return preRenderResult.response;\n }\n\n const layoutFlags = preRenderResult.layoutFlags;\n\n // Render the CANONICAL element. The outgoing payload carries per-layout\n // static/dynamic flags under `__layoutFlags` so the client can later tell\n // which layouts are safe to skip on subsequent navigations.\n const artifactCompatibility = createAppPageArtifactCompatibility(\n options.element,\n options.routePattern,\n );\n const outgoingElement = AppElementsWire.encodeOutgoingPayload({\n element: options.element,\n layoutFlags,\n ...(artifactCompatibility ? { artifactCompatibility } : {}),\n });\n\n const compileEnd = options.isProduction ? undefined : performance.now();\n const baseOnError = options.createRscOnErrorHandler(options.cleanPathname, options.routePattern);\n const rscErrorTracker = createAppPageRscErrorTracker(baseOnError);\n const rscStream = options.renderToReadableStream(outgoingElement, {\n onError: rscErrorTracker.onRenderError,\n });\n\n let revalidateSeconds = options.revalidateSeconds;\n let expireSeconds = options.expireSeconds;\n const shouldCaptureRscForCacheMetadata =\n (options.isProduction || options.isPrerender === true) &&\n (revalidateSeconds === null || (revalidateSeconds > 0 && revalidateSeconds !== Infinity)) &&\n !options.isForceDynamic;\n const rscCapture = teeAppPageRscStreamForCapture(rscStream, shouldCaptureRscForCacheMetadata);\n const rscForResponse = rscCapture.ssrStream;\n\n // When the fused tee (#981) is active, the sideStream carries both the embed\n // transform AND the raw RSC byte accumulation. For RSC requests, we consume\n // the sideStream directly. For HTML requests, handleSsr creates an embed\n // transform from it and fills capturedRscDataRef. The ref object is threaded\n // through so .value is read lazily after handleSsr completes.\n const capturedRscDataRef: { value: Promise<ArrayBuffer> | null } = { value: null };\n if (rscCapture.sideStream && options.isRscRequest) {\n capturedRscDataRef.value = readAppPageBinaryStream(rscCapture.sideStream);\n }\n\n if (options.isRscRequest) {\n if (options.isPrerender === true) {\n await settleCapturedRscRenderForCacheMetadata(capturedRscDataRef.value);\n ({ expireSeconds, revalidateSeconds } = applyRequestCacheLife({\n expireSeconds,\n requestCacheLife: readRequestCacheLifeForPrerender(options),\n revalidateSeconds,\n }));\n }\n\n const dynamicUsedDuringBuild = options.consumeDynamicUsage();\n const rscResponsePolicy = resolveAppPageRscResponsePolicy({\n dynamicUsedDuringBuild,\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n expireSeconds,\n revalidateSeconds,\n });\n const rscResponse = buildAppPageRscResponse(rscForResponse, {\n middlewareContext: options.middlewareContext,\n mountedSlotsHeader: options.mountedSlotsHeader,\n params: options.params,\n policy: rscResponsePolicy,\n timing: buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n responseKind: \"rsc\",\n }),\n });\n\n // In dev mode, wrap the RSC response body to forward invalid dynamic usage\n // errors after the stream is consumed. This mirrors Next.js behavior where\n // workStore.invalidDynamicUsageError is checked after the accumulated chunks\n // promise resolves (app-render.tsx generateDynamicFlightRenderResultWithStagesInDev).\n // Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n //\n // Note: This only covers RSC responses (client-side navigations). The HTML path\n // (initial page loads) intentionally defers this coverage — the error is still\n // thrown through the RSC pipeline and captured by rscErrorTracker.onRenderError\n // if uncaught by user code. Full parity with Next.js would require checking\n // invalidDynamicUsageError after SSR rendering, which is deferred as out of scope\n // for this PR focused on client-side navigations.\n const devRscResponse =\n !options.isProduction && rscResponse.body && options.consumeInvalidDynamicUsageError\n ? wrapRscResponseForDevErrorReporting(rscResponse, options.consumeInvalidDynamicUsageError)\n : rscResponse;\n\n return finalizeAppPageRscCacheResponse(devRscResponse, {\n capturedRscDataPromise:\n options.isProduction && shouldCaptureRscForCacheMetadata ? capturedRscDataRef.value : null,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n dynamicUsedDuringBuild,\n getPageTags() {\n return options.getPageTags();\n },\n getRequestCacheLife() {\n return options.getRequestCacheLife();\n },\n isrDebug: options.isrDebug,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n mountedSlotsHeader: options.mountedSlotsHeader,\n preserveClientResponseHeaders: rscResponsePolicy.cacheState !== \"MISS\",\n expireSeconds,\n revalidateSeconds,\n waitUntil(promise) {\n options.waitUntil?.(promise);\n },\n });\n }\n\n const fontData = createAppPageFontData({\n getLinks: options.getFontLinks,\n getPreloads: options.getFontPreloads,\n getStyles: options.getFontStyles,\n });\n const fontLinkHeader = buildAppPageFontLinkHeader(fontData.preloads);\n let renderEnd: number | undefined;\n\n const htmlRender = await renderAppPageHtmlStreamWithRecovery({\n onShellRendered() {\n if (!options.isProduction) {\n renderEnd = performance.now();\n }\n },\n renderErrorBoundaryResponse(error) {\n return options.renderErrorBoundaryResponse(error);\n },\n async renderHtmlStream() {\n const ssrHandler = await options.loadSsrHandler();\n return renderAppPageHtmlStream({\n capturedRscDataRef,\n fontData,\n navigationContext: options.getNavigationContext(),\n rscStream: rscForResponse,\n scriptNonce: options.scriptNonce,\n sideStream: rscCapture.sideStream,\n ssrHandler,\n });\n },\n renderSpecialErrorResponse(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n });\n if (htmlRender.response) {\n return htmlRender.response;\n }\n const htmlStream = htmlRender.htmlStream;\n if (!htmlStream) {\n throw new Error(\"[vinext] Expected an HTML stream when no fallback response was returned\");\n }\n\n // Routes with a route-level Suspense boundary (loading.tsx) skip the page\n // probe — the page render happens once, inside the RSC stream. Mirror\n // Next.js's `app-render.tsx:4293` catch shape: by the time the SSR shell\n // promise has resolved, any redirect()/notFound() throw whose async work\n // settles in microtasks during shell rendering has already fired through\n // React's onError and been captured by the tracker. Convert that to a\n // 307/404 before any bytes are flushed.\n //\n // Late rejections — ones that settle after macrotask boundaries (real\n // I/O, setTimeout, etc.) — fall through to the streamed body, exactly\n // as Next.js does. The digest survives in the Flight payload for the\n // client router to consume.\n if (options.hasLoadingBoundary) {\n const captured = rscErrorTracker.getCapturedSpecialError();\n if (captured) {\n const specialError = resolveAppPageSpecialError(captured);\n if (specialError) {\n void htmlStream.cancel().catch(() => {});\n return options.renderPageSpecialError(specialError);\n }\n }\n }\n\n if (\n shouldRerenderAppPageWithGlobalError({\n capturedError: rscErrorTracker.getCapturedError(),\n hasLocalBoundary: options.routeHasLocalBoundary,\n })\n ) {\n const cleanResponse = await options.renderErrorBoundaryResponse(\n rscErrorTracker.getCapturedError(),\n );\n if (cleanResponse) {\n return cleanResponse;\n }\n }\n\n // Eagerly read values that must be captured before the stream is consumed.\n if (options.isPrerender === true) {\n await settleCapturedRscRenderForCacheMetadata(capturedRscDataRef.value);\n ({ expireSeconds, revalidateSeconds } = applyRequestCacheLife({\n expireSeconds,\n requestCacheLife: readRequestCacheLifeForPrerender(options),\n revalidateSeconds,\n }));\n }\n const draftCookie = options.getDraftModeCookieHeader();\n const dynamicUsedDuringRender = options.consumeDynamicUsage();\n let dynamicUsedBeforeContextCleanup = dynamicUsedDuringRender;\n\n // Defer clearRequestContext() until the HTML stream is fully consumed by the\n // HTTP layer. The RSC/SSR pipeline is lazy — Server Components execute while\n // the response body is being pulled, not when the stream handle is returned.\n // Clearing the context synchronously here would race those executions, causing\n // headers()/cookies() to see a null context on warm (module-cached) requests.\n // See: https://github.com/cloudflare/vinext/issues/660\n const safeHtmlStream = deferUntilStreamConsumed(htmlStream, () => {\n dynamicUsedBeforeContextCleanup =\n dynamicUsedBeforeContextCleanup || options.consumeDynamicUsage();\n options.clearRequestContext();\n });\n\n const htmlResponsePolicy = resolveAppPageHtmlResponsePolicy({\n dynamicUsedDuringRender,\n hasScriptNonce: Boolean(options.scriptNonce),\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n expireSeconds,\n revalidateSeconds,\n });\n const htmlResponseTiming = buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n renderEnd,\n responseKind: \"html\",\n });\n\n const shouldSpeculativelyWriteCache =\n options.isProduction &&\n shouldCaptureRscForCacheMetadata &&\n revalidateSeconds === null &&\n !options.isDynamicError &&\n !options.isForceStatic &&\n !options.scriptNonce &&\n !dynamicUsedDuringRender;\n\n if (htmlResponsePolicy.shouldWriteToCache || shouldSpeculativelyWriteCache) {\n const isrResponse = buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n\n if (options.isPrerender === true) {\n return isrResponse;\n }\n\n return finalizeAppPageHtmlCacheResponse(isrResponse, {\n capturedDynamicUsageBeforeContextCleanup() {\n return dynamicUsedBeforeContextCleanup;\n },\n capturedRscDataPromise: capturedRscDataRef.value,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n getPageTags() {\n return options.getPageTags();\n },\n getRequestCacheLife() {\n return options.getRequestCacheLife();\n },\n isrDebug: options.isrDebug,\n isrHtmlKey: options.isrHtmlKey,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n preserveClientResponseHeaders: !htmlResponsePolicy.shouldWriteToCache,\n expireSeconds,\n revalidateSeconds,\n waitUntil(cachePromise) {\n options.waitUntil?.(cachePromise);\n },\n });\n }\n\n return buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n}\n\nasync function settleCapturedRscRenderForCacheMetadata(\n capturedRscDataPromise: Promise<ArrayBuffer> | null,\n): Promise<void> {\n if (!capturedRscDataPromise) {\n return;\n }\n\n try {\n await capturedRscDataPromise;\n } catch {\n // The response stream and cache-write path own render error propagation.\n // This pre-read only makes \"use cache\" metadata available before headers\n // and ISR seed metadata are finalized.\n }\n}\n"],"mappings":";;;;;;;;;AAkHA,SAAS,oBACP,SAKmC;AACnC,KAAI,QAAQ,aACV;AAGF,QAAO;EACL,YAAY,QAAQ;EACpB,cAAc,QAAQ;EACtB,WAAW,QAAQ;EACnB,cAAc,QAAQ;EACvB;;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yB,gBAAgB;EAC9C;EACA;EACA,mBAAmB,QAAQ;EAC3B,QAAQ;EACR,QAAQ;EACT,CAAC;;AAGJ,eAAe,wCACb,wBACe;AACf,KAAI,CAAC,uBACH;AAGF,KAAI;AACF,QAAM;SACA"}
|
|
@@ -17,7 +17,6 @@ type ValidateAppPageDynamicParamsOptions = {
|
|
|
17
17
|
enforceStaticParamsOnly: boolean;
|
|
18
18
|
generateStaticParams?: GenerateStaticParams | GenerateStaticParamsSource | readonly (GenerateStaticParams | GenerateStaticParamsSource | null | undefined)[] | null;
|
|
19
19
|
isDynamicRoute: boolean;
|
|
20
|
-
logGenerateStaticParamsError?: (error: unknown) => void;
|
|
21
20
|
params: AppPageParams;
|
|
22
21
|
};
|
|
23
22
|
type ResolveAppPageGenerateStaticParamsSourcesOptions = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { notFoundResponse } from "./http-error-responses.js";
|
|
1
2
|
import { getAppPageSegmentParamName } from "./app-page-params.js";
|
|
2
3
|
//#region src/server/app-page-request.ts
|
|
3
4
|
function pickRouteParams(matchedParams, routeParamNames) {
|
|
@@ -61,18 +62,14 @@ async function validateAppPageDynamicParams(options) {
|
|
|
61
62
|
const generateStaticParamsSources = normalizeGenerateStaticParams(options.generateStaticParams);
|
|
62
63
|
if (generateStaticParamsSources.length === 0) {
|
|
63
64
|
options.clearRequestContext();
|
|
64
|
-
return
|
|
65
|
+
return notFoundResponse();
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return new Response("Not Found", { status: 404 });
|
|
72
|
-
}
|
|
67
|
+
for (const source of generateStaticParamsSources) {
|
|
68
|
+
const staticParams = await source.generateStaticParams({ params: pickRouteParams(options.params, source.parentParamNames) });
|
|
69
|
+
if (Array.isArray(staticParams) && !areStaticParamsAllowed(options.params, staticParams)) {
|
|
70
|
+
options.clearRequestContext();
|
|
71
|
+
return notFoundResponse();
|
|
73
72
|
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
options.logGenerateStaticParamsError?.(error);
|
|
76
73
|
}
|
|
77
74
|
return null;
|
|
78
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-request.js","names":[],"sources":["../../src/server/app-page-request.ts"],"sourcesContent":["import type { AppPageSpecialError } from \"./app-page-execution.js\";\nimport { getAppPageSegmentParamName } from \"./app-page-params.js\";\n\ntype AppPageParams = Record<string, string | string[]>;\ntype GenerateStaticParams = (args: { params: AppPageParams }) => unknown;\n\ntype GenerateStaticParamsModule = {\n generateStaticParams?: GenerateStaticParams | null;\n};\n\ntype GenerateStaticParamsSource = {\n generateStaticParams: GenerateStaticParams;\n parentParamNames: readonly string[];\n};\n\nexport type ValidateAppPageDynamicParamsOptions = {\n clearRequestContext: () => void;\n enforceStaticParamsOnly: boolean;\n generateStaticParams?:\n | GenerateStaticParams\n | GenerateStaticParamsSource\n | readonly (GenerateStaticParams | GenerateStaticParamsSource | null | undefined)[]\n | null;\n isDynamicRoute: boolean;\n logGenerateStaticParamsError?: (error: unknown) => void;\n params: AppPageParams;\n};\n\ntype ResolveAppPageGenerateStaticParamsSourcesOptions = {\n layouts?: readonly (GenerateStaticParamsModule | null | undefined)[];\n layoutTreePositions?: readonly number[];\n page?: GenerateStaticParamsModule | null;\n routeSegments: readonly string[];\n};\n\ntype BuildAppPageElementOptions<TElement> = {\n buildPageElement: () => Promise<TElement>;\n renderErrorBoundaryPage: (error: unknown) => Promise<Response | null>;\n renderSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => AppPageSpecialError | null;\n};\n\ntype BuildAppPageElementResult<TElement> = {\n element: TElement | null;\n response: Response | null;\n};\n\ntype AppPageInterceptMatch<TPage = unknown> = {\n matchedParams: AppPageParams;\n page: TPage;\n slotKey: string;\n sourceRouteIndex: number;\n};\n\ntype ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts;\n matchedParams: AppPageParams;\n sourceParams: AppPageParams;\n sourceRoute: TRoute;\n};\n\ntype AppPageInterceptState<TRoute, TPage> =\n | { kind: \"none\" }\n | { kind: \"current-route\"; intercept: AppPageInterceptMatch<TPage> }\n | { kind: \"source-route\"; intercept: AppPageInterceptMatch<TPage>; sourceRoute: TRoute };\n\ntype ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentParams: AppPageParams;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n navigationParams: AppPageParams;\n params: AppPageParams;\n route: TRoute;\n};\n\ntype ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement> = {\n buildPageElement: (\n route: TRoute,\n params: AppPageParams,\n interceptOpts: TInterceptOpts | undefined,\n searchParams: URLSearchParams,\n ) => Promise<TElement>;\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n renderInterceptResponse: (route: TRoute, element: TElement) => Promise<Response> | Response;\n searchParams: URLSearchParams;\n setNavigationContext: (context: {\n params: AppPageParams;\n pathname: string;\n searchParams: URLSearchParams;\n }) => void;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptResult<TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n response: Response | null;\n};\n\nfunction pickRouteParams(\n matchedParams: AppPageParams,\n routeParamNames: readonly string[],\n): AppPageParams {\n const params: AppPageParams = {};\n\n for (const paramName of routeParamNames) {\n const value = matchedParams[paramName];\n if (value !== undefined) {\n params[paramName] = value;\n }\n }\n\n return params;\n}\n\nfunction collectParentParamNames(\n routeSegments: readonly string[],\n boundaryPosition: number,\n): string[] {\n const limit = Math.max(0, Math.min(boundaryPosition, routeSegments.length));\n const names: string[] = [];\n\n for (const segment of routeSegments.slice(0, limit)) {\n const name = getAppPageSegmentParamName(segment);\n if (name && !names.includes(name)) {\n names.push(name);\n }\n }\n\n return names;\n}\n\nfunction getLayoutGenerateStaticParamsBoundary(layoutTreePosition: number | undefined): number {\n // A layout at app/[id]/layout.tsx has tree position 1, but its\n // generateStaticParams belongs to the [id] segment and receives only parent\n // params from segments before [id].\n return (layoutTreePosition ?? 0) - 1;\n}\n\nexport function resolveAppPageGenerateStaticParamsSources(\n options: ResolveAppPageGenerateStaticParamsSourcesOptions,\n): GenerateStaticParamsSource[] {\n const sources: GenerateStaticParamsSource[] = [];\n\n options.layouts?.forEach((layout, index) => {\n if (typeof layout?.generateStaticParams !== \"function\") return;\n\n sources.push({\n generateStaticParams: layout.generateStaticParams,\n parentParamNames: collectParentParamNames(\n options.routeSegments,\n getLayoutGenerateStaticParamsBoundary(options.layoutTreePositions?.[index]),\n ),\n });\n });\n\n if (typeof options.page?.generateStaticParams === \"function\") {\n sources.push({\n generateStaticParams: options.page.generateStaticParams,\n parentParamNames: collectParentParamNames(\n options.routeSegments,\n Math.max(0, options.routeSegments.length - 1),\n ),\n });\n }\n\n return sources;\n}\n\nfunction areStaticParamsAllowed(\n params: AppPageParams,\n staticParams: readonly Record<string, unknown>[],\n): boolean {\n const paramKeys = Object.keys(params);\n\n return staticParams.some((staticParamSet) =>\n paramKeys.every((key) => {\n const value = params[key];\n const staticValue = staticParamSet[key];\n\n // Parent params may not appear in the leaf route's returned set because\n // Next.js passes them top-down through nested generateStaticParams calls.\n if (staticValue === undefined) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }\n\n if (\n typeof staticValue === \"string\" ||\n typeof staticValue === \"number\" ||\n typeof staticValue === \"boolean\"\n ) {\n return String(value) === String(staticValue);\n }\n\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }),\n );\n}\n\nfunction normalizeGenerateStaticParams(\n generateStaticParams: ValidateAppPageDynamicParamsOptions[\"generateStaticParams\"],\n): GenerateStaticParamsSource[] {\n const sources = Array.isArray(generateStaticParams)\n ? generateStaticParams\n : [generateStaticParams];\n\n return sources.flatMap((source) => {\n if (typeof source === \"function\") {\n return [{ generateStaticParams: source, parentParamNames: [] }];\n }\n\n if (typeof source?.generateStaticParams === \"function\") {\n return [source];\n }\n\n return [];\n });\n}\n\nexport async function validateAppPageDynamicParams(\n options: ValidateAppPageDynamicParamsOptions,\n): Promise<Response | null> {\n if (!options.enforceStaticParamsOnly || !options.isDynamicRoute) {\n return null;\n }\n\n const generateStaticParamsSources = normalizeGenerateStaticParams(options.generateStaticParams);\n if (generateStaticParamsSources.length === 0) {\n options.clearRequestContext();\n return new Response(\"Not Found\", { status: 404 });\n }\n\n try {\n for (const source of generateStaticParamsSources) {\n const staticParams = await source.generateStaticParams({\n params: pickRouteParams(options.params, source.parentParamNames),\n });\n if (Array.isArray(staticParams) && !areStaticParamsAllowed(options.params, staticParams)) {\n options.clearRequestContext();\n return new Response(\"Not Found\", { status: 404 });\n }\n }\n } catch (error) {\n options.logGenerateStaticParamsError?.(error);\n }\n\n return null;\n}\n\n/**\n * Pure: decides whether the incoming request should re-render an intercepted\n * source-route tree, and if so returns the source route, the source-route's\n * param slice, the full matched param set (the URL params the client sees),\n * and an opaque `interceptOpts` bag for the caller's render pipeline.\n *\n * Returns `null` in three decision-fallthrough cases:\n * - non-RSC requests (server rendering the direct page for a full HTML load)\n * - no intercepting route matches the path\n * - the match's source route IS the current route (the same branch today\n * returns `interceptOpts` for the direct render)\n *\n * Shared by both the GET path (resolveAppPageIntercept, which layers on\n * `setNavigationContext` + element build + Response wrap) and the server-action\n * POST path (entries/app-rsc-entry.ts), which runs its own response pipeline.\n */\nexport function resolveAppPageInterceptMatch<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> | null {\n const interceptState = resolveAppPageInterceptState(options);\n if (interceptState.kind !== \"source-route\") {\n return null;\n }\n\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n matchedParams: interceptState.intercept.matchedParams,\n sourceParams: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n sourceRoute: interceptState.sourceRoute,\n };\n}\n\nfunction resolveAppPageInterceptState<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): AppPageInterceptState<TRoute, TPage> {\n if (!options.isRscRequest) {\n return { kind: \"none\" };\n }\n\n const intercept = options.findIntercept(options.cleanPathname);\n if (!intercept) {\n return { kind: \"none\" };\n }\n\n const sourceRoute = options.getSourceRoute(intercept.sourceRouteIndex);\n if (!sourceRoute) {\n return { kind: \"none\" };\n }\n\n if (sourceRoute === options.currentRoute) {\n return { kind: \"current-route\", intercept };\n }\n\n return { kind: \"source-route\", intercept, sourceRoute };\n}\n\nexport function resolveAppPageActionRerenderTarget<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n navigationParams: interceptState.intercept.matchedParams,\n params: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n route: interceptState.sourceRoute,\n };\n }\n\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n navigationParams: options.currentParams,\n params: options.currentParams,\n route: options.currentRoute,\n };\n}\n\nexport async function resolveAppPageIntercept<TRoute, TPage, TInterceptOpts, TElement>(\n options: ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement>,\n): Promise<ResolveAppPageInterceptResult<TInterceptOpts>> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n options.setNavigationContext({\n params: interceptState.intercept.matchedParams,\n pathname: options.cleanPathname,\n searchParams: options.searchParams,\n });\n const interceptElement = await options.buildPageElement(\n interceptState.sourceRoute,\n pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n options.toInterceptOpts(interceptState.intercept),\n options.searchParams,\n );\n\n return {\n interceptOpts: undefined,\n response: await options.renderInterceptResponse(interceptState.sourceRoute, interceptElement),\n };\n }\n\n // Reproduce the current-route-is-source branch where we still need the opts\n // bag even though we did not render a separate intercepted response.\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n response: null,\n };\n}\n\nexport async function buildAppPageElement<TElement>(\n options: BuildAppPageElementOptions<TElement>,\n): Promise<BuildAppPageElementResult<TElement>> {\n try {\n return {\n element: await options.buildPageElement(),\n response: null,\n };\n } catch (error) {\n const specialError = options.resolveSpecialError(error);\n if (specialError) {\n return {\n element: null,\n response: await options.renderSpecialError(specialError),\n };\n }\n\n const errorBoundaryResponse = await options.renderErrorBoundaryPage(error);\n if (errorBoundaryResponse) {\n return {\n element: null,\n response: errorBoundaryResponse,\n };\n }\n\n throw error;\n }\n}\n"],"mappings":";;AA0HA,SAAS,gBACP,eACA,iBACe;CACf,MAAM,SAAwB,EAAE;AAEhC,MAAK,MAAM,aAAa,iBAAiB;EACvC,MAAM,QAAQ,cAAc;AAC5B,MAAI,UAAU,KAAA,EACZ,QAAO,aAAa;;AAIxB,QAAO;;AAGT,SAAS,wBACP,eACA,kBACU;CACV,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,kBAAkB,cAAc,OAAO,CAAC;CAC3E,MAAM,QAAkB,EAAE;AAE1B,MAAK,MAAM,WAAW,cAAc,MAAM,GAAG,MAAM,EAAE;EACnD,MAAM,OAAO,2BAA2B,QAAQ;AAChD,MAAI,QAAQ,CAAC,MAAM,SAAS,KAAK,CAC/B,OAAM,KAAK,KAAK;;AAIpB,QAAO;;AAGT,SAAS,sCAAsC,oBAAgD;AAI7F,SAAQ,sBAAsB,KAAK;;AAGrC,SAAgB,0CACd,SAC8B;CAC9B,MAAM,UAAwC,EAAE;AAEhD,SAAQ,SAAS,SAAS,QAAQ,UAAU;AAC1C,MAAI,OAAO,QAAQ,yBAAyB,WAAY;AAExD,UAAQ,KAAK;GACX,sBAAsB,OAAO;GAC7B,kBAAkB,wBAChB,QAAQ,eACR,sCAAsC,QAAQ,sBAAsB,OAAO,CAC5E;GAC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BAAmB,aAAa;GACzD;EAGH,MAAM,wBAAwB,MAAM,QAAQ,wBAAwB,MAAM;AAC1E,MAAI,sBACF,QAAO;GACL,SAAS;GACT,UAAU;GACX;AAGH,QAAM"}
|
|
1
|
+
{"version":3,"file":"app-page-request.js","names":[],"sources":["../../src/server/app-page-request.ts"],"sourcesContent":["import type { AppPageSpecialError } from \"./app-page-execution.js\";\nimport { getAppPageSegmentParamName } from \"./app-page-params.js\";\nimport { notFoundResponse } from \"./http-error-responses.js\";\n\ntype AppPageParams = Record<string, string | string[]>;\ntype GenerateStaticParams = (args: { params: AppPageParams }) => unknown;\n\ntype GenerateStaticParamsModule = {\n generateStaticParams?: GenerateStaticParams | null;\n};\n\ntype GenerateStaticParamsSource = {\n generateStaticParams: GenerateStaticParams;\n parentParamNames: readonly string[];\n};\n\nexport type ValidateAppPageDynamicParamsOptions = {\n clearRequestContext: () => void;\n enforceStaticParamsOnly: boolean;\n generateStaticParams?:\n | GenerateStaticParams\n | GenerateStaticParamsSource\n | readonly (GenerateStaticParams | GenerateStaticParamsSource | null | undefined)[]\n | null;\n isDynamicRoute: boolean;\n params: AppPageParams;\n};\n\ntype ResolveAppPageGenerateStaticParamsSourcesOptions = {\n layouts?: readonly (GenerateStaticParamsModule | null | undefined)[];\n layoutTreePositions?: readonly number[];\n page?: GenerateStaticParamsModule | null;\n routeSegments: readonly string[];\n};\n\ntype BuildAppPageElementOptions<TElement> = {\n buildPageElement: () => Promise<TElement>;\n renderErrorBoundaryPage: (error: unknown) => Promise<Response | null>;\n renderSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => AppPageSpecialError | null;\n};\n\ntype BuildAppPageElementResult<TElement> = {\n element: TElement | null;\n response: Response | null;\n};\n\ntype AppPageInterceptMatch<TPage = unknown> = {\n matchedParams: AppPageParams;\n page: TPage;\n slotKey: string;\n sourceRouteIndex: number;\n};\n\ntype ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts;\n matchedParams: AppPageParams;\n sourceParams: AppPageParams;\n sourceRoute: TRoute;\n};\n\ntype AppPageInterceptState<TRoute, TPage> =\n | { kind: \"none\" }\n | { kind: \"current-route\"; intercept: AppPageInterceptMatch<TPage> }\n | { kind: \"source-route\"; intercept: AppPageInterceptMatch<TPage>; sourceRoute: TRoute };\n\ntype ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentParams: AppPageParams;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n navigationParams: AppPageParams;\n params: AppPageParams;\n route: TRoute;\n};\n\ntype ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement> = {\n buildPageElement: (\n route: TRoute,\n params: AppPageParams,\n interceptOpts: TInterceptOpts | undefined,\n searchParams: URLSearchParams,\n ) => Promise<TElement>;\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n renderInterceptResponse: (route: TRoute, element: TElement) => Promise<Response> | Response;\n searchParams: URLSearchParams;\n setNavigationContext: (context: {\n params: AppPageParams;\n pathname: string;\n searchParams: URLSearchParams;\n }) => void;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptResult<TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n response: Response | null;\n};\n\nfunction pickRouteParams(\n matchedParams: AppPageParams,\n routeParamNames: readonly string[],\n): AppPageParams {\n const params: AppPageParams = {};\n\n for (const paramName of routeParamNames) {\n const value = matchedParams[paramName];\n if (value !== undefined) {\n params[paramName] = value;\n }\n }\n\n return params;\n}\n\nfunction collectParentParamNames(\n routeSegments: readonly string[],\n boundaryPosition: number,\n): string[] {\n const limit = Math.max(0, Math.min(boundaryPosition, routeSegments.length));\n const names: string[] = [];\n\n for (const segment of routeSegments.slice(0, limit)) {\n const name = getAppPageSegmentParamName(segment);\n if (name && !names.includes(name)) {\n names.push(name);\n }\n }\n\n return names;\n}\n\nfunction getLayoutGenerateStaticParamsBoundary(layoutTreePosition: number | undefined): number {\n // A layout at app/[id]/layout.tsx has tree position 1, but its\n // generateStaticParams belongs to the [id] segment and receives only parent\n // params from segments before [id].\n return (layoutTreePosition ?? 0) - 1;\n}\n\nexport function resolveAppPageGenerateStaticParamsSources(\n options: ResolveAppPageGenerateStaticParamsSourcesOptions,\n): GenerateStaticParamsSource[] {\n const sources: GenerateStaticParamsSource[] = [];\n\n options.layouts?.forEach((layout, index) => {\n if (typeof layout?.generateStaticParams !== \"function\") return;\n\n sources.push({\n generateStaticParams: layout.generateStaticParams,\n parentParamNames: collectParentParamNames(\n options.routeSegments,\n getLayoutGenerateStaticParamsBoundary(options.layoutTreePositions?.[index]),\n ),\n });\n });\n\n if (typeof options.page?.generateStaticParams === \"function\") {\n sources.push({\n generateStaticParams: options.page.generateStaticParams,\n parentParamNames: collectParentParamNames(\n options.routeSegments,\n Math.max(0, options.routeSegments.length - 1),\n ),\n });\n }\n\n return sources;\n}\n\nfunction areStaticParamsAllowed(\n params: AppPageParams,\n staticParams: readonly Record<string, unknown>[],\n): boolean {\n const paramKeys = Object.keys(params);\n\n return staticParams.some((staticParamSet) =>\n paramKeys.every((key) => {\n const value = params[key];\n const staticValue = staticParamSet[key];\n\n // Parent params may not appear in the leaf route's returned set because\n // Next.js passes them top-down through nested generateStaticParams calls.\n if (staticValue === undefined) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }\n\n if (\n typeof staticValue === \"string\" ||\n typeof staticValue === \"number\" ||\n typeof staticValue === \"boolean\"\n ) {\n return String(value) === String(staticValue);\n }\n\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }),\n );\n}\n\nfunction normalizeGenerateStaticParams(\n generateStaticParams: ValidateAppPageDynamicParamsOptions[\"generateStaticParams\"],\n): GenerateStaticParamsSource[] {\n const sources = Array.isArray(generateStaticParams)\n ? generateStaticParams\n : [generateStaticParams];\n\n return sources.flatMap((source) => {\n if (typeof source === \"function\") {\n return [{ generateStaticParams: source, parentParamNames: [] }];\n }\n\n if (typeof source?.generateStaticParams === \"function\") {\n return [source];\n }\n\n return [];\n });\n}\n\nexport async function validateAppPageDynamicParams(\n options: ValidateAppPageDynamicParamsOptions,\n): Promise<Response | null> {\n if (!options.enforceStaticParamsOnly || !options.isDynamicRoute) {\n return null;\n }\n\n const generateStaticParamsSources = normalizeGenerateStaticParams(options.generateStaticParams);\n if (generateStaticParamsSources.length === 0) {\n options.clearRequestContext();\n return notFoundResponse();\n }\n\n for (const source of generateStaticParamsSources) {\n const staticParams = await source.generateStaticParams({\n params: pickRouteParams(options.params, source.parentParamNames),\n });\n if (Array.isArray(staticParams) && !areStaticParamsAllowed(options.params, staticParams)) {\n options.clearRequestContext();\n return notFoundResponse();\n }\n }\n\n return null;\n}\n\n/**\n * Pure: decides whether the incoming request should re-render an intercepted\n * source-route tree, and if so returns the source route, the source-route's\n * param slice, the full matched param set (the URL params the client sees),\n * and an opaque `interceptOpts` bag for the caller's render pipeline.\n *\n * Returns `null` in three decision-fallthrough cases:\n * - non-RSC requests (server rendering the direct page for a full HTML load)\n * - no intercepting route matches the path\n * - the match's source route IS the current route (the same branch today\n * returns `interceptOpts` for the direct render)\n *\n * Shared by both the GET path (resolveAppPageIntercept, which layers on\n * `setNavigationContext` + element build + Response wrap) and the server-action\n * POST path (entries/app-rsc-entry.ts), which runs its own response pipeline.\n */\nexport function resolveAppPageInterceptMatch<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> | null {\n const interceptState = resolveAppPageInterceptState(options);\n if (interceptState.kind !== \"source-route\") {\n return null;\n }\n\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n matchedParams: interceptState.intercept.matchedParams,\n sourceParams: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n sourceRoute: interceptState.sourceRoute,\n };\n}\n\nfunction resolveAppPageInterceptState<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): AppPageInterceptState<TRoute, TPage> {\n if (!options.isRscRequest) {\n return { kind: \"none\" };\n }\n\n const intercept = options.findIntercept(options.cleanPathname);\n if (!intercept) {\n return { kind: \"none\" };\n }\n\n const sourceRoute = options.getSourceRoute(intercept.sourceRouteIndex);\n if (!sourceRoute) {\n return { kind: \"none\" };\n }\n\n if (sourceRoute === options.currentRoute) {\n return { kind: \"current-route\", intercept };\n }\n\n return { kind: \"source-route\", intercept, sourceRoute };\n}\n\nexport function resolveAppPageActionRerenderTarget<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n navigationParams: interceptState.intercept.matchedParams,\n params: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n route: interceptState.sourceRoute,\n };\n }\n\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n navigationParams: options.currentParams,\n params: options.currentParams,\n route: options.currentRoute,\n };\n}\n\nexport async function resolveAppPageIntercept<TRoute, TPage, TInterceptOpts, TElement>(\n options: ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement>,\n): Promise<ResolveAppPageInterceptResult<TInterceptOpts>> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n options.setNavigationContext({\n params: interceptState.intercept.matchedParams,\n pathname: options.cleanPathname,\n searchParams: options.searchParams,\n });\n const interceptElement = await options.buildPageElement(\n interceptState.sourceRoute,\n pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n options.toInterceptOpts(interceptState.intercept),\n options.searchParams,\n );\n\n return {\n interceptOpts: undefined,\n response: await options.renderInterceptResponse(interceptState.sourceRoute, interceptElement),\n };\n }\n\n // Reproduce the current-route-is-source branch where we still need the opts\n // bag even though we did not render a separate intercepted response.\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n response: null,\n };\n}\n\nexport async function buildAppPageElement<TElement>(\n options: BuildAppPageElementOptions<TElement>,\n): Promise<BuildAppPageElementResult<TElement>> {\n try {\n return {\n element: await options.buildPageElement(),\n response: null,\n };\n } catch (error) {\n const specialError = options.resolveSpecialError(error);\n if (specialError) {\n return {\n element: null,\n response: await options.renderSpecialError(specialError),\n };\n }\n\n const errorBoundaryResponse = await options.renderErrorBoundaryPage(error);\n if (errorBoundaryResponse) {\n return {\n element: null,\n response: errorBoundaryResponse,\n };\n }\n\n throw error;\n }\n}\n"],"mappings":";;;AA0HA,SAAS,gBACP,eACA,iBACe;CACf,MAAM,SAAwB,EAAE;AAEhC,MAAK,MAAM,aAAa,iBAAiB;EACvC,MAAM,QAAQ,cAAc;AAC5B,MAAI,UAAU,KAAA,EACZ,QAAO,aAAa;;AAIxB,QAAO;;AAGT,SAAS,wBACP,eACA,kBACU;CACV,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,kBAAkB,cAAc,OAAO,CAAC;CAC3E,MAAM,QAAkB,EAAE;AAE1B,MAAK,MAAM,WAAW,cAAc,MAAM,GAAG,MAAM,EAAE;EACnD,MAAM,OAAO,2BAA2B,QAAQ;AAChD,MAAI,QAAQ,CAAC,MAAM,SAAS,KAAK,CAC/B,OAAM,KAAK,KAAK;;AAIpB,QAAO;;AAGT,SAAS,sCAAsC,oBAAgD;AAI7F,SAAQ,sBAAsB,KAAK;;AAGrC,SAAgB,0CACd,SAC8B;CAC9B,MAAM,UAAwC,EAAE;AAEhD,SAAQ,SAAS,SAAS,QAAQ,UAAU;AAC1C,MAAI,OAAO,QAAQ,yBAAyB,WAAY;AAExD,UAAQ,KAAK;GACX,sBAAsB,OAAO;GAC7B,kBAAkB,wBAChB,QAAQ,eACR,sCAAsC,QAAQ,sBAAsB,OAAO,CAC5E;GACF,CAAC;GACF;AAEF,KAAI,OAAO,QAAQ,MAAM,yBAAyB,WAChD,SAA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C_VARY_HEADER } from "./app-rsc-cache-busting.js";
|
|
1
2
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
2
3
|
import { NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, buildRevalidateCacheControl } from "./cache-control.js";
|
|
3
4
|
//#region src/server/app-page-response.ts
|
|
@@ -58,7 +59,7 @@ function resolveAppPageHtmlResponsePolicy(options) {
|
|
|
58
59
|
function buildAppPageRscResponse(body, options) {
|
|
59
60
|
const headers = new Headers({
|
|
60
61
|
"Content-Type": "text/x-component; charset=utf-8",
|
|
61
|
-
Vary:
|
|
62
|
+
Vary: VINEXT_RSC_VARY_HEADER
|
|
62
63
|
});
|
|
63
64
|
if (options.params && Object.keys(options.params).length > 0) headers.set("X-Vinext-Params", encodeURIComponent(JSON.stringify(options.params)));
|
|
64
65
|
if (options.mountedSlotsHeader) headers.set("X-Vinext-Mounted-Slots", options.mountedSlotsHeader);
|
|
@@ -74,7 +75,7 @@ function buildAppPageRscResponse(body, options) {
|
|
|
74
75
|
function buildAppPageHtmlResponse(body, options) {
|
|
75
76
|
const headers = new Headers({
|
|
76
77
|
"Content-Type": "text/html; charset=utf-8",
|
|
77
|
-
Vary:
|
|
78
|
+
Vary: VINEXT_RSC_VARY_HEADER
|
|
78
79
|
});
|
|
79
80
|
if (options.policy.cacheControl) headers.set("Cache-Control", options.policy.cacheControl);
|
|
80
81
|
if (options.policy.cacheState) headers.set("X-Vinext-Cache", options.policy.cacheState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-response.js","names":[],"sources":["../../src/server/app-page-response.ts"],"sourcesContent":["import {\n buildRevalidateCacheControl,\n NO_STORE_CACHE_CONTROL,\n STATIC_CACHE_CONTROL,\n} from \"./cache-control.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\nexport type AppPageMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\nexport type AppPageResponseTiming = {\n compileEnd?: number;\n handlerStart: number;\n renderEnd?: number;\n responseKind: \"html\" | \"rsc\";\n};\n\ntype AppPageResponsePolicy = {\n cacheControl?: string;\n cacheState?: \"MISS\" | \"STATIC\";\n};\n\ntype ResolveAppPageResponsePolicyBaseOptions = {\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isProduction: boolean;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n};\n\ntype ResolveAppPageRscResponsePolicyOptions = {\n dynamicUsedDuringBuild: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype ResolveAppPageHtmlResponsePolicyOptions = {\n dynamicUsedDuringRender: boolean;\n hasScriptNonce: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype AppPageHtmlResponsePolicy = {\n shouldWriteToCache: boolean;\n} & AppPageResponsePolicy;\n\ntype BuildAppPageRscResponseOptions = {\n middlewareContext: AppPageMiddlewareContext;\n mountedSlotsHeader?: string | null;\n params?: Record<string, unknown>;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\ntype BuildAppPageHtmlResponseOptions = {\n draftCookie?: string | null;\n fontLinkHeader?: string;\n middlewareContext: AppPageMiddlewareContext;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\nfunction applyTimingHeader(headers: Headers, timing?: AppPageResponseTiming): void {\n if (!timing) {\n return;\n }\n\n const handlerStart = Math.round(timing.handlerStart);\n const compileMs =\n timing.compileEnd !== undefined ? Math.round(timing.compileEnd - timing.handlerStart) : -1;\n const renderMs =\n timing.responseKind === \"html\" &&\n timing.renderEnd !== undefined &&\n timing.compileEnd !== undefined\n ? Math.round(timing.renderEnd - timing.compileEnd)\n : -1;\n\n headers.set(\"x-vinext-timing\", `${handlerStart},${compileMs},${renderMs}`);\n}\n\nexport function resolveAppPageRscResponsePolicy(\n options: ResolveAppPageRscResponsePolicyOptions,\n): AppPageResponsePolicy {\n if (options.isForceDynamic || options.dynamicUsedDuringBuild) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which uses !revalidateSeconds\n // and would incorrectly catch 0 as a falsy value.\n if (options.revalidateSeconds === 0) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n if (\n ((options.isForceStatic || options.isDynamicError) && !options.revalidateSeconds) ||\n options.revalidateSeconds === Infinity\n ) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n };\n }\n\n if (options.revalidateSeconds) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),\n // Emit MISS as part of the initial RSC response shape rather than bolting\n // it on later in the cache-write block so response construction stays\n // centralized in this helper. This matches the eventual write path: the\n // first ISR-eligible production response is a cache miss.\n cacheState: options.isProduction ? \"MISS\" : undefined,\n };\n }\n\n return {};\n}\n\nexport function resolveAppPageHtmlResponsePolicy(\n options: ResolveAppPageHtmlResponsePolicyOptions,\n): AppPageHtmlResponsePolicy {\n if (options.isForceDynamic) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (options.hasScriptNonce) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which matches revalidateSeconds\n // === 0 and would incorrectly return a static Cache-Control.\n if (options.revalidateSeconds === 0) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if ((options.isForceStatic || options.isDynamicError) && options.revalidateSeconds === null) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n if (options.dynamicUsedDuringRender) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (\n options.revalidateSeconds !== null &&\n options.revalidateSeconds > 0 &&\n options.revalidateSeconds !== Infinity\n ) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),\n cacheState: options.isProduction ? \"MISS\" : undefined,\n shouldWriteToCache: options.isProduction,\n };\n }\n\n if (options.revalidateSeconds === Infinity) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n return { shouldWriteToCache: false };\n}\n\nexport { mergeMiddlewareResponseHeaders };\n\nexport function buildAppPageRscResponse(\n body: ReadableStream,\n options: BuildAppPageRscResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/x-component; charset=utf-8\",\n Vary: \"RSC, Accept\",\n });\n\n if (options.params && Object.keys(options.params).length > 0) {\n // encodeURIComponent so non-ASCII params (e.g. Korean slugs) survive the\n // HTTP ByteString constraint — Headers.set() rejects chars above U+00FF.\n headers.set(\"X-Vinext-Params\", encodeURIComponent(JSON.stringify(options.params)));\n }\n if (options.mountedSlotsHeader) {\n headers.set(\"X-Vinext-Mounted-Slots\", options.mountedSlotsHeader);\n }\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n\nexport function buildAppPageHtmlResponse(\n body: ReadableStream,\n options: BuildAppPageHtmlResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/html; charset=utf-8\",\n Vary: \"RSC, Accept\",\n });\n\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n if (options.draftCookie) {\n headers.append(\"Set-Cookie\", options.draftCookie);\n }\n if (options.fontLinkHeader) {\n headers.set(\"Link\", options.fontLinkHeader);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n"],"mappings":";;;AA8DA,SAAS,kBAAkB,SAAkB,QAAsC;AACjF,KAAI,CAAC,OACH;CAGF,MAAM,eAAe,KAAK,MAAM,OAAO,aAAa;CACpD,MAAM,YACJ,OAAO,eAAe,KAAA,IAAY,KAAK,MAAM,OAAO,aAAa,OAAO,aAAa,GAAG;CAC1F,MAAM,WACJ,OAAO,iBAAiB,UACxB,OAAO,cAAc,KAAA,KACrB,OAAO,eAAe,KAAA,IAClB,KAAK,MAAM,OAAO,YAAY,OAAO,WAAW,GAChD;AAEN,SAAQ,IAAI,mBAAmB,GAAG,aAAa,GAAG,UAAU,GAAG,WAAW;;AAG5E,SAAgB,gCACd,SACuB;AACvB,KAAI,QAAQ,kBAAkB,QAAQ,uBACpC,QAAO,EAAE,cAAc,wBAAwB;AAOjD,KAAI,QAAQ,sBAAsB,EAChC,QAAO,EAAE,cAAc,wBAAwB;AAGjD,MACI,QAAQ,iBAAiB,QAAQ,mBAAmB,CAAC,QAAQ,qBAC/D,QAAQ,sBAAsB,SAE9B,QAAO;EACL,cAAc;EACd,YAAY;EACb;AAGH,KAAI,QAAQ,kBACV,QAAO;EACL,cAAc,4BAA4B,QAAQ,mBAAmB,QAAQ,cAAc;EAK3F,YAAY,QAAQ,eAAe,SAAS,KAAA;EAC7C;AAGH,QAAO,EAAE;;AAGX,SAAgB,iCACd,SAC2B;AAC3B,KAAI,QAAQ,eACV,QAAO;EACL,cAAc;EACd,oBAAoB;EACrB;AAGH,KAAI,QAAQ,eACV,QAAO;EACL,cAAc;EACd,oBAAoB;EACrB;AAOH,KAAI,QAA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;EAChB,MAAM;EACP,CAAC;AAEF,KAAI,QAAQ,OAAO,aACjB,SAAQ,IAAI,iBAAiB,QAAQ,OAAO,aAAa;AAE3D,KAAI,QAAQ,OAAO,WACjB,SAAQ,IAAI,kBAAkB,QAAQ,OAAO,WAAW;AAE1D,KAAI,QAAQ,YACV,SAAQ,OAAO,cAAc,QAAQ,YAAY;AAEnD,KAAI,QAAQ,eACV,SAAQ,IAAI,QAAQ,QAAQ,eAAe;AAG7C,gCAA+B,SAAS,QAAQ,kBAAkB,QAAQ;AAE1E,mBAAkB,SAAS,QAAQ,OAAO;AAE1C,QAAO,IAAI,SAAS,MAAM;EACxB,QAAQ,QAAQ,kBAAkB,UAAU;EAC5C;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"app-page-response.js","names":[],"sources":["../../src/server/app-page-response.ts"],"sourcesContent":["import {\n buildRevalidateCacheControl,\n NO_STORE_CACHE_CONTROL,\n STATIC_CACHE_CONTROL,\n} from \"./cache-control.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\nimport { VINEXT_RSC_VARY_HEADER } from \"./app-rsc-cache-busting.js\";\n\nexport type AppPageMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\nexport type AppPageResponseTiming = {\n compileEnd?: number;\n handlerStart: number;\n renderEnd?: number;\n responseKind: \"html\" | \"rsc\";\n};\n\ntype AppPageResponsePolicy = {\n cacheControl?: string;\n cacheState?: \"MISS\" | \"STATIC\";\n};\n\ntype ResolveAppPageResponsePolicyBaseOptions = {\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isProduction: boolean;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n};\n\ntype ResolveAppPageRscResponsePolicyOptions = {\n dynamicUsedDuringBuild: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype ResolveAppPageHtmlResponsePolicyOptions = {\n dynamicUsedDuringRender: boolean;\n hasScriptNonce: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype AppPageHtmlResponsePolicy = {\n shouldWriteToCache: boolean;\n} & AppPageResponsePolicy;\n\ntype BuildAppPageRscResponseOptions = {\n middlewareContext: AppPageMiddlewareContext;\n mountedSlotsHeader?: string | null;\n params?: Record<string, unknown>;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\ntype BuildAppPageHtmlResponseOptions = {\n draftCookie?: string | null;\n fontLinkHeader?: string;\n middlewareContext: AppPageMiddlewareContext;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\nfunction applyTimingHeader(headers: Headers, timing?: AppPageResponseTiming): void {\n if (!timing) {\n return;\n }\n\n const handlerStart = Math.round(timing.handlerStart);\n const compileMs =\n timing.compileEnd !== undefined ? Math.round(timing.compileEnd - timing.handlerStart) : -1;\n const renderMs =\n timing.responseKind === \"html\" &&\n timing.renderEnd !== undefined &&\n timing.compileEnd !== undefined\n ? Math.round(timing.renderEnd - timing.compileEnd)\n : -1;\n\n headers.set(\"x-vinext-timing\", `${handlerStart},${compileMs},${renderMs}`);\n}\n\nexport function resolveAppPageRscResponsePolicy(\n options: ResolveAppPageRscResponsePolicyOptions,\n): AppPageResponsePolicy {\n if (options.isForceDynamic || options.dynamicUsedDuringBuild) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which uses !revalidateSeconds\n // and would incorrectly catch 0 as a falsy value.\n if (options.revalidateSeconds === 0) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n if (\n ((options.isForceStatic || options.isDynamicError) && !options.revalidateSeconds) ||\n options.revalidateSeconds === Infinity\n ) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n };\n }\n\n if (options.revalidateSeconds) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),\n // Emit MISS as part of the initial RSC response shape rather than bolting\n // it on later in the cache-write block so response construction stays\n // centralized in this helper. This matches the eventual write path: the\n // first ISR-eligible production response is a cache miss.\n cacheState: options.isProduction ? \"MISS\" : undefined,\n };\n }\n\n return {};\n}\n\nexport function resolveAppPageHtmlResponsePolicy(\n options: ResolveAppPageHtmlResponsePolicyOptions,\n): AppPageHtmlResponsePolicy {\n if (options.isForceDynamic) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (options.hasScriptNonce) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which matches revalidateSeconds\n // === 0 and would incorrectly return a static Cache-Control.\n if (options.revalidateSeconds === 0) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if ((options.isForceStatic || options.isDynamicError) && options.revalidateSeconds === null) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n if (options.dynamicUsedDuringRender) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (\n options.revalidateSeconds !== null &&\n options.revalidateSeconds > 0 &&\n options.revalidateSeconds !== Infinity\n ) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),\n cacheState: options.isProduction ? \"MISS\" : undefined,\n shouldWriteToCache: options.isProduction,\n };\n }\n\n if (options.revalidateSeconds === Infinity) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n return { shouldWriteToCache: false };\n}\n\nexport { mergeMiddlewareResponseHeaders };\n\nexport function buildAppPageRscResponse(\n body: ReadableStream,\n options: BuildAppPageRscResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/x-component; charset=utf-8\",\n Vary: VINEXT_RSC_VARY_HEADER,\n });\n\n if (options.params && Object.keys(options.params).length > 0) {\n // encodeURIComponent so non-ASCII params (e.g. Korean slugs) survive the\n // HTTP ByteString constraint — Headers.set() rejects chars above U+00FF.\n headers.set(\"X-Vinext-Params\", encodeURIComponent(JSON.stringify(options.params)));\n }\n if (options.mountedSlotsHeader) {\n headers.set(\"X-Vinext-Mounted-Slots\", options.mountedSlotsHeader);\n }\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n\nexport function buildAppPageHtmlResponse(\n body: ReadableStream,\n options: BuildAppPageHtmlResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/html; charset=utf-8\",\n Vary: VINEXT_RSC_VARY_HEADER,\n });\n\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n if (options.draftCookie) {\n headers.append(\"Set-Cookie\", options.draftCookie);\n }\n if (options.fontLinkHeader) {\n headers.set(\"Link\", options.fontLinkHeader);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n"],"mappings":";;;;AA+DA,SAAS,kBAAkB,SAAkB,QAAsC;AACjF,KAAI,CAAC,OACH;CAGF,MAAM,eAAe,KAAK,MAAM,OAAO,aAAa;CACpD,MAAM,YACJ,OAAO,eAAe,KAAA,IAAY,KAAK,M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kBAAkB,UAAU;EAC5C;EACD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppRouteSemanticIds } from "../routing/app-route-graph.js";
|
|
2
|
+
import { AppElements } from "./app-elements-wire.js";
|
|
2
3
|
import { AppPageParams } from "./app-page-boundary.js";
|
|
3
4
|
import { Metadata, Viewport } from "../shims/metadata.js";
|
|
4
5
|
import { ComponentType, ReactNode } from "react";
|
|
@@ -22,7 +23,8 @@ type AppPageErrorModule = Record<string, unknown> & {
|
|
|
22
23
|
default?: AppPageErrorComponent | null | undefined;
|
|
23
24
|
};
|
|
24
25
|
type AppPageRouteWiringSlot<TModule extends AppPageModule = AppPageModule, TErrorModule extends AppPageErrorModule = AppPageErrorModule> = {
|
|
25
|
-
/** Slot prop name passed to the owning layout (e.g. "modal" from @modal). */
|
|
26
|
+
/** Graph-owned semantic slot identity. */id?: string | null; /** Slot prop name passed to the owning layout (e.g. "modal" from @modal). */
|
|
27
|
+
name: string;
|
|
26
28
|
default?: TModule | null;
|
|
27
29
|
error?: TErrorModule | null;
|
|
28
30
|
layout?: TModule | null;
|
|
@@ -40,6 +42,7 @@ type AppPageRouteWiringSlot<TModule extends AppPageModule = AppPageModule, TErro
|
|
|
40
42
|
slotParamNames?: readonly string[] | null;
|
|
41
43
|
};
|
|
42
44
|
type AppPageRouteWiringRoute<TModule extends AppPageModule = AppPageModule, TErrorModule extends AppPageErrorModule = AppPageErrorModule> = {
|
|
45
|
+
ids?: AppRouteSemanticIds | null;
|
|
43
46
|
error?: TErrorModule | null;
|
|
44
47
|
errors?: readonly (TErrorModule | null | undefined)[] | null;
|
|
45
48
|
layoutTreePositions?: readonly number[] | null;
|