vinext 0.0.45 → 0.0.46
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/dist/build/prerender.js +10 -3
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/standalone.js +4 -3
- package/dist/build/standalone.js.map +1 -1
- package/dist/check.js +30 -18
- package/dist/check.js.map +1 -1
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/config/config-matchers.js +1 -0
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +38 -2
- package/dist/config/next-config.js +24 -0
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +18 -23
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +331 -1732
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +24 -0
- package/dist/entries/app-rsc-manifest.js +153 -0
- package/dist/entries/app-rsc-manifest.js.map +1 -0
- package/dist/entries/pages-server-entry.js +13 -103
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.js +54 -34
- package/dist/index.js.map +1 -1
- package/dist/plugins/rsc-client-shim-excludes.d.ts +6 -0
- package/dist/plugins/rsc-client-shim-excludes.js +27 -0
- package/dist/plugins/rsc-client-shim-excludes.js.map +1 -0
- package/dist/routing/app-router.d.ts +14 -5
- package/dist/routing/app-router.js +75 -1
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/route-pattern.d.ts +9 -0
- package/dist/routing/route-pattern.js +90 -0
- package/dist/routing/route-pattern.js.map +1 -0
- package/dist/routing/route-trie.js +10 -11
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/server/app-browser-entry.js +30 -2
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-middleware.d.ts +32 -0
- package/dist/server/app-middleware.js +147 -0
- package/dist/server/app-middleware.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +2 -0
- package/dist/server/app-page-boundary-render.js +50 -30
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +12 -1
- package/dist/server/app-page-boundary.js +27 -12
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +4 -1
- package/dist/server/app-page-cache.js +38 -2
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +120 -0
- package/dist/server/app-page-dispatch.js +332 -0
- package/dist/server/app-page-dispatch.js.map +1 -0
- package/dist/server/app-page-execution.d.ts +4 -3
- package/dist/server/app-page-execution.js +5 -8
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.d.ts +55 -0
- package/dist/server/app-page-head.js +196 -0
- package/dist/server/app-page-head.js.map +1 -0
- package/dist/server/app-page-method.d.ts +16 -0
- package/dist/server/app-page-method.js +30 -0
- package/dist/server/app-page-method.js.map +1 -0
- package/dist/server/app-page-params.d.ts +7 -0
- package/dist/server/app-page-params.js +28 -0
- package/dist/server/app-page-params.js.map +1 -0
- package/dist/server/app-page-render.d.ts +2 -1
- package/dist/server/app-page-render.js +54 -8
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +4 -4
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +14 -3
- package/dist/server/app-page-route-wiring.js +30 -8
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +10 -0
- package/dist/server/app-page-stream.js +5 -1
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-prerender-endpoints.d.ts +19 -0
- package/dist/server/app-prerender-endpoints.js +96 -0
- package/dist/server/app-prerender-endpoints.js.map +1 -0
- package/dist/server/app-prerender-static-params.d.ts +16 -0
- package/dist/server/app-prerender-static-params.js +14 -0
- package/dist/server/app-prerender-static-params.js.map +1 -0
- package/dist/server/app-route-handler-cache.d.ts +3 -0
- package/dist/server/app-route-handler-cache.js +6 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +42 -0
- package/dist/server/app-route-handler-dispatch.js +147 -0
- package/dist/server/app-route-handler-dispatch.js.map +1 -0
- package/dist/server/app-route-handler-execution.d.ts +6 -2
- package/dist/server/app-route-handler-execution.js +23 -2
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-response.d.ts +2 -1
- package/dist/server/app-route-handler-response.js +44 -4
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +107 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-errors.d.ts +27 -0
- package/dist/server/app-rsc-errors.js +42 -0
- package/dist/server/app-rsc-errors.js.map +1 -0
- package/dist/server/app-rsc-route-matching.d.ts +40 -0
- package/dist/server/app-rsc-route-matching.js +66 -0
- package/dist/server/app-rsc-route-matching.js.map +1 -0
- package/dist/server/app-server-action-execution.d.ts +86 -1
- package/dist/server/app-server-action-execution.js +255 -5
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.d.ts +7 -0
- package/dist/server/app-ssr-entry.js +30 -9
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +4 -2
- package/dist/server/app-ssr-stream.js +29 -2
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/app-static-generation.d.ts +15 -0
- package/dist/server/app-static-generation.js +20 -0
- package/dist/server/app-static-generation.js.map +1 -0
- package/dist/server/dev-route-files.d.ts +7 -0
- package/dist/server/dev-route-files.js +73 -0
- package/dist/server/dev-route-files.js.map +1 -0
- package/dist/server/dev-server.js +4 -0
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/file-based-metadata.d.ts +17 -0
- package/dist/server/file-based-metadata.js +356 -0
- package/dist/server/file-based-metadata.js.map +1 -0
- package/dist/server/implicit-tags.d.ts +6 -0
- package/dist/server/implicit-tags.js +42 -0
- package/dist/server/implicit-tags.js.map +1 -0
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/isr-cache.d.ts +20 -2
- package/dist/server/isr-cache.js +58 -7
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-route-build-data.d.ts +25 -0
- package/dist/server/metadata-route-build-data.js +150 -0
- package/dist/server/metadata-route-build-data.js.map +1 -0
- package/dist/server/metadata-route-response.d.ts +17 -0
- package/dist/server/metadata-route-response.js +187 -0
- package/dist/server/metadata-route-response.js.map +1 -0
- package/dist/server/metadata-routes.d.ts +42 -4
- package/dist/server/metadata-routes.js +127 -11
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-matcher.d.ts +15 -0
- package/dist/server/middleware-matcher.js +102 -0
- package/dist/server/middleware-matcher.js.map +1 -0
- package/dist/server/middleware-request-headers.js +2 -1
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware-runtime.d.ts +39 -0
- package/dist/server/middleware-runtime.js +159 -0
- package/dist/server/middleware-runtime.js.map +1 -0
- package/dist/server/middleware.d.ts +4 -36
- package/dist/server/middleware.js +18 -228
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +5 -1
- package/dist/server/pages-page-data.js +4 -0
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.js +2 -1
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prerender-work-unit-setup.d.ts +7 -0
- package/dist/server/prerender-work-unit-setup.js +30 -0
- package/dist/server/prerender-work-unit-setup.js.map +1 -0
- package/dist/server/prod-server.js +10 -14
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +46 -5
- package/dist/server/request-pipeline.js +84 -5
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/rsc-stream-hints.d.ts +5 -0
- package/dist/server/rsc-stream-hints.js +35 -0
- package/dist/server/rsc-stream-hints.js.map +1 -0
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/server-action-not-found.d.ts +9 -0
- package/dist/server/server-action-not-found.js +40 -0
- package/dist/server/server-action-not-found.js.map +1 -0
- package/dist/shims/cache.d.ts +25 -2
- package/dist/shims/cache.js +52 -2
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +50 -5
- package/dist/shims/error-boundary.js +76 -4
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +5 -4
- package/dist/shims/font-google-base.js +61 -13
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/headers.d.ts +14 -2
- package/dist/shims/headers.js +127 -17
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.js +26 -8
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/make-hanging-promise.d.ts +16 -0
- package/dist/shims/internal/make-hanging-promise.js +46 -0
- package/dist/shims/internal/make-hanging-promise.js.map +1 -0
- package/dist/shims/internal/work-unit-async-storage.d.ts +26 -3
- package/dist/shims/internal/work-unit-async-storage.js +6 -3
- package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
- package/dist/shims/metadata.d.ts +38 -26
- package/dist/shims/metadata.js +75 -45
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +10 -1
- package/dist/shims/navigation.js +18 -1
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/navigation.react-server.d.ts +2 -2
- package/dist/shims/navigation.react-server.js +2 -2
- package/dist/shims/navigation.react-server.js.map +1 -1
- package/dist/shims/offline.d.ts +5 -0
- package/dist/shims/offline.js +17 -0
- package/dist/shims/offline.js.map +1 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/root-params.d.ts +11 -0
- package/dist/shims/root-params.js +24 -0
- package/dist/shims/root-params.js.map +1 -0
- package/dist/shims/router.js +1 -1
- package/dist/shims/server.d.ts +3 -1
- package/dist/shims/server.js +83 -5
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/thenable-params.d.ts +5 -0
- package/dist/shims/thenable-params.js +37 -0
- package/dist/shims/thenable-params.js.map +1 -0
- package/dist/shims/unified-request-context.d.ts +2 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/unified-request-context.js.map +1 -1
- package/package.json +6 -1
- package/dist/server/middleware-codegen.d.ts +0 -54
- package/dist/server/middleware-codegen.js +0 -414
- package/dist/server/middleware-codegen.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { resolveEntryPath } from "./runtime-entry-module.js";
|
|
2
2
|
import { isProxyFile } from "../server/middleware.js";
|
|
3
|
-
import {
|
|
3
|
+
import { buildAppRscManifestCode } from "./app-rsc-manifest.js";
|
|
4
4
|
import { generateDevOriginCheckCode } from "../server/dev-origin-check.js";
|
|
5
|
-
import fs from "node:fs";
|
|
6
5
|
//#region src/entries/app-rsc-entry.ts
|
|
7
6
|
/**
|
|
8
7
|
* App Router RSC entry generator.
|
|
@@ -15,26 +14,32 @@ import fs from "node:fs";
|
|
|
15
14
|
*/
|
|
16
15
|
const configMatchersPath = resolveEntryPath("../config/config-matchers.js", import.meta.url);
|
|
17
16
|
const requestPipelinePath = resolveEntryPath("../server/request-pipeline.js", import.meta.url);
|
|
17
|
+
const appMiddlewarePath = resolveEntryPath("../server/app-middleware.js", import.meta.url);
|
|
18
18
|
const middlewareRequestHeadersPath = resolveEntryPath("../server/middleware-request-headers.js", import.meta.url);
|
|
19
19
|
const requestContextShimPath = resolveEntryPath("../shims/request-context.js", import.meta.url);
|
|
20
20
|
const normalizePathModulePath = resolveEntryPath("../server/normalize-path.js", import.meta.url);
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const appRouteHandlerExecutionPath = resolveEntryPath("../server/app-route-handler-execution.js", import.meta.url);
|
|
21
|
+
const routingUtilsPath = resolveEntryPath("../routing/utils.js", import.meta.url);
|
|
22
|
+
const appRouteHandlerDispatchPath = resolveEntryPath("../server/app-route-handler-dispatch.js", import.meta.url);
|
|
24
23
|
const appServerActionExecutionPath = resolveEntryPath("../server/app-server-action-execution.js", import.meta.url);
|
|
25
|
-
const
|
|
26
|
-
const
|
|
24
|
+
const appRscErrorsPath = resolveEntryPath("../server/app-rsc-errors.js", import.meta.url);
|
|
25
|
+
const implicitTagsPath = resolveEntryPath("../server/implicit-tags.js", import.meta.url);
|
|
27
26
|
const appPageExecutionPath = resolveEntryPath("../server/app-page-execution.js", import.meta.url);
|
|
28
27
|
const appPageBoundaryRenderPath = resolveEntryPath("../server/app-page-boundary-render.js", import.meta.url);
|
|
29
28
|
const appElementsPath = resolveEntryPath("../server/app-elements.js", import.meta.url);
|
|
30
29
|
const appPageRouteWiringPath = resolveEntryPath("../server/app-page-route-wiring.js", import.meta.url);
|
|
31
|
-
const
|
|
30
|
+
const appPageHeadPath = resolveEntryPath("../server/app-page-head.js", import.meta.url);
|
|
31
|
+
const appPageParamsPath = resolveEntryPath("../server/app-page-params.js", import.meta.url);
|
|
32
32
|
const appPageResponsePath = resolveEntryPath("../server/app-page-response.js", import.meta.url);
|
|
33
|
+
const appPageDispatchPath = resolveEntryPath("../server/app-page-dispatch.js", import.meta.url);
|
|
33
34
|
const cspPath = resolveEntryPath("../server/csp.js", import.meta.url);
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
const appRscRouteMatchingPath = resolveEntryPath("../server/app-rsc-route-matching.js", import.meta.url);
|
|
36
|
+
const appPrerenderEndpointsPath = resolveEntryPath("../server/app-prerender-endpoints.js", import.meta.url);
|
|
37
|
+
const prerenderWorkUnitSetupPath = resolveEntryPath("../server/prerender-work-unit-setup.js", import.meta.url);
|
|
38
|
+
const rscStreamHintsPath = resolveEntryPath("../server/rsc-stream-hints.js", import.meta.url);
|
|
39
|
+
const isrCachePath = resolveEntryPath("../server/isr-cache.js", import.meta.url);
|
|
40
|
+
const rootParamsShimPath = resolveEntryPath("../shims/root-params.js", import.meta.url);
|
|
41
|
+
const thenableParamsShimPath = resolveEntryPath("../shims/thenable-params.js", import.meta.url);
|
|
42
|
+
const metadataRouteResponsePath = resolveEntryPath("../server/metadata-route-response.js", import.meta.url);
|
|
38
43
|
const errorCausePath = resolveEntryPath("../utils/error-cause.js", import.meta.url);
|
|
39
44
|
/**
|
|
40
45
|
* Generate the virtual RSC entry module.
|
|
@@ -58,131 +63,18 @@ function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes, global
|
|
|
58
63
|
const i18nConfig = config?.i18n ?? null;
|
|
59
64
|
const hasPagesDir = config?.hasPagesDir ?? false;
|
|
60
65
|
const publicFiles = config?.publicFiles ?? [];
|
|
61
|
-
const imports =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (importMap.has(filePath)) return importMap.get(filePath);
|
|
66
|
-
const varName = `mod_${importIdx++}`;
|
|
67
|
-
const absPath = filePath.replace(/\\/g, "/");
|
|
68
|
-
imports.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
|
|
69
|
-
importMap.set(filePath, varName);
|
|
70
|
-
return varName;
|
|
71
|
-
}
|
|
72
|
-
for (const route of routes) {
|
|
73
|
-
if (route.pagePath) getImportVar(route.pagePath);
|
|
74
|
-
if (route.routePath) getImportVar(route.routePath);
|
|
75
|
-
for (const layout of route.layouts) getImportVar(layout);
|
|
76
|
-
for (const tmpl of route.templates) getImportVar(tmpl);
|
|
77
|
-
if (route.loadingPath) getImportVar(route.loadingPath);
|
|
78
|
-
if (route.errorPath) getImportVar(route.errorPath);
|
|
79
|
-
if (route.layoutErrorPaths) {
|
|
80
|
-
for (const ep of route.layoutErrorPaths) if (ep) getImportVar(ep);
|
|
81
|
-
}
|
|
82
|
-
if (route.notFoundPath) getImportVar(route.notFoundPath);
|
|
83
|
-
for (const nfp of route.notFoundPaths || []) if (nfp) getImportVar(nfp);
|
|
84
|
-
if (route.forbiddenPath) getImportVar(route.forbiddenPath);
|
|
85
|
-
if (route.unauthorizedPath) getImportVar(route.unauthorizedPath);
|
|
86
|
-
for (const slot of route.parallelSlots) {
|
|
87
|
-
if (slot.pagePath) getImportVar(slot.pagePath);
|
|
88
|
-
if (slot.defaultPath) getImportVar(slot.defaultPath);
|
|
89
|
-
if (slot.layoutPath) getImportVar(slot.layoutPath);
|
|
90
|
-
if (slot.loadingPath) getImportVar(slot.loadingPath);
|
|
91
|
-
if (slot.errorPath) getImportVar(slot.errorPath);
|
|
92
|
-
for (const ir of slot.interceptingRoutes) {
|
|
93
|
-
getImportVar(ir.pagePath);
|
|
94
|
-
for (const layoutPath of ir.layoutPaths) getImportVar(layoutPath);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const routeEntries = routes.map((route, routeIdx) => {
|
|
99
|
-
const layoutVars = route.layouts.map((l) => getImportVar(l));
|
|
100
|
-
const templateVars = route.templates.map((t) => getImportVar(t));
|
|
101
|
-
const notFoundVars = (route.notFoundPaths || []).map((nf) => nf ? getImportVar(nf) : "null");
|
|
102
|
-
const slotEntries = route.parallelSlots.map((slot) => {
|
|
103
|
-
const interceptEntries = slot.interceptingRoutes.map((ir) => ` {
|
|
104
|
-
convention: ${JSON.stringify(ir.convention)},
|
|
105
|
-
targetPattern: ${JSON.stringify(ir.targetPattern)},
|
|
106
|
-
interceptLayouts: [${ir.layoutPaths.map((layoutPath) => getImportVar(layoutPath)).join(", ")}],
|
|
107
|
-
page: ${getImportVar(ir.pagePath)},
|
|
108
|
-
params: ${JSON.stringify(ir.params)},
|
|
109
|
-
}`);
|
|
110
|
-
return ` ${JSON.stringify(slot.key)}: {
|
|
111
|
-
name: ${JSON.stringify(slot.name)},
|
|
112
|
-
page: ${slot.pagePath ? getImportVar(slot.pagePath) : "null"},
|
|
113
|
-
default: ${slot.defaultPath ? getImportVar(slot.defaultPath) : "null"},
|
|
114
|
-
layout: ${slot.layoutPath ? getImportVar(slot.layoutPath) : "null"},
|
|
115
|
-
loading: ${slot.loadingPath ? getImportVar(slot.loadingPath) : "null"},
|
|
116
|
-
error: ${slot.errorPath ? getImportVar(slot.errorPath) : "null"},
|
|
117
|
-
layoutIndex: ${slot.layoutIndex},
|
|
118
|
-
routeSegments: ${JSON.stringify(slot.routeSegments)},
|
|
119
|
-
intercepts: [
|
|
120
|
-
${interceptEntries.join(",\n")}
|
|
121
|
-
],
|
|
122
|
-
}`;
|
|
123
|
-
});
|
|
124
|
-
const layoutErrorVars = (route.layoutErrorPaths || []).map((ep) => ep ? getImportVar(ep) : "null");
|
|
125
|
-
return ` {
|
|
126
|
-
__buildTimeClassifications: __VINEXT_CLASS(${routeIdx}), // evaluated once at module load
|
|
127
|
-
__buildTimeReasons: __classDebug ? __VINEXT_CLASS_REASONS(${routeIdx}) : null,
|
|
128
|
-
pattern: ${JSON.stringify(route.pattern)},
|
|
129
|
-
patternParts: ${JSON.stringify(route.patternParts)},
|
|
130
|
-
isDynamic: ${route.isDynamic},
|
|
131
|
-
params: ${JSON.stringify(route.params)},
|
|
132
|
-
page: ${route.pagePath ? getImportVar(route.pagePath) : "null"},
|
|
133
|
-
routeHandler: ${route.routePath ? getImportVar(route.routePath) : "null"},
|
|
134
|
-
layouts: [${layoutVars.join(", ")}],
|
|
135
|
-
routeSegments: ${JSON.stringify(route.routeSegments)},
|
|
136
|
-
templateTreePositions: ${JSON.stringify(route.templateTreePositions)},
|
|
137
|
-
layoutTreePositions: ${JSON.stringify(route.layoutTreePositions)},
|
|
138
|
-
templates: [${templateVars.join(", ")}],
|
|
139
|
-
errors: [${layoutErrorVars.join(", ")}],
|
|
140
|
-
slots: {
|
|
141
|
-
${slotEntries.join(",\n")}
|
|
142
|
-
},
|
|
143
|
-
loading: ${route.loadingPath ? getImportVar(route.loadingPath) : "null"},
|
|
144
|
-
error: ${route.errorPath ? getImportVar(route.errorPath) : "null"},
|
|
145
|
-
notFound: ${route.notFoundPath ? getImportVar(route.notFoundPath) : "null"},
|
|
146
|
-
notFounds: [${notFoundVars.join(", ")}],
|
|
147
|
-
forbidden: ${route.forbiddenPath ? getImportVar(route.forbiddenPath) : "null"},
|
|
148
|
-
unauthorized: ${route.unauthorizedPath ? getImportVar(route.unauthorizedPath) : "null"},
|
|
149
|
-
}`;
|
|
150
|
-
});
|
|
151
|
-
const rootRoute = routes.find((r) => r.pattern === "/");
|
|
152
|
-
const rootNotFoundVar = rootRoute?.notFoundPath ? getImportVar(rootRoute.notFoundPath) : null;
|
|
153
|
-
const rootForbiddenVar = rootRoute?.forbiddenPath ? getImportVar(rootRoute.forbiddenPath) : null;
|
|
154
|
-
const rootUnauthorizedVar = rootRoute?.unauthorizedPath ? getImportVar(rootRoute.unauthorizedPath) : null;
|
|
155
|
-
const rootLayoutVars = rootRoute ? rootRoute.layouts.map((l) => getImportVar(l)) : [];
|
|
156
|
-
const globalErrorVar = globalErrorPath ? getImportVar(globalErrorPath) : null;
|
|
157
|
-
const effectiveMetaRoutes = metadataRoutes ?? [];
|
|
158
|
-
const dynamicMetaRoutes = effectiveMetaRoutes.filter((r) => r.isDynamic);
|
|
159
|
-
for (const mr of dynamicMetaRoutes) getImportVar(mr.filePath);
|
|
160
|
-
const metaRouteEntries = effectiveMetaRoutes.map((mr) => {
|
|
161
|
-
const patternParts = mr.isDynamic && mr.servedUrl.includes("[") ? JSON.stringify(mr.servedUrl.split("/").filter(Boolean).map((seg) => {
|
|
162
|
-
if (seg.startsWith("[[...") && seg.endsWith("]]")) return ":" + seg.slice(5, -2) + "*";
|
|
163
|
-
if (seg.startsWith("[...") && seg.endsWith("]")) return ":" + seg.slice(4, -1) + "+";
|
|
164
|
-
if (seg.startsWith("[") && seg.endsWith("]")) return ":" + seg.slice(1, -1);
|
|
165
|
-
return seg;
|
|
166
|
-
})) : null;
|
|
167
|
-
if (mr.isDynamic) return ` {
|
|
168
|
-
type: ${JSON.stringify(mr.type)},
|
|
169
|
-
isDynamic: true,
|
|
170
|
-
servedUrl: ${JSON.stringify(mr.servedUrl)},
|
|
171
|
-
contentType: ${JSON.stringify(mr.contentType)},
|
|
172
|
-
module: ${getImportVar(mr.filePath)},${patternParts ? `\n patternParts: ${patternParts},` : ""}
|
|
173
|
-
}`;
|
|
174
|
-
let fileDataBase64 = "";
|
|
175
|
-
try {
|
|
176
|
-
fileDataBase64 = fs.readFileSync(mr.filePath).toString("base64");
|
|
177
|
-
} catch {}
|
|
178
|
-
return ` {
|
|
179
|
-
type: ${JSON.stringify(mr.type)},
|
|
180
|
-
isDynamic: false,
|
|
181
|
-
servedUrl: ${JSON.stringify(mr.servedUrl)},
|
|
182
|
-
contentType: ${JSON.stringify(mr.contentType)},
|
|
183
|
-
fileDataBase64: ${JSON.stringify(fileDataBase64)},
|
|
184
|
-
}`;
|
|
66
|
+
const { imports, routeEntries, metaRouteEntries, generateStaticParamsEntries, rootNotFoundVar, rootForbiddenVar, rootUnauthorizedVar, rootLayoutVars, globalErrorVar } = buildAppRscManifestCode({
|
|
67
|
+
routes,
|
|
68
|
+
metadataRoutes,
|
|
69
|
+
globalErrorPath
|
|
185
70
|
});
|
|
71
|
+
const loadPrerenderPagesRoutesCode = hasPagesDir ? `
|
|
72
|
+
async function __loadPrerenderPagesRoutes() {
|
|
73
|
+
const __gspSsrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
|
|
74
|
+
return __gspSsrEntry.pageRoutes;
|
|
75
|
+
}
|
|
76
|
+
` : "";
|
|
77
|
+
const prerenderPagesLoaderOption = hasPagesDir ? " loadPagesRoutes: __loadPrerenderPagesRoutes,\n" : "";
|
|
186
78
|
return `
|
|
187
79
|
import {
|
|
188
80
|
renderToReadableStream as _renderToReadableStream,
|
|
@@ -193,70 +85,42 @@ import {
|
|
|
193
85
|
} from "@vitejs/plugin-rsc/rsc";
|
|
194
86
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
195
87
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// Flight lines are newline-delimited, so we buffer partial lines across chunks
|
|
201
|
-
// to guarantee the regex never sees a split hint.
|
|
88
|
+
import {
|
|
89
|
+
normalizeReactFlightPreloadHints as __normalizeReactFlightPreloadHints,
|
|
90
|
+
} from ${JSON.stringify(rscStreamHintsPath)};
|
|
91
|
+
|
|
202
92
|
function renderToReadableStream(model, options) {
|
|
203
|
-
|
|
204
|
-
const stream = _renderToReadableStream(model, options);
|
|
205
|
-
const decoder = new TextDecoder();
|
|
206
|
-
const encoder = new TextEncoder();
|
|
207
|
-
let carry = "";
|
|
208
|
-
return stream.pipeThrough(new TransformStream({
|
|
209
|
-
transform(chunk, controller) {
|
|
210
|
-
const text = carry + decoder.decode(chunk, { stream: true });
|
|
211
|
-
const lastNl = text.lastIndexOf("\\n");
|
|
212
|
-
if (lastNl === -1) {
|
|
213
|
-
carry = text;
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
carry = text.slice(lastNl + 1);
|
|
217
|
-
controller.enqueue(encoder.encode(text.slice(0, lastNl + 1).replace(_hlFixRe, '$1,"style"$2')));
|
|
218
|
-
},
|
|
219
|
-
flush(controller) {
|
|
220
|
-
const text = carry + decoder.decode();
|
|
221
|
-
if (text) controller.enqueue(encoder.encode(text.replace(_hlFixRe, '$1,"style"$2')));
|
|
222
|
-
}
|
|
223
|
-
}));
|
|
93
|
+
return __normalizeReactFlightPreloadHints(_renderToReadableStream(model, options));
|
|
224
94
|
}
|
|
225
95
|
import { createElement } from "react";
|
|
226
96
|
import { setNavigationContext as _setNavigationContextOrig, getNavigationContext as _getNavigationContext } from "next/navigation";
|
|
227
|
-
import { setHeadersContext, headersContextFromRequest, getDraftModeCookieHeader, getAndClearPendingCookies, consumeDynamicUsage,
|
|
228
|
-
import { NextRequest, NextFetchEvent } from "next/server";
|
|
97
|
+
import { setHeadersContext, headersContextFromRequest, getDraftModeCookieHeader, getAndClearPendingCookies, consumeDynamicUsage, consumeInvalidDynamicUsageError, markDynamicUsage, getHeadersContext, setHeadersAccessPhase } from "next/headers";
|
|
229
98
|
import { mergeMetadata, resolveModuleMetadata, mergeViewport, resolveModuleViewport } from "vinext/metadata";
|
|
230
99
|
${middlewarePath ? `import * as middlewareModule from ${JSON.stringify(middlewarePath.replace(/\\/g, "/"))};` : ""}
|
|
231
100
|
${instrumentationPath ? `import * as _instrumentation from ${JSON.stringify(instrumentationPath.replace(/\\/g, "/"))};` : ""}
|
|
232
|
-
|
|
233
|
-
import { requestContextFromRequest, normalizeHost, matchRedirect, matchRewrite,
|
|
234
|
-
import { decodePathParams as __decodePathParams } from ${JSON.stringify(normalizePathModulePath)};
|
|
101
|
+
import { handleMetadataRouteRequest as __handleMetadataRouteRequest } from ${JSON.stringify(metadataRouteResponsePath)};
|
|
102
|
+
import { requestContextFromRequest, normalizeHost, matchRedirect, matchRewrite, isExternalUrl, proxyExternalRequest, sanitizeDestination } from ${JSON.stringify(configMatchersPath)};
|
|
103
|
+
import { decodePathParams as __decodePathParams, normalizePath as __normalizePath } from ${JSON.stringify(normalizePathModulePath)};
|
|
104
|
+
import { normalizePathnameForRouteMatch as __normalizePathnameForRouteMatch, normalizePathnameForRouteMatchStrict as __normalizePathnameForRouteMatchStrict } from ${JSON.stringify(routingUtilsPath)};
|
|
235
105
|
import { buildRequestHeadersFromMiddlewareResponse as __buildRequestHeadersFromMiddlewareResponse } from ${JSON.stringify(middlewareRequestHeadersPath)};
|
|
236
|
-
import {
|
|
237
|
-
import {
|
|
238
|
-
isKnownDynamicAppRoute as __isKnownDynamicAppRoute,
|
|
239
|
-
} from ${JSON.stringify(appRouteHandlerRuntimePath)};
|
|
106
|
+
import { applyConfigHeadersToResponse, resolvePublicFileRoute, validateImageUrl, guardProtocolRelativeUrl, hasBasePath, stripBasePath, normalizeTrailingSlash } from ${JSON.stringify(requestPipelinePath)};
|
|
107
|
+
import { applyAppMiddleware as __applyAppMiddleware } from ${JSON.stringify(appMiddlewarePath)};
|
|
240
108
|
import {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
resolveAppRouteHandlerMethod as __resolveAppRouteHandlerMethod,
|
|
244
|
-
shouldReadAppRouteHandlerCache as __shouldReadAppRouteHandlerCache,
|
|
245
|
-
} from ${JSON.stringify(appRouteHandlerPolicyPath)};
|
|
246
|
-
import {
|
|
247
|
-
executeAppRouteHandler as __executeAppRouteHandler,
|
|
248
|
-
} from ${JSON.stringify(appRouteHandlerExecutionPath)};
|
|
109
|
+
dispatchAppRouteHandler as __dispatchAppRouteHandler,
|
|
110
|
+
} from ${JSON.stringify(appRouteHandlerDispatchPath)};
|
|
249
111
|
import {
|
|
250
112
|
handleProgressiveServerActionRequest as __handleProgressiveServerActionRequest,
|
|
113
|
+
handleServerActionRscRequest as __handleServerActionRscRequest,
|
|
114
|
+
readActionBodyWithLimit as __readBodyWithLimit,
|
|
115
|
+
readActionFormDataWithLimit as __readFormDataWithLimit,
|
|
251
116
|
} from ${JSON.stringify(appServerActionExecutionPath)};
|
|
252
|
-
import {
|
|
253
|
-
|
|
117
|
+
import {
|
|
118
|
+
createRscOnErrorHandler as __createRscOnErrorHandler,
|
|
119
|
+
sanitizeErrorForClient as __sanitizeErrorForClient,
|
|
120
|
+
} from ${JSON.stringify(appRscErrorsPath)};
|
|
254
121
|
import {
|
|
255
122
|
buildAppPageFontLinkHeader as __buildAppPageFontLinkHeader,
|
|
256
|
-
buildAppPageSpecialErrorResponse as __buildAppPageSpecialErrorResponse,
|
|
257
|
-
readAppPageTextStream as __readAppPageTextStream,
|
|
258
123
|
resolveAppPageSpecialError as __resolveAppPageSpecialError,
|
|
259
|
-
teeAppPageRscStreamForCapture as __teeAppPageRscStreamForCapture,
|
|
260
124
|
} from ${JSON.stringify(appPageExecutionPath)};
|
|
261
125
|
import {
|
|
262
126
|
renderAppPageErrorBoundary as __renderAppPageErrorBoundary,
|
|
@@ -272,27 +136,43 @@ import {
|
|
|
272
136
|
resolveAppPageChildSegments as __resolveAppPageChildSegments,
|
|
273
137
|
} from ${JSON.stringify(appPageRouteWiringPath)};
|
|
274
138
|
import {
|
|
275
|
-
|
|
276
|
-
} from ${JSON.stringify(
|
|
139
|
+
resolveAppPageSegmentParams as __resolveAppPageSegmentParams,
|
|
140
|
+
} from ${JSON.stringify(appPageParamsPath)};
|
|
141
|
+
import {
|
|
142
|
+
collectAppPageSearchParams as __collectAppPageSearchParams,
|
|
143
|
+
resolveActiveParallelRouteHeadInputs as __resolveActiveParallelRouteHeadInputs,
|
|
144
|
+
resolveAppPageHead as __resolveAppPageHead,
|
|
145
|
+
} from ${JSON.stringify(appPageHeadPath)};
|
|
277
146
|
import {
|
|
278
147
|
mergeMiddlewareResponseHeaders as __mergeMiddlewareResponseHeaders,
|
|
279
148
|
} from ${JSON.stringify(appPageResponsePath)};
|
|
149
|
+
import {
|
|
150
|
+
dispatchAppPage as __dispatchAppPage,
|
|
151
|
+
} from ${JSON.stringify(appPageDispatchPath)};
|
|
280
152
|
import { getScriptNonceFromHeaderSources as __getScriptNonceFromHeaderSources } from ${JSON.stringify(cspPath)};
|
|
153
|
+
import { buildPageCacheTags } from ${JSON.stringify(implicitTagsPath)};
|
|
154
|
+
import { getRequestExecutionContext as _getRequestExecutionContext } from ${JSON.stringify(requestContextShimPath)};
|
|
155
|
+
import { setRootParams as __setRootParams, pickRootParams as __pickRootParams } from ${JSON.stringify(rootParamsShimPath)};
|
|
156
|
+
import { makeThenableParams } from ${JSON.stringify(thenableParamsShimPath)};
|
|
157
|
+
import { ensureFetchPatch as _ensureFetchPatch, setCurrentFetchSoftTags } from "vinext/fetch-cache";
|
|
281
158
|
import {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
resolveAppPageIntercept as __resolveAppPageIntercept,
|
|
285
|
-
validateAppPageDynamicParams as __validateAppPageDynamicParams,
|
|
286
|
-
} from ${JSON.stringify(appPageRequestPath)};
|
|
159
|
+
createAppRscRouteMatcher as __createAppRscRouteMatcher,
|
|
160
|
+
} from ${JSON.stringify(appRscRouteMatchingPath)};
|
|
287
161
|
import {
|
|
288
|
-
|
|
289
|
-
} from ${JSON.stringify(
|
|
290
|
-
import {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
162
|
+
handleAppPrerenderEndpoint as __handleAppPrerenderEndpoint,
|
|
163
|
+
} from ${JSON.stringify(appPrerenderEndpointsPath)};
|
|
164
|
+
import {
|
|
165
|
+
appIsrHtmlKey as __isrHtmlKey,
|
|
166
|
+
appIsrRscKey as __isrRscKey,
|
|
167
|
+
appIsrRouteKey as __isrRouteKey,
|
|
168
|
+
isrGet as __isrGet,
|
|
169
|
+
isrSet as __isrSet,
|
|
170
|
+
normalizeMountedSlotsHeader as __normalizeMountedSlotsHeader,
|
|
171
|
+
triggerBackgroundRegeneration as __triggerBackgroundRegeneration,
|
|
172
|
+
} from ${JSON.stringify(isrCachePath)};
|
|
294
173
|
// Import server-only state module to register ALS-backed accessors.
|
|
295
174
|
import "vinext/navigation-state";
|
|
175
|
+
import { runWithPrerenderWorkUnit as __runWithPrerenderWorkUnit } from ${JSON.stringify(prerenderWorkUnitSetupPath)};
|
|
296
176
|
import { runWithRequestContext as _runWithUnifiedCtx, createRequestContext as _createUnifiedCtx } from "vinext/unified-request-context";
|
|
297
177
|
import { reportRequestError as _reportRequestError } from "vinext/instrumentation";
|
|
298
178
|
import { flattenErrorCauses as __flattenErrorCauses } from ${JSON.stringify(errorCausePath)};
|
|
@@ -300,7 +180,7 @@ import { getSSRFontLinks as _getSSRFontLinks, getSSRFontStyles as _getSSRFontSty
|
|
|
300
180
|
import { getSSRFontStyles as _getSSRFontStylesLocal, getSSRFontPreloads as _getSSRFontPreloadsLocal } from "next/font/local";
|
|
301
181
|
function _getSSRFontStyles() { return [..._getSSRFontStylesGoogle(), ..._getSSRFontStylesLocal()]; }
|
|
302
182
|
function _getSSRFontPreloads() { return [..._getSSRFontPreloadsGoogle(), ..._getSSRFontPreloadsLocal()]; }
|
|
303
|
-
${hasPagesDir ? `//
|
|
183
|
+
${hasPagesDir ? `// Pages Router routes are loaded lazily from the SSR environment for internal prerender requests.` : ""}
|
|
304
184
|
|
|
305
185
|
// ALS used to suppress the expected "Invalid hook call" dev warning when
|
|
306
186
|
// layout/page components are probed outside React's render cycle. Patching
|
|
@@ -323,48 +203,15 @@ console.error = (...args) => {
|
|
|
323
203
|
// it in a module-level variable (that would leak between concurrent requests).
|
|
324
204
|
function setNavigationContext(ctx) {
|
|
325
205
|
_setNavigationContextOrig(ctx);
|
|
206
|
+
if (ctx === null) __setRootParams(null);
|
|
326
207
|
}
|
|
327
208
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
//
|
|
332
|
-
//
|
|
333
|
-
// These helpers are inlined instead of imported from isr-cache.js because
|
|
334
|
-
// the virtual RSC entry module runs in the RSC Vite environment which
|
|
335
|
-
// cannot use dynamic imports at the module-evaluation level for server-only
|
|
336
|
-
// modules, and direct imports must use the pre-computed absolute paths.
|
|
337
|
-
async function __isrGet(key) {
|
|
338
|
-
const handler = getCacheHandler();
|
|
339
|
-
const result = await handler.get(key);
|
|
340
|
-
if (!result || !result.value) return null;
|
|
341
|
-
return { value: result, isStale: result.cacheState === "stale" };
|
|
342
|
-
}
|
|
343
|
-
async function __isrSet(key, data, revalidateSeconds, tags) {
|
|
344
|
-
const handler = getCacheHandler();
|
|
345
|
-
await handler.set(key, data, { revalidate: revalidateSeconds, tags: Array.isArray(tags) ? tags : [] });
|
|
346
|
-
}
|
|
347
|
-
function __pageCacheTags(pathname, extraTags) {
|
|
348
|
-
const tags = [pathname, "_N_T_" + pathname];
|
|
349
|
-
// Layout hierarchy tags — matches Next.js getDerivedTags.
|
|
350
|
-
tags.push("_N_T_/layout");
|
|
351
|
-
const segments = pathname.split("/");
|
|
352
|
-
let built = "";
|
|
353
|
-
for (let i = 1; i < segments.length; i++) {
|
|
354
|
-
if (segments[i]) {
|
|
355
|
-
built += "/" + segments[i];
|
|
356
|
-
tags.push("_N_T_" + built + "/layout");
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
// Leaf page tag — revalidatePath(path, "page") targets this.
|
|
360
|
-
tags.push("_N_T_" + built + "/page");
|
|
361
|
-
if (Array.isArray(extraTags)) {
|
|
362
|
-
for (const tag of extraTags) {
|
|
363
|
-
if (!tags.includes(tag)) tags.push(tag);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return tags;
|
|
209
|
+
function __clearRequestContext() {
|
|
210
|
+
setHeadersContext(null);
|
|
211
|
+
setNavigationContext(null);
|
|
212
|
+
// setNavigationContext(null) already clears root params internally
|
|
367
213
|
}
|
|
214
|
+
|
|
368
215
|
// Note: cache entries are written with \`headers: undefined\`. Next.js stores
|
|
369
216
|
// response headers (e.g. set-cookie from cookies().set() during render) in the
|
|
370
217
|
// cache entry so they can be replayed on HIT. We don't do this because:
|
|
@@ -375,68 +222,6 @@ function __pageCacheTags(pathname, extraTags) {
|
|
|
375
222
|
// In practice this means ISR-cached responses won't replay render-time set-cookie
|
|
376
223
|
// headers — but that case is already prevented by the dynamic-usage opt-out.
|
|
377
224
|
// TODO: capture render-time response headers for full Next.js parity.
|
|
378
|
-
const __pendingRegenerations = new Map();
|
|
379
|
-
function __triggerBackgroundRegeneration(key, renderFn) {
|
|
380
|
-
if (__pendingRegenerations.has(key)) return;
|
|
381
|
-
const promise = renderFn()
|
|
382
|
-
.catch((err) => console.error("[vinext] ISR regen failed for " + key + ":", err))
|
|
383
|
-
.finally(() => __pendingRegenerations.delete(key));
|
|
384
|
-
__pendingRegenerations.set(key, promise);
|
|
385
|
-
const ctx = _getRequestExecutionContext();
|
|
386
|
-
if (ctx && typeof ctx.waitUntil === "function") ctx.waitUntil(promise);
|
|
387
|
-
}
|
|
388
|
-
// HTML and RSC are stored under separate keys — matching Next.js's file-system
|
|
389
|
-
// layout (.html / .rsc) — so each request type reads and writes its own key
|
|
390
|
-
// independently with no races or partial-entry sentinels.
|
|
391
|
-
//
|
|
392
|
-
// Key format: "app:<buildId>:<pathname>:<suffix>"
|
|
393
|
-
// Long-pathname fallback: "app:<buildId>:__hash:<fnv1a64(pathname)>:<suffix>"
|
|
394
|
-
// Without buildId (should not happen in production): "app:<pathname>:<suffix>"
|
|
395
|
-
// The 200-char threshold keeps the full key well under Cloudflare KV's 512-byte limit
|
|
396
|
-
// even after adding the build ID and suffix. FNV-1a 64 is used for the hash (two
|
|
397
|
-
// 32-bit rounds) to give a ~64-bit output with negligible collision probability for
|
|
398
|
-
// realistic pathname lengths.
|
|
399
|
-
// Keep prefix construction and hashing logic in sync with isrCacheKey() in server/isr-cache.ts.
|
|
400
|
-
function __isrFnv1a64(s) {
|
|
401
|
-
// h1 uses the standard FNV-1a 32-bit offset basis (0x811c9dc5).
|
|
402
|
-
let h1 = 0x811c9dc5;
|
|
403
|
-
for (let i = 0; i < s.length; i++) { h1 ^= s.charCodeAt(i); h1 = (h1 * 0x01000193) >>> 0; }
|
|
404
|
-
// h2 uses a different seed (0x050c5d1f — the FNV-1a hash of the string "vinext")
|
|
405
|
-
// so the two rounds are independently seeded and their outputs are decorrelated.
|
|
406
|
-
// Concatenating two independently-seeded 32-bit FNV-1a hashes gives an effective
|
|
407
|
-
// 64-bit hash. A random non-standard seed would also work; we derive it from a
|
|
408
|
-
// fixed string so the choice is auditable and deterministic across rebuilds.
|
|
409
|
-
let h2 = 0x050c5d1f;
|
|
410
|
-
for (let i = 0; i < s.length; i++) { h2 ^= s.charCodeAt(i); h2 = (h2 * 0x01000193) >>> 0; }
|
|
411
|
-
return h1.toString(36) + h2.toString(36);
|
|
412
|
-
}
|
|
413
|
-
function __isrCacheKey(pathname, suffix) {
|
|
414
|
-
const normalized = pathname === "/" ? "/" : pathname.replace(/\\/$/, "");
|
|
415
|
-
// __VINEXT_BUILD_ID is replaced at compile time by Vite's define plugin.
|
|
416
|
-
const buildId = process.env.__VINEXT_BUILD_ID;
|
|
417
|
-
const prefix = buildId ? "app:" + buildId : "app";
|
|
418
|
-
const key = prefix + ":" + normalized + ":" + suffix;
|
|
419
|
-
if (key.length <= 200) return key;
|
|
420
|
-
// Pathname too long — hash it to keep under KV's 512-byte key limit.
|
|
421
|
-
return prefix + ":__hash:" + __isrFnv1a64(normalized) + ":" + suffix;
|
|
422
|
-
}
|
|
423
|
-
function __isrHtmlKey(pathname) { return __isrCacheKey(pathname, "html"); }
|
|
424
|
-
function __isrRscKey(pathname, mountedSlotsHeader) {
|
|
425
|
-
if (!mountedSlotsHeader) return __isrCacheKey(pathname, "rsc");
|
|
426
|
-
return __isrCacheKey(pathname, "rsc:" + __isrFnv1a64(mountedSlotsHeader));
|
|
427
|
-
}
|
|
428
|
-
function __normalizeMountedSlotsHeader(raw) {
|
|
429
|
-
if (!raw) return null;
|
|
430
|
-
const normalized = Array.from(
|
|
431
|
-
new Set(
|
|
432
|
-
raw
|
|
433
|
-
.split(/\\s+/)
|
|
434
|
-
.filter(Boolean),
|
|
435
|
-
),
|
|
436
|
-
).sort().join(" ");
|
|
437
|
-
return normalized || null;
|
|
438
|
-
}
|
|
439
|
-
function __isrRouteKey(pathname) { return __isrCacheKey(pathname, "route"); }
|
|
440
225
|
// Verbose cache logging — opt in with NEXT_PRIVATE_DEBUG_CACHE=1.
|
|
441
226
|
// Matches the env var Next.js uses for its own cache debug output so operators
|
|
442
227
|
// have a single knob for all cache tracing.
|
|
@@ -454,124 +239,6 @@ const __classDebug = process.env.VINEXT_DEBUG_CLASSIFICATION
|
|
|
454
239
|
}
|
|
455
240
|
: undefined;
|
|
456
241
|
|
|
457
|
-
// Normalize null-prototype objects from matchPattern() into thenable objects
|
|
458
|
-
// that work both as Promises (for Next.js 15+ async params) and as plain
|
|
459
|
-
// objects with synchronous property access (for pre-15 code like params.id).
|
|
460
|
-
//
|
|
461
|
-
// matchPattern() uses Object.create(null), producing objects without
|
|
462
|
-
// Object.prototype. The RSC serializer rejects these. Spreading ({...obj})
|
|
463
|
-
// restores a normal prototype. Object.assign onto the Promise preserves
|
|
464
|
-
// synchronous property access (params.id, params.slug) that existing
|
|
465
|
-
// components and test fixtures rely on.
|
|
466
|
-
function makeThenableParams(obj) {
|
|
467
|
-
const plain = { ...obj };
|
|
468
|
-
return Object.assign(Promise.resolve(plain), plain);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// djb2 hash — matches Next.js's stringHash for digest generation.
|
|
472
|
-
// Produces a stable numeric string from error message + stack.
|
|
473
|
-
function __errorDigest(str) {
|
|
474
|
-
let hash = 5381;
|
|
475
|
-
for (let i = str.length - 1; i >= 0; i--) {
|
|
476
|
-
hash = (hash * 33) ^ str.charCodeAt(i);
|
|
477
|
-
}
|
|
478
|
-
return (hash >>> 0).toString();
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// Sanitize an error for client consumption. In production, replaces the error
|
|
482
|
-
// with a generic Error that only carries a digest hash (matching Next.js
|
|
483
|
-
// behavior). In development, returns the original error for debugging.
|
|
484
|
-
// Navigation errors (redirect, notFound, etc.) are always passed through
|
|
485
|
-
// unchanged since their digests are used for client-side routing.
|
|
486
|
-
function __sanitizeErrorForClient(error) {
|
|
487
|
-
// Navigation errors must pass through with their digest intact
|
|
488
|
-
if (__resolveAppPageSpecialError(error)) {
|
|
489
|
-
return error;
|
|
490
|
-
}
|
|
491
|
-
// In development, pass through the original error for debugging
|
|
492
|
-
if (process.env.NODE_ENV !== "production") {
|
|
493
|
-
return error;
|
|
494
|
-
}
|
|
495
|
-
// In production, create a sanitized error with only a digest hash
|
|
496
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
497
|
-
const stack = error instanceof Error ? (error.stack || "") : "";
|
|
498
|
-
const sanitized = new Error(
|
|
499
|
-
"An error occurred in the Server Components render. " +
|
|
500
|
-
"The specific message is omitted in production builds to avoid leaking sensitive details. " +
|
|
501
|
-
"A digest property is included on this error instance which may provide additional details about the nature of the error."
|
|
502
|
-
);
|
|
503
|
-
sanitized.digest = __errorDigest(msg + stack);
|
|
504
|
-
return sanitized;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// onError callback for renderToReadableStream — preserves the digest for
|
|
508
|
-
// Next.js navigation errors (redirect, notFound, forbidden, unauthorized)
|
|
509
|
-
// thrown during RSC streaming (e.g. inside Suspense boundaries).
|
|
510
|
-
// For non-navigation errors in production, generates a digest hash so the
|
|
511
|
-
// error can be correlated with server logs without leaking details.
|
|
512
|
-
function rscOnError(error, requestInfo, errorContext) {
|
|
513
|
-
if (error && typeof error === "object" && "digest" in error) {
|
|
514
|
-
return String(error.digest);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// In dev, detect the "Only plain objects" RSC serialization error and emit
|
|
518
|
-
// an actionable hint. This error occurs when a Server Component passes a
|
|
519
|
-
// class instance, ES module namespace object, or null-prototype object as a
|
|
520
|
-
// prop to a Client Component.
|
|
521
|
-
//
|
|
522
|
-
// Root cause: Vite bundles modules as true ESM (module namespace objects
|
|
523
|
-
// have a null-like internal slot), while Next.js's webpack build produces
|
|
524
|
-
// plain CJS-wrapped objects with __esModule:true. React's RSC serializer
|
|
525
|
-
// accepts the latter as plain objects but rejects the former — which means
|
|
526
|
-
// code that accidentally passes "import * as X" works in webpack/Next.js
|
|
527
|
-
// but correctly fails in vinext.
|
|
528
|
-
//
|
|
529
|
-
// Common triggers:
|
|
530
|
-
// - "import * as utils from './utils'" passed as a prop
|
|
531
|
-
// - class instances (new Foo()) passed as props
|
|
532
|
-
// - Date / Map / Set instances passed as props
|
|
533
|
-
// - Objects with Object.create(null) (null prototype)
|
|
534
|
-
if (
|
|
535
|
-
process.env.NODE_ENV !== "production" &&
|
|
536
|
-
error instanceof Error &&
|
|
537
|
-
error.message.includes("Only plain objects, and a few built-ins, can be passed to Client Components")
|
|
538
|
-
) {
|
|
539
|
-
console.error(
|
|
540
|
-
"[vinext] RSC serialization error: a non-plain object was passed from a Server Component to a Client Component.\\n" +
|
|
541
|
-
"\\n" +
|
|
542
|
-
"Common causes:\\n" +
|
|
543
|
-
" * Passing a module namespace (import * as X) directly as a prop.\\n" +
|
|
544
|
-
" Unlike Next.js (webpack), Vite produces real ESM module namespace objects\\n" +
|
|
545
|
-
" which are not serializable. Fix: pass individual values instead,\\n" +
|
|
546
|
-
" e.g. <Comp value={module.value} />\\n" +
|
|
547
|
-
" * Passing a class instance (new Foo()) as a prop.\\n" +
|
|
548
|
-
" Fix: convert to a plain object, e.g. { id: foo.id, name: foo.name }\\n" +
|
|
549
|
-
" * Passing a Date, Map, or Set. Use .toISOString(), [...map.entries()], etc.\\n" +
|
|
550
|
-
" * Passing Object.create(null). Use { ...obj } to restore a prototype.\\n" +
|
|
551
|
-
"\\n" +
|
|
552
|
-
"Original error:",
|
|
553
|
-
error.message,
|
|
554
|
-
);
|
|
555
|
-
return undefined;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (requestInfo && errorContext && error) {
|
|
559
|
-
_reportRequestError(
|
|
560
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
561
|
-
requestInfo,
|
|
562
|
-
errorContext,
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// In production, generate a digest hash for non-navigation errors
|
|
567
|
-
if (process.env.NODE_ENV === "production" && error) {
|
|
568
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
569
|
-
const stack = error instanceof Error ? (error.stack || "") : "";
|
|
570
|
-
return __errorDigest(msg + stack);
|
|
571
|
-
}
|
|
572
|
-
return undefined;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
242
|
function createRscOnErrorHandler(request, pathname, routePath) {
|
|
576
243
|
const requestInfo = {
|
|
577
244
|
path: pathname,
|
|
@@ -583,9 +250,11 @@ function createRscOnErrorHandler(request, pathname, routePath) {
|
|
|
583
250
|
routePath: routePath || pathname,
|
|
584
251
|
routeType: "render",
|
|
585
252
|
};
|
|
586
|
-
return
|
|
587
|
-
|
|
588
|
-
|
|
253
|
+
return __createRscOnErrorHandler({
|
|
254
|
+
errorContext,
|
|
255
|
+
reportRequestError: _reportRequestError,
|
|
256
|
+
requestInfo,
|
|
257
|
+
});
|
|
589
258
|
}
|
|
590
259
|
|
|
591
260
|
${imports.join("\n")}
|
|
@@ -643,7 +312,7 @@ function __VINEXT_CLASS_REASONS(routeIdx) {
|
|
|
643
312
|
const routes = [
|
|
644
313
|
${routeEntries.join(",\n")}
|
|
645
314
|
];
|
|
646
|
-
const
|
|
315
|
+
const __routeMatcher = __createAppRscRouteMatcher(routes);
|
|
647
316
|
|
|
648
317
|
const metadataRoutes = [
|
|
649
318
|
${metaRouteEntries.join(",\n")}
|
|
@@ -667,8 +336,7 @@ async function renderHTTPAccessFallbackPage(route, statusCode, isRscRequest, req
|
|
|
667
336
|
boundaryComponent: opts?.boundaryComponent ?? null,
|
|
668
337
|
buildFontLinkHeader: __buildAppPageFontLinkHeader,
|
|
669
338
|
clearRequestContext() {
|
|
670
|
-
|
|
671
|
-
setNavigationContext(null);
|
|
339
|
+
__clearRequestContext();
|
|
672
340
|
},
|
|
673
341
|
createRscOnErrorHandler(pathname, routePath) {
|
|
674
342
|
return createRscOnErrorHandler(request, pathname, routePath);
|
|
@@ -686,6 +354,7 @@ async function renderHTTPAccessFallbackPage(route, statusCode, isRscRequest, req
|
|
|
686
354
|
makeThenableParams,
|
|
687
355
|
matchedParams: opts?.matchedParams ?? route?.params ?? {},
|
|
688
356
|
middlewareContext: middlewareContext ?? __APP_PAGE_EMPTY_MW_CTX,
|
|
357
|
+
metadataRoutes,
|
|
689
358
|
requestUrl: request.url,
|
|
690
359
|
resolveChildSegments: __resolveAppPageChildSegments,
|
|
691
360
|
rootForbiddenModule: rootForbiddenModule,
|
|
@@ -715,8 +384,7 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
|
|
|
715
384
|
return __renderAppPageErrorBoundary({
|
|
716
385
|
buildFontLinkHeader: __buildAppPageFontLinkHeader,
|
|
717
386
|
clearRequestContext() {
|
|
718
|
-
|
|
719
|
-
setNavigationContext(null);
|
|
387
|
+
__clearRequestContext();
|
|
720
388
|
},
|
|
721
389
|
createRscOnErrorHandler(pathname, routePath) {
|
|
722
390
|
return createRscOnErrorHandler(request, pathname, routePath);
|
|
@@ -734,6 +402,7 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
|
|
|
734
402
|
makeThenableParams,
|
|
735
403
|
matchedParams: matchedParams ?? route?.params ?? {},
|
|
736
404
|
middlewareContext: middlewareContext ?? __APP_PAGE_EMPTY_MW_CTX,
|
|
405
|
+
metadataRoutes,
|
|
737
406
|
requestUrl: request.url,
|
|
738
407
|
resolveChildSegments: __resolveAppPageChildSegments,
|
|
739
408
|
rootLayouts: rootLayouts,
|
|
@@ -745,84 +414,7 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
|
|
|
745
414
|
}
|
|
746
415
|
|
|
747
416
|
function matchRoute(url) {
|
|
748
|
-
|
|
749
|
-
let normalizedUrl = pathname === "/" ? "/" : pathname.replace(/\\/$/, "");
|
|
750
|
-
// NOTE: Do NOT decodeURIComponent here. The caller is responsible for decoding
|
|
751
|
-
// the pathname exactly once at the request entry point. Decoding again here
|
|
752
|
-
// would cause inconsistent path matching between middleware and routing.
|
|
753
|
-
const urlParts = normalizedUrl.split("/").filter(Boolean);
|
|
754
|
-
return _trieMatch(_routeTrie, urlParts);
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
function __createStaticFileSignal(pathname, _mwCtx) {
|
|
758
|
-
const headers = new Headers({
|
|
759
|
-
"x-vinext-static-file": encodeURIComponent(pathname),
|
|
760
|
-
});
|
|
761
|
-
if (_mwCtx.headers) {
|
|
762
|
-
for (const [key, value] of _mwCtx.headers) {
|
|
763
|
-
headers.append(key, value);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
return new Response(null, {
|
|
767
|
-
status: _mwCtx.status ?? 200,
|
|
768
|
-
headers,
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
// matchPattern is kept for findIntercept (linear scan over small interceptLookup array).
|
|
773
|
-
function matchPattern(urlParts, patternParts) {
|
|
774
|
-
const params = Object.create(null);
|
|
775
|
-
for (let i = 0; i < patternParts.length; i++) {
|
|
776
|
-
const pp = patternParts[i];
|
|
777
|
-
if (pp.endsWith("+")) {
|
|
778
|
-
if (i !== patternParts.length - 1) return null;
|
|
779
|
-
const paramName = pp.slice(1, -1);
|
|
780
|
-
const remaining = urlParts.slice(i);
|
|
781
|
-
if (remaining.length === 0) return null;
|
|
782
|
-
params[paramName] = remaining;
|
|
783
|
-
return params;
|
|
784
|
-
}
|
|
785
|
-
if (pp.endsWith("*")) {
|
|
786
|
-
if (i !== patternParts.length - 1) return null;
|
|
787
|
-
const paramName = pp.slice(1, -1);
|
|
788
|
-
params[paramName] = urlParts.slice(i);
|
|
789
|
-
return params;
|
|
790
|
-
}
|
|
791
|
-
if (pp.startsWith(":")) {
|
|
792
|
-
if (i >= urlParts.length) return null;
|
|
793
|
-
params[pp.slice(1)] = urlParts[i];
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
if (i >= urlParts.length || urlParts[i] !== pp) return null;
|
|
797
|
-
}
|
|
798
|
-
if (urlParts.length !== patternParts.length) return null;
|
|
799
|
-
return params;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
function mergeMatchedParams(sourceParams, targetParams) {
|
|
803
|
-
return Object.assign(Object.create(null), sourceParams, targetParams);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// Build a global intercepting route lookup for RSC navigation.
|
|
807
|
-
// Maps target URL patterns to { sourceRouteIndex, slotKey, interceptPage, interceptLayouts, params }.
|
|
808
|
-
const interceptLookup = [];
|
|
809
|
-
for (let ri = 0; ri < routes.length; ri++) {
|
|
810
|
-
const r = routes[ri];
|
|
811
|
-
if (!r.slots) continue;
|
|
812
|
-
for (const [slotKey, slotMod] of Object.entries(r.slots)) {
|
|
813
|
-
if (!slotMod.intercepts) continue;
|
|
814
|
-
for (const intercept of slotMod.intercepts) {
|
|
815
|
-
interceptLookup.push({
|
|
816
|
-
sourceRouteIndex: ri,
|
|
817
|
-
slotKey,
|
|
818
|
-
targetPattern: intercept.targetPattern,
|
|
819
|
-
targetPatternParts: intercept.targetPattern.split("/").filter(Boolean),
|
|
820
|
-
interceptLayouts: intercept.interceptLayouts,
|
|
821
|
-
page: intercept.page,
|
|
822
|
-
params: intercept.params,
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
}
|
|
417
|
+
return __routeMatcher.matchRoute(url);
|
|
826
418
|
}
|
|
827
419
|
|
|
828
420
|
/**
|
|
@@ -830,25 +422,7 @@ for (let ri = 0; ri < routes.length; ri++) {
|
|
|
830
422
|
* Returns the match info or null.
|
|
831
423
|
*/
|
|
832
424
|
function findIntercept(pathname, sourcePathname = null) {
|
|
833
|
-
|
|
834
|
-
for (const entry of interceptLookup) {
|
|
835
|
-
const params = matchPattern(urlParts, entry.targetPatternParts);
|
|
836
|
-
if (params !== null) {
|
|
837
|
-
let sourceParams = Object.create(null);
|
|
838
|
-
if (sourcePathname !== null) {
|
|
839
|
-
const sourceRoute = routes[entry.sourceRouteIndex];
|
|
840
|
-
const sourceParts = sourcePathname.split("/").filter(Boolean);
|
|
841
|
-
const matchedSourceParams = sourceRoute
|
|
842
|
-
? matchPattern(sourceParts, sourceRoute.patternParts)
|
|
843
|
-
: null;
|
|
844
|
-
if (matchedSourceParams !== null) {
|
|
845
|
-
sourceParams = matchedSourceParams;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
return { ...entry, matchedParams: mergeMatchedParams(sourceParams, params) };
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
return null;
|
|
425
|
+
return __routeMatcher.findIntercept(pathname, sourcePathname);
|
|
852
426
|
}
|
|
853
427
|
|
|
854
428
|
async function buildPageElements(route, params, routePath, pageRequest) {
|
|
@@ -879,83 +453,30 @@ async function buildPageElements(route, params, routePath, pageRequest) {
|
|
|
879
453
|
};
|
|
880
454
|
}
|
|
881
455
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
const layoutMods = route.layouts.filter(Boolean);
|
|
907
|
-
|
|
908
|
-
// Convert URLSearchParams → plain object for page generateMetadata() and
|
|
909
|
-
// pageProps.searchParams. Built before the layout loop so the page metadata
|
|
910
|
-
// call (below) and pageProps can reference the same object.
|
|
911
|
-
// NOTE: Layouts do NOT receive searchParams in generateMetadata() — only
|
|
912
|
-
// pages do. This matches Next.js behavior (resolve-metadata.ts:777).
|
|
913
|
-
const spObj = Object.create(null);
|
|
914
|
-
let hasSearchParams = false;
|
|
915
|
-
if (searchParams && searchParams.forEach) {
|
|
916
|
-
searchParams.forEach(function(v, k) {
|
|
917
|
-
hasSearchParams = true;
|
|
918
|
-
if (k in spObj) {
|
|
919
|
-
spObj[k] = Array.isArray(spObj[k]) ? spObj[k].concat(v) : [spObj[k], v];
|
|
920
|
-
} else {
|
|
921
|
-
spObj[k] = v;
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
// Build the parent promise chain and kick off metadata resolution in one pass.
|
|
927
|
-
// Each layout module is called exactly once. layoutMetaPromises[i] is the
|
|
928
|
-
// promise for layout[i]'s own metadata result.
|
|
929
|
-
//
|
|
930
|
-
// All calls are kicked off immediately (concurrent I/O), but each layout's
|
|
931
|
-
// "parent" promise only resolves after the preceding layout's metadata is done.
|
|
932
|
-
const layoutMetaPromises = [];
|
|
933
|
-
let accumulatedMetaPromise = Promise.resolve({});
|
|
934
|
-
for (let i = 0; i < layoutMods.length; i++) {
|
|
935
|
-
const parentForThisLayout = accumulatedMetaPromise;
|
|
936
|
-
// Kick off this layout's metadata resolution now (concurrent with others).
|
|
937
|
-
const metaPromise = resolveModuleMetadata(layoutMods[i], params, undefined, parentForThisLayout)
|
|
938
|
-
.catch((err) => { console.error("[vinext] Layout generateMetadata() failed:", err); return null; });
|
|
939
|
-
layoutMetaPromises.push(metaPromise);
|
|
940
|
-
// Advance accumulator: resolves to merged(layouts[0..i]) once layout[i] is done.
|
|
941
|
-
accumulatedMetaPromise = metaPromise.then(async (result) =>
|
|
942
|
-
result ? mergeMetadata([await parentForThisLayout, result]) : await parentForThisLayout
|
|
943
|
-
);
|
|
944
|
-
}
|
|
945
|
-
// Page's parent is the fully-accumulated layout metadata.
|
|
946
|
-
const pageParentPromise = accumulatedMetaPromise;
|
|
947
|
-
|
|
948
|
-
const [layoutMetaResults, layoutVpResults, pageMeta, pageVp] = await Promise.all([
|
|
949
|
-
Promise.all(layoutMetaPromises),
|
|
950
|
-
Promise.all(layoutMods.map((mod) => resolveModuleViewport(mod, params).catch((err) => { console.error("[vinext] Layout generateViewport() failed:", err); return null; }))),
|
|
951
|
-
route.page ? resolveModuleMetadata(route.page, params, spObj, pageParentPromise) : Promise.resolve(null),
|
|
952
|
-
route.page ? resolveModuleViewport(route.page, params) : Promise.resolve(null),
|
|
953
|
-
]);
|
|
954
|
-
|
|
955
|
-
const metadataList = [...layoutMetaResults.filter(Boolean), ...(pageMeta ? [pageMeta] : [])];
|
|
956
|
-
const viewportList = [...layoutVpResults.filter(Boolean), ...(pageVp ? [pageVp] : [])];
|
|
957
|
-
const resolvedMetadata = metadataList.length > 0 ? mergeMetadata(metadataList) : null;
|
|
958
|
-
const resolvedViewport = mergeViewport(viewportList);
|
|
456
|
+
const {
|
|
457
|
+
hasSearchParams,
|
|
458
|
+
metadata: resolvedMetadata,
|
|
459
|
+
pageSearchParams,
|
|
460
|
+
viewport: resolvedViewport,
|
|
461
|
+
} = await __resolveAppPageHead({
|
|
462
|
+
layoutModules: route.layouts,
|
|
463
|
+
layoutTreePositions: route.layoutTreePositions,
|
|
464
|
+
metadataRoutes,
|
|
465
|
+
pageModule: route.page,
|
|
466
|
+
parallelRoutes: __resolveActiveParallelRouteHeadInputs({
|
|
467
|
+
interceptLayouts: opts?.interceptLayouts ?? null,
|
|
468
|
+
interceptPage: opts?.interceptPage ?? null,
|
|
469
|
+
interceptParams: opts?.interceptParams ?? null,
|
|
470
|
+
interceptSlotKey: opts?.interceptSlotKey ?? null,
|
|
471
|
+
params,
|
|
472
|
+
routeSegments: route.routeSegments,
|
|
473
|
+
slots: route.slots,
|
|
474
|
+
}),
|
|
475
|
+
params,
|
|
476
|
+
routePath: route.pattern,
|
|
477
|
+
routeSegments: route.routeSegments,
|
|
478
|
+
searchParams,
|
|
479
|
+
});
|
|
959
480
|
|
|
960
481
|
// Build the route tree from the leaf page, then delegate the boundary/layout/
|
|
961
482
|
// template/segment wiring to a typed runtime helper so the generated entry
|
|
@@ -965,7 +486,7 @@ async function buildPageElements(route, params, routePath, pageRequest) {
|
|
|
965
486
|
// Always provide searchParams prop when the URL object is available, even
|
|
966
487
|
// when the query string is empty -- pages that do "await searchParams" need
|
|
967
488
|
// it to be a thenable rather than undefined.
|
|
968
|
-
pageProps.searchParams = makeThenableParams(
|
|
489
|
+
pageProps.searchParams = makeThenableParams(pageSearchParams);
|
|
969
490
|
// If the URL has query parameters, mark the page as dynamic.
|
|
970
491
|
// In Next.js, only accessing the searchParams prop signals dynamic usage,
|
|
971
492
|
// but a Proxy-based approach doesn't work here because React's RSC debug
|
|
@@ -996,6 +517,8 @@ async function buildPageElements(route, params, routePath, pageRequest) {
|
|
|
996
517
|
interceptionContext: opts?.interceptionContext ?? null,
|
|
997
518
|
routePath,
|
|
998
519
|
rootNotFoundModule: ${rootNotFoundVar ? rootNotFoundVar : "null"},
|
|
520
|
+
rootForbiddenModule: ${rootForbiddenVar ? rootForbiddenVar : "null"},
|
|
521
|
+
rootUnauthorizedModule: ${rootUnauthorizedVar ? rootUnauthorizedVar : "null"},
|
|
999
522
|
route,
|
|
1000
523
|
slotOverrides:
|
|
1001
524
|
opts && opts.interceptSlotKey && opts.interceptPage
|
|
@@ -1010,8 +533,6 @@ async function buildPageElements(route, params, routePath, pageRequest) {
|
|
|
1010
533
|
});
|
|
1011
534
|
}
|
|
1012
535
|
|
|
1013
|
-
${middlewarePath ? generateMiddlewareMatcherCode("modern") : ""}
|
|
1014
|
-
|
|
1015
536
|
const __basePath = ${JSON.stringify(bp)};
|
|
1016
537
|
const __trailingSlash = ${JSON.stringify(ts)};
|
|
1017
538
|
const __i18nConfig = ${JSON.stringify(i18nConfig)};
|
|
@@ -1023,13 +544,6 @@ const __allowedOrigins = ${JSON.stringify(allowedOrigins)};
|
|
|
1023
544
|
|
|
1024
545
|
${generateDevOriginCheckCode(config?.allowedDevOrigins)}
|
|
1025
546
|
|
|
1026
|
-
// ── ReDoS-safe regex compilation (still needed for middleware matching) ──
|
|
1027
|
-
${generateSafeRegExpCode("modern")}
|
|
1028
|
-
|
|
1029
|
-
// ── Path normalization ──────────────────────────────────────────────────
|
|
1030
|
-
${generateNormalizePathCode("modern")}
|
|
1031
|
-
${generateRouteMatchNormalizationCode("modern")}
|
|
1032
|
-
|
|
1033
547
|
// ── Config pattern matching, redirects, rewrites, headers, CSRF validation,
|
|
1034
548
|
// external URL proxy, cookie parsing, and request context are imported from
|
|
1035
549
|
// config-matchers.ts and request-pipeline.ts (see import statements above).
|
|
@@ -1068,63 +582,6 @@ function __buildPostMwRequestContext(request) {
|
|
|
1068
582
|
*/
|
|
1069
583
|
var __MAX_ACTION_BODY_SIZE = ${JSON.stringify(bodySizeLimit)};
|
|
1070
584
|
|
|
1071
|
-
/**
|
|
1072
|
-
* Read a request body as text with a size limit.
|
|
1073
|
-
* Enforces the limit on the actual byte stream to prevent bypasses
|
|
1074
|
-
* via chunked transfer-encoding where Content-Length is absent or spoofed.
|
|
1075
|
-
*/
|
|
1076
|
-
async function __readBodyWithLimit(request, maxBytes) {
|
|
1077
|
-
if (!request.body) return "";
|
|
1078
|
-
var reader = request.body.getReader();
|
|
1079
|
-
var decoder = new TextDecoder();
|
|
1080
|
-
var chunks = [];
|
|
1081
|
-
var totalSize = 0;
|
|
1082
|
-
for (;;) {
|
|
1083
|
-
var result = await reader.read();
|
|
1084
|
-
if (result.done) break;
|
|
1085
|
-
totalSize += result.value.byteLength;
|
|
1086
|
-
if (totalSize > maxBytes) {
|
|
1087
|
-
reader.cancel();
|
|
1088
|
-
throw new Error("Request body too large");
|
|
1089
|
-
}
|
|
1090
|
-
chunks.push(decoder.decode(result.value, { stream: true }));
|
|
1091
|
-
}
|
|
1092
|
-
chunks.push(decoder.decode());
|
|
1093
|
-
return chunks.join("");
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
* Read a request body as FormData with a size limit.
|
|
1098
|
-
* Consumes the body stream with a byte counter and then parses the
|
|
1099
|
-
* collected bytes as multipart form data via the Response constructor.
|
|
1100
|
-
*/
|
|
1101
|
-
async function __readFormDataWithLimit(request, maxBytes) {
|
|
1102
|
-
if (!request.body) return new FormData();
|
|
1103
|
-
var reader = request.body.getReader();
|
|
1104
|
-
var chunks = [];
|
|
1105
|
-
var totalSize = 0;
|
|
1106
|
-
for (;;) {
|
|
1107
|
-
var result = await reader.read();
|
|
1108
|
-
if (result.done) break;
|
|
1109
|
-
totalSize += result.value.byteLength;
|
|
1110
|
-
if (totalSize > maxBytes) {
|
|
1111
|
-
reader.cancel();
|
|
1112
|
-
throw new Error("Request body too large");
|
|
1113
|
-
}
|
|
1114
|
-
chunks.push(result.value);
|
|
1115
|
-
}
|
|
1116
|
-
// Reconstruct a Response with the original Content-Type so that
|
|
1117
|
-
// the FormData parser can handle multipart boundaries correctly.
|
|
1118
|
-
var combined = new Uint8Array(totalSize);
|
|
1119
|
-
var offset = 0;
|
|
1120
|
-
for (var chunk of chunks) {
|
|
1121
|
-
combined.set(chunk, offset);
|
|
1122
|
-
offset += chunk.byteLength;
|
|
1123
|
-
}
|
|
1124
|
-
var contentType = request.headers.get("content-type") || "";
|
|
1125
|
-
return new Response(combined, { headers: { "Content-Type": contentType } }).formData();
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
585
|
// Map from route pattern to generateStaticParams function.
|
|
1129
586
|
// Used by the prerender phase to enumerate dynamic route URLs without
|
|
1130
587
|
// loading route modules via the dev server.
|
|
@@ -1134,7 +591,10 @@ export const generateStaticParamsMap = {
|
|
|
1134
591
|
// to provide parent params for nested dynamic routes, but they don't have a pagePath
|
|
1135
592
|
// so they are excluded here. Supporting layout-level generateStaticParams requires
|
|
1136
593
|
// scanning layout.tsx files separately and including them in this map.
|
|
1137
|
-
${
|
|
594
|
+
${generateStaticParamsEntries.join("\n")}
|
|
595
|
+
};${loadPrerenderPagesRoutesCode}
|
|
596
|
+
const rootParamNamesMap = {
|
|
597
|
+
${routes.filter((r) => r.isDynamic && r.pagePath && r.rootParamNames && r.rootParamNames.length > 0).map((r) => ` ${JSON.stringify(r.pattern)}: ${JSON.stringify(r.rootParamNames)},`).join("\n")}
|
|
1138
598
|
};
|
|
1139
599
|
|
|
1140
600
|
export default async function handler(request, ctx) {
|
|
@@ -1151,7 +611,8 @@ export default async function handler(request, ctx) {
|
|
|
1151
611
|
executionContext: ctx ?? _getRequestExecutionContext() ?? null,
|
|
1152
612
|
unstableCacheRevalidation: "background",
|
|
1153
613
|
});
|
|
1154
|
-
return _runWithUnifiedCtx(__uCtx,
|
|
614
|
+
return _runWithUnifiedCtx(__uCtx, () =>
|
|
615
|
+
__runWithPrerenderWorkUnit(async () => {
|
|
1155
616
|
_ensureFetchPatch();
|
|
1156
617
|
const __reqCtx = requestContextFromRequest(request);
|
|
1157
618
|
// Per-request container for middleware state. Passed into
|
|
@@ -1184,25 +645,16 @@ export default async function handler(request, ctx) {
|
|
|
1184
645
|
let pathname;
|
|
1185
646
|
try { pathname = __normalizePath(__normalizePathnameForRouteMatch(url.pathname)); } catch { pathname = url.pathname; }
|
|
1186
647
|
${bp ? `if (pathname.startsWith(${JSON.stringify(bp)})) pathname = pathname.slice(${JSON.stringify(bp)}.length) || "/";` : ""}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
// for correct CDN caching behavior.
|
|
1193
|
-
const lk = h.key.toLowerCase();
|
|
1194
|
-
if (lk === "vary" || lk === "set-cookie") {
|
|
1195
|
-
response.headers.append(h.key, h.value);
|
|
1196
|
-
} else if (!response.headers.has(lk)) {
|
|
1197
|
-
// Middleware headers take precedence: skip config keys already
|
|
1198
|
-
// set by middleware so middleware headers always win.
|
|
1199
|
-
response.headers.set(h.key, h.value);
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
648
|
+
applyConfigHeadersToResponse(response.headers, {
|
|
649
|
+
configHeaders: __configHeaders,
|
|
650
|
+
pathname,
|
|
651
|
+
requestContext: __reqCtx,
|
|
652
|
+
});
|
|
1202
653
|
}
|
|
1203
654
|
}
|
|
1204
655
|
return response;
|
|
1205
|
-
|
|
656
|
+
}, { route: () => new URL(request.url).pathname })
|
|
657
|
+
);
|
|
1206
658
|
}
|
|
1207
659
|
|
|
1208
660
|
async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
@@ -1241,74 +693,16 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1241
693
|
pathname = stripBasePath(pathname, __basePath);
|
|
1242
694
|
` : ""}
|
|
1243
695
|
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
return new Response("Not Found", { status: 404 });
|
|
1255
|
-
}
|
|
1256
|
-
const pattern = url.searchParams.get("pattern");
|
|
1257
|
-
if (!pattern) return new Response("missing pattern", { status: 400 });
|
|
1258
|
-
const fn = generateStaticParamsMap[pattern];
|
|
1259
|
-
if (typeof fn !== "function") return new Response("null", { status: 200, headers: { "content-type": "application/json" } });
|
|
1260
|
-
try {
|
|
1261
|
-
const parentParams = url.searchParams.get("parentParams");
|
|
1262
|
-
const raw = parentParams ? JSON.parse(parentParams) : {};
|
|
1263
|
-
// Ensure params is a plain object — reject primitives, arrays, and null
|
|
1264
|
-
// so user-authored generateStaticParams always receives { params: {} }
|
|
1265
|
-
// rather than { params: 5 } or similar if input is malformed.
|
|
1266
|
-
const params = (typeof raw === "object" && raw !== null && !Array.isArray(raw)) ? raw : {};
|
|
1267
|
-
const result = await fn({ params });
|
|
1268
|
-
return new Response(JSON.stringify(result), { status: 200, headers: { "content-type": "application/json" } });
|
|
1269
|
-
} catch (e) {
|
|
1270
|
-
return new Response(JSON.stringify({ error: String(e) }), { status: 500, headers: { "content-type": "application/json" } });
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
${hasPagesDir ? `
|
|
1275
|
-
// ── Prerender: pages-static-paths endpoint ───────────────────────────
|
|
1276
|
-
// Internal endpoint used by prerenderPages() during a CF Workers hybrid
|
|
1277
|
-
// build to call getStaticPaths() for dynamic Pages Router routes via
|
|
1278
|
-
// wrangler unstable_startWorker. Returns JSON-serialised getStaticPaths result.
|
|
1279
|
-
// Gated on VINEXT_PRERENDER=1 to prevent exposure in normal deployments.
|
|
1280
|
-
// See static-params endpoint above for process.env vs CF vars notes.
|
|
1281
|
-
//
|
|
1282
|
-
// pageRoutes lives in the SSR environment (virtual:vinext-server-entry).
|
|
1283
|
-
// We load it lazily via import.meta.viteRsc.loadModule — the same pattern
|
|
1284
|
-
// used by handleSsr() elsewhere in this template. At build time, Vite's RSC
|
|
1285
|
-
// plugin transforms this call into a bundled cross-environment import, so it
|
|
1286
|
-
// works correctly in the CF Workers production bundle running in Miniflare.
|
|
1287
|
-
if (pathname === "/__vinext/prerender/pages-static-paths") {
|
|
1288
|
-
if (process.env.VINEXT_PRERENDER !== "1") {
|
|
1289
|
-
return new Response("Not Found", { status: 404 });
|
|
1290
|
-
}
|
|
1291
|
-
const __gspPattern = url.searchParams.get("pattern");
|
|
1292
|
-
if (!__gspPattern) return new Response("missing pattern", { status: 400 });
|
|
1293
|
-
try {
|
|
1294
|
-
const __gspSsrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
|
|
1295
|
-
const __pagesRoutes = __gspSsrEntry.pageRoutes;
|
|
1296
|
-
const __gspRoute = Array.isArray(__pagesRoutes)
|
|
1297
|
-
? __pagesRoutes.find((r) => r.pattern === __gspPattern)
|
|
1298
|
-
: undefined;
|
|
1299
|
-
if (!__gspRoute || typeof __gspRoute.module?.getStaticPaths !== "function") {
|
|
1300
|
-
return new Response("null", { status: 200, headers: { "content-type": "application/json" } });
|
|
1301
|
-
}
|
|
1302
|
-
const __localesParam = url.searchParams.get("locales");
|
|
1303
|
-
const __locales = __localesParam ? JSON.parse(__localesParam) : [];
|
|
1304
|
-
const __defaultLocale = url.searchParams.get("defaultLocale") ?? "";
|
|
1305
|
-
const __gspResult = await __gspRoute.module.getStaticPaths({ locales: __locales, defaultLocale: __defaultLocale });
|
|
1306
|
-
return new Response(JSON.stringify(__gspResult), { status: 200, headers: { "content-type": "application/json" } });
|
|
1307
|
-
} catch (e) {
|
|
1308
|
-
return new Response(JSON.stringify({ error: String(e) }), { status: 500, headers: { "content-type": "application/json" } });
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
` : ""}
|
|
696
|
+
const __prerenderEndpointResponse = await __handleAppPrerenderEndpoint(request, {
|
|
697
|
+
isPrerenderEnabled() {
|
|
698
|
+
return process.env.VINEXT_PRERENDER === "1";
|
|
699
|
+
},
|
|
700
|
+
${prerenderPagesLoaderOption}
|
|
701
|
+
pathname,
|
|
702
|
+
rootParamNamesByPattern: rootParamNamesMap,
|
|
703
|
+
staticParamsMap: generateStaticParamsMap,
|
|
704
|
+
});
|
|
705
|
+
if (__prerenderEndpointResponse) return __prerenderEndpointResponse;
|
|
1312
706
|
|
|
1313
707
|
// Trailing slash normalization (redirect to canonical form)
|
|
1314
708
|
const __tsRedirect = normalizeTrailingSlash(pathname, __basePath, __trailingSlash, url.search);
|
|
@@ -1352,142 +746,19 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1352
746
|
// every response path without module-level state that races on Workers.
|
|
1353
747
|
|
|
1354
748
|
${middlewarePath ? `
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
// Note: h may include x-middleware-request-* internal headers so
|
|
1369
|
-
// applyMiddlewareRequestHeaders() can unpack them below.
|
|
1370
|
-
// processMiddlewareHeaders() strips them before any response.
|
|
1371
|
-
_mwCtx.headers = new Headers();
|
|
1372
|
-
for (const [key, value] of __mwCtxData.h) {
|
|
1373
|
-
_mwCtx.headers.append(key, value);
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
if (__mwCtxData.s != null) {
|
|
1377
|
-
_mwCtx.status = __mwCtxData.s;
|
|
1378
|
-
}
|
|
1379
|
-
// Apply forwarded middleware rewrite so routing uses the rewritten path.
|
|
1380
|
-
// The RSC plugin constructs its Request from the original HTTP request,
|
|
1381
|
-
// not from req.url, so the connect handler's req.url rewrite is invisible.
|
|
1382
|
-
if (__mwCtxData.r) {
|
|
1383
|
-
const __rewriteParsed = new URL(__mwCtxData.r, request.url);
|
|
1384
|
-
cleanPathname = __rewriteParsed.pathname;
|
|
1385
|
-
url.search = __rewriteParsed.search;
|
|
1386
|
-
}
|
|
1387
|
-
// Flag set after full context application — if any step fails (e.g. malformed
|
|
1388
|
-
// rewrite URL), we fall back to re-running middleware as a safety net.
|
|
1389
|
-
__mwCtxApplied = true;
|
|
1390
|
-
} catch (e) {
|
|
1391
|
-
console.error("[vinext] Failed to parse forwarded middleware context:", e);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
if (!__mwCtxApplied) {
|
|
1396
|
-
// Run proxy/middleware if present and path matches.
|
|
1397
|
-
// Validate exports match the file type (proxy.ts vs middleware.ts), matching Next.js behavior.
|
|
1398
|
-
// https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts
|
|
1399
|
-
const _isProxy = ${JSON.stringify(isProxyFile(middlewarePath))};
|
|
1400
|
-
const middlewareFn = _isProxy
|
|
1401
|
-
? (middlewareModule.proxy ?? middlewareModule.default)
|
|
1402
|
-
: (middlewareModule.middleware ?? middlewareModule.default);
|
|
1403
|
-
if (typeof middlewareFn !== "function") {
|
|
1404
|
-
const _fileType = _isProxy ? "Proxy" : "Middleware";
|
|
1405
|
-
const _expectedExport = _isProxy ? "proxy" : "middleware";
|
|
1406
|
-
throw new Error("The " + _fileType + " file must export a function named \`" + _expectedExport + "\` or a \`default\` function.");
|
|
1407
|
-
}
|
|
1408
|
-
const middlewareMatcher = middlewareModule.config?.matcher;
|
|
1409
|
-
if (matchesMiddleware(cleanPathname, middlewareMatcher, request, __i18nConfig)) {
|
|
1410
|
-
try {
|
|
1411
|
-
// Wrap in NextRequest so middleware gets .nextUrl, .cookies, .geo, .ip, etc.
|
|
1412
|
-
// Always construct a new Request with the fully decoded + normalized pathname
|
|
1413
|
-
// so middleware and the router see the same canonical path.
|
|
1414
|
-
const mwUrl = new URL(request.url);
|
|
1415
|
-
mwUrl.pathname = cleanPathname;
|
|
1416
|
-
const mwRequest = new Request(mwUrl, request);
|
|
1417
|
-
const __mwNextConfig = (__basePath || __i18nConfig) ? { basePath: __basePath, i18n: __i18nConfig ?? undefined } : undefined;
|
|
1418
|
-
const nextRequest = mwRequest instanceof NextRequest ? mwRequest : new NextRequest(mwRequest, __mwNextConfig ? { nextConfig: __mwNextConfig } : undefined);
|
|
1419
|
-
const mwFetchEvent = new NextFetchEvent({ page: cleanPathname });
|
|
1420
|
-
let mwResponse;
|
|
1421
|
-
try {
|
|
1422
|
-
mwResponse = await middlewareFn(nextRequest, mwFetchEvent);
|
|
1423
|
-
} finally {
|
|
1424
|
-
const _mwWaitUntil = mwFetchEvent.drainWaitUntil();
|
|
1425
|
-
const _mwExecCtx = _getRequestExecutionContext();
|
|
1426
|
-
if (_mwExecCtx && typeof _mwExecCtx.waitUntil === "function") { _mwExecCtx.waitUntil(_mwWaitUntil); }
|
|
1427
|
-
}
|
|
1428
|
-
if (mwResponse) {
|
|
1429
|
-
// Check for x-middleware-next (continue)
|
|
1430
|
-
if (mwResponse.headers.get("x-middleware-next") === "1") {
|
|
1431
|
-
// Middleware wants to continue — collect all headers except the two
|
|
1432
|
-
// control headers we've already consumed. x-middleware-request-*
|
|
1433
|
-
// headers are kept so applyMiddlewareRequestHeaders() can unpack them;
|
|
1434
|
-
// the blanket strip loop after that call removes every remaining
|
|
1435
|
-
// x-middleware-* header before the set is merged into the response.
|
|
1436
|
-
_mwCtx.headers = new Headers();
|
|
1437
|
-
for (const [key, value] of mwResponse.headers) {
|
|
1438
|
-
if (key !== "x-middleware-next" && key !== "x-middleware-rewrite") {
|
|
1439
|
-
_mwCtx.headers.append(key, value);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
} else {
|
|
1443
|
-
// Check for redirect
|
|
1444
|
-
if (mwResponse.status >= 300 && mwResponse.status < 400) {
|
|
1445
|
-
return mwResponse;
|
|
1446
|
-
}
|
|
1447
|
-
// Check for rewrite
|
|
1448
|
-
const rewriteUrl = mwResponse.headers.get("x-middleware-rewrite");
|
|
1449
|
-
if (rewriteUrl) {
|
|
1450
|
-
const rewriteParsed = new URL(rewriteUrl, request.url);
|
|
1451
|
-
cleanPathname = rewriteParsed.pathname;
|
|
1452
|
-
// Carry over query params from the rewrite URL so that
|
|
1453
|
-
// searchParams props, useSearchParams(), and navigation context
|
|
1454
|
-
// reflect the rewrite destination, not the original request.
|
|
1455
|
-
url.search = rewriteParsed.search;
|
|
1456
|
-
// Capture custom status code from rewrite (e.g. NextResponse.rewrite(url, { status: 403 }))
|
|
1457
|
-
if (mwResponse.status !== 200) {
|
|
1458
|
-
_mwCtx.status = mwResponse.status;
|
|
1459
|
-
}
|
|
1460
|
-
// Also save any other headers from the rewrite response
|
|
1461
|
-
_mwCtx.headers = new Headers();
|
|
1462
|
-
for (const [key, value] of mwResponse.headers) {
|
|
1463
|
-
if (key !== "x-middleware-next" && key !== "x-middleware-rewrite") {
|
|
1464
|
-
_mwCtx.headers.append(key, value);
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
} else {
|
|
1468
|
-
// Middleware returned a custom response
|
|
1469
|
-
return mwResponse;
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
} catch (err) {
|
|
1474
|
-
console.error("[vinext] Middleware error:", err);
|
|
1475
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
} // end of if (!__mwCtxApplied)
|
|
1479
|
-
|
|
1480
|
-
// Unpack x-middleware-request-* headers into the request context so that
|
|
1481
|
-
// headers() returns the middleware-modified headers instead of the original
|
|
1482
|
-
// request headers. Strip ALL x-middleware-* headers from the set that will
|
|
1483
|
-
// be merged into the outgoing HTTP response — this prefix is reserved for
|
|
1484
|
-
// internal routing signals and must never reach clients.
|
|
1485
|
-
if (_mwCtx.headers) {
|
|
1486
|
-
// Preserve the pre-strip header set so route handlers can reconstruct
|
|
1487
|
-
// a request object with middleware header overrides applied.
|
|
1488
|
-
_mwCtx.requestHeaders = new Headers(_mwCtx.headers);
|
|
1489
|
-
applyMiddlewareRequestHeaders(_mwCtx.headers);
|
|
1490
|
-
processMiddlewareHeaders(_mwCtx.headers);
|
|
749
|
+
const __mwResult = await __applyAppMiddleware({
|
|
750
|
+
basePath: __basePath,
|
|
751
|
+
cleanPathname,
|
|
752
|
+
context: _mwCtx,
|
|
753
|
+
i18nConfig: __i18nConfig,
|
|
754
|
+
isProxy: ${JSON.stringify(isProxyFile(middlewarePath))},
|
|
755
|
+
module: middlewareModule,
|
|
756
|
+
request,
|
|
757
|
+
});
|
|
758
|
+
if (__mwResult.kind === "response") return __mwResult.response;
|
|
759
|
+
cleanPathname = __mwResult.cleanPathname;
|
|
760
|
+
if (__mwResult.search !== null) {
|
|
761
|
+
url.search = __mwResult.search;
|
|
1491
762
|
}
|
|
1492
763
|
` : ""}
|
|
1493
764
|
|
|
@@ -1506,8 +777,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1506
777
|
const __rewritten = matchRewrite(cleanPathname, __configRewrites.beforeFiles, __postMwReqCtx);
|
|
1507
778
|
if (__rewritten) {
|
|
1508
779
|
if (isExternalUrl(__rewritten)) {
|
|
1509
|
-
|
|
1510
|
-
setNavigationContext(null);
|
|
780
|
+
__clearRequestContext();
|
|
1511
781
|
return proxyExternalRequest(request, __rewritten);
|
|
1512
782
|
}
|
|
1513
783
|
cleanPathname = __rewritten;
|
|
@@ -1522,91 +792,25 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1522
792
|
return Response.redirect(new URL(__imgResult, url.origin).href, 302);
|
|
1523
793
|
}
|
|
1524
794
|
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
metaRoute.type === "sitemap" &&
|
|
1532
|
-
metaRoute.isDynamic &&
|
|
1533
|
-
typeof metaRoute.module.generateSitemaps === "function"
|
|
1534
|
-
) {
|
|
1535
|
-
const sitemapPrefix = metaRoute.servedUrl.slice(0, -4); // strip ".xml"
|
|
1536
|
-
// Match exactly /{prefix}/{id}.xml — one segment only (no slashes in id)
|
|
1537
|
-
if (cleanPathname.startsWith(sitemapPrefix + "/") && cleanPathname.endsWith(".xml")) {
|
|
1538
|
-
const rawId = cleanPathname.slice(sitemapPrefix.length + 1, -4);
|
|
1539
|
-
if (rawId.includes("/")) continue; // multi-segment — not a paginated sitemap
|
|
1540
|
-
const sitemaps = await metaRoute.module.generateSitemaps();
|
|
1541
|
-
const matched = sitemaps.find(function(s) { return String(s.id) === rawId; });
|
|
1542
|
-
if (!matched) return new Response("Not Found", { status: 404 });
|
|
1543
|
-
// Pass the original typed id from generateSitemaps() so numeric IDs stay numeric.
|
|
1544
|
-
// TODO: wrap with makeThenableParams-style Promise when upgrading to Next.js 16
|
|
1545
|
-
// full-Promise param semantics (id becomes Promise<string> in v16).
|
|
1546
|
-
const result = await metaRoute.module.default({ id: matched.id });
|
|
1547
|
-
if (result instanceof Response) return result;
|
|
1548
|
-
return new Response(sitemapToXml(result), {
|
|
1549
|
-
headers: { "Content-Type": metaRoute.contentType },
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
|
-
// Skip — the base servedUrl is not served when generateSitemaps exists
|
|
1553
|
-
continue;
|
|
1554
|
-
}
|
|
1555
|
-
// Match metadata route — use pattern matching for dynamic segments,
|
|
1556
|
-
// strict equality for static paths.
|
|
1557
|
-
var _metaParams = null;
|
|
1558
|
-
if (metaRoute.patternParts) {
|
|
1559
|
-
var _metaUrlParts = cleanPathname.split("/").filter(Boolean);
|
|
1560
|
-
_metaParams = matchPattern(_metaUrlParts, metaRoute.patternParts);
|
|
1561
|
-
if (!_metaParams) continue;
|
|
1562
|
-
} else if (cleanPathname !== metaRoute.servedUrl) {
|
|
1563
|
-
continue;
|
|
1564
|
-
}
|
|
1565
|
-
if (metaRoute.isDynamic) {
|
|
1566
|
-
// Dynamic metadata route — call the default export and serialize
|
|
1567
|
-
const metaFn = metaRoute.module.default;
|
|
1568
|
-
if (typeof metaFn === "function") {
|
|
1569
|
-
const result = await metaFn({ params: makeThenableParams(_metaParams || {}) });
|
|
1570
|
-
let body;
|
|
1571
|
-
// If it's already a Response (e.g., ImageResponse), return directly
|
|
1572
|
-
if (result instanceof Response) return result;
|
|
1573
|
-
// Serialize based on type
|
|
1574
|
-
if (metaRoute.type === "sitemap") body = sitemapToXml(result);
|
|
1575
|
-
else if (metaRoute.type === "robots") body = robotsToText(result);
|
|
1576
|
-
else if (metaRoute.type === "manifest") body = manifestToJson(result);
|
|
1577
|
-
else body = JSON.stringify(result);
|
|
1578
|
-
return new Response(body, {
|
|
1579
|
-
headers: { "Content-Type": metaRoute.contentType },
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
} else {
|
|
1583
|
-
// Static metadata file — decode from embedded base64 data
|
|
1584
|
-
try {
|
|
1585
|
-
const binary = atob(metaRoute.fileDataBase64);
|
|
1586
|
-
const bytes = new Uint8Array(binary.length);
|
|
1587
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
1588
|
-
return new Response(bytes, {
|
|
1589
|
-
headers: {
|
|
1590
|
-
"Content-Type": metaRoute.contentType,
|
|
1591
|
-
"Cache-Control": "public, max-age=0, must-revalidate",
|
|
1592
|
-
},
|
|
1593
|
-
});
|
|
1594
|
-
} catch {
|
|
1595
|
-
return new Response("Not Found", { status: 404 });
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
795
|
+
const metadataRouteResponse = await __handleMetadataRouteRequest({
|
|
796
|
+
metadataRoutes,
|
|
797
|
+
cleanPathname,
|
|
798
|
+
makeThenableParams,
|
|
799
|
+
});
|
|
800
|
+
if (metadataRouteResponse) return metadataRouteResponse;
|
|
1599
801
|
|
|
1600
802
|
// Serve public/ files as filesystem routes after middleware and before
|
|
1601
803
|
// afterFiles/fallback rewrites, matching Next.js routing semantics.
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
804
|
+
const __publicFileResponse = resolvePublicFileRoute({
|
|
805
|
+
cleanPathname,
|
|
806
|
+
middlewareContext: _mwCtx,
|
|
807
|
+
pathname,
|
|
808
|
+
publicFiles: __publicFiles,
|
|
809
|
+
request,
|
|
810
|
+
});
|
|
811
|
+
if (__publicFileResponse) {
|
|
812
|
+
__clearRequestContext();
|
|
813
|
+
return __publicFileResponse;
|
|
1610
814
|
}
|
|
1611
815
|
|
|
1612
816
|
// Set navigation context for Server Components.
|
|
@@ -1625,8 +829,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1625
829
|
allowedOrigins: __allowedOrigins,
|
|
1626
830
|
cleanPathname,
|
|
1627
831
|
clearRequestContext() {
|
|
1628
|
-
|
|
1629
|
-
setNavigationContext(null);
|
|
832
|
+
__clearRequestContext();
|
|
1630
833
|
},
|
|
1631
834
|
contentType: actionContentType,
|
|
1632
835
|
decodeAction,
|
|
@@ -1641,240 +844,97 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1641
844
|
});
|
|
1642
845
|
if (progressiveActionResponse) return progressiveActionResponse;
|
|
1643
846
|
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
let body;
|
|
1664
|
-
try {
|
|
1665
|
-
body = actionContentType.startsWith("multipart/form-data")
|
|
1666
|
-
? await __readFormDataWithLimit(request, __MAX_ACTION_BODY_SIZE)
|
|
1667
|
-
: await __readBodyWithLimit(request, __MAX_ACTION_BODY_SIZE);
|
|
1668
|
-
} catch (sizeErr) {
|
|
1669
|
-
if (sizeErr && sizeErr.message === "Request body too large") {
|
|
1670
|
-
setHeadersContext(null);
|
|
1671
|
-
setNavigationContext(null);
|
|
1672
|
-
return new Response("Payload Too Large", { status: 413 });
|
|
1673
|
-
}
|
|
1674
|
-
throw sizeErr;
|
|
1675
|
-
}
|
|
1676
|
-
const payloadResponse = await validateServerActionPayload(body);
|
|
1677
|
-
if (payloadResponse) {
|
|
1678
|
-
setHeadersContext(null);
|
|
1679
|
-
setNavigationContext(null);
|
|
1680
|
-
return payloadResponse;
|
|
1681
|
-
}
|
|
1682
|
-
const temporaryReferences = createTemporaryReferenceSet();
|
|
1683
|
-
const args = await decodeReply(body, { temporaryReferences });
|
|
1684
|
-
const action = await loadServerAction(actionId);
|
|
1685
|
-
let returnValue;
|
|
1686
|
-
let actionRedirect = null;
|
|
1687
|
-
const previousHeadersPhase = setHeadersAccessPhase("action");
|
|
1688
|
-
try {
|
|
1689
|
-
try {
|
|
1690
|
-
const data = await action.apply(null, args);
|
|
1691
|
-
returnValue = { ok: true, data };
|
|
1692
|
-
} catch (e) {
|
|
1693
|
-
// Detect redirect() / permanentRedirect() called inside the action.
|
|
1694
|
-
// These throw errors with digest "NEXT_REDIRECT;replace;url[;status]".
|
|
1695
|
-
// The URL is encodeURIComponent-encoded to prevent semicolons in the URL
|
|
1696
|
-
// from corrupting the delimiter-based digest format.
|
|
1697
|
-
if (e && typeof e === "object" && "digest" in e) {
|
|
1698
|
-
const digest = String(e.digest);
|
|
1699
|
-
if (digest.startsWith("NEXT_REDIRECT;")) {
|
|
1700
|
-
const parts = digest.split(";");
|
|
1701
|
-
actionRedirect = {
|
|
1702
|
-
url: decodeURIComponent(parts[2]),
|
|
1703
|
-
type: parts[1] || "push", // "push" or "replace"
|
|
1704
|
-
status: parts[3] ? parseInt(parts[3], 10) : 307,
|
|
1705
|
-
};
|
|
1706
|
-
returnValue = { ok: true, data: undefined };
|
|
1707
|
-
} else if (digest === "NEXT_NOT_FOUND" || digest.startsWith("NEXT_HTTP_ERROR_FALLBACK;")) {
|
|
1708
|
-
// notFound() / forbidden() / unauthorized() in action — package as error
|
|
1709
|
-
returnValue = { ok: false, data: e };
|
|
1710
|
-
} else {
|
|
1711
|
-
// Non-navigation digest error — sanitize in production to avoid
|
|
1712
|
-
// leaking internal details (connection strings, paths, etc.)
|
|
1713
|
-
console.error("[vinext] Server action error:", e);
|
|
1714
|
-
returnValue = { ok: false, data: __sanitizeErrorForClient(e) };
|
|
1715
|
-
}
|
|
1716
|
-
} else {
|
|
1717
|
-
// Unhandled error — sanitize in production to avoid leaking
|
|
1718
|
-
// internal details (database errors, file paths, stack traces, etc.)
|
|
1719
|
-
console.error("[vinext] Server action error:", e);
|
|
1720
|
-
returnValue = { ok: false, data: __sanitizeErrorForClient(e) };
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
} finally {
|
|
1724
|
-
setHeadersAccessPhase(previousHeadersPhase);
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
// If the action called redirect(), signal the client to navigate.
|
|
1728
|
-
// We can't use a real HTTP redirect (the fetch would follow it automatically
|
|
1729
|
-
// and receive a page HTML instead of RSC stream). Instead, we return a 200
|
|
1730
|
-
// with x-action-redirect header that the client entry detects and handles.
|
|
1731
|
-
if (actionRedirect) {
|
|
1732
|
-
const actionPendingCookies = getAndClearPendingCookies();
|
|
1733
|
-
const actionDraftCookie = getDraftModeCookieHeader();
|
|
1734
|
-
setHeadersContext(null);
|
|
1735
|
-
setNavigationContext(null);
|
|
1736
|
-
const redirectHeaders = new Headers({
|
|
1737
|
-
"Content-Type": "text/x-component; charset=utf-8",
|
|
1738
|
-
"Vary": "RSC, Accept",
|
|
1739
|
-
});
|
|
1740
|
-
__mergeMiddlewareResponseHeaders(redirectHeaders, _mwCtx.headers);
|
|
1741
|
-
redirectHeaders.set("x-action-redirect", actionRedirect.url);
|
|
1742
|
-
redirectHeaders.set("x-action-redirect-type", actionRedirect.type);
|
|
1743
|
-
redirectHeaders.set("x-action-redirect-status", String(actionRedirect.status));
|
|
1744
|
-
for (const cookie of actionPendingCookies) {
|
|
1745
|
-
redirectHeaders.append("Set-Cookie", cookie);
|
|
1746
|
-
}
|
|
1747
|
-
if (actionDraftCookie) redirectHeaders.append("Set-Cookie", actionDraftCookie);
|
|
1748
|
-
// Send an empty RSC-like body (client will navigate instead of parsing)
|
|
1749
|
-
return new Response("", { status: 200, headers: redirectHeaders });
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
// After the action, re-render the current page so the client
|
|
1753
|
-
// gets an updated React tree reflecting any mutations.
|
|
1754
|
-
//
|
|
1755
|
-
// When the original request came from inside an intercepted modal
|
|
1756
|
-
// (X-Vinext-Interception-Context present + source route still
|
|
1757
|
-
// matches), rebuild the intercepted tree — otherwise the modal would
|
|
1758
|
-
// unmount and the direct route would render in its place. Mirrors
|
|
1759
|
-
// the interception resolution used by the GET path.
|
|
1760
|
-
const match = matchRoute(cleanPathname);
|
|
1761
|
-
let element;
|
|
1762
|
-
let errorPattern = match ? match.route.pattern : cleanPathname;
|
|
1763
|
-
if (match) {
|
|
1764
|
-
const { route: actionRoute, params: actionParams } = match;
|
|
1765
|
-
const __actionRerenderTarget = __resolveAppPageActionRerenderTarget({
|
|
1766
|
-
cleanPathname,
|
|
1767
|
-
currentParams: actionParams,
|
|
1768
|
-
currentRoute: actionRoute,
|
|
1769
|
-
findIntercept(pathname) {
|
|
1770
|
-
return findIntercept(pathname, interceptionContextHeader);
|
|
1771
|
-
},
|
|
1772
|
-
getRouteParamNames(sourceRoute) {
|
|
1773
|
-
return sourceRoute.params;
|
|
1774
|
-
},
|
|
1775
|
-
getSourceRoute(sourceRouteIndex) {
|
|
1776
|
-
return routes[sourceRouteIndex];
|
|
1777
|
-
},
|
|
1778
|
-
isRscRequest,
|
|
1779
|
-
toInterceptOpts(intercept) {
|
|
1780
|
-
return {
|
|
1781
|
-
interceptionContext: interceptionContextHeader,
|
|
1782
|
-
interceptLayouts: intercept.interceptLayouts,
|
|
1783
|
-
interceptSlotKey: intercept.slotKey,
|
|
1784
|
-
interceptPage: intercept.page,
|
|
1785
|
-
interceptParams: intercept.matchedParams,
|
|
1786
|
-
};
|
|
1787
|
-
},
|
|
1788
|
-
});
|
|
1789
|
-
|
|
1790
|
-
setNavigationContext({
|
|
1791
|
-
pathname: cleanPathname,
|
|
1792
|
-
searchParams: url.searchParams,
|
|
1793
|
-
params: __actionRerenderTarget.navigationParams,
|
|
1794
|
-
});
|
|
1795
|
-
element = buildPageElements(
|
|
1796
|
-
__actionRerenderTarget.route,
|
|
1797
|
-
__actionRerenderTarget.params,
|
|
1798
|
-
cleanPathname,
|
|
1799
|
-
{
|
|
1800
|
-
opts: __actionRerenderTarget.interceptOpts,
|
|
1801
|
-
searchParams: url.searchParams,
|
|
1802
|
-
isRscRequest,
|
|
1803
|
-
request,
|
|
1804
|
-
mountedSlotsHeader: __mountedSlotsHeader,
|
|
1805
|
-
},
|
|
1806
|
-
);
|
|
1807
|
-
errorPattern = __actionRerenderTarget.route.pattern;
|
|
1808
|
-
} else {
|
|
1809
|
-
const _actionRouteId = __createAppPayloadRouteId(cleanPathname, null);
|
|
1810
|
-
element = {
|
|
1811
|
-
[__APP_INTERCEPTION_CONTEXT_KEY]: null,
|
|
1812
|
-
__route: _actionRouteId,
|
|
1813
|
-
__rootLayout: null,
|
|
1814
|
-
[_actionRouteId]: createElement("div", null, "Page not found"),
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
const onRenderError = createRscOnErrorHandler(
|
|
1819
|
-
request,
|
|
1820
|
-
cleanPathname,
|
|
1821
|
-
errorPattern,
|
|
1822
|
-
);
|
|
1823
|
-
const rscStream = renderToReadableStream(
|
|
1824
|
-
{ root: element, returnValue },
|
|
1825
|
-
{ temporaryReferences, onError: onRenderError },
|
|
1826
|
-
);
|
|
1827
|
-
|
|
1828
|
-
// Collect cookies set during the action synchronously (before stream is consumed).
|
|
1829
|
-
// Do NOT clear headers/navigation context here — the RSC stream is consumed lazily
|
|
1830
|
-
// by the client, and async server components that run during consumption need the
|
|
1831
|
-
// context to still be live. The AsyncLocalStorage scope from runWithRequestContext
|
|
1832
|
-
// handles cleanup naturally when all async continuations complete.
|
|
1833
|
-
const actionPendingCookies = getAndClearPendingCookies();
|
|
1834
|
-
const actionDraftCookie = getDraftModeCookieHeader();
|
|
1835
|
-
|
|
1836
|
-
const actionHeaders = new Headers({
|
|
1837
|
-
"Content-Type": "text/x-component; charset=utf-8",
|
|
1838
|
-
"Vary": "RSC, Accept",
|
|
1839
|
-
});
|
|
1840
|
-
__mergeMiddlewareResponseHeaders(actionHeaders, _mwCtx.headers);
|
|
1841
|
-
const actionResponse = new Response(rscStream, {
|
|
1842
|
-
status: _mwCtx.status ?? 200,
|
|
1843
|
-
headers: actionHeaders,
|
|
847
|
+
const serverActionResponse = await __handleServerActionRscRequest({
|
|
848
|
+
actionId,
|
|
849
|
+
allowedOrigins: __allowedOrigins,
|
|
850
|
+
buildPageElement({
|
|
851
|
+
route: actionRoute,
|
|
852
|
+
params: actionParams,
|
|
853
|
+
cleanPathname: actionCleanPathname,
|
|
854
|
+
interceptOpts,
|
|
855
|
+
searchParams,
|
|
856
|
+
isRscRequest: actionIsRscRequest,
|
|
857
|
+
request: actionRequest,
|
|
858
|
+
mountedSlotsHeader,
|
|
859
|
+
}) {
|
|
860
|
+
return buildPageElements(actionRoute, actionParams, actionCleanPathname, {
|
|
861
|
+
opts: interceptOpts,
|
|
862
|
+
searchParams,
|
|
863
|
+
isRscRequest: actionIsRscRequest,
|
|
864
|
+
request: actionRequest,
|
|
865
|
+
mountedSlotsHeader,
|
|
1844
866
|
});
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
867
|
+
},
|
|
868
|
+
cleanPathname,
|
|
869
|
+
clearRequestContext() {
|
|
870
|
+
__clearRequestContext();
|
|
871
|
+
},
|
|
872
|
+
contentType: actionContentType,
|
|
873
|
+
createNotFoundElement(actionRouteId) {
|
|
874
|
+
return {
|
|
875
|
+
[__APP_INTERCEPTION_CONTEXT_KEY]: null,
|
|
876
|
+
__route: actionRouteId,
|
|
877
|
+
__rootLayout: null,
|
|
878
|
+
[actionRouteId]: createElement("div", null, "Page not found"),
|
|
879
|
+
};
|
|
880
|
+
},
|
|
881
|
+
createPayloadRouteId(pathnameToRender, interceptionContext) {
|
|
882
|
+
return __createAppPayloadRouteId(pathnameToRender, interceptionContext);
|
|
883
|
+
},
|
|
884
|
+
createRscOnErrorHandler(actionRequest, actionPathname, routePattern) {
|
|
885
|
+
return createRscOnErrorHandler(actionRequest, actionPathname, routePattern);
|
|
886
|
+
},
|
|
887
|
+
createTemporaryReferenceSet,
|
|
888
|
+
decodeReply,
|
|
889
|
+
findIntercept(pathnameToMatch) {
|
|
890
|
+
return findIntercept(pathnameToMatch, interceptionContextHeader);
|
|
891
|
+
},
|
|
892
|
+
getAndClearPendingCookies,
|
|
893
|
+
getDraftModeCookieHeader,
|
|
894
|
+
getRouteParamNames(sourceRoute) {
|
|
895
|
+
return sourceRoute.params;
|
|
896
|
+
},
|
|
897
|
+
getSourceRoute(sourceRouteIndex) {
|
|
898
|
+
return routes[sourceRouteIndex];
|
|
899
|
+
},
|
|
900
|
+
isRscRequest,
|
|
901
|
+
loadServerAction,
|
|
902
|
+
matchRoute(pathnameToMatch) {
|
|
903
|
+
return matchRoute(pathnameToMatch);
|
|
904
|
+
},
|
|
905
|
+
maxActionBodySize: __MAX_ACTION_BODY_SIZE,
|
|
906
|
+
middlewareHeaders: _mwCtx.headers,
|
|
907
|
+
middlewareStatus: _mwCtx.status,
|
|
908
|
+
mountedSlotsHeader: __mountedSlotsHeader,
|
|
909
|
+
readBodyWithLimit: __readBodyWithLimit,
|
|
910
|
+
readFormDataWithLimit: __readFormDataWithLimit,
|
|
911
|
+
renderToReadableStream,
|
|
912
|
+
reportRequestError: _reportRequestError,
|
|
913
|
+
request,
|
|
914
|
+
sanitizeErrorForClient(error) {
|
|
915
|
+
return __sanitizeErrorForClient(error);
|
|
916
|
+
},
|
|
917
|
+
searchParams: url.searchParams,
|
|
918
|
+
setHeadersAccessPhase,
|
|
919
|
+
setNavigationContext,
|
|
920
|
+
toInterceptOpts(intercept) {
|
|
921
|
+
return {
|
|
922
|
+
interceptionContext: interceptionContextHeader,
|
|
923
|
+
interceptLayouts: intercept.interceptLayouts,
|
|
924
|
+
interceptSlotKey: intercept.slotKey,
|
|
925
|
+
interceptPage: intercept.page,
|
|
926
|
+
interceptParams: intercept.matchedParams,
|
|
927
|
+
};
|
|
928
|
+
},
|
|
929
|
+
});
|
|
930
|
+
if (serverActionResponse) return serverActionResponse;
|
|
1870
931
|
|
|
1871
932
|
// ── Apply afterFiles rewrites from next.config.js ──────────────────────
|
|
1872
933
|
if (__configRewrites.afterFiles && __configRewrites.afterFiles.length) {
|
|
1873
934
|
const __afterRewritten = matchRewrite(cleanPathname, __configRewrites.afterFiles, __postMwReqCtx);
|
|
1874
935
|
if (__afterRewritten) {
|
|
1875
936
|
if (isExternalUrl(__afterRewritten)) {
|
|
1876
|
-
|
|
1877
|
-
setNavigationContext(null);
|
|
937
|
+
__clearRequestContext();
|
|
1878
938
|
return proxyExternalRequest(request, __afterRewritten);
|
|
1879
939
|
}
|
|
1880
940
|
cleanPathname = __afterRewritten;
|
|
@@ -1888,8 +948,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1888
948
|
const __fallbackRewritten = matchRewrite(cleanPathname, __configRewrites.fallback, __postMwReqCtx);
|
|
1889
949
|
if (__fallbackRewritten) {
|
|
1890
950
|
if (isExternalUrl(__fallbackRewritten)) {
|
|
1891
|
-
|
|
1892
|
-
setNavigationContext(null);
|
|
951
|
+
__clearRequestContext();
|
|
1893
952
|
return proxyExternalRequest(request, __fallbackRewritten);
|
|
1894
953
|
}
|
|
1895
954
|
cleanPathname = __fallbackRewritten;
|
|
@@ -1930,8 +989,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1930
989
|
// (non-404). A 404 means the path isn't a Pages route either,
|
|
1931
990
|
// so fall through to the App Router not-found page below.
|
|
1932
991
|
if (__pagesRes.status !== 404) {
|
|
1933
|
-
|
|
1934
|
-
setNavigationContext(null);
|
|
992
|
+
__clearRequestContext();
|
|
1935
993
|
return __pagesRes;
|
|
1936
994
|
}
|
|
1937
995
|
}
|
|
@@ -1940,15 +998,13 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1940
998
|
// Render custom not-found page if available, otherwise plain 404
|
|
1941
999
|
const notFoundResponse = await renderNotFoundPage(null, isRscRequest, request, undefined, _scriptNonce, _mwCtx);
|
|
1942
1000
|
if (notFoundResponse) return notFoundResponse;
|
|
1943
|
-
|
|
1944
|
-
setNavigationContext(null);
|
|
1001
|
+
__clearRequestContext();
|
|
1945
1002
|
const notFoundHeaders = new Headers();
|
|
1946
1003
|
__mergeMiddlewareResponseHeaders(notFoundHeaders, _mwCtx.headers);
|
|
1947
1004
|
return new Response("Not Found", { status: 404, headers: notFoundHeaders });
|
|
1948
1005
|
}
|
|
1949
1006
|
|
|
1950
1007
|
const { route, params } = match;
|
|
1951
|
-
setCurrentFetchSoftTags(__pageCacheTags(cleanPathname, []));
|
|
1952
1008
|
|
|
1953
1009
|
// Update navigation context with matched params
|
|
1954
1010
|
setNavigationContext({
|
|
@@ -1956,587 +1012,130 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
|
|
|
1956
1012
|
searchParams: url.searchParams,
|
|
1957
1013
|
params,
|
|
1958
1014
|
});
|
|
1015
|
+
__setRootParams(__pickRootParams(params, route.rootParamNames));
|
|
1959
1016
|
|
|
1960
1017
|
// Handle route.ts API handlers
|
|
1961
1018
|
if (route.routeHandler) {
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
const revalidateSeconds = __getAppRouteHandlerRevalidateSeconds(handler);
|
|
1965
|
-
if (__hasAppRouteHandlerDefaultExport(handler) && process.env.NODE_ENV === "development") {
|
|
1966
|
-
console.error(
|
|
1967
|
-
"[vinext] Detected default export in route handler " + route.pattern + ". Export a named export for each HTTP method instead.",
|
|
1968
|
-
);
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
const {
|
|
1972
|
-
allowHeaderForOptions,
|
|
1973
|
-
handlerFn,
|
|
1974
|
-
isAutoHead,
|
|
1975
|
-
shouldAutoRespondToOptions,
|
|
1976
|
-
} = __resolveAppRouteHandlerMethod(handler, method);
|
|
1977
|
-
|
|
1978
|
-
if (shouldAutoRespondToOptions) {
|
|
1979
|
-
setHeadersContext(null);
|
|
1980
|
-
setNavigationContext(null);
|
|
1981
|
-
return __applyRouteHandlerMiddlewareContext(
|
|
1982
|
-
new Response(null, {
|
|
1983
|
-
status: 204,
|
|
1984
|
-
headers: { "Allow": allowHeaderForOptions },
|
|
1985
|
-
}),
|
|
1986
|
-
_mwCtx,
|
|
1987
|
-
);
|
|
1988
|
-
}
|
|
1989
|
-
|
|
1990
|
-
// ISR cache read for route handlers (production only).
|
|
1991
|
-
// Only GET/HEAD (auto-HEAD) with finite revalidate > 0 are ISR-eligible.
|
|
1992
|
-
// Known-dynamic handlers skip the read entirely so stale cache entries
|
|
1993
|
-
// from earlier requests do not replay once the process has learned they
|
|
1994
|
-
// access request-specific data.
|
|
1995
|
-
if (
|
|
1996
|
-
__shouldReadAppRouteHandlerCache({
|
|
1997
|
-
dynamicConfig: handler.dynamic,
|
|
1998
|
-
handlerFn,
|
|
1999
|
-
isAutoHead,
|
|
2000
|
-
isKnownDynamic: __isKnownDynamicAppRoute(route.pattern),
|
|
2001
|
-
isProduction: process.env.NODE_ENV === "production",
|
|
2002
|
-
method,
|
|
2003
|
-
revalidateSeconds,
|
|
2004
|
-
})
|
|
2005
|
-
) {
|
|
2006
|
-
const __cachedRouteResponse = await __readAppRouteHandlerCacheResponse({
|
|
2007
|
-
basePath: __basePath,
|
|
2008
|
-
buildPageCacheTags: __pageCacheTags,
|
|
2009
|
-
cleanPathname,
|
|
2010
|
-
clearRequestContext: function() {
|
|
2011
|
-
setHeadersContext(null);
|
|
2012
|
-
setNavigationContext(null);
|
|
2013
|
-
},
|
|
2014
|
-
consumeDynamicUsage,
|
|
2015
|
-
getCollectedFetchTags,
|
|
2016
|
-
handlerFn,
|
|
2017
|
-
i18n: __i18nConfig,
|
|
2018
|
-
isAutoHead,
|
|
2019
|
-
isrDebug: __isrDebug,
|
|
2020
|
-
isrGet: __isrGet,
|
|
2021
|
-
isrRouteKey: __isrRouteKey,
|
|
2022
|
-
isrSet: __isrSet,
|
|
2023
|
-
markDynamicUsage,
|
|
2024
|
-
middlewareContext: _mwCtx,
|
|
2025
|
-
params,
|
|
2026
|
-
requestUrl: request.url,
|
|
2027
|
-
revalidateSearchParams: url.searchParams,
|
|
2028
|
-
revalidateSeconds,
|
|
2029
|
-
routePattern: route.pattern,
|
|
2030
|
-
runInRevalidationContext: async function(renderFn) {
|
|
2031
|
-
const __revalHeadCtx = { headers: new Headers(), cookies: new Map() };
|
|
2032
|
-
const __revalUCtx = _createUnifiedCtx({
|
|
2033
|
-
headersContext: __revalHeadCtx,
|
|
2034
|
-
executionContext: _getRequestExecutionContext(),
|
|
2035
|
-
unstableCacheRevalidation: "foreground",
|
|
2036
|
-
});
|
|
2037
|
-
await _runWithUnifiedCtx(__revalUCtx, async () => {
|
|
2038
|
-
_ensureFetchPatch();
|
|
2039
|
-
setCurrentFetchSoftTags(__pageCacheTags(cleanPathname, []));
|
|
2040
|
-
await renderFn();
|
|
2041
|
-
});
|
|
2042
|
-
},
|
|
2043
|
-
scheduleBackgroundRegeneration: __triggerBackgroundRegeneration,
|
|
2044
|
-
setNavigationContext,
|
|
2045
|
-
});
|
|
2046
|
-
if (__cachedRouteResponse) {
|
|
2047
|
-
return __cachedRouteResponse;
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
if (typeof handlerFn === "function") {
|
|
2052
|
-
return __executeAppRouteHandler({
|
|
2053
|
-
basePath: __basePath,
|
|
2054
|
-
buildPageCacheTags: __pageCacheTags,
|
|
2055
|
-
cleanPathname,
|
|
2056
|
-
clearRequestContext: function() {
|
|
2057
|
-
setHeadersContext(null);
|
|
2058
|
-
setNavigationContext(null);
|
|
2059
|
-
},
|
|
2060
|
-
consumeDynamicUsage,
|
|
2061
|
-
executionContext: _getRequestExecutionContext(),
|
|
2062
|
-
getAndClearPendingCookies,
|
|
2063
|
-
getCollectedFetchTags,
|
|
2064
|
-
getDraftModeCookieHeader,
|
|
2065
|
-
handler,
|
|
2066
|
-
handlerFn,
|
|
2067
|
-
i18n: __i18nConfig,
|
|
2068
|
-
isAutoHead,
|
|
2069
|
-
isProduction: process.env.NODE_ENV === "production",
|
|
2070
|
-
isrDebug: __isrDebug,
|
|
2071
|
-
isrRouteKey: __isrRouteKey,
|
|
2072
|
-
isrSet: __isrSet,
|
|
2073
|
-
markDynamicUsage,
|
|
2074
|
-
method,
|
|
2075
|
-
middlewareContext: _mwCtx,
|
|
2076
|
-
middlewareRequestHeaders: _mwCtx.requestHeaders,
|
|
2077
|
-
params: makeThenableParams(params),
|
|
2078
|
-
reportRequestError: _reportRequestError,
|
|
2079
|
-
request,
|
|
2080
|
-
revalidateSeconds,
|
|
2081
|
-
routePattern: route.pattern,
|
|
2082
|
-
setHeadersAccessPhase,
|
|
2083
|
-
});
|
|
2084
|
-
}
|
|
2085
|
-
setHeadersContext(null);
|
|
2086
|
-
setNavigationContext(null);
|
|
2087
|
-
return __applyRouteHandlerMiddlewareContext(
|
|
2088
|
-
new Response(null, {
|
|
2089
|
-
status: 405,
|
|
2090
|
-
}),
|
|
2091
|
-
_mwCtx,
|
|
1019
|
+
setCurrentFetchSoftTags(
|
|
1020
|
+
buildPageCacheTags(cleanPathname, [], route.routeSegments, "route"),
|
|
2092
1021
|
);
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
// Build the component tree: layouts wrapping the page
|
|
2096
|
-
const hasPageModule = !!route.page;
|
|
2097
|
-
const PageComponent = route.page?.default;
|
|
2098
|
-
if (hasPageModule && !PageComponent) {
|
|
2099
|
-
setHeadersContext(null);
|
|
2100
|
-
setNavigationContext(null);
|
|
2101
|
-
return new Response("Page has no default export", { status: 500 });
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
// Read route segment config from page module exports
|
|
2105
|
-
let revalidateSeconds = typeof route.page?.revalidate === "number" ? route.page.revalidate : null;
|
|
2106
|
-
const dynamicConfig = route.page?.dynamic; // 'auto' | 'force-dynamic' | 'force-static' | 'error'
|
|
2107
|
-
const dynamicParamsConfig = route.page?.dynamicParams; // true (default) | false
|
|
2108
|
-
const isForceStatic = dynamicConfig === "force-static";
|
|
2109
|
-
const isDynamicError = dynamicConfig === "error";
|
|
2110
|
-
|
|
2111
|
-
// force-static: replace headers/cookies context with empty values and
|
|
2112
|
-
// clear searchParams so dynamic APIs return defaults instead of real data
|
|
2113
|
-
if (isForceStatic) {
|
|
2114
|
-
setHeadersContext({ headers: new Headers(), cookies: new Map() });
|
|
2115
|
-
setNavigationContext({
|
|
2116
|
-
pathname: cleanPathname,
|
|
2117
|
-
searchParams: new URLSearchParams(),
|
|
2118
|
-
params,
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
|
|
2122
|
-
// dynamic = 'error': install an access error so request APIs fail with the
|
|
2123
|
-
// static-generation message even for legacy sync property access.
|
|
2124
|
-
if (isDynamicError) {
|
|
2125
|
-
const errorMsg = 'Page with \`dynamic = "error"\` used a dynamic API. ' +
|
|
2126
|
-
'This page was expected to be fully static, but headers(), cookies(), ' +
|
|
2127
|
-
'or searchParams was accessed. Remove the dynamic API usage or change ' +
|
|
2128
|
-
'the dynamic config to "auto" or "force-dynamic".';
|
|
2129
|
-
setHeadersContext({
|
|
2130
|
-
headers: new Headers(),
|
|
2131
|
-
cookies: new Map(),
|
|
2132
|
-
accessError: new Error(errorMsg),
|
|
2133
|
-
});
|
|
2134
|
-
setNavigationContext({
|
|
2135
|
-
pathname: cleanPathname,
|
|
2136
|
-
searchParams: new URLSearchParams(),
|
|
2137
|
-
params,
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
|
-
// force-dynamic: set no-store Cache-Control
|
|
2142
|
-
const isForceDynamic = dynamicConfig === "force-dynamic";
|
|
2143
|
-
|
|
2144
|
-
// ── ISR cache read (production only) ─────────────────────────────────────
|
|
2145
|
-
// Read from cache BEFORE generateStaticParams and all rendering work.
|
|
2146
|
-
// This is the critical performance optimization: on a cache hit we skip
|
|
2147
|
-
// ALL expensive work (generateStaticParams, buildPageElement, layout probe,
|
|
2148
|
-
// page probe, renderToReadableStream, SSR). Both HTML and RSC requests
|
|
2149
|
-
// (client-side navigation / prefetch) are served from cache.
|
|
2150
|
-
//
|
|
2151
|
-
// HTML and RSC are stored under separate keys (matching Next.js's .html/.rsc
|
|
2152
|
-
// file layout) so each request type reads and writes independently — no races,
|
|
2153
|
-
// no partial-entry sentinels, no read-before-write hacks needed.
|
|
2154
|
-
//
|
|
2155
|
-
// force-static and dynamic='error' are compatible with ISR — they control
|
|
2156
|
-
// how dynamic APIs behave during rendering, not whether results are cached.
|
|
2157
|
-
// Only force-dynamic truly bypasses the ISR cache.
|
|
2158
|
-
if (
|
|
2159
|
-
process.env.NODE_ENV === "production" &&
|
|
2160
|
-
!isForceDynamic &&
|
|
2161
|
-
(isRscRequest || !_scriptNonce) &&
|
|
2162
|
-
revalidateSeconds !== null && revalidateSeconds > 0 && revalidateSeconds !== Infinity
|
|
2163
|
-
) {
|
|
2164
|
-
const __cachedPageResponse = await __readAppPageCacheResponse({
|
|
1022
|
+
return __dispatchAppRouteHandler({
|
|
1023
|
+
basePath: __basePath,
|
|
2165
1024
|
cleanPathname,
|
|
2166
1025
|
clearRequestContext: function() {
|
|
2167
|
-
|
|
2168
|
-
setNavigationContext(null);
|
|
1026
|
+
__clearRequestContext();
|
|
2169
1027
|
},
|
|
2170
|
-
|
|
1028
|
+
i18n: __i18nConfig,
|
|
2171
1029
|
isrDebug: __isrDebug,
|
|
2172
1030
|
isrGet: __isrGet,
|
|
2173
|
-
|
|
2174
|
-
isrRscKey: __isrRscKey,
|
|
1031
|
+
isrRouteKey: __isrRouteKey,
|
|
2175
1032
|
isrSet: __isrSet,
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
const __revalUCtx = _createUnifiedCtx({
|
|
2185
|
-
headersContext: __revalHeadCtx,
|
|
2186
|
-
executionContext: _getRequestExecutionContext(),
|
|
2187
|
-
unstableCacheRevalidation: "foreground",
|
|
2188
|
-
});
|
|
2189
|
-
return _runWithUnifiedCtx(__revalUCtx, async () => {
|
|
2190
|
-
_ensureFetchPatch();
|
|
2191
|
-
setCurrentFetchSoftTags(__pageCacheTags(cleanPathname, []));
|
|
2192
|
-
setNavigationContext({ pathname: cleanPathname, searchParams: new URLSearchParams(), params });
|
|
2193
|
-
// Slot context (X-Vinext-Mounted-Slots) is inherited from the
|
|
2194
|
-
// triggering request so the regen result is cached under the
|
|
2195
|
-
// correct slot-variant key.
|
|
2196
|
-
const __revalElement = await buildPageElements(
|
|
2197
|
-
route,
|
|
2198
|
-
params,
|
|
2199
|
-
cleanPathname,
|
|
2200
|
-
{
|
|
2201
|
-
opts: undefined,
|
|
2202
|
-
searchParams: new URLSearchParams(),
|
|
2203
|
-
isRscRequest,
|
|
2204
|
-
request,
|
|
2205
|
-
mountedSlotsHeader: __mountedSlotsHeader,
|
|
2206
|
-
},
|
|
2207
|
-
);
|
|
2208
|
-
const __revalOnError = createRscOnErrorHandler(request, cleanPathname, route.pattern);
|
|
2209
|
-
const __revalRscStream = renderToReadableStream(__revalElement, { onError: __revalOnError });
|
|
2210
|
-
const __revalRscCapture = __teeAppPageRscStreamForCapture(__revalRscStream, true);
|
|
2211
|
-
const __revalFontData = { links: _getSSRFontLinks(), styles: _getSSRFontStyles(), preloads: _getSSRFontPreloads() };
|
|
2212
|
-
const __revalSsrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
|
|
2213
|
-
const __revalHtmlStream = await __revalSsrEntry.handleSsr(
|
|
2214
|
-
__revalRscCapture.responseStream,
|
|
2215
|
-
_getNavigationContext(),
|
|
2216
|
-
__revalFontData,
|
|
2217
|
-
);
|
|
2218
|
-
setHeadersContext(null);
|
|
2219
|
-
setNavigationContext(null);
|
|
2220
|
-
const __freshHtml = await __readAppPageTextStream(__revalHtmlStream);
|
|
2221
|
-
const __freshRscData = await __revalRscCapture.capturedRscDataPromise;
|
|
2222
|
-
const __pageTags = __pageCacheTags(cleanPathname, getCollectedFetchTags());
|
|
2223
|
-
return { html: __freshHtml, rscData: __freshRscData, tags: __pageTags };
|
|
2224
|
-
});
|
|
1033
|
+
middlewareContext: _mwCtx,
|
|
1034
|
+
middlewareRequestHeaders: _mwCtx.requestHeaders,
|
|
1035
|
+
params,
|
|
1036
|
+
request,
|
|
1037
|
+
route: {
|
|
1038
|
+
pattern: route.pattern,
|
|
1039
|
+
routeHandler: route.routeHandler,
|
|
1040
|
+
routeSegments: route.routeSegments,
|
|
2225
1041
|
},
|
|
2226
1042
|
scheduleBackgroundRegeneration: __triggerBackgroundRegeneration,
|
|
1043
|
+
searchParams: url.searchParams,
|
|
2227
1044
|
});
|
|
2228
|
-
if (__cachedPageResponse) {
|
|
2229
|
-
return __cachedPageResponse;
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
// dynamicParams = false: only params from generateStaticParams are allowed.
|
|
2234
|
-
// This runs AFTER the ISR cache read so that a cache hit skips this work entirely.
|
|
2235
|
-
const __dynamicParamsResponse = await __validateAppPageDynamicParams({
|
|
2236
|
-
clearRequestContext() {
|
|
2237
|
-
setHeadersContext(null);
|
|
2238
|
-
setNavigationContext(null);
|
|
2239
|
-
},
|
|
2240
|
-
enforceStaticParamsOnly: dynamicParamsConfig === false,
|
|
2241
|
-
generateStaticParams: route.page?.generateStaticParams,
|
|
2242
|
-
isDynamicRoute: route.isDynamic,
|
|
2243
|
-
logGenerateStaticParamsError(err) {
|
|
2244
|
-
console.error("[vinext] generateStaticParams error:", err);
|
|
2245
|
-
},
|
|
2246
|
-
params,
|
|
2247
|
-
});
|
|
2248
|
-
if (__dynamicParamsResponse) {
|
|
2249
|
-
return __dynamicParamsResponse;
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
// Check for intercepting routes on RSC requests (client-side navigation).
|
|
2253
|
-
// If the target URL matches an intercepting route in a parallel slot,
|
|
2254
|
-
// render the source route with the intercepting page in the slot.
|
|
2255
|
-
const __interceptResult = await __resolveAppPageIntercept({
|
|
2256
|
-
buildPageElement(interceptRoute, interceptParams, interceptOpts, interceptSearchParams) {
|
|
2257
|
-
return buildPageElements(
|
|
2258
|
-
interceptRoute,
|
|
2259
|
-
interceptParams,
|
|
2260
|
-
cleanPathname,
|
|
2261
|
-
{
|
|
2262
|
-
opts: interceptOpts,
|
|
2263
|
-
searchParams: interceptSearchParams,
|
|
2264
|
-
isRscRequest,
|
|
2265
|
-
request,
|
|
2266
|
-
mountedSlotsHeader: __mountedSlotsHeader,
|
|
2267
|
-
},
|
|
2268
|
-
);
|
|
2269
|
-
},
|
|
2270
|
-
cleanPathname,
|
|
2271
|
-
currentRoute: route,
|
|
2272
|
-
findIntercept(pathname) {
|
|
2273
|
-
return findIntercept(pathname, interceptionContextHeader);
|
|
2274
|
-
},
|
|
2275
|
-
getRouteParamNames(sourceRoute) {
|
|
2276
|
-
return sourceRoute.params;
|
|
2277
|
-
},
|
|
2278
|
-
getSourceRoute(sourceRouteIndex) {
|
|
2279
|
-
return routes[sourceRouteIndex];
|
|
2280
|
-
},
|
|
2281
|
-
isRscRequest,
|
|
2282
|
-
renderInterceptResponse(sourceRoute, interceptElement) {
|
|
2283
|
-
const interceptOnError = createRscOnErrorHandler(
|
|
2284
|
-
request,
|
|
2285
|
-
cleanPathname,
|
|
2286
|
-
sourceRoute.pattern,
|
|
2287
|
-
);
|
|
2288
|
-
const interceptStream = renderToReadableStream(interceptElement, {
|
|
2289
|
-
onError: interceptOnError,
|
|
2290
|
-
});
|
|
2291
|
-
// Do NOT clear headers/navigation context here — the RSC stream is consumed lazily
|
|
2292
|
-
// by the client, and async server components that run during consumption need the
|
|
2293
|
-
// context to still be live. The AsyncLocalStorage scope from runWithRequestContext
|
|
2294
|
-
// handles cleanup naturally when all async continuations complete.
|
|
2295
|
-
const interceptHeaders = new Headers({
|
|
2296
|
-
"Content-Type": "text/x-component; charset=utf-8",
|
|
2297
|
-
"Vary": "RSC, Accept",
|
|
2298
|
-
});
|
|
2299
|
-
__mergeMiddlewareResponseHeaders(interceptHeaders, _mwCtx.headers);
|
|
2300
|
-
return new Response(interceptStream, {
|
|
2301
|
-
status: _mwCtx.status ?? 200,
|
|
2302
|
-
headers: interceptHeaders,
|
|
2303
|
-
});
|
|
2304
|
-
},
|
|
2305
|
-
searchParams: url.searchParams,
|
|
2306
|
-
setNavigationContext,
|
|
2307
|
-
toInterceptOpts(intercept) {
|
|
2308
|
-
return {
|
|
2309
|
-
interceptionContext: interceptionContextHeader,
|
|
2310
|
-
interceptLayouts: intercept.interceptLayouts,
|
|
2311
|
-
interceptSlotKey: intercept.slotKey,
|
|
2312
|
-
interceptPage: intercept.page,
|
|
2313
|
-
interceptParams: intercept.matchedParams,
|
|
2314
|
-
};
|
|
2315
|
-
},
|
|
2316
|
-
});
|
|
2317
|
-
if (__interceptResult.response) {
|
|
2318
|
-
return __interceptResult.response;
|
|
2319
1045
|
}
|
|
2320
|
-
const interceptOpts = __interceptResult.interceptOpts;
|
|
2321
1046
|
|
|
2322
|
-
const
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
1047
|
+
const PageComponent = route.page?.default;
|
|
1048
|
+
const _asyncRouteParams = makeThenableParams(params);
|
|
1049
|
+
return __dispatchAppPage({
|
|
1050
|
+
buildPageElement(targetRoute, targetParams, targetOpts, targetSearchParams) {
|
|
1051
|
+
return buildPageElements(targetRoute, targetParams, cleanPathname, {
|
|
1052
|
+
opts: targetOpts,
|
|
1053
|
+
searchParams: targetSearchParams,
|
|
2327
1054
|
isRscRequest,
|
|
2328
1055
|
request,
|
|
2329
1056
|
mountedSlotsHeader: __mountedSlotsHeader,
|
|
2330
1057
|
});
|
|
2331
1058
|
},
|
|
2332
|
-
renderErrorBoundaryPage(buildErr) {
|
|
2333
|
-
return renderErrorBoundaryPage(route, buildErr, isRscRequest, request, params, _scriptNonce, _mwCtx);
|
|
2334
|
-
},
|
|
2335
|
-
renderSpecialError(__buildSpecialError) {
|
|
2336
|
-
return __buildAppPageSpecialErrorResponse({
|
|
2337
|
-
clearRequestContext() {
|
|
2338
|
-
setHeadersContext(null);
|
|
2339
|
-
setNavigationContext(null);
|
|
2340
|
-
},
|
|
2341
|
-
middlewareContext: _mwCtx,
|
|
2342
|
-
renderFallbackPage(statusCode) {
|
|
2343
|
-
return renderHTTPAccessFallbackPage(
|
|
2344
|
-
route,
|
|
2345
|
-
statusCode,
|
|
2346
|
-
isRscRequest,
|
|
2347
|
-
request,
|
|
2348
|
-
{
|
|
2349
|
-
matchedParams: params,
|
|
2350
|
-
},
|
|
2351
|
-
_scriptNonce,
|
|
2352
|
-
// buildAppPageSpecialErrorResponse merges _mwCtx onto this returned
|
|
2353
|
-
// fallback response; keep this inner boundary render unmerged so
|
|
2354
|
-
// additive headers like Set-Cookie and Vary are not duplicated.
|
|
2355
|
-
null,
|
|
2356
|
-
);
|
|
2357
|
-
},
|
|
2358
|
-
requestUrl: request.url,
|
|
2359
|
-
specialError: __buildSpecialError,
|
|
2360
|
-
});
|
|
2361
|
-
},
|
|
2362
|
-
resolveSpecialError: __resolveAppPageSpecialError,
|
|
2363
|
-
});
|
|
2364
|
-
if (__pageBuildResult.response) {
|
|
2365
|
-
return __pageBuildResult.response;
|
|
2366
|
-
}
|
|
2367
|
-
const element = __pageBuildResult.element;
|
|
2368
|
-
|
|
2369
|
-
// Note: CSS is automatically injected by @vitejs/plugin-rsc's
|
|
2370
|
-
// rscCssTransform — no manual loadCss() call needed.
|
|
2371
|
-
const _hasLoadingBoundary = !!(route.loading && route.loading.default);
|
|
2372
|
-
const _asyncLayoutParams = makeThenableParams(params);
|
|
2373
|
-
return __renderAppPageLifecycle({
|
|
2374
1059
|
cleanPathname,
|
|
2375
1060
|
clearRequestContext() {
|
|
2376
|
-
|
|
2377
|
-
setNavigationContext(null);
|
|
1061
|
+
__clearRequestContext();
|
|
2378
1062
|
},
|
|
2379
|
-
consumeDynamicUsage,
|
|
2380
1063
|
createRscOnErrorHandler(pathname, routePath) {
|
|
2381
1064
|
return createRscOnErrorHandler(request, pathname, routePath);
|
|
2382
1065
|
},
|
|
2383
|
-
|
|
2384
|
-
|
|
1066
|
+
debugClassification: __classDebug,
|
|
1067
|
+
dynamicConfig: route.page?.dynamic,
|
|
1068
|
+
dynamicParamsConfig: route.page?.dynamicParams,
|
|
1069
|
+
findIntercept(pathname) {
|
|
1070
|
+
return findIntercept(pathname, interceptionContextHeader);
|
|
1071
|
+
},
|
|
1072
|
+
generateStaticParams: route.page?.generateStaticParams,
|
|
2385
1073
|
getFontLinks: _getSSRFontLinks,
|
|
2386
1074
|
getFontPreloads: _getSSRFontPreloads,
|
|
2387
1075
|
getFontStyles: _getSSRFontStyles,
|
|
2388
1076
|
getNavigationContext: _getNavigationContext,
|
|
2389
|
-
|
|
2390
|
-
return
|
|
2391
|
-
},
|
|
2392
|
-
getRequestCacheLife() {
|
|
2393
|
-
return _consumeRequestScopedCacheLife();
|
|
1077
|
+
getSourceRoute(sourceRouteIndex) {
|
|
1078
|
+
return routes[sourceRouteIndex];
|
|
2394
1079
|
},
|
|
1080
|
+
hasGenerateStaticParams: typeof route.page?.generateStaticParams === "function",
|
|
1081
|
+
hasPageDefaultExport: !!PageComponent,
|
|
1082
|
+
hasPageModule: !!route.page,
|
|
2395
1083
|
handlerStart: __reqStart,
|
|
2396
|
-
|
|
2397
|
-
isDynamicError,
|
|
2398
|
-
isForceDynamic,
|
|
2399
|
-
isForceStatic,
|
|
1084
|
+
interceptionContext: interceptionContextHeader,
|
|
2400
1085
|
isProduction: process.env.NODE_ENV === "production",
|
|
2401
1086
|
isRscRequest,
|
|
2402
1087
|
isrDebug: __isrDebug,
|
|
1088
|
+
isrGet: __isrGet,
|
|
2403
1089
|
isrHtmlKey: __isrHtmlKey,
|
|
2404
1090
|
isrRscKey: __isrRscKey,
|
|
2405
1091
|
isrSet: __isrSet,
|
|
2406
|
-
layoutCount: route.layouts?.length ?? 0,
|
|
2407
1092
|
loadSsrHandler() {
|
|
2408
1093
|
return import.meta.viteRsc.loadModule("ssr", "index");
|
|
2409
1094
|
},
|
|
2410
1095
|
middlewareContext: _mwCtx,
|
|
1096
|
+
mountedSlotsHeader: __mountedSlotsHeader,
|
|
2411
1097
|
params,
|
|
2412
1098
|
probeLayoutAt(li) {
|
|
2413
1099
|
const LayoutComp = route.layouts[li]?.default;
|
|
2414
1100
|
if (!LayoutComp) return null;
|
|
2415
|
-
return LayoutComp({
|
|
1101
|
+
return LayoutComp({
|
|
1102
|
+
params: makeThenableParams(__resolveAppPageSegmentParams(
|
|
1103
|
+
route.routeSegments,
|
|
1104
|
+
route.layoutTreePositions?.[li] ?? 0,
|
|
1105
|
+
params,
|
|
1106
|
+
)),
|
|
1107
|
+
children: null,
|
|
1108
|
+
});
|
|
2416
1109
|
},
|
|
2417
1110
|
probePage() {
|
|
2418
1111
|
if (!PageComponent) return null;
|
|
2419
|
-
const
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
? _probeSearchObj[k].concat(v)
|
|
2424
|
-
: [_probeSearchObj[k], v];
|
|
2425
|
-
} else {
|
|
2426
|
-
_probeSearchObj[k] = v;
|
|
2427
|
-
}
|
|
2428
|
-
});
|
|
2429
|
-
const _asyncSearchParams = makeThenableParams(_probeSearchObj);
|
|
2430
|
-
return PageComponent({ params: _asyncLayoutParams, searchParams: _asyncSearchParams });
|
|
2431
|
-
},
|
|
2432
|
-
classification: {
|
|
2433
|
-
getLayoutId(index) {
|
|
2434
|
-
const tp = route.layoutTreePositions?.[index] ?? 0;
|
|
2435
|
-
return "layout:" + __createAppPageTreePath(route.routeSegments, tp);
|
|
2436
|
-
},
|
|
2437
|
-
buildTimeClassifications: route.__buildTimeClassifications,
|
|
2438
|
-
buildTimeReasons: route.__buildTimeReasons,
|
|
2439
|
-
debugClassification: __classDebug,
|
|
2440
|
-
async runWithIsolatedDynamicScope(fn) {
|
|
2441
|
-
const priorDynamic = consumeDynamicUsage();
|
|
2442
|
-
try {
|
|
2443
|
-
const result = await fn();
|
|
2444
|
-
const dynamicDetected = consumeDynamicUsage();
|
|
2445
|
-
return { result, dynamicDetected };
|
|
2446
|
-
} finally {
|
|
2447
|
-
consumeDynamicUsage();
|
|
2448
|
-
if (priorDynamic) markDynamicUsage();
|
|
2449
|
-
}
|
|
2450
|
-
},
|
|
1112
|
+
const _asyncSearchParams = makeThenableParams(
|
|
1113
|
+
__collectAppPageSearchParams(url.searchParams).searchParamsObject,
|
|
1114
|
+
);
|
|
1115
|
+
return PageComponent({ params: _asyncRouteParams, searchParams: _asyncSearchParams });
|
|
2451
1116
|
},
|
|
2452
|
-
|
|
2453
|
-
mountedSlotsHeader: __mountedSlotsHeader,
|
|
2454
|
-
renderErrorBoundaryResponse(renderErr) {
|
|
1117
|
+
renderErrorBoundaryPage(renderErr) {
|
|
2455
1118
|
return renderErrorBoundaryPage(route, renderErr, isRscRequest, request, params, _scriptNonce, _mwCtx);
|
|
2456
1119
|
},
|
|
2457
|
-
|
|
2458
|
-
return
|
|
2459
|
-
clearRequestContext() {
|
|
2460
|
-
setHeadersContext(null);
|
|
2461
|
-
setNavigationContext(null);
|
|
2462
|
-
},
|
|
2463
|
-
middlewareContext: _mwCtx,
|
|
2464
|
-
renderFallbackPage(statusCode) {
|
|
2465
|
-
// Find the not-found component from the parent level (the boundary that
|
|
2466
|
-
// would catch this in Next.js). Walk up from the throwing layout to find
|
|
2467
|
-
// the nearest not-found at a parent layout's directory.
|
|
2468
|
-
let parentNotFound = null;
|
|
2469
|
-
if (route.notFounds) {
|
|
2470
|
-
for (let pi = li - 1; pi >= 0; pi--) {
|
|
2471
|
-
if (route.notFounds[pi]?.default) {
|
|
2472
|
-
parentNotFound = route.notFounds[pi].default;
|
|
2473
|
-
break;
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
if (!parentNotFound) parentNotFound = ${rootNotFoundVar ? `${rootNotFoundVar}?.default` : "null"};
|
|
2478
|
-
const parentLayouts = route.layouts.slice(0, li);
|
|
2479
|
-
return renderHTTPAccessFallbackPage(
|
|
2480
|
-
route,
|
|
2481
|
-
statusCode,
|
|
2482
|
-
isRscRequest,
|
|
2483
|
-
request,
|
|
2484
|
-
{
|
|
2485
|
-
boundaryComponent: parentNotFound,
|
|
2486
|
-
layouts: parentLayouts,
|
|
2487
|
-
matchedParams: params,
|
|
2488
|
-
},
|
|
2489
|
-
_scriptNonce,
|
|
2490
|
-
// buildAppPageSpecialErrorResponse merges _mwCtx onto this returned
|
|
2491
|
-
// fallback response; keep this inner boundary render unmerged so
|
|
2492
|
-
// additive headers like Set-Cookie and Vary are not duplicated.
|
|
2493
|
-
null,
|
|
2494
|
-
);
|
|
2495
|
-
},
|
|
2496
|
-
requestUrl: request.url,
|
|
2497
|
-
specialError: __layoutSpecialError,
|
|
2498
|
-
});
|
|
2499
|
-
},
|
|
2500
|
-
async renderPageSpecialError(specialError) {
|
|
2501
|
-
return __buildAppPageSpecialErrorResponse({
|
|
2502
|
-
clearRequestContext() {
|
|
2503
|
-
setHeadersContext(null);
|
|
2504
|
-
setNavigationContext(null);
|
|
2505
|
-
},
|
|
2506
|
-
middlewareContext: _mwCtx,
|
|
2507
|
-
renderFallbackPage(statusCode) {
|
|
2508
|
-
return renderHTTPAccessFallbackPage(
|
|
2509
|
-
route,
|
|
2510
|
-
statusCode,
|
|
2511
|
-
isRscRequest,
|
|
2512
|
-
request,
|
|
2513
|
-
{
|
|
2514
|
-
matchedParams: params,
|
|
2515
|
-
},
|
|
2516
|
-
_scriptNonce,
|
|
2517
|
-
// buildAppPageSpecialErrorResponse merges _mwCtx onto this returned
|
|
2518
|
-
// fallback response; keep this inner boundary render unmerged so
|
|
2519
|
-
// additive headers like Set-Cookie and Vary are not duplicated.
|
|
2520
|
-
null,
|
|
2521
|
-
);
|
|
2522
|
-
},
|
|
2523
|
-
requestUrl: request.url,
|
|
2524
|
-
specialError,
|
|
2525
|
-
});
|
|
1120
|
+
renderHttpAccessFallbackPage(statusCode, opts, middlewareContext) {
|
|
1121
|
+
return renderHTTPAccessFallbackPage(route, statusCode, isRscRequest, request, opts, _scriptNonce, middlewareContext);
|
|
2526
1122
|
},
|
|
2527
1123
|
renderToReadableStream,
|
|
2528
|
-
|
|
2529
|
-
|
|
1124
|
+
request,
|
|
1125
|
+
revalidateSeconds: typeof route.page?.revalidate === "number" ? route.page.revalidate : null,
|
|
1126
|
+
rootForbiddenModule,
|
|
1127
|
+
rootNotFoundModule,
|
|
1128
|
+
rootUnauthorizedModule,
|
|
1129
|
+
route,
|
|
2530
1130
|
runWithSuppressedHookWarning(probe) {
|
|
2531
|
-
// Run inside ALS context so the module-level console.error patch suppresses
|
|
2532
|
-
// "Invalid hook call" only for this request's probe — concurrent requests
|
|
2533
|
-
// each have their own ALS store and are unaffected.
|
|
2534
1131
|
return _suppressHookWarningAls.run(true, probe);
|
|
2535
1132
|
},
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
_getRequestExecutionContext()?.waitUntil(__cachePromise);
|
|
1133
|
+
scheduleBackgroundRegeneration(key, renderFn, errorContext) {
|
|
1134
|
+
__triggerBackgroundRegeneration(key, renderFn, errorContext);
|
|
2539
1135
|
},
|
|
1136
|
+
scriptNonce: _scriptNonce,
|
|
1137
|
+
searchParams: url.searchParams,
|
|
1138
|
+
setNavigationContext,
|
|
2540
1139
|
});
|
|
2541
1140
|
}
|
|
2542
1141
|
|