vinext 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -30
- package/dist/build/css-url-assets.d.ts +3 -1
- package/dist/build/css-url-assets.js +18 -1
- package/dist/build/inject-pregenerated-paths.d.ts +7 -0
- package/dist/build/inject-pregenerated-paths.js +21 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender-server-entry.d.ts +1 -0
- package/dist/build/prerender-server-entry.js +49 -0
- package/dist/build/prerender-server-pool.d.ts +44 -0
- package/dist/build/prerender-server-pool.js +194 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +98 -27
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +12 -2
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +4 -6
- package/dist/check.js +48 -11
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +112 -96
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/vinext-next-data.d.ts +4 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/config/config-matchers.js +45 -19
- package/dist/config/next-config.d.ts +41 -9
- package/dist/config/next-config.js +60 -3
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-browser-entry.js +5 -1
- package/dist/entries/app-rsc-entry.d.ts +5 -3
- package/dist/entries/app-rsc-entry.js +44 -10
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +28 -3
- package/dist/entries/pages-server-entry.js +23 -6
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +482 -120
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +209 -99
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +9 -2
- package/dist/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +272 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +44 -20
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/og-assets.js +2 -1
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
- package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
- package/dist/plugins/sass.d.ts +17 -1
- package/dist/plugins/sass.js +74 -1
- package/dist/plugins/styled-jsx.d.ts +16 -0
- package/dist/plugins/styled-jsx.js +149 -0
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +23 -2
- package/dist/routing/app-route-graph.js +138 -38
- package/dist/routing/file-matcher.d.ts +11 -1
- package/dist/routing/file-matcher.js +18 -3
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +198 -57
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +1 -1
- package/dist/server/app-browser-server-action-client.js +8 -7
- package/dist/server/app-browser-state.d.ts +12 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +42 -24
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +2 -1
- package/dist/server/app-fallback-renderer.js +10 -6
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +5 -4
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +27 -7
- package/dist/server/app-page-dispatch.d.ts +1 -0
- package/dist/server/app-page-dispatch.js +26 -8
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +59 -4
- package/dist/server/app-page-execution.js +2 -1
- package/dist/server/app-page-probe.js +5 -0
- package/dist/server/app-page-render-identity.d.ts +2 -0
- package/dist/server/app-page-render-identity.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +85 -16
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -4
- package/dist/server/app-page-response.d.ts +7 -0
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-route-wiring.d.ts +8 -1
- package/dist/server/app-page-route-wiring.js +32 -18
- package/dist/server/app-page-segment-state.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +7 -1
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-route-handler-execution.js +5 -1
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-tree-prefetch.d.ts +43 -0
- package/dist/server/app-route-tree-prefetch.js +187 -0
- package/dist/server/app-router-entry.js +9 -2
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +9 -4
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +148 -39
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.d.ts +6 -6
- package/dist/server/app-rsc-request-normalization.js +10 -8
- package/dist/server/app-segment-config.d.ts +11 -0
- package/dist/server/app-segment-config.js +62 -6
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +61 -30
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +13 -5
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/cache-control.d.ts +3 -1
- package/dist/server/cache-control.js +13 -1
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-route-files.js +4 -0
- package/dist/server/dev-server.d.ts +11 -1
- package/dist/server/dev-server.js +94 -35
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +11 -18
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +3 -2
- package/dist/server/isr-cache.js +9 -5
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-api-route.js +2 -2
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-data-route.d.ts +4 -2
- package/dist/server/pages-data-route.js +18 -4
- package/dist/server/pages-dev-module-url.d.ts +2 -1
- package/dist/server/pages-dev-module-url.js +6 -3
- package/dist/server/pages-node-compat.d.ts +19 -1
- package/dist/server/pages-node-compat.js +81 -4
- package/dist/server/pages-page-data.d.ts +33 -1
- package/dist/server/pages-page-data.js +62 -33
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +38 -19
- package/dist/server/pages-page-response.d.ts +8 -0
- package/dist/server/pages-page-response.js +7 -3
- package/dist/server/pages-request-pipeline.d.ts +9 -5
- package/dist/server/pages-request-pipeline.js +55 -7
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +5 -3
- package/dist/server/prod-server.js +68 -39
- package/dist/server/request-pipeline.js +2 -1
- package/dist/server/seed-cache.js +4 -4
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache-handler.js +8 -1
- package/dist/shims/cache.js +22 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +77 -52
- package/dist/shims/form.d.ts +4 -2
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +7 -1
- package/dist/shims/headers.js +17 -3
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
- package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +40 -58
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +10 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +84 -14
- package/dist/shims/internal/pages-data-target.d.ts +18 -12
- package/dist/shims/internal/pages-data-target.js +97 -13
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.d.ts +1 -1
- package/dist/shims/link.js +224 -58
- package/dist/shims/navigation.d.ts +19 -3
- package/dist/shims/navigation.js +245 -47
- package/dist/shims/request-context.js +18 -0
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +387 -102
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/typegen.js +1 -1
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +3 -3
- package/dist/utils/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- package/dist/utils/protocol-headers.d.ts +23 -0
- package/dist/utils/protocol-headers.js +23 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/dist/utils/vite-version.d.ts +2 -0
- package/dist/utils/vite-version.js +11 -1
- package/package.json +47 -2
- package/dist/deploy.d.ts +0 -197
- package/dist/deploy.js +0 -1040
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
|
@@ -37,6 +37,65 @@ function resolveDynamicStaleTimeSeconds(current, value) {
|
|
|
37
37
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return current;
|
|
38
38
|
return current === void 0 ? value : Math.min(current, value);
|
|
39
39
|
}
|
|
40
|
+
function isDynamicSegment(segment) {
|
|
41
|
+
return segment.startsWith("[") && segment.endsWith("]");
|
|
42
|
+
}
|
|
43
|
+
function getParallelSegments(options) {
|
|
44
|
+
if (!options.parallelBranches) return options.parallelSegments ?? [];
|
|
45
|
+
return options.parallelBranches.flatMap((branch) => branch ? [
|
|
46
|
+
branch.layout,
|
|
47
|
+
...branch.configLayouts ?? [],
|
|
48
|
+
branch.page
|
|
49
|
+
] : []);
|
|
50
|
+
}
|
|
51
|
+
function resolveDynamicParamsConfig(options) {
|
|
52
|
+
const parallelSegments = getParallelSegments(options);
|
|
53
|
+
const segments = [
|
|
54
|
+
...options.layouts ?? [],
|
|
55
|
+
options.page,
|
|
56
|
+
...parallelSegments
|
|
57
|
+
];
|
|
58
|
+
let dynamicParamsConfig;
|
|
59
|
+
for (const segment of segments) if (segment?.dynamicParams === false) dynamicParamsConfig = false;
|
|
60
|
+
else if (segment?.dynamicParams === true && dynamicParamsConfig !== false) dynamicParamsConfig = true;
|
|
61
|
+
if (dynamicParamsConfig !== false || !options.routeSegments) return dynamicParamsConfig;
|
|
62
|
+
let lastDynamicPosition = -1;
|
|
63
|
+
for (let index = options.routeSegments.length - 1; index >= 0; index--) if (isDynamicSegment(options.routeSegments[index])) {
|
|
64
|
+
lastDynamicPosition = index;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
if (lastDynamicPosition < 0) return dynamicParamsConfig;
|
|
68
|
+
const layouts = options.layouts ?? [];
|
|
69
|
+
const layoutPositions = options.layoutTreePositions ?? [];
|
|
70
|
+
let lastDynamicSegmentIsStaticOnly = false;
|
|
71
|
+
let lastDynamicSegmentHasStaticParams = false;
|
|
72
|
+
layouts.forEach((layout, index) => {
|
|
73
|
+
if ((layoutPositions[index] ?? 0) - 1 !== lastDynamicPosition) return;
|
|
74
|
+
if (layout?.dynamicParams === false) lastDynamicSegmentIsStaticOnly = true;
|
|
75
|
+
if (typeof layout?.generateStaticParams === "function") lastDynamicSegmentHasStaticParams = true;
|
|
76
|
+
});
|
|
77
|
+
if (options.page?.dynamicParams === false) lastDynamicSegmentIsStaticOnly = true;
|
|
78
|
+
if (typeof options.page?.generateStaticParams === "function") lastDynamicSegmentHasStaticParams = true;
|
|
79
|
+
for (const branch of options.parallelBranches ?? []) {
|
|
80
|
+
if (!branch) continue;
|
|
81
|
+
const branchStartPosition = options.routeSegments.length - (branch.routeSegments?.length ?? 0);
|
|
82
|
+
const checkSegment = (segment, ownerPosition) => {
|
|
83
|
+
if (ownerPosition !== lastDynamicPosition) return;
|
|
84
|
+
if (segment?.dynamicParams === false) lastDynamicSegmentIsStaticOnly = true;
|
|
85
|
+
if (typeof segment?.generateStaticParams === "function") lastDynamicSegmentHasStaticParams = true;
|
|
86
|
+
};
|
|
87
|
+
checkSegment(branch.layout, branchStartPosition - 1);
|
|
88
|
+
branch.configLayouts?.forEach((layout, index) => {
|
|
89
|
+
checkSegment(layout, branchStartPosition + (branch.configLayoutTreePositions?.[index] ?? 0) - 1);
|
|
90
|
+
});
|
|
91
|
+
checkSegment(branch.page, branchStartPosition + (branch.routeSegments?.length ?? 0) - 1);
|
|
92
|
+
}
|
|
93
|
+
if (!options.parallelBranches) for (const segment of parallelSegments) {
|
|
94
|
+
if (segment?.dynamicParams === false) lastDynamicSegmentIsStaticOnly = true;
|
|
95
|
+
if (typeof segment?.generateStaticParams === "function") lastDynamicSegmentHasStaticParams = true;
|
|
96
|
+
}
|
|
97
|
+
return lastDynamicSegmentIsStaticOnly || lastDynamicSegmentHasStaticParams ? false : void 0;
|
|
98
|
+
}
|
|
40
99
|
function isCacheFetchCacheMode(value) {
|
|
41
100
|
return value === "default-cache" || value === "force-cache" || value === "only-cache";
|
|
42
101
|
}
|
|
@@ -53,7 +112,9 @@ function describeFetchCacheConflict(value) {
|
|
|
53
112
|
*/
|
|
54
113
|
function resolveAppPageSegmentConfig(options) {
|
|
55
114
|
const segments = [...options.layouts ?? [], options.page];
|
|
115
|
+
const parallelSegments = getParallelSegments(options);
|
|
56
116
|
const config = { revalidateSeconds: null };
|
|
117
|
+
config.dynamicParamsConfig = resolveDynamicParamsConfig(options);
|
|
57
118
|
let hasForceCache = false;
|
|
58
119
|
let hasForceNoStore = false;
|
|
59
120
|
let hasOnlyCache = false;
|
|
@@ -67,8 +128,6 @@ function resolveAppPageSegmentConfig(options) {
|
|
|
67
128
|
config.dynamicConfig = hasForceDynamic ? "force-dynamic" : segment.dynamic;
|
|
68
129
|
}
|
|
69
130
|
if (isRouteSegmentRuntime(segment.runtime)) config.runtime = segment.runtime;
|
|
70
|
-
if (segment.dynamicParams === false) config.dynamicParamsConfig = false;
|
|
71
|
-
else if (segment.dynamicParams === true && config.dynamicParamsConfig !== false) config.dynamicParamsConfig = true;
|
|
72
131
|
if (isRouteSegmentFetchCache(segment.fetchCache)) {
|
|
73
132
|
const fetchCache = segment.fetchCache;
|
|
74
133
|
if (hasParentDefaultNoStore && (fetchCache === "auto" || isCacheFetchCacheMode(fetchCache))) throw new Error(describeFetchCacheConflict(fetchCache));
|
|
@@ -86,14 +145,12 @@ function resolveAppPageSegmentConfig(options) {
|
|
|
86
145
|
}
|
|
87
146
|
config.revalidateSeconds = resolveRevalidateSeconds(config.revalidateSeconds, segment.revalidate);
|
|
88
147
|
}
|
|
89
|
-
for (const segment of
|
|
148
|
+
for (const segment of parallelSegments) {
|
|
90
149
|
if (!segment) continue;
|
|
91
150
|
if (segment.dynamic === "force-dynamic") {
|
|
92
151
|
hasForceDynamic = true;
|
|
93
152
|
config.dynamicConfig = "force-dynamic";
|
|
94
153
|
} else if (config.dynamicConfig === void 0 && isRouteSegmentDynamic(segment.dynamic)) config.dynamicConfig = segment.dynamic;
|
|
95
|
-
if (segment.dynamicParams === false) config.dynamicParamsConfig = false;
|
|
96
|
-
else if (segment.dynamicParams === true && config.dynamicParamsConfig === void 0) config.dynamicParamsConfig = true;
|
|
97
154
|
if (config.runtime === void 0 && isRouteSegmentRuntime(segment.runtime)) config.runtime = segment.runtime;
|
|
98
155
|
if (isRouteSegmentFetchCache(segment.fetchCache)) {
|
|
99
156
|
const fetchCache = segment.fetchCache;
|
|
@@ -120,7 +177,6 @@ function resolveAppPageSegmentConfig(options) {
|
|
|
120
177
|
if (config.fetchCache === void 0) {
|
|
121
178
|
if (config.dynamicConfig === "error") config.fetchCache = "only-cache";
|
|
122
179
|
}
|
|
123
|
-
if (config.dynamicParamsConfig === void 0 && (config.dynamicConfig === "error" || config.dynamicConfig === "force-static")) config.dynamicParamsConfig = false;
|
|
124
180
|
return config;
|
|
125
181
|
}
|
|
126
182
|
function resolveAppPageFetchCacheMode(options) {
|
|
@@ -13,6 +13,7 @@ import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityI
|
|
|
13
13
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
14
14
|
import { applyEdgeRuntimeHeader } from "./app-page-response.js";
|
|
15
15
|
import { getNextErrorDigest, parseNextHttpErrorDigest, parseNextRedirectDigest } from "./next-error-digest.js";
|
|
16
|
+
import { createRootParamsUsageController, pickRootParams, runWithRootParamsScope, runWithRootParamsUsage } from "../shims/root-params.js";
|
|
16
17
|
import { createServerActionNotFoundResponse, getServerActionNotFoundMessage, isServerActionNotFoundError } from "./server-action-not-found.js";
|
|
17
18
|
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
18
19
|
import "./app-page-stream.js";
|
|
@@ -24,7 +25,10 @@ import { createStaticGenerationHeadersContext } from "./app-static-generation.js
|
|
|
24
25
|
//#region src/server/app-server-action-execution.ts
|
|
25
26
|
function prepareActionPageRerenderContext(options) {
|
|
26
27
|
if (options.dynamicConfig === "force-static" || options.dynamicConfig === "error") setHeadersContext(createStaticGenerationHeadersContext({
|
|
27
|
-
draftModeEnabled: isDraftModeRequest(
|
|
28
|
+
draftModeEnabled: isDraftModeRequest(createActionRerenderRequest({
|
|
29
|
+
draftModeCookie: options.draftModeCookie,
|
|
30
|
+
request: options.request
|
|
31
|
+
}), options.draftModeSecret),
|
|
28
32
|
draftModeSecret: options.draftModeSecret,
|
|
29
33
|
dynamicConfig: options.dynamicConfig,
|
|
30
34
|
routeKind: "page",
|
|
@@ -32,6 +36,14 @@ function prepareActionPageRerenderContext(options) {
|
|
|
32
36
|
}));
|
|
33
37
|
return options.dynamicConfig === "force-static" ? new URLSearchParams() : options.searchParams;
|
|
34
38
|
}
|
|
39
|
+
function createActionRerenderRequest(options) {
|
|
40
|
+
if (!options.draftModeCookie) return options.request;
|
|
41
|
+
const headers = new Headers(options.request.headers);
|
|
42
|
+
const cookieHeader = applySetCookieMutationsToRequestCookieHeader(headers.get("cookie"), [options.draftModeCookie]);
|
|
43
|
+
if (cookieHeader === null) headers.delete("cookie");
|
|
44
|
+
else headers.set("cookie", cookieHeader);
|
|
45
|
+
return new Request(options.request.url, { headers });
|
|
46
|
+
}
|
|
35
47
|
/**
|
|
36
48
|
* Matches Next.js' server action argument cap to prevent stack overflow in
|
|
37
49
|
* Function.prototype.apply when decoding hostile action payloads.
|
|
@@ -362,11 +374,14 @@ async function handleProgressiveServerActionRequest(options) {
|
|
|
362
374
|
let actionRedirect = null;
|
|
363
375
|
let actionError = void 0;
|
|
364
376
|
let actionFailed = false;
|
|
377
|
+
let actionThrew = false;
|
|
365
378
|
let actionResult;
|
|
379
|
+
const rootParamsUsage = createRootParamsUsageController();
|
|
366
380
|
const previousHeadersPhase = options.setHeadersAccessPhase("action");
|
|
367
381
|
try {
|
|
368
|
-
actionResult = await action
|
|
382
|
+
actionResult = await runWithRootParamsUsage({ kind: "server-action" }, action, rootParamsUsage);
|
|
369
383
|
} catch (error) {
|
|
384
|
+
actionThrew = true;
|
|
370
385
|
actionRedirect = getActionRedirect(error);
|
|
371
386
|
if (!actionRedirect) {
|
|
372
387
|
actionError = error;
|
|
@@ -386,8 +401,10 @@ async function handleProgressiveServerActionRequest(options) {
|
|
|
386
401
|
}
|
|
387
402
|
} finally {
|
|
388
403
|
options.setHeadersAccessPhase(previousHeadersPhase);
|
|
404
|
+
if (actionThrew) rootParamsUsage.transitionToRender();
|
|
389
405
|
}
|
|
390
406
|
if (!actionRedirect) {
|
|
407
|
+
if (!actionThrew) rootParamsUsage.transitionToRender();
|
|
391
408
|
const actionPendingCookies = dedupePendingCookies(options.getAndClearPendingCookies());
|
|
392
409
|
const actionDraftCookie = options.getDraftModeCookieHeader();
|
|
393
410
|
const revalidationKind = resolveActionRevalidationKind(actionPendingCookies.length > 0 || Boolean(actionDraftCookie));
|
|
@@ -555,16 +572,19 @@ async function handleServerActionRscRequest(options) {
|
|
|
555
572
|
let returnValue;
|
|
556
573
|
let actionRedirect = null;
|
|
557
574
|
let actionStatus = 200;
|
|
575
|
+
let actionThrew = false;
|
|
558
576
|
const actionWasForwarded = Boolean(options.request.headers.get(ACTION_FORWARDED_HEADER));
|
|
577
|
+
const rootParamsUsage = createRootParamsUsageController();
|
|
559
578
|
const previousHeadersPhase = options.setHeadersAccessPhase("action");
|
|
560
579
|
try {
|
|
561
580
|
try {
|
|
562
581
|
validateServerActionArgs(args);
|
|
563
582
|
returnValue = {
|
|
564
583
|
ok: true,
|
|
565
|
-
data: await action.apply(null, args)
|
|
584
|
+
data: await runWithRootParamsUsage({ kind: "server-action" }, () => action.apply(null, args), rootParamsUsage)
|
|
566
585
|
};
|
|
567
586
|
} catch (error) {
|
|
587
|
+
actionThrew = true;
|
|
568
588
|
actionRedirect = getActionRedirect(error);
|
|
569
589
|
if (actionRedirect) returnValue = {
|
|
570
590
|
ok: true,
|
|
@@ -579,6 +599,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
579
599
|
data: error
|
|
580
600
|
};
|
|
581
601
|
} else {
|
|
602
|
+
actionStatus = 500;
|
|
582
603
|
console.error("[vinext] Server action error:", error);
|
|
583
604
|
returnValue = {
|
|
584
605
|
ok: false,
|
|
@@ -589,6 +610,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
589
610
|
}
|
|
590
611
|
} finally {
|
|
591
612
|
options.setHeadersAccessPhase(previousHeadersPhase);
|
|
613
|
+
if (actionThrew && !actionWasForwarded) rootParamsUsage.transitionToRender();
|
|
592
614
|
}
|
|
593
615
|
if (actionRedirect) {
|
|
594
616
|
const actionPendingCookies = dedupePendingCookies(options.getAndClearPendingCookies());
|
|
@@ -633,9 +655,10 @@ async function handleServerActionRscRequest(options) {
|
|
|
633
655
|
request: options.request,
|
|
634
656
|
url: redirectTarget
|
|
635
657
|
});
|
|
636
|
-
setHeadersContext(headersContextFromRequest(redirectRenderRequest));
|
|
658
|
+
setHeadersContext(headersContextFromRequest(redirectRenderRequest, { draftModeSecret: options.draftModeSecret }));
|
|
637
659
|
const redirectDynamicConfig = options.resolveRouteDynamicConfig?.(targetMatch.route);
|
|
638
660
|
const redirectSearchParams = prepareActionPageRerenderContext({
|
|
661
|
+
draftModeCookie: actionDraftCookie,
|
|
639
662
|
draftModeSecret: options.draftModeSecret,
|
|
640
663
|
dynamicConfig: redirectDynamicConfig,
|
|
641
664
|
request: redirectRenderRequest,
|
|
@@ -651,27 +674,29 @@ async function handleServerActionRscRequest(options) {
|
|
|
651
674
|
setCurrentFetchCacheMode(options.resolveRouteFetchCacheMode?.(targetMatch.route) ?? null);
|
|
652
675
|
setCurrentForceDynamicFetchDefault(redirectDynamicConfig === "force-dynamic");
|
|
653
676
|
setCurrentFetchSoftTags(buildServerActionPageTags(targetMatch.route, targetPathname));
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
677
|
+
return createServerActionRscResponse(await runWithRootParamsScope(pickRootParams(targetMatch.params, targetMatch.route.rootParamNames), () => runWithRootParamsUsage({ kind: "route" }, async () => {
|
|
678
|
+
const element = options.buildPageElement({
|
|
679
|
+
cleanPathname: targetPathname,
|
|
680
|
+
interceptOpts: void 0,
|
|
681
|
+
isRscRequest: true,
|
|
682
|
+
mountedSlotsHeader: null,
|
|
683
|
+
params: targetMatch.params,
|
|
684
|
+
request: redirectRenderRequest,
|
|
685
|
+
route: targetMatch.route,
|
|
686
|
+
searchParams: redirectSearchParams,
|
|
687
|
+
renderMode: APP_RSC_RENDER_MODE_ACTION_RERENDER_PRESERVE_UI,
|
|
688
|
+
observeMetadataSearchParamsAccess: redirectDynamicConfig !== "force-static",
|
|
689
|
+
observePageSearchParamsAccess: redirectDynamicConfig !== "force-static"
|
|
690
|
+
});
|
|
691
|
+
const onRenderError = options.createRscOnErrorHandler(redirectRenderRequest, targetPathname, targetMatch.route.pattern);
|
|
692
|
+
return options.renderToReadableStream({
|
|
693
|
+
root: element,
|
|
694
|
+
returnValue
|
|
695
|
+
}, {
|
|
696
|
+
temporaryReferences,
|
|
697
|
+
onError: onRenderError
|
|
698
|
+
});
|
|
699
|
+
})), {
|
|
675
700
|
status: shouldUseForwardedActionRedirectStatus({
|
|
676
701
|
actionWasForwarded,
|
|
677
702
|
currentPathname: options.cleanPathname,
|
|
@@ -686,7 +711,8 @@ async function handleServerActionRscRequest(options) {
|
|
|
686
711
|
const actionPendingCookies = dedupePendingCookies(options.getAndClearPendingCookies());
|
|
687
712
|
const actionDraftCookie = options.getDraftModeCookieHeader();
|
|
688
713
|
const actionRevalidationKind = resolveActionRevalidationKind(actionPendingCookies.length > 0 || Boolean(actionDraftCookie));
|
|
689
|
-
|
|
714
|
+
const isHttpFallback = actionStatus === 401 || actionStatus === 403 || actionStatus === 404;
|
|
715
|
+
if (!isHttpFallback && (actionWasForwarded || actionRevalidationKind === ACTION_DID_NOT_REVALIDATE)) {
|
|
690
716
|
const onRenderError = options.createRscOnErrorHandler(options.request, options.cleanPathname, options.cleanPathname);
|
|
691
717
|
const rscStream = await options.renderToReadableStream({ returnValue }, {
|
|
692
718
|
temporaryReferences,
|
|
@@ -707,9 +733,11 @@ async function handleServerActionRscRequest(options) {
|
|
|
707
733
|
headers: actionHeaders
|
|
708
734
|
}, options.clearRequestContext);
|
|
709
735
|
}
|
|
736
|
+
if (!actionThrew) rootParamsUsage.transitionToRender();
|
|
710
737
|
const match = options.matchRoute(options.cleanPathname);
|
|
711
738
|
let element;
|
|
712
739
|
let errorPattern = match ? match.route.pattern : options.cleanPathname;
|
|
740
|
+
const actionRerenderIsRscRequest = true;
|
|
713
741
|
if (match) {
|
|
714
742
|
const { route: actionRoute, params: actionParams } = match;
|
|
715
743
|
const actionRerenderTarget = await resolveAppPageActionRerenderTarget({
|
|
@@ -719,13 +747,14 @@ async function handleServerActionRscRequest(options) {
|
|
|
719
747
|
findIntercept: options.findIntercept,
|
|
720
748
|
getRouteParamNames: options.getRouteParamNames,
|
|
721
749
|
getSourceRoute: options.getSourceRoute,
|
|
722
|
-
isRscRequest:
|
|
750
|
+
isRscRequest: actionRerenderIsRscRequest,
|
|
723
751
|
toInterceptOpts: options.toInterceptOpts
|
|
724
752
|
});
|
|
725
753
|
const resolvedActionNavigationParams = resolveAppPageNavigationParams(actionRerenderTarget.route, actionRerenderTarget.navigationParams, options.cleanPathname, actionRerenderTarget.interceptOpts);
|
|
726
754
|
await options.ensureRouteLoaded?.(actionRerenderTarget.route);
|
|
727
755
|
const actionRerenderDynamicConfig = options.resolveRouteDynamicConfig?.(actionRerenderTarget.route);
|
|
728
756
|
const actionRerenderSearchParams = prepareActionPageRerenderContext({
|
|
757
|
+
draftModeCookie: actionDraftCookie,
|
|
729
758
|
draftModeSecret: options.draftModeSecret,
|
|
730
759
|
dynamicConfig: actionRerenderDynamicConfig,
|
|
731
760
|
request: options.request,
|
|
@@ -740,10 +769,10 @@ async function handleServerActionRscRequest(options) {
|
|
|
740
769
|
setCurrentFetchCacheMode(options.resolveRouteFetchCacheMode?.(actionRerenderTarget.route) ?? null);
|
|
741
770
|
setCurrentForceDynamicFetchDefault(actionRerenderDynamicConfig === "force-dynamic");
|
|
742
771
|
setCurrentFetchSoftTags(buildServerActionPageTags(actionRerenderTarget.route, options.cleanPathname));
|
|
743
|
-
|
|
772
|
+
const buildActionRerenderElement = () => options.buildPageElement({
|
|
744
773
|
cleanPathname: options.cleanPathname,
|
|
745
774
|
interceptOpts: actionRerenderTarget.interceptOpts,
|
|
746
|
-
isRscRequest:
|
|
775
|
+
isRscRequest: actionRerenderIsRscRequest,
|
|
747
776
|
mountedSlotsHeader: options.mountedSlotsHeader,
|
|
748
777
|
params: actionRerenderTarget.params,
|
|
749
778
|
request: options.request,
|
|
@@ -753,19 +782,21 @@ async function handleServerActionRscRequest(options) {
|
|
|
753
782
|
observeMetadataSearchParamsAccess: actionRerenderDynamicConfig !== "force-static",
|
|
754
783
|
observePageSearchParamsAccess: actionRerenderDynamicConfig !== "force-static"
|
|
755
784
|
});
|
|
785
|
+
element = actionWasForwarded && isHttpFallback ? await runWithRootParamsUsage({ kind: "route" }, async () => buildActionRerenderElement()) : buildActionRerenderElement();
|
|
756
786
|
errorPattern = actionRerenderTarget.route.pattern;
|
|
757
787
|
} else {
|
|
758
788
|
const actionRouteId = options.createPayloadRouteId(options.cleanPathname, null);
|
|
759
789
|
element = options.createNotFoundElement(actionRouteId);
|
|
760
790
|
}
|
|
761
791
|
const onRenderError = options.createRscOnErrorHandler(options.request, options.cleanPathname, errorPattern);
|
|
762
|
-
const
|
|
792
|
+
const renderActionRerender = () => options.renderToReadableStream({
|
|
763
793
|
root: element,
|
|
764
794
|
returnValue
|
|
765
795
|
}, {
|
|
766
796
|
temporaryReferences,
|
|
767
797
|
onError: onRenderError
|
|
768
798
|
});
|
|
799
|
+
const rscStream = await (actionWasForwarded && isHttpFallback ? runWithRootParamsUsage({ kind: "route" }, renderActionRerender) : renderActionRerender());
|
|
769
800
|
const actionHeaders = new Headers({
|
|
770
801
|
"Content-Type": VINEXT_RSC_CONTENT_TYPE,
|
|
771
802
|
Vary: VINEXT_RSC_VARY_HEADER
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
2
2
|
import { RootParams } from "../shims/root-params.js";
|
|
3
|
+
import { InitialNavigationCacheMetadata } from "./app-ssr-stream.js";
|
|
3
4
|
import { AppSsrRenderResult } from "./app-page-stream.js";
|
|
4
5
|
import { ReactFormState } from "react-dom/client";
|
|
5
6
|
|
|
@@ -44,6 +45,8 @@ declare function handleSsr(rscStream: ReadableStream<Uint8Array>, navContext: Na
|
|
|
44
45
|
* and ISR cache writes to avoid caching fallback content. */
|
|
45
46
|
waitForAllReady?: boolean;
|
|
46
47
|
fallbackToErrorDocumentOnShellError?: boolean;
|
|
48
|
+
dynamicStaleTimeSeconds?: number;
|
|
49
|
+
getInitialNavigationCacheMetadata?: () => InitialNavigationCacheMetadata;
|
|
47
50
|
}): Promise<AppSsrRenderResult>;
|
|
48
51
|
declare const _default: {
|
|
49
52
|
fetch(request: Request): Promise<Response>;
|
|
@@ -12,6 +12,7 @@ import { runWithNavigationContext } from "../shims/navigation-state.js";
|
|
|
12
12
|
import { withScriptNonce } from "../shims/script-nonce-context.js";
|
|
13
13
|
import { createInlineScriptTag, createNonceAttribute, escapeHtmlAttr, safeJsonStringify } from "./html.js";
|
|
14
14
|
import { getClientTraceMetadataHTML } from "./client-trace-metadata.js";
|
|
15
|
+
import { setPagesClientAssets } from "./pages-client-assets.js";
|
|
15
16
|
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
16
17
|
import { BfcacheStateKeyMapContext, ElementsContext, Slot } from "../shims/slot.js";
|
|
17
18
|
import { createSsrErrorMetaRenderer } from "./app-ssr-error-meta.js";
|
|
@@ -27,9 +28,12 @@ import { createInitialDevServerErrorScript } from "./dev-initial-server-error.js
|
|
|
27
28
|
import { ssrAppRouterInstance } from "./app-ssr-router-instance.js";
|
|
28
29
|
import { Fragment, createElement, use } from "react";
|
|
29
30
|
import { renderToReadableStream, renderToStaticMarkup } from "react-dom/server.edge";
|
|
31
|
+
import { preinitModule } from "react-dom";
|
|
30
32
|
import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
31
33
|
import clientReferences from "virtual:vite-rsc/client-references";
|
|
34
|
+
import pagesClientAssets from "virtual:vinext-pages-client-assets";
|
|
32
35
|
//#region src/server/app-ssr-entry.ts
|
|
36
|
+
setPagesClientAssets(pagesClientAssets);
|
|
33
37
|
/**
|
|
34
38
|
* Default cap for the preload `Link` header, matching Next.js's
|
|
35
39
|
* `defaultConfig.reactMaxHeadersLength`. Used when no config value threads
|
|
@@ -149,12 +153,12 @@ function buildModulePreloadHtml(bootstrapModuleUrl, nonce) {
|
|
|
149
153
|
if (!bootstrapModuleUrl) return "";
|
|
150
154
|
return `<link rel="modulepreload"${createNonceAttribute(nonce)} href="${escapeHtmlAttr(bootstrapModuleUrl)}" />\n`;
|
|
151
155
|
}
|
|
152
|
-
function buildHeadInjectionHtml(navContext, bootstrapModuleUrl, formState, insertedHTML, fontHTML, scriptNonce) {
|
|
156
|
+
function buildHeadInjectionHtml(navContext, bootstrapModuleUrl, formState, insertedHTML, fontHTML, dynamicStaleTimeSeconds, scriptNonce) {
|
|
153
157
|
const navPayload = {
|
|
154
158
|
pathname: navContext.pathname,
|
|
155
159
|
searchParams: [...navContext.searchParams.entries()]
|
|
156
160
|
};
|
|
157
|
-
return createInlineScriptTag(createNavigationRuntimeRscMetadataScript(navContext.params, navPayload), scriptNonce) + (formState === null ? "" : createInlineScriptTag("self[" + safeJsonStringify(RSC_FORM_STATE_GLOBAL) + "]=" + safeJsonStringify(formState), scriptNonce)) + buildModulePreloadHtml(bootstrapModuleUrl, scriptNonce) + insertedHTML + fontHTML;
|
|
161
|
+
return createInlineScriptTag(createNavigationRuntimeRscMetadataScript(navContext.params, navPayload, dynamicStaleTimeSeconds), scriptNonce) + (formState === null ? "" : createInlineScriptTag("self[" + safeJsonStringify(RSC_FORM_STATE_GLOBAL) + "]=" + safeJsonStringify(formState), scriptNonce)) + buildModulePreloadHtml(bootstrapModuleUrl, scriptNonce) + insertedHTML + fontHTML;
|
|
158
162
|
}
|
|
159
163
|
function requireNavigationContext(navContext) {
|
|
160
164
|
if (!navContext) throw new Error("App SSR requires navigation context for BFCache state keys");
|
|
@@ -176,15 +180,19 @@ async function handleSsr(rscStream, navContext, fontData, options) {
|
|
|
176
180
|
let rscEmbed;
|
|
177
181
|
if (options?.sideStream) {
|
|
178
182
|
ssrStream = rscStream;
|
|
179
|
-
rscEmbed = createRscEmbedTransform(options.sideStream, options?.scriptNonce);
|
|
183
|
+
rscEmbed = createRscEmbedTransform(options.sideStream, options?.scriptNonce, options?.getInitialNavigationCacheMetadata);
|
|
180
184
|
if (options.capturedRscDataRef) options.capturedRscDataRef.value = rscEmbed.getRawBuffer();
|
|
181
185
|
} else {
|
|
182
186
|
const [s1, s2] = rscStream.tee();
|
|
183
187
|
ssrStream = s1;
|
|
184
|
-
rscEmbed = createRscEmbedTransform(s2, options?.scriptNonce);
|
|
188
|
+
rscEmbed = createRscEmbedTransform(s2, options?.scriptNonce, options?.getInitialNavigationCacheMetadata);
|
|
185
189
|
}
|
|
186
190
|
let flightRoot = null;
|
|
187
191
|
function VinextFlightRoot() {
|
|
192
|
+
for (const moduleUrl of pagesClientAssets.appBootstrapPreinitModules ?? []) preinitModule(moduleUrl, {
|
|
193
|
+
as: "script",
|
|
194
|
+
nonce: options?.scriptNonce
|
|
195
|
+
});
|
|
188
196
|
if (!flightRoot) flightRoot = createFromReadableStream(ssrStream);
|
|
189
197
|
const wireElements = use(flightRoot);
|
|
190
198
|
const elements = AppElementsWire.decode(wireElements);
|
|
@@ -270,7 +278,7 @@ async function handleSsr(rscStream, navContext, fontData, options) {
|
|
|
270
278
|
const initialDevServerErrorHTML = createInitialDevServerErrorScript(options?.initialDevServerError, options?.scriptNonce);
|
|
271
279
|
if (didInjectHeadHTML) return insertedHTML + errorMetaHTML;
|
|
272
280
|
didInjectHeadHTML = true;
|
|
273
|
-
return buildHeadInjectionHtml(ssrNavigationContext, bootstrapModuleUrl, options?.formState ?? null, insertedHTML + errorMetaHTML + getTraceMetaHTML() + initialDevServerErrorHTML, fontHTML, options?.scriptNonce);
|
|
281
|
+
return buildHeadInjectionHtml(ssrNavigationContext, bootstrapModuleUrl, options?.formState ?? null, insertedHTML + errorMetaHTML + getTraceMetaHTML() + initialDevServerErrorHTML, fontHTML, options?.dynamicStaleTimeSeconds, options?.scriptNonce);
|
|
274
282
|
};
|
|
275
283
|
const getBeforeInteractiveHeadHTML = () => renderBeforeInteractiveInlineScripts(beforeInteractiveInlineScripts);
|
|
276
284
|
return {
|
|
@@ -6,11 +6,15 @@ type RscEmbedTransform = {
|
|
|
6
6
|
};
|
|
7
7
|
type HtmlInsertion = string | (() => string);
|
|
8
8
|
type InlineCssManifest = Record<string, string>;
|
|
9
|
+
type InitialNavigationCacheMetadata = {
|
|
10
|
+
kind: "dynamic" | "static";
|
|
11
|
+
dynamicStaleTimeSeconds?: number;
|
|
12
|
+
};
|
|
9
13
|
declare function navigationRuntimeRscBootstrapExpression(): string;
|
|
10
14
|
declare function createNavigationRuntimeRscMetadataScript(params: Record<string, string | string[]>, nav: {
|
|
11
15
|
pathname: string;
|
|
12
16
|
searchParams: [string, string][];
|
|
13
|
-
}): string;
|
|
17
|
+
}, dynamicStaleTimeSeconds?: number): string;
|
|
14
18
|
/**
|
|
15
19
|
* Fix invalid preload "as" values in RSC Flight hint lines before they reach
|
|
16
20
|
* the client. React Flight emits HL hints with as="stylesheet" for CSS, but
|
|
@@ -21,7 +25,7 @@ declare function fixFlightHints(text: string): string;
|
|
|
21
25
|
* Create a helper that progressively embeds RSC chunks as inline <script> tags.
|
|
22
26
|
* The browser entry turns the embedded chunks back into Uint8Array data.
|
|
23
27
|
*/
|
|
24
|
-
declare function createRscEmbedTransform(embedStream: ReadableStream<Uint8Array>, scriptNonce?: string): RscEmbedTransform;
|
|
28
|
+
declare function createRscEmbedTransform(embedStream: ReadableStream<Uint8Array>, scriptNonce?: string, getInitialNavigationCacheMetadata?: () => InitialNavigationCacheMetadata): RscEmbedTransform;
|
|
25
29
|
/**
|
|
26
30
|
* Fix invalid preload "as" values in server-rendered HTML.
|
|
27
31
|
* React Fizz emits <link rel="preload" as="stylesheet"> for CSS, but the
|
|
@@ -57,4 +61,4 @@ declare function fixPreloadAs(html: string): string;
|
|
|
57
61
|
*/
|
|
58
62
|
declare function createTickBufferedTransform(rscEmbed: RscEmbedTransform, injectHTML?: HtmlInsertion, injectAfterHeadOpenHTML?: HtmlInsertion, inlineCssManifest?: InlineCssManifest, inlineCssPrependCss?: string, inlineCssPrependFallbackHTML?: string, inlineCssScriptNonce?: string): TransformStream<Uint8Array, Uint8Array>;
|
|
59
63
|
//#endregion
|
|
60
|
-
export { createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform, fixFlightHints, fixPreloadAs, navigationRuntimeRscBootstrapExpression };
|
|
64
|
+
export { InitialNavigationCacheMetadata, createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform, fixFlightHints, fixPreloadAs, navigationRuntimeRscBootstrapExpression };
|
|
@@ -6,14 +6,18 @@ const NAVIGATION_RUNTIME_REFERENCE = `self[Symbol.for(${safeJsonStringify(NAVIGA
|
|
|
6
6
|
function navigationRuntimeRscBootstrapExpression() {
|
|
7
7
|
return `((${NAVIGATION_RUNTIME_REFERENCE}??={bootstrap:{routeManifest:null},functions:{}}).bootstrap.rsc??={rsc:[]})`;
|
|
8
8
|
}
|
|
9
|
-
function createNavigationRuntimeRscMetadataScript(params, nav) {
|
|
10
|
-
return "Object.assign(" + navigationRuntimeRscBootstrapExpression() + ",{params:" + safeJsonStringify(params) + ",nav:" + safeJsonStringify(nav) + "})";
|
|
9
|
+
function createNavigationRuntimeRscMetadataScript(params, nav, dynamicStaleTimeSeconds) {
|
|
10
|
+
return "Object.assign(" + navigationRuntimeRscBootstrapExpression() + ",{params:" + safeJsonStringify(params) + ",nav:" + safeJsonStringify(nav) + (dynamicStaleTimeSeconds === void 0 ? "" : ",dynamicStaleTimeSeconds:" + safeJsonStringify(dynamicStaleTimeSeconds)) + "})";
|
|
11
11
|
}
|
|
12
12
|
function createNavigationRuntimeRscChunkScript(chunk) {
|
|
13
13
|
return navigationRuntimeRscBootstrapExpression() + ".rsc.push(" + safeJsonStringify(chunk) + ")";
|
|
14
14
|
}
|
|
15
|
-
function createNavigationRuntimeRscDoneScript() {
|
|
16
|
-
|
|
15
|
+
function createNavigationRuntimeRscDoneScript(metadata) {
|
|
16
|
+
const bootstrap = navigationRuntimeRscBootstrapExpression();
|
|
17
|
+
return (metadata === void 0 ? "" : "Object.assign(" + bootstrap + "," + safeJsonStringify({
|
|
18
|
+
initialCacheKind: metadata.kind,
|
|
19
|
+
...metadata.dynamicStaleTimeSeconds === void 0 ? {} : { dynamicStaleTimeSeconds: metadata.dynamicStaleTimeSeconds }
|
|
20
|
+
}) + ");") + bootstrap + ".done=true";
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
23
|
* Fix invalid preload "as" values in RSC Flight hint lines before they reach
|
|
@@ -27,7 +31,7 @@ function fixFlightHints(text) {
|
|
|
27
31
|
* Create a helper that progressively embeds RSC chunks as inline <script> tags.
|
|
28
32
|
* The browser entry turns the embedded chunks back into Uint8Array data.
|
|
29
33
|
*/
|
|
30
|
-
function createRscEmbedTransform(embedStream, scriptNonce) {
|
|
34
|
+
function createRscEmbedTransform(embedStream, scriptNonce, getInitialNavigationCacheMetadata) {
|
|
31
35
|
const reader = embedStream.getReader();
|
|
32
36
|
let pendingChunks = [];
|
|
33
37
|
const rawChunks = [];
|
|
@@ -67,7 +71,7 @@ function createRscEmbedTransform(embedStream, scriptNonce) {
|
|
|
67
71
|
async finalize() {
|
|
68
72
|
await pumpPromise;
|
|
69
73
|
let scripts = this.flush();
|
|
70
|
-
scripts += createInlineScriptTag(createNavigationRuntimeRscDoneScript(), scriptNonce);
|
|
74
|
+
scripts += createInlineScriptTag(createNavigationRuntimeRscDoneScript(getInitialNavigationCacheMetadata?.()), scriptNonce);
|
|
71
75
|
return scripts;
|
|
72
76
|
},
|
|
73
77
|
async getRawBuffer() {
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import { AppElements } from "./app-elements-wire.js";
|
|
1
2
|
import { CachedRscResponse } from "../shims/navigation.js";
|
|
2
3
|
|
|
3
4
|
//#region src/server/app-visited-response-cache.d.ts
|
|
4
5
|
type VisitedResponseCacheNavigationKind = "navigate" | "refresh" | "traverse";
|
|
5
6
|
type VisitedResponseCacheEntry = {
|
|
6
7
|
createdAt: number;
|
|
8
|
+
elements?: AppElements;
|
|
7
9
|
expiresAt: number;
|
|
10
|
+
mountedSlotsHeader: string | null;
|
|
8
11
|
params: Record<string, string | string[]>;
|
|
9
12
|
response: CachedRscResponse;
|
|
10
13
|
};
|
|
11
14
|
declare const VISITED_RESPONSE_CACHE_TTL: number;
|
|
12
15
|
declare const MAX_TRAVERSAL_CACHE_TTL: number;
|
|
13
16
|
declare function createVisitedResponseCacheEntry(options: {
|
|
17
|
+
elements?: AppElements;
|
|
18
|
+
fallbackTtlMs?: number;
|
|
14
19
|
now: number;
|
|
20
|
+
mountedSlotsHeader?: string | null;
|
|
15
21
|
params: Record<string, string | string[]>;
|
|
16
22
|
response: CachedRscResponse;
|
|
17
23
|
}): VisitedResponseCacheEntry;
|
|
@@ -5,7 +5,9 @@ const MAX_TRAVERSAL_CACHE_TTL = 30 * 6e4;
|
|
|
5
5
|
function createVisitedResponseCacheEntry(options) {
|
|
6
6
|
return {
|
|
7
7
|
createdAt: options.now,
|
|
8
|
-
|
|
8
|
+
...options.elements ? { elements: options.elements } : {},
|
|
9
|
+
expiresAt: resolveCachedRscResponseExpiresAt(options.now, options.response, options.fallbackTtlMs ?? 3e5),
|
|
10
|
+
mountedSlotsHeader: options.mountedSlotsHeader ?? null,
|
|
9
11
|
params: options.params,
|
|
10
12
|
response: options.response
|
|
11
13
|
};
|
|
@@ -2,8 +2,10 @@ import { CdnCacheableHeaderInput } from "../shims/cdn-cache.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/server/cache-control.d.ts
|
|
4
4
|
declare const NEVER_CACHE_CONTROL = "private, no-cache, no-store, max-age=0, must-revalidate";
|
|
5
|
+
declare const BROWSER_REVALIDATE_CACHE_CONTROL = "public, max-age=0, must-revalidate";
|
|
5
6
|
declare const STATIC_CACHE_CONTROL = "s-maxage=31536000, stale-while-revalidate";
|
|
6
7
|
declare const NO_STORE_CACHE_CONTROL = "no-store, must-revalidate";
|
|
8
|
+
declare function shouldUseNextDeployCacheControl(): boolean;
|
|
7
9
|
/**
|
|
8
10
|
* Route a cacheable response's headers through the active CDN cache adapter and
|
|
9
11
|
* apply the result to `headers`. The default adapter yields a single
|
|
@@ -34,4 +36,4 @@ declare function buildRevalidateCacheControl(revalidateSeconds: number, expireSe
|
|
|
34
36
|
*/
|
|
35
37
|
declare function buildCachedRevalidateCacheControl(cacheState: "HIT" | "STALE", revalidateSeconds: number, expireSeconds?: number): string;
|
|
36
38
|
//#endregion
|
|
37
|
-
export { NEVER_CACHE_CONTROL, NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, applyCdnResponseHeaders, buildCachedRevalidateCacheControl, buildRevalidateCacheControl };
|
|
39
|
+
export { BROWSER_REVALIDATE_CACHE_CONTROL, NEVER_CACHE_CONTROL, NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, applyCdnResponseHeaders, buildCachedRevalidateCacheControl, buildRevalidateCacheControl, shouldUseNextDeployCacheControl };
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { getCdnCacheAdapter } from "../shims/cdn-cache.js";
|
|
2
2
|
//#region src/server/cache-control.ts
|
|
3
3
|
const NEVER_CACHE_CONTROL = "private, no-cache, no-store, max-age=0, must-revalidate";
|
|
4
|
+
const BROWSER_REVALIDATE_CACHE_CONTROL = "public, max-age=0, must-revalidate";
|
|
4
5
|
const STATIC_CACHE_CONTROL = "s-maxage=31536000, stale-while-revalidate";
|
|
5
6
|
const STALE_REVALIDATE_CACHE_CONTROL = "s-maxage=0, stale-while-revalidate";
|
|
6
7
|
const NO_STORE_CACHE_CONTROL = "no-store, must-revalidate";
|
|
8
|
+
const SHARED_CACHE_DIRECTIVE_RE = /(?:^|,)\s*s-maxage\s*=/i;
|
|
9
|
+
function shouldUseNextDeployCacheControl() {
|
|
10
|
+
return process.env.VINEXT_NEXT_DEPLOY_CACHE_CONTROL === "1";
|
|
11
|
+
}
|
|
12
|
+
function isSharedCacheControl(cacheControl) {
|
|
13
|
+
return SHARED_CACHE_DIRECTIVE_RE.test(cacheControl);
|
|
14
|
+
}
|
|
7
15
|
/**
|
|
8
16
|
* Route a cacheable response's headers through the active CDN cache adapter and
|
|
9
17
|
* apply the result to `headers`. The default adapter yields a single
|
|
@@ -17,6 +25,10 @@ const NO_STORE_CACHE_CONTROL = "no-store, must-revalidate";
|
|
|
17
25
|
*/
|
|
18
26
|
function applyCdnResponseHeaders(headers, input) {
|
|
19
27
|
headers.delete("Cache-Control");
|
|
28
|
+
if (shouldUseNextDeployCacheControl() && isSharedCacheControl(input.cacheControl)) {
|
|
29
|
+
headers.set("Cache-Control", BROWSER_REVALIDATE_CACHE_CONTROL);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
20
32
|
const map = getCdnCacheAdapter().buildResponseHeaders(input);
|
|
21
33
|
for (const [name, value] of Object.entries(map)) {
|
|
22
34
|
if (value === null) {
|
|
@@ -53,4 +65,4 @@ function buildCachedRevalidateCacheControl(cacheState, revalidateSeconds, expire
|
|
|
53
65
|
return buildRevalidateCacheControl(revalidateSeconds, expireSeconds);
|
|
54
66
|
}
|
|
55
67
|
//#endregion
|
|
56
|
-
export { NEVER_CACHE_CONTROL, NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, applyCdnResponseHeaders, buildCachedRevalidateCacheControl, buildRevalidateCacheControl };
|
|
68
|
+
export { BROWSER_REVALIDATE_CACHE_CONTROL, NEVER_CACHE_CONTROL, NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, applyCdnResponseHeaders, buildCachedRevalidateCacheControl, buildRevalidateCacheControl, shouldUseNextDeployCacheControl };
|
|
@@ -24,7 +24,32 @@ const carrierSetter = { set(carrier, key, value) {
|
|
|
24
24
|
value
|
|
25
25
|
});
|
|
26
26
|
} };
|
|
27
|
+
const OPEN_TELEMETRY_API_SYMBOL = Symbol.for("opentelemetry.js.api.1");
|
|
28
|
+
const OPEN_TELEMETRY_SPAN_SYMBOL = Symbol.for("OpenTelemetry Context Key SPAN");
|
|
29
|
+
function getRegisteredOpenTelemetryTraceData() {
|
|
30
|
+
let metadataSpan = null;
|
|
31
|
+
try {
|
|
32
|
+
const registry = globalThis[OPEN_TELEMETRY_API_SYMBOL];
|
|
33
|
+
if (!registry?.context || !registry.propagation) return null;
|
|
34
|
+
const contextApi = registry.context;
|
|
35
|
+
const propagation = registry.propagation;
|
|
36
|
+
const activeContext = contextApi.active();
|
|
37
|
+
metadataSpan = activeContext.getValue(OPEN_TELEMETRY_SPAN_SYMBOL) !== void 0 ? null : registry.trace?.getTracer("vinext").startSpan("vinext.clientTraceMetadata", void 0, activeContext) ?? null;
|
|
38
|
+
const context = metadataSpan ? activeContext.setValue(OPEN_TELEMETRY_SPAN_SYMBOL, metadataSpan) : activeContext;
|
|
39
|
+
const entries = [];
|
|
40
|
+
contextApi.with(context, () => {
|
|
41
|
+
propagation.inject(context, entries, carrierSetter);
|
|
42
|
+
});
|
|
43
|
+
return entries;
|
|
44
|
+
} catch {
|
|
45
|
+
return [];
|
|
46
|
+
} finally {
|
|
47
|
+
metadataSpan?.end();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
27
50
|
function getOpenTelemetryTraceData() {
|
|
51
|
+
const registeredEntries = getRegisteredOpenTelemetryTraceData();
|
|
52
|
+
if (registeredEntries) return registeredEntries;
|
|
28
53
|
let api;
|
|
29
54
|
try {
|
|
30
55
|
const req = globalThis.require;
|
|
@@ -75,6 +100,7 @@ function renderClientTraceMetadataTags(entries) {
|
|
|
75
100
|
*/
|
|
76
101
|
function getClientTraceMetadataHTML(allowList) {
|
|
77
102
|
if (!allowList || allowList.length === 0) return "";
|
|
103
|
+
if (typeof process !== "undefined" && process.env.VINEXT_PRERENDER === "1") return "";
|
|
78
104
|
return renderClientTraceMetadataTags(filterClientTraceMetadata(getOpenTelemetryTraceData(), allowList));
|
|
79
105
|
}
|
|
80
106
|
//#endregion
|