vinext 0.1.3 → 0.1.5
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/client-build-config.d.ts +11 -2
- package/dist/build/client-build-config.js +17 -6
- package/dist/build/css-url-assets.d.ts +1 -1
- package/dist/build/css-url-assets.js +9 -7
- package/dist/build/prerender.js +3 -1
- package/dist/cache/cache-adapters-virtual.js +1 -1
- package/dist/client/pages-router-link-navigation.d.ts +33 -7
- package/dist/client/pages-router-link-navigation.js +32 -2
- package/dist/client/vinext-next-data.js +2 -0
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
- package/dist/config/config-matchers.d.ts +11 -1
- package/dist/config/config-matchers.js +14 -2
- package/dist/config/tsconfig-paths.js +14 -1
- package/dist/deploy.js +20 -13
- package/dist/entries/app-rsc-entry.js +27 -22
- package/dist/entries/pages-client-entry.js +14 -13
- package/dist/entries/pages-server-entry.js +8 -27
- package/dist/index.js +365 -147
- package/dist/plugins/css-data-url.js +30 -26
- package/dist/plugins/dynamic-preload-metadata.js +2 -4
- package/dist/plugins/extensionless-dynamic-import.js +27 -24
- package/dist/plugins/fonts.js +5 -4
- package/dist/plugins/import-meta-url.js +21 -15
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/middleware-server-only.js +7 -6
- package/dist/plugins/og-assets.js +48 -46
- package/dist/plugins/optimize-imports.js +9 -3
- package/dist/plugins/remove-console.d.ts +7 -1
- package/dist/plugins/remove-console.js +4 -1
- package/dist/plugins/require-context.js +21 -20
- package/dist/plugins/strip-server-exports.d.ts +16 -8
- package/dist/plugins/strip-server-exports.js +496 -46
- package/dist/routing/app-route-graph.js +2 -2
- package/dist/server/app-bfcache-identity.d.ts +26 -0
- package/dist/server/app-bfcache-identity.js +127 -0
- package/dist/server/app-browser-action-result.js +1 -1
- package/dist/server/app-browser-entry.js +22 -12
- package/dist/server/app-browser-navigation-controller.d.ts +1 -1
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.d.ts +3 -22
- package/dist/server/app-browser-state.js +23 -139
- package/dist/server/app-browser-stream.js +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +1 -1
- package/dist/server/app-browser-visible-commit.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +1 -1
- package/dist/server/app-layout-param-observation.d.ts +1 -1
- package/dist/server/app-layout-param-observation.js +1 -1
- package/dist/server/app-middleware.js +2 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -1
- package/dist/server/app-page-boundary.js +1 -1
- package/dist/server/app-page-cache-finalizer.d.ts +62 -0
- package/dist/server/app-page-cache-finalizer.js +122 -0
- package/dist/server/app-page-cache-render.d.ts +2 -2
- package/dist/server/app-page-cache-render.js +1 -1
- package/dist/server/app-page-cache.d.ts +2 -53
- package/dist/server/app-page-cache.js +5 -131
- package/dist/server/app-page-dispatch.d.ts +2 -2
- package/dist/server/app-page-dispatch.js +10 -8
- package/dist/server/app-page-probe.js +3 -2
- package/dist/server/app-page-render-observation.js +2 -2
- package/dist/server/app-page-render.d.ts +3 -3
- package/dist/server/app-page-render.js +3 -2
- package/dist/server/app-page-stream.d.ts +2 -9
- package/dist/server/app-page-stream.js +1 -35
- package/dist/server/app-pages-bridge.d.ts +5 -1
- package/dist/server/app-pages-bridge.js +5 -13
- package/dist/server/app-request-context.d.ts +1 -2
- package/dist/server/app-request-context.js +2 -1
- package/dist/server/app-route-handler-dispatch.js +3 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-router-entry.js +2 -1
- package/dist/server/app-rsc-handler.d.ts +3 -0
- package/dist/server/app-rsc-handler.js +73 -31
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.js +6 -2
- package/dist/server/app-server-action-execution.d.ts +1 -1
- package/dist/server/app-server-action-execution.js +10 -6
- package/dist/server/app-ssr-entry.d.ts +1 -1
- package/dist/server/app-ssr-entry.js +12 -38
- package/dist/server/app-ssr-router-instance.d.ts +6 -0
- package/dist/server/app-ssr-router-instance.js +24 -0
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/before-interactive-head.d.ts +17 -0
- package/dist/server/before-interactive-head.js +35 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/csp.js +1 -4
- package/dist/server/defer-until-stream-consumed.d.ts +7 -0
- package/dist/server/defer-until-stream-consumed.js +34 -0
- package/dist/server/dev-server.js +82 -37
- package/dist/server/instrumentation.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/isr-decision.d.ts +1 -1
- package/dist/server/middleware-matcher.js +20 -9
- package/dist/server/middleware-runtime.d.ts +3 -4
- package/dist/server/middleware-runtime.js +4 -2
- package/dist/server/navigation-planner.d.ts +3 -12
- package/dist/server/navigation-planner.js +24 -0
- package/dist/server/navigation-trace.d.ts +2 -1
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/open-redirect.d.ts +12 -0
- package/dist/server/open-redirect.js +21 -0
- package/dist/server/operation-token.d.ts +40 -0
- package/dist/server/operation-token.js +85 -0
- package/dist/server/pages-data-route.d.ts +1 -1
- package/dist/server/pages-data-route.js +7 -4
- package/dist/server/pages-dev-module-url.d.ts +4 -0
- package/dist/server/pages-dev-module-url.js +15 -0
- package/dist/server/pages-document-initial-props.d.ts +4 -15
- package/dist/server/pages-document-initial-props.js +27 -56
- package/dist/server/pages-i18n.js +2 -2
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-data.js +3 -1
- package/dist/server/pages-page-handler.js +3 -1
- package/dist/server/pages-page-response.d.ts +3 -1
- package/dist/server/pages-page-response.js +6 -6
- package/dist/server/pages-readiness.js +1 -1
- package/dist/server/pages-request-pipeline.d.ts +7 -7
- package/dist/server/pages-request-pipeline.js +63 -21
- package/dist/server/prod-server.d.ts +3 -1
- package/dist/server/prod-server.js +43 -11
- package/dist/server/request-pipeline.d.ts +1 -24
- package/dist/server/request-pipeline.js +1 -33
- package/dist/server/seed-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js +16 -4
- package/dist/shims/before-interactive-context.d.ts +14 -3
- package/dist/shims/cache-handler.d.ts +106 -0
- package/dist/shims/cache-handler.js +176 -0
- package/dist/shims/cache-request-state.d.ts +47 -0
- package/dist/shims/cache-request-state.js +126 -0
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +3 -14
- package/dist/shims/cache.d.ts +3 -231
- package/dist/shims/cache.js +17 -383
- package/dist/shims/cdn-cache.d.ts +1 -1
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/document.d.ts +15 -20
- package/dist/shims/document.js +5 -8
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +44 -0
- package/dist/shims/error-boundary.js +10 -8
- package/dist/shims/error.js +2 -1
- package/dist/shims/fetch-cache.js +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/image.js +74 -9
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
- package/dist/shims/internal/app-page-props-cache-key.js +16 -0
- package/dist/shims/internal/navigation-untracked.js +2 -1
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +6 -7
- package/dist/shims/internal/pages-data-fetch-dedup.js +67 -14
- package/dist/shims/internal/pages-data-target.js +1 -1
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/layout-segment-context.js +2 -1
- package/dist/shims/link.js +38 -17
- package/dist/shims/metadata.js +4 -4
- package/dist/shims/navigation-context-state.d.ts +40 -0
- package/dist/shims/navigation-context-state.js +116 -0
- package/dist/shims/navigation-errors.d.ts +55 -0
- package/dist/shims/navigation-errors.js +110 -0
- package/dist/shims/navigation-server.d.ts +3 -0
- package/dist/shims/navigation-server.js +3 -0
- package/dist/shims/navigation-state.d.ts +1 -2
- package/dist/shims/navigation-state.js +2 -1
- package/dist/shims/navigation.d.ts +3 -291
- package/dist/shims/navigation.js +16 -445
- package/dist/shims/navigation.react-server.d.ts +2 -2
- package/dist/shims/navigation.react-server.js +3 -1
- package/dist/shims/request-state-types.d.ts +3 -3
- package/dist/shims/router.d.ts +6 -2
- package/dist/shims/router.js +99 -20
- package/dist/shims/script.js +9 -5
- package/dist/shims/slot.js +3 -1
- package/dist/shims/unified-request-context.d.ts +2 -2
- package/dist/utils/has-trailing-comma.d.ts +24 -0
- package/dist/utils/has-trailing-comma.js +62 -0
- package/dist/utils/text-stream.d.ts +1 -1
- package/dist/utils/text-stream.js +2 -2
- package/dist/utils/virtual-module.d.ts +5 -0
- package/dist/utils/virtual-module.js +0 -0
- package/dist/utils/vite-version.d.ts +12 -1
- package/dist/utils/vite-version.js +9 -1
- package/package.json +5 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { RenderObservation } from "./cache-proof.js";
|
|
2
|
+
import { CachedAppPageValue } from "../shims/cache-handler.js";
|
|
3
|
+
import { AppRscRenderMode } from "./app-rsc-render-mode.js";
|
|
4
|
+
import { AppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
5
|
+
|
|
6
|
+
//#region src/server/app-page-cache-finalizer.d.ts
|
|
7
|
+
type AppPageDebugLogger = (event: string, detail: string) => void;
|
|
8
|
+
type AppPageCacheSetter = (key: string, data: CachedAppPageValue, revalidateSeconds: number, tags: string[], expireSeconds?: number) => Promise<void>;
|
|
9
|
+
type AppPageRscCacheKeyBuilder = (pathname: string, mountedSlotsHeader?: string | null, renderMode?: AppRscRenderMode, interceptionContext?: string | null) => string;
|
|
10
|
+
type AppPageRequestCacheLife = {
|
|
11
|
+
revalidate?: number;
|
|
12
|
+
expire?: number;
|
|
13
|
+
};
|
|
14
|
+
type BuildAppPageCacheRenderObservation = (input: {
|
|
15
|
+
cacheTags: readonly string[];
|
|
16
|
+
state: AppPageRenderObservationState;
|
|
17
|
+
}) => RenderObservation;
|
|
18
|
+
type FinalizeAppPageHtmlCacheResponseOptions = {
|
|
19
|
+
capturedDynamicUsageBeforeContextCleanup?: () => boolean;
|
|
20
|
+
capturedRscDataPromise: Promise<ArrayBuffer> | null;
|
|
21
|
+
cleanPathname: string;
|
|
22
|
+
consumeDynamicUsage: () => boolean;
|
|
23
|
+
consumeRenderObservationState?: () => AppPageRenderObservationState;
|
|
24
|
+
createHtmlRenderObservation?: BuildAppPageCacheRenderObservation;
|
|
25
|
+
createRscRenderObservation?: BuildAppPageCacheRenderObservation;
|
|
26
|
+
getPageTags: () => string[];
|
|
27
|
+
getRequestCacheLife?: () => AppPageRequestCacheLife | null;
|
|
28
|
+
isrDebug?: AppPageDebugLogger;
|
|
29
|
+
isrHtmlKey: (pathname: string) => string;
|
|
30
|
+
isrRscKey: AppPageRscCacheKeyBuilder;
|
|
31
|
+
isrSet: AppPageCacheSetter;
|
|
32
|
+
interceptionContext?: string | null;
|
|
33
|
+
preserveClientResponseHeaders?: boolean;
|
|
34
|
+
expireSeconds?: number;
|
|
35
|
+
revalidateSeconds: number | null;
|
|
36
|
+
waitUntil?: (promise: Promise<void>) => void;
|
|
37
|
+
};
|
|
38
|
+
type ScheduleAppPageRscCacheWriteOptions = {
|
|
39
|
+
capturedRscDataPromise: Promise<ArrayBuffer> | null;
|
|
40
|
+
cleanPathname: string;
|
|
41
|
+
consumeDynamicUsage: () => boolean;
|
|
42
|
+
consumeRenderObservationState?: () => AppPageRenderObservationState;
|
|
43
|
+
createRscRenderObservation?: BuildAppPageCacheRenderObservation;
|
|
44
|
+
dynamicUsedDuringBuild: boolean;
|
|
45
|
+
getPageTags: () => string[];
|
|
46
|
+
getRequestCacheLife?: () => AppPageRequestCacheLife | null;
|
|
47
|
+
isrDebug?: AppPageDebugLogger;
|
|
48
|
+
isrRscKey: AppPageRscCacheKeyBuilder;
|
|
49
|
+
isrSet: AppPageCacheSetter;
|
|
50
|
+
interceptionContext?: string | null;
|
|
51
|
+
mountedSlotsHeader?: string | null;
|
|
52
|
+
renderMode?: AppRscRenderMode;
|
|
53
|
+
preserveClientResponseHeaders?: boolean;
|
|
54
|
+
expireSeconds?: number;
|
|
55
|
+
revalidateSeconds: number | null;
|
|
56
|
+
waitUntil?: (promise: Promise<void>) => void;
|
|
57
|
+
};
|
|
58
|
+
declare function finalizeAppPageHtmlCacheResponse(response: Response, options: FinalizeAppPageHtmlCacheResponseOptions): Response;
|
|
59
|
+
declare function finalizeAppPageRscCacheResponse(response: Response, options: ScheduleAppPageRscCacheWriteOptions): Response;
|
|
60
|
+
declare function scheduleAppPageRscCacheWrite(options: ScheduleAppPageRscCacheWriteOptions): boolean;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse, scheduleAppPageRscCacheWrite };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { setCacheStateHeaders } from "./cache-headers.js";
|
|
2
|
+
import { applyCdnResponseHeaders } from "./cache-control.js";
|
|
3
|
+
import { buildAppPageCacheValue } from "./isr-cache.js";
|
|
4
|
+
import { readStreamAsText } from "../utils/text-stream.js";
|
|
5
|
+
import { createEmptyAppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
6
|
+
//#region src/server/app-page-cache-finalizer.ts
|
|
7
|
+
function applyPendingDynamicCdnHeaders(headers, tags) {
|
|
8
|
+
applyCdnResponseHeaders(headers, {
|
|
9
|
+
cacheControl: headers.get("Cache-Control") ?? "",
|
|
10
|
+
pendingDynamicCheck: true,
|
|
11
|
+
tags
|
|
12
|
+
});
|
|
13
|
+
setCacheStateHeaders(headers, "MISS");
|
|
14
|
+
}
|
|
15
|
+
function resolveAppPageCacheWritePolicy(options) {
|
|
16
|
+
let revalidateSeconds = options.revalidateSeconds;
|
|
17
|
+
let expireSeconds = options.expireSeconds;
|
|
18
|
+
const requestCacheLife = options.requestCacheLife;
|
|
19
|
+
if (requestCacheLife?.revalidate !== void 0) revalidateSeconds = revalidateSeconds === null ? requestCacheLife.revalidate : Math.min(revalidateSeconds, requestCacheLife.revalidate);
|
|
20
|
+
if (requestCacheLife?.expire !== void 0) expireSeconds = requestCacheLife.expire;
|
|
21
|
+
if (revalidateSeconds === null || Number.isNaN(revalidateSeconds) || revalidateSeconds <= 0) return null;
|
|
22
|
+
return {
|
|
23
|
+
expireSeconds,
|
|
24
|
+
revalidateSeconds
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function finalizeAppPageHtmlCacheResponse(response, options) {
|
|
28
|
+
if (!response.body) return response;
|
|
29
|
+
const [streamForClient, streamForCache] = response.body.tee();
|
|
30
|
+
const htmlKey = options.isrHtmlKey(options.cleanPathname);
|
|
31
|
+
const rscKey = options.isrRscKey(options.cleanPathname, null, void 0, options.interceptionContext);
|
|
32
|
+
const clientHeaders = new Headers(response.headers);
|
|
33
|
+
if (options.preserveClientResponseHeaders !== true) applyPendingDynamicCdnHeaders(clientHeaders, options.getPageTags());
|
|
34
|
+
const cachePromise = (async () => {
|
|
35
|
+
try {
|
|
36
|
+
const cachedHtml = await readStreamAsText(streamForCache);
|
|
37
|
+
if (options.capturedDynamicUsageBeforeContextCleanup?.() === true || options.consumeDynamicUsage()) {
|
|
38
|
+
options.isrDebug?.("HTML cache write skipped (dynamic usage during render)", htmlKey);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const cachePolicy = resolveAppPageCacheWritePolicy({
|
|
42
|
+
expireSeconds: options.expireSeconds,
|
|
43
|
+
requestCacheLife: options.getRequestCacheLife?.(),
|
|
44
|
+
revalidateSeconds: options.revalidateSeconds
|
|
45
|
+
});
|
|
46
|
+
if (!cachePolicy) {
|
|
47
|
+
options.isrDebug?.("HTML cache write skipped (no cache policy)", htmlKey);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const pageTags = options.getPageTags();
|
|
51
|
+
const observationState = options.consumeRenderObservationState?.() ?? createEmptyAppPageRenderObservationState();
|
|
52
|
+
const htmlRenderObservation = options.createHtmlRenderObservation?.({
|
|
53
|
+
cacheTags: pageTags,
|
|
54
|
+
state: observationState
|
|
55
|
+
});
|
|
56
|
+
const rscRenderObservation = options.createRscRenderObservation?.({
|
|
57
|
+
cacheTags: pageTags,
|
|
58
|
+
state: observationState
|
|
59
|
+
});
|
|
60
|
+
const writes = [options.isrSet(htmlKey, buildAppPageCacheValue(cachedHtml, void 0, 200, htmlRenderObservation), cachePolicy.revalidateSeconds, pageTags, cachePolicy.expireSeconds)];
|
|
61
|
+
if (options.capturedRscDataPromise) writes.push(options.capturedRscDataPromise.then((rscData) => options.isrSet(rscKey, buildAppPageCacheValue("", rscData, 200, rscRenderObservation), cachePolicy.revalidateSeconds, pageTags, cachePolicy.expireSeconds)));
|
|
62
|
+
await Promise.all(writes);
|
|
63
|
+
options.isrDebug?.("HTML cache written", htmlKey);
|
|
64
|
+
} catch (cacheError) {
|
|
65
|
+
console.error("[vinext] ISR cache write error:", cacheError);
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
options.waitUntil?.(cachePromise);
|
|
69
|
+
return new Response(streamForClient, {
|
|
70
|
+
status: response.status,
|
|
71
|
+
statusText: response.statusText,
|
|
72
|
+
headers: clientHeaders
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function finalizeAppPageRscCacheResponse(response, options) {
|
|
76
|
+
if (!scheduleAppPageRscCacheWrite(options)) return response;
|
|
77
|
+
if (options.preserveClientResponseHeaders === true) return response;
|
|
78
|
+
const clientHeaders = new Headers(response.headers);
|
|
79
|
+
applyPendingDynamicCdnHeaders(clientHeaders, options.getPageTags());
|
|
80
|
+
return new Response(response.body, {
|
|
81
|
+
status: response.status,
|
|
82
|
+
statusText: response.statusText,
|
|
83
|
+
headers: clientHeaders
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function scheduleAppPageRscCacheWrite(options) {
|
|
87
|
+
const capturedRscDataPromise = options.capturedRscDataPromise;
|
|
88
|
+
if (!capturedRscDataPromise || options.dynamicUsedDuringBuild) return false;
|
|
89
|
+
const rscKey = options.isrRscKey(options.cleanPathname, options.mountedSlotsHeader, options.renderMode, options.interceptionContext);
|
|
90
|
+
const cachePromise = (async () => {
|
|
91
|
+
try {
|
|
92
|
+
const rscData = await capturedRscDataPromise;
|
|
93
|
+
if (options.consumeDynamicUsage()) {
|
|
94
|
+
options.isrDebug?.("RSC cache write skipped (dynamic usage during render)", rscKey);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const cachePolicy = resolveAppPageCacheWritePolicy({
|
|
98
|
+
expireSeconds: options.expireSeconds,
|
|
99
|
+
requestCacheLife: options.getRequestCacheLife?.(),
|
|
100
|
+
revalidateSeconds: options.revalidateSeconds
|
|
101
|
+
});
|
|
102
|
+
if (!cachePolicy) {
|
|
103
|
+
options.isrDebug?.("RSC cache write skipped (no cache policy)", rscKey);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const pageTags = options.getPageTags();
|
|
107
|
+
const observationState = options.consumeRenderObservationState?.() ?? createEmptyAppPageRenderObservationState();
|
|
108
|
+
const rscRenderObservation = options.createRscRenderObservation?.({
|
|
109
|
+
cacheTags: pageTags,
|
|
110
|
+
state: observationState
|
|
111
|
+
});
|
|
112
|
+
await options.isrSet(rscKey, buildAppPageCacheValue("", rscData, 200, rscRenderObservation), cachePolicy.revalidateSeconds, pageTags, cachePolicy.expireSeconds);
|
|
113
|
+
options.isrDebug?.("RSC cache written", rscKey);
|
|
114
|
+
} catch (cacheError) {
|
|
115
|
+
console.error("[vinext] ISR RSC cache write error:", cacheError);
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
options.waitUntil?.(cachePromise);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
export { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse, scheduleAppPageRscCacheWrite };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CacheControlMetadata } from "../shims/cache.js";
|
|
2
|
-
import { NavigationContext } from "../shims/navigation.js";
|
|
1
|
+
import { CacheControlMetadata } from "../shims/cache-handler.js";
|
|
2
|
+
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
3
3
|
import { AppPageFontPreload } from "./app-page-execution.js";
|
|
4
4
|
import { RootParams } from "../shims/root-params.js";
|
|
5
5
|
import { AppPageSsrHandler } from "./app-page-stream.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { consumeDynamicUsage, consumeInvalidDynamicUsageError } from "../shims/headers.js";
|
|
2
|
-
import { _consumeRequestScopedCacheLife } from "../shims/cache.js";
|
|
2
|
+
import { _consumeRequestScopedCacheLife } from "../shims/cache-request-state.js";
|
|
3
3
|
import { getCollectedFetchTags } from "../shims/fetch-cache.js";
|
|
4
4
|
import { readStreamAsText } from "../utils/text-stream.js";
|
|
5
5
|
import { teeAppPageRscStreamForCapture } from "./app-page-execution.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RenderObservation } from "./cache-proof.js";
|
|
2
|
-
import { CacheControlMetadata, CachedAppPageValue } from "../shims/cache.js";
|
|
3
|
-
import { AppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
2
|
+
import { CacheControlMetadata, CachedAppPageValue } from "../shims/cache-handler.js";
|
|
4
3
|
import { AppRscRenderMode } from "./app-rsc-render-mode.js";
|
|
4
|
+
import { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse, scheduleAppPageRscCacheWrite } from "./app-page-cache-finalizer.js";
|
|
5
5
|
import { ISRCacheEntry } from "./isr-cache.js";
|
|
6
6
|
|
|
7
7
|
//#region src/server/app-page-cache.d.ts
|
|
@@ -10,10 +10,6 @@ type AppPageCacheGetter = (key: string) => Promise<ISRCacheEntry | null>;
|
|
|
10
10
|
type AppPageCacheSetter = (key: string, data: CachedAppPageValue, revalidateSeconds: number, tags: string[], expireSeconds?: number) => Promise<void>;
|
|
11
11
|
type AppPageBackgroundRegenerator = (key: string, renderFn: () => Promise<void>) => void;
|
|
12
12
|
type AppPageRscCacheKeyBuilder = (pathname: string, mountedSlotsHeader?: string | null, renderMode?: AppRscRenderMode, interceptionContext?: string | null) => string;
|
|
13
|
-
type AppPageRequestCacheLife = {
|
|
14
|
-
revalidate?: number;
|
|
15
|
-
expire?: number;
|
|
16
|
-
};
|
|
17
13
|
type AppPageCacheOutcomeMetric = Readonly<{
|
|
18
14
|
artifact: "html" | "rsc";
|
|
19
15
|
/**
|
|
@@ -25,10 +21,6 @@ type AppPageCacheOutcomeMetric = Readonly<{
|
|
|
25
21
|
reason: "empty-entry" | "no-entry" | "non-app-page-entry" | "query-variant-unproven" | "read-error" | "served" | "stale-empty-entry";
|
|
26
22
|
}>;
|
|
27
23
|
type AppPageCacheOutcomeRecorder = (metric: AppPageCacheOutcomeMetric) => void;
|
|
28
|
-
type BuildAppPageCacheRenderObservation = (input: {
|
|
29
|
-
cacheTags: readonly string[];
|
|
30
|
-
state: AppPageRenderObservationState;
|
|
31
|
-
}) => RenderObservation;
|
|
32
24
|
type AppPageCacheRenderResult = {
|
|
33
25
|
cacheControl?: CacheControlMetadata;
|
|
34
26
|
html: string;
|
|
@@ -83,52 +75,9 @@ type ReadAppPageFallbackShellCacheResponseOptions = {
|
|
|
83
75
|
revalidateSeconds: number;
|
|
84
76
|
rewriteHtml: (html: string) => string;
|
|
85
77
|
};
|
|
86
|
-
type FinalizeAppPageHtmlCacheResponseOptions = {
|
|
87
|
-
capturedDynamicUsageBeforeContextCleanup?: () => boolean;
|
|
88
|
-
capturedRscDataPromise: Promise<ArrayBuffer> | null;
|
|
89
|
-
cleanPathname: string;
|
|
90
|
-
consumeDynamicUsage: () => boolean;
|
|
91
|
-
consumeRenderObservationState?: () => AppPageRenderObservationState;
|
|
92
|
-
createHtmlRenderObservation?: BuildAppPageCacheRenderObservation;
|
|
93
|
-
createRscRenderObservation?: BuildAppPageCacheRenderObservation;
|
|
94
|
-
getPageTags: () => string[];
|
|
95
|
-
getRequestCacheLife?: () => AppPageRequestCacheLife | null;
|
|
96
|
-
isrDebug?: AppPageDebugLogger;
|
|
97
|
-
isrHtmlKey: (pathname: string) => string;
|
|
98
|
-
isrRscKey: AppPageRscCacheKeyBuilder;
|
|
99
|
-
isrSet: AppPageCacheSetter;
|
|
100
|
-
interceptionContext?: string | null;
|
|
101
|
-
preserveClientResponseHeaders?: boolean;
|
|
102
|
-
expireSeconds?: number;
|
|
103
|
-
revalidateSeconds: number | null;
|
|
104
|
-
waitUntil?: (promise: Promise<void>) => void;
|
|
105
|
-
};
|
|
106
|
-
type ScheduleAppPageRscCacheWriteOptions = {
|
|
107
|
-
capturedRscDataPromise: Promise<ArrayBuffer> | null;
|
|
108
|
-
cleanPathname: string;
|
|
109
|
-
consumeDynamicUsage: () => boolean;
|
|
110
|
-
consumeRenderObservationState?: () => AppPageRenderObservationState;
|
|
111
|
-
createRscRenderObservation?: BuildAppPageCacheRenderObservation;
|
|
112
|
-
dynamicUsedDuringBuild: boolean;
|
|
113
|
-
getPageTags: () => string[];
|
|
114
|
-
getRequestCacheLife?: () => AppPageRequestCacheLife | null;
|
|
115
|
-
isrDebug?: AppPageDebugLogger;
|
|
116
|
-
isrRscKey: AppPageRscCacheKeyBuilder;
|
|
117
|
-
isrSet: AppPageCacheSetter;
|
|
118
|
-
interceptionContext?: string | null;
|
|
119
|
-
mountedSlotsHeader?: string | null;
|
|
120
|
-
renderMode?: AppRscRenderMode;
|
|
121
|
-
preserveClientResponseHeaders?: boolean;
|
|
122
|
-
expireSeconds?: number;
|
|
123
|
-
revalidateSeconds: number | null;
|
|
124
|
-
waitUntil?: (promise: Promise<void>) => void;
|
|
125
|
-
};
|
|
126
78
|
declare function buildAppPageCacheTags(pathname: string, extraTags: readonly string[]): string[];
|
|
127
79
|
declare function buildAppPageCachedResponse(cachedValue: CachedAppPageValue, options: BuildAppPageCachedResponseOptions): Response | null;
|
|
128
80
|
declare function readAppPageCacheResponse(options: ReadAppPageCacheResponseOptions): Promise<Response | null>;
|
|
129
81
|
declare function readAppPageFallbackShellCacheResponse(options: ReadAppPageFallbackShellCacheResponseOptions): Promise<Response | null>;
|
|
130
|
-
declare function finalizeAppPageHtmlCacheResponse(response: Response, options: FinalizeAppPageHtmlCacheResponseOptions): Response;
|
|
131
|
-
declare function finalizeAppPageRscCacheResponse(response: Response, options: ScheduleAppPageRscCacheWriteOptions): Response;
|
|
132
|
-
declare function scheduleAppPageRscCacheWrite(options: ScheduleAppPageRscCacheWriteOptions): boolean;
|
|
133
82
|
//#endregion
|
|
134
83
|
export { AppPageCacheOutcomeMetric, buildAppPageCacheTags, buildAppPageCachedResponse, finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse, readAppPageCacheResponse, readAppPageFallbackShellCacheResponse, scheduleAppPageRscCacheWrite };
|
|
@@ -1,35 +1,16 @@
|
|
|
1
1
|
import { VINEXT_MOUNTED_SLOTS_HEADER } from "./headers.js";
|
|
2
2
|
import { setCacheStateHeaders } from "./cache-headers.js";
|
|
3
|
-
import { encodeCacheTag } from "../utils/encode-cache-tag.js";
|
|
4
3
|
import { applyCdnResponseHeaders } from "./cache-control.js";
|
|
5
4
|
import { decideIsr } from "./isr-decision.js";
|
|
6
5
|
import { buildAppPageCacheValue } from "./isr-cache.js";
|
|
6
|
+
import { encodeCacheTag } from "../utils/encode-cache-tag.js";
|
|
7
7
|
import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader } from "./app-rsc-cache-busting.js";
|
|
8
|
-
import { readStreamAsText } from "../utils/text-stream.js";
|
|
9
8
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
10
9
|
import { applyEdgeRuntimeHeader } from "./app-page-response.js";
|
|
11
10
|
import { hasCompleteNegativeRequestApiProof } from "./cache-proof.js";
|
|
12
|
-
import { createEmptyAppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
13
11
|
import { isAppPprDynamicFallbackShellHtml } from "./app-ppr-fallback-shell.js";
|
|
12
|
+
import { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse, scheduleAppPageRscCacheWrite } from "./app-page-cache-finalizer.js";
|
|
14
13
|
//#region src/server/app-page-cache.ts
|
|
15
|
-
/**
|
|
16
|
-
* Apply the CDN cache adapter's headers to a freshly-streamed response whose
|
|
17
|
-
* dynamic-ness is not yet proven.
|
|
18
|
-
*
|
|
19
|
-
* The cacheable `Cache-Control` value computed by the response policy is already
|
|
20
|
-
* present on `headers`; the default adapter replaces it with `no-store` (so the
|
|
21
|
-
* page is served from the origin store on later requests), while an edge adapter
|
|
22
|
-
* may instead emit `CDN-Cache-Control`/`Cache-Tag` so the CDN performs SWR and
|
|
23
|
-
* can be purged by tag. `tags` are the page's render tags (canonicalised).
|
|
24
|
-
*/
|
|
25
|
-
function applyPendingDynamicCdnHeaders(headers, tags) {
|
|
26
|
-
applyCdnResponseHeaders(headers, {
|
|
27
|
-
cacheControl: headers.get("Cache-Control") ?? "",
|
|
28
|
-
pendingDynamicCheck: true,
|
|
29
|
-
tags
|
|
30
|
-
});
|
|
31
|
-
setCacheStateHeaders(headers, "MISS");
|
|
32
|
-
}
|
|
33
14
|
function recordAppPageCacheOutcome(recordCacheOutcome, input) {
|
|
34
15
|
try {
|
|
35
16
|
recordCacheOutcome?.(input);
|
|
@@ -72,18 +53,6 @@ function getCachedAppPageValue(entry) {
|
|
|
72
53
|
function hasQueryInvariantAppPageProof(cachedValue) {
|
|
73
54
|
return cachedValue.renderObservation !== void 0 && hasCompleteNegativeRequestApiProof(cachedValue.renderObservation, ["searchParams"]);
|
|
74
55
|
}
|
|
75
|
-
function resolveAppPageCacheWritePolicy(options) {
|
|
76
|
-
let revalidateSeconds = options.revalidateSeconds;
|
|
77
|
-
let expireSeconds = options.expireSeconds;
|
|
78
|
-
const requestCacheLife = options.requestCacheLife;
|
|
79
|
-
if (requestCacheLife?.revalidate !== void 0) revalidateSeconds = revalidateSeconds === null ? requestCacheLife.revalidate : Math.min(revalidateSeconds, requestCacheLife.revalidate);
|
|
80
|
-
if (requestCacheLife?.expire !== void 0) expireSeconds = requestCacheLife.expire;
|
|
81
|
-
if (revalidateSeconds === null || Number.isNaN(revalidateSeconds) || revalidateSeconds <= 0) return null;
|
|
82
|
-
return {
|
|
83
|
-
expireSeconds,
|
|
84
|
-
revalidateSeconds
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
56
|
function buildAppPageCachedResponse(cachedValue, options) {
|
|
88
57
|
const status = options.middlewareStatus ?? (cachedValue.status || 200);
|
|
89
58
|
const { cacheControl } = decideIsr({
|
|
@@ -203,13 +172,12 @@ async function readAppPageCacheResponse(options) {
|
|
|
203
172
|
options.isrDebug?.("MISS (empty cached entry)", options.cleanPathname);
|
|
204
173
|
}
|
|
205
174
|
if (cached?.isStale && cachedValue) {
|
|
206
|
-
|
|
207
|
-
options.scheduleBackgroundRegeneration(regenerationKey, async () => {
|
|
175
|
+
options.scheduleBackgroundRegeneration(isrKey, async () => {
|
|
208
176
|
const revalidatedPage = await options.renderFreshPageForCache();
|
|
209
177
|
const revalidateSeconds = revalidatedPage.cacheControl?.revalidate ?? options.revalidateSeconds;
|
|
210
178
|
const expireSeconds = revalidatedPage.cacheControl?.expire ?? options.expireSeconds;
|
|
211
|
-
const writes = [options.isrSet(options.isrRscKey(options.cleanPathname, options.mountedSlotsHeader, options.renderMode, options.interceptionContext), buildAppPageCacheValue("", revalidatedPage.rscData, 200, revalidatedPage.rscRenderObservation), revalidateSeconds, revalidatedPage.tags, expireSeconds)];
|
|
212
|
-
if (!options.isRscRequest) writes.push(options.isrSet(
|
|
179
|
+
const writes = [options.isrSet(options.isRscRequest ? isrKey : options.isrRscKey(options.cleanPathname, options.mountedSlotsHeader, options.renderMode, options.interceptionContext), buildAppPageCacheValue("", revalidatedPage.rscData, 200, revalidatedPage.rscRenderObservation), revalidateSeconds, revalidatedPage.tags, expireSeconds)];
|
|
180
|
+
if (!options.isRscRequest) writes.push(options.isrSet(isrKey, buildAppPageCacheValue(revalidatedPage.html, void 0, 200, revalidatedPage.htmlRenderObservation), revalidateSeconds, revalidatedPage.tags, expireSeconds));
|
|
213
181
|
await Promise.all(writes);
|
|
214
182
|
options.isrDebug?.("regen complete", options.cleanPathname);
|
|
215
183
|
});
|
|
@@ -300,99 +268,5 @@ async function readAppPageFallbackShellCacheResponse(options) {
|
|
|
300
268
|
return null;
|
|
301
269
|
}
|
|
302
270
|
}
|
|
303
|
-
function finalizeAppPageHtmlCacheResponse(response, options) {
|
|
304
|
-
if (!response.body) return response;
|
|
305
|
-
const [streamForClient, streamForCache] = response.body.tee();
|
|
306
|
-
const htmlKey = options.isrHtmlKey(options.cleanPathname);
|
|
307
|
-
const rscKey = options.isrRscKey(options.cleanPathname, null, void 0, options.interceptionContext);
|
|
308
|
-
const clientHeaders = new Headers(response.headers);
|
|
309
|
-
if (options.preserveClientResponseHeaders !== true) applyPendingDynamicCdnHeaders(clientHeaders, options.getPageTags());
|
|
310
|
-
const cachePromise = (async () => {
|
|
311
|
-
try {
|
|
312
|
-
const cachedHtml = await readStreamAsText(streamForCache);
|
|
313
|
-
if (options.capturedDynamicUsageBeforeContextCleanup?.() === true || options.consumeDynamicUsage()) {
|
|
314
|
-
options.isrDebug?.("HTML cache write skipped (dynamic usage during render)", htmlKey);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const cachePolicy = resolveAppPageCacheWritePolicy({
|
|
318
|
-
expireSeconds: options.expireSeconds,
|
|
319
|
-
requestCacheLife: options.getRequestCacheLife?.(),
|
|
320
|
-
revalidateSeconds: options.revalidateSeconds
|
|
321
|
-
});
|
|
322
|
-
if (!cachePolicy) {
|
|
323
|
-
options.isrDebug?.("HTML cache write skipped (no cache policy)", htmlKey);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
const pageTags = options.getPageTags();
|
|
327
|
-
const observationState = options.consumeRenderObservationState?.() ?? createEmptyAppPageRenderObservationState();
|
|
328
|
-
const htmlRenderObservation = options.createHtmlRenderObservation?.({
|
|
329
|
-
cacheTags: pageTags,
|
|
330
|
-
state: observationState
|
|
331
|
-
});
|
|
332
|
-
const rscRenderObservation = options.createRscRenderObservation?.({
|
|
333
|
-
cacheTags: pageTags,
|
|
334
|
-
state: observationState
|
|
335
|
-
});
|
|
336
|
-
const writes = [options.isrSet(htmlKey, buildAppPageCacheValue(cachedHtml, void 0, 200, htmlRenderObservation), cachePolicy.revalidateSeconds, pageTags, cachePolicy.expireSeconds)];
|
|
337
|
-
if (options.capturedRscDataPromise) writes.push(options.capturedRscDataPromise.then((rscData) => options.isrSet(rscKey, buildAppPageCacheValue("", rscData, 200, rscRenderObservation), cachePolicy.revalidateSeconds, pageTags, cachePolicy.expireSeconds)));
|
|
338
|
-
await Promise.all(writes);
|
|
339
|
-
options.isrDebug?.("HTML cache written", htmlKey);
|
|
340
|
-
} catch (cacheError) {
|
|
341
|
-
console.error("[vinext] ISR cache write error:", cacheError);
|
|
342
|
-
}
|
|
343
|
-
})();
|
|
344
|
-
options.waitUntil?.(cachePromise);
|
|
345
|
-
return new Response(streamForClient, {
|
|
346
|
-
status: response.status,
|
|
347
|
-
statusText: response.statusText,
|
|
348
|
-
headers: clientHeaders
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
function finalizeAppPageRscCacheResponse(response, options) {
|
|
352
|
-
if (!scheduleAppPageRscCacheWrite(options)) return response;
|
|
353
|
-
if (options.preserveClientResponseHeaders === true) return response;
|
|
354
|
-
const clientHeaders = new Headers(response.headers);
|
|
355
|
-
applyPendingDynamicCdnHeaders(clientHeaders, options.getPageTags());
|
|
356
|
-
return new Response(response.body, {
|
|
357
|
-
status: response.status,
|
|
358
|
-
statusText: response.statusText,
|
|
359
|
-
headers: clientHeaders
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
function scheduleAppPageRscCacheWrite(options) {
|
|
363
|
-
const capturedRscDataPromise = options.capturedRscDataPromise;
|
|
364
|
-
if (!capturedRscDataPromise || options.dynamicUsedDuringBuild) return false;
|
|
365
|
-
const rscKey = options.isrRscKey(options.cleanPathname, options.mountedSlotsHeader, options.renderMode, options.interceptionContext);
|
|
366
|
-
const cachePromise = (async () => {
|
|
367
|
-
try {
|
|
368
|
-
const rscData = await capturedRscDataPromise;
|
|
369
|
-
if (options.consumeDynamicUsage()) {
|
|
370
|
-
options.isrDebug?.("RSC cache write skipped (dynamic usage during render)", rscKey);
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
const cachePolicy = resolveAppPageCacheWritePolicy({
|
|
374
|
-
expireSeconds: options.expireSeconds,
|
|
375
|
-
requestCacheLife: options.getRequestCacheLife?.(),
|
|
376
|
-
revalidateSeconds: options.revalidateSeconds
|
|
377
|
-
});
|
|
378
|
-
if (!cachePolicy) {
|
|
379
|
-
options.isrDebug?.("RSC cache write skipped (no cache policy)", rscKey);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
const pageTags = options.getPageTags();
|
|
383
|
-
const observationState = options.consumeRenderObservationState?.() ?? createEmptyAppPageRenderObservationState();
|
|
384
|
-
const rscRenderObservation = options.createRscRenderObservation?.({
|
|
385
|
-
cacheTags: pageTags,
|
|
386
|
-
state: observationState
|
|
387
|
-
});
|
|
388
|
-
await options.isrSet(rscKey, buildAppPageCacheValue("", rscData, 200, rscRenderObservation), cachePolicy.revalidateSeconds, pageTags, cachePolicy.expireSeconds);
|
|
389
|
-
options.isrDebug?.("RSC cache written", rscKey);
|
|
390
|
-
} catch (cacheError) {
|
|
391
|
-
console.error("[vinext] ISR RSC cache write error:", cacheError);
|
|
392
|
-
}
|
|
393
|
-
})();
|
|
394
|
-
options.waitUntil?.(cachePromise);
|
|
395
|
-
return true;
|
|
396
|
-
}
|
|
397
271
|
//#endregion
|
|
398
272
|
export { buildAppPageCacheTags, buildAppPageCachedResponse, finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse, readAppPageCacheResponse, readAppPageFallbackShellCacheResponse, scheduleAppPageRscCacheWrite };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ClassificationReason } from "../build/layout-classification-types.js";
|
|
2
|
-
import { CachedAppPageValue } from "../shims/cache.js";
|
|
2
|
+
import { CachedAppPageValue } from "../shims/cache-handler.js";
|
|
3
3
|
import { ClientReuseManifestParseResult } from "./client-reuse-manifest.js";
|
|
4
4
|
import { AppOutgoingElements } from "./app-elements-wire.js";
|
|
5
|
-
import { NavigationContext } from "../shims/navigation.js";
|
|
5
|
+
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
6
6
|
import { AppPageFontPreload, LayoutClassificationOptions } from "./app-page-execution.js";
|
|
7
7
|
import { AppPageMiddlewareContext } from "./app-page-response.js";
|
|
8
8
|
import { RootParams } from "../shims/root-params.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequestContext, runWithRequestContext } from "../shims/unified-request-context.js";
|
|
2
2
|
import { getRequestExecutionContext } from "../shims/request-context.js";
|
|
3
|
-
import { beginPprFallbackShellFinalRender, createPprFallbackShellState, getPprFallbackShellState, runWithPprFallbackShellState } from "../shims/ppr-fallback-shell.js";
|
|
4
|
-
import { consumeDynamicUsage, consumeInvalidDynamicUsageError, getAndClearPendingCookies, getDraftModeCookieHeader, isDraftModeRequest, markDynamicUsage, peekRenderRequestApiUsage, setHeadersContext } from "../shims/headers.js";
|
|
5
|
-
import { _consumeRequestScopedCacheLife, _peekRequestScopedCacheLife } from "../shims/cache.js";
|
|
6
3
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
7
4
|
import { shouldSuppressLoadingBoundaries } from "./app-rsc-render-mode.js";
|
|
8
5
|
import "./app-elements.js";
|
|
6
|
+
import { beginPprFallbackShellFinalRender, createPprFallbackShellState, getPprFallbackShellState, runWithPprFallbackShellState } from "../shims/ppr-fallback-shell.js";
|
|
7
|
+
import { consumeDynamicUsage, consumeInvalidDynamicUsageError, getAndClearPendingCookies, getDraftModeCookieHeader, isDraftModeRequest, markDynamicUsage, peekRenderRequestApiUsage, setHeadersContext } from "../shims/headers.js";
|
|
8
|
+
import { _consumeRequestScopedCacheLife, _peekRequestScopedCacheLife } from "../shims/cache-request-state.js";
|
|
9
9
|
import { ensureFetchPatch, getCollectedFetchTags, peekDynamicFetchObservations, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault } from "../shims/fetch-cache.js";
|
|
10
10
|
import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader } from "./app-rsc-cache-busting.js";
|
|
11
11
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
@@ -13,19 +13,14 @@ import "./app-page-response.js";
|
|
|
13
13
|
import { buildAppPageSpecialErrorResponse, probeAppPageThrownError, resolveAppPageSpecialError } from "./app-page-execution.js";
|
|
14
14
|
import { createAppPageTreePath } from "./app-page-route-wiring.js";
|
|
15
15
|
import { consumeAppPageRenderObservationState, discardAppPageRenderState } from "./app-page-render-observation.js";
|
|
16
|
-
import { rewriteAppPprFallbackShellHtmlNavigation } from "./app-ppr-fallback-shell.js";
|
|
17
|
-
import { readAppPageCacheResponse, readAppPageFallbackShellCacheResponse } from "./app-page-cache.js";
|
|
18
16
|
import { resolveAppPageParentHttpAccessBoundary, resolveAppPageParentHttpAccessBoundaryModule } from "./app-page-boundary.js";
|
|
19
17
|
import { createAppLayoutParamAccessTracker, isAppLayoutObservationUnsafeForStaticReuse } from "./app-layout-param-observation.js";
|
|
20
18
|
import { buildAppPageTags } from "./implicit-tags.js";
|
|
21
|
-
import { renderAppPageCacheArtifacts } from "./app-page-cache-render.js";
|
|
22
|
-
import { warmPprFallbackShellCaches } from "./app-ppr-fallback-shell-render.js";
|
|
23
19
|
import { resolveAppPageMethodResponse } from "./app-page-method.js";
|
|
24
20
|
import { shouldServeStreamingMetadata } from "./streaming-metadata.js";
|
|
25
21
|
import { resolveAppPageNavigationParams } from "./app-page-element-builder.js";
|
|
26
22
|
import { buildAppPageElement, resolveAppPageIntercept, resolveAppPageInterceptionRerenderTarget, validateAppPageDynamicParams } from "./app-page-request.js";
|
|
27
23
|
import { renderAppPageLifecycle } from "./app-page-render.js";
|
|
28
|
-
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
29
24
|
import React from "react";
|
|
30
25
|
//#region src/server/app-page-dispatch.ts
|
|
31
26
|
function resolveAppPageRouteBoundaryModule(route, statusCode) {
|
|
@@ -110,6 +105,7 @@ function hasSearchParams(searchParams) {
|
|
|
110
105
|
return searchParams !== null && searchParams !== void 0 && searchParams.size > 0;
|
|
111
106
|
}
|
|
112
107
|
async function runAppPageRevalidationContext(options, renderFn) {
|
|
108
|
+
const { createStaticGenerationHeadersContext } = await import("./app-static-generation.js");
|
|
113
109
|
return runWithRequestContext(createRequestContext({
|
|
114
110
|
headersContext: createStaticGenerationHeadersContext({
|
|
115
111
|
draftModeSecret: options.draftModeSecret,
|
|
@@ -170,6 +166,8 @@ function classifyPprFallbackShellEligibility(options, currentRevalidateSeconds,
|
|
|
170
166
|
};
|
|
171
167
|
}
|
|
172
168
|
async function probePprFallbackShellCache(options, route, fallbackShells, currentRevalidateSeconds) {
|
|
169
|
+
const { readAppPageFallbackShellCacheResponse } = await import("./app-page-cache.js");
|
|
170
|
+
const { rewriteAppPprFallbackShellHtmlNavigation } = await import("./app-ppr-fallback-shell.js");
|
|
173
171
|
for (const fallbackShell of fallbackShells) {
|
|
174
172
|
const fallbackShellResponse = await readAppPageFallbackShellCacheResponse({
|
|
175
173
|
clearRequestContext: options.clearRequestContext,
|
|
@@ -241,6 +239,7 @@ async function dispatchAppPageInner(options) {
|
|
|
241
239
|
return methodResponse;
|
|
242
240
|
}
|
|
243
241
|
if ((isForceStatic || isDynamicError) && !isDraftMode) {
|
|
242
|
+
const { createStaticGenerationHeadersContext } = await import("./app-static-generation.js");
|
|
244
243
|
setHeadersContext(createStaticGenerationHeadersContext({
|
|
245
244
|
draftModeSecret: options.draftModeSecret,
|
|
246
245
|
dynamicConfig,
|
|
@@ -263,6 +262,7 @@ async function dispatchAppPageInner(options) {
|
|
|
263
262
|
revalidateSeconds: currentRevalidateSeconds,
|
|
264
263
|
scriptNonce: options.scriptNonce
|
|
265
264
|
})) {
|
|
265
|
+
const { readAppPageCacheResponse } = await import("./app-page-cache.js");
|
|
266
266
|
const cachedPageResponse = await readAppPageCacheResponse({
|
|
267
267
|
cleanPathname: options.cleanPathname,
|
|
268
268
|
clearRequestContext: options.clearRequestContext,
|
|
@@ -311,6 +311,7 @@ async function dispatchAppPageInner(options) {
|
|
|
311
311
|
routeSegments: revalidationTarget.route.routeSegments,
|
|
312
312
|
setNavigationContext: options.setNavigationContext
|
|
313
313
|
}, async () => {
|
|
314
|
+
const { renderAppPageCacheArtifacts } = await import("./app-page-cache-render.js");
|
|
314
315
|
const revalidatedElement = await options.buildPageElement(revalidationTarget.route, revalidationTarget.params, revalidationTarget.interceptOpts, new URLSearchParams());
|
|
315
316
|
const revalidatedOnError = options.createRscOnErrorHandler(options.cleanPathname, revalidationTarget.route.pattern);
|
|
316
317
|
const rendered = await renderAppPageCacheArtifacts({
|
|
@@ -436,6 +437,7 @@ async function dispatchAppPageInner(options) {
|
|
|
436
437
|
if (fallbackShellState && process.env.VINEXT_PRERENDER === "1" && !options.isRscRequest) {
|
|
437
438
|
const warmupBuildResult = await buildCurrentPageElement();
|
|
438
439
|
if (warmupBuildResult.response) return warmupBuildResult.response;
|
|
440
|
+
const { warmPprFallbackShellCaches } = await import("./app-ppr-fallback-shell-render.js");
|
|
439
441
|
await warmPprFallbackShellCaches({
|
|
440
442
|
element: warmupBuildResult.element,
|
|
441
443
|
onError: options.createRscOnErrorHandler(options.cleanPathname, route.pattern),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { markAppPagePropsForUseCache } from "../shims/cache-
|
|
2
|
-
import { isNextRouterError } from "../shims/navigation.js";
|
|
1
|
+
import { markAppPagePropsForUseCache } from "../shims/internal/app-page-props-cache-key.js";
|
|
2
|
+
import { isNextRouterError } from "../shims/navigation-errors.js";
|
|
3
|
+
import "../shims/navigation-server.js";
|
|
3
4
|
import { isPromiseLike } from "../utils/promise.js";
|
|
4
5
|
import { probeAppPageComponent, probeAppPageLayouts } from "./app-page-execution.js";
|
|
5
6
|
import { collectAppPageSearchParams } from "./app-page-head.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage } from "../shims/headers.js";
|
|
2
1
|
import { fnv1a64 } from "../utils/hash.js";
|
|
3
|
-
import { _consumeRequestScopedCacheLife } from "../shims/cache.js";
|
|
4
2
|
import { AppElementsWire, isAppElementsRecord } from "./app-elements-wire.js";
|
|
5
3
|
import { normalizeMountedSlotsHeader } from "./app-mounted-slots-header.js";
|
|
6
4
|
import "./app-elements.js";
|
|
5
|
+
import { consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage } from "../shims/headers.js";
|
|
6
|
+
import { _consumeRequestScopedCacheLife } from "../shims/cache-request-state.js";
|
|
7
7
|
import { consumeDynamicFetchObservations } from "../shims/fetch-cache.js";
|
|
8
8
|
import { buildRenderObservation, buildRenderRequestApiObservations } from "./cache-proof.js";
|
|
9
9
|
//#region src/server/app-page-render-observation.ts
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CachedAppPageValue } from "../shims/cache.js";
|
|
1
|
+
import { CachedAppPageValue } from "../shims/cache-handler.js";
|
|
2
2
|
import { ClientReuseManifestParseResult, ClientReuseManifestSkipDisposition } from "./client-reuse-manifest.js";
|
|
3
3
|
import { AppOutgoingElements } from "./app-elements-wire.js";
|
|
4
|
-
import { NavigationContext } from "../shims/navigation.js";
|
|
4
|
+
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
5
5
|
import { AppPageFontPreload, AppPageSpecialError, LayoutClassificationOptions } from "./app-page-execution.js";
|
|
6
6
|
import { AppPageMiddlewareContext } from "./app-page-response.js";
|
|
7
7
|
import { RootParams } from "../shims/root-params.js";
|
|
8
8
|
import { AppPageSsrHandler } from "./app-page-stream.js";
|
|
9
9
|
import { AppLayoutParamAccessTracker } from "./app-layout-param-observation.js";
|
|
10
|
-
import { AppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
11
10
|
import { AppRscRenderMode } from "./app-rsc-render-mode.js";
|
|
11
|
+
import { AppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
12
12
|
import { ReactNode } from "react";
|
|
13
13
|
import { ReactFormState } from "react-dom/client";
|
|
14
14
|
|
|
@@ -8,9 +8,10 @@ import { buildAppPageFontLinkHeader, readAppPageBinaryStream, resolveAppPageSpec
|
|
|
8
8
|
import { probeAppPageBeforeRender } from "./app-page-probe.js";
|
|
9
9
|
import { DEFAULT_CACHE_VARIANT_BUDGET, buildCacheVariantWithRouteBudget, buildRenderObservation, buildRenderRequestApiObservations, createStaticLayoutArtifactReuseDecision } from "./cache-proof.js";
|
|
10
10
|
import { createAppPageHtmlOutputScope, createAppPageRenderObservation, createAppPageRscOutputScope, createEmptyAppPageRenderObservationState } from "./app-page-render-observation.js";
|
|
11
|
-
import { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse } from "./app-page-cache.js";
|
|
11
|
+
import { finalizeAppPageHtmlCacheResponse, finalizeAppPageRscCacheResponse } from "./app-page-cache-finalizer.js";
|
|
12
12
|
import { createStaticLayoutClientReuseArtifactCompatibility, createStaticLayoutClientReusePayloadHash, createStaticLayoutClientReuseRouteId } from "./static-layout-client-reuse-proof.js";
|
|
13
|
-
import {
|
|
13
|
+
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
14
|
+
import { buildAppPageLinkHeader, createAppPageFontData, createAppPageRscErrorTracker, renderAppPageHtmlStream, renderAppPageHtmlStreamWithRecovery } from "./app-page-stream.js";
|
|
14
15
|
import { getStaticLayoutObservationSkipRejection } from "./app-layout-param-observation.js";
|
|
15
16
|
import { hasDigest } from "./app-rsc-errors.js";
|
|
16
17
|
import { createClientReuseSkipTransportPlan, crossCheckClientReuseManifestEntryWithCache } from "./skip-cache-proof.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { NavigationContext } from "../shims/navigation.js";
|
|
1
|
+
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
2
2
|
import { AppPageFontPreload } from "./app-page-execution.js";
|
|
3
3
|
import { RootParams } from "../shims/root-params.js";
|
|
4
|
+
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
4
5
|
import { ReactFormState } from "react-dom/client";
|
|
5
6
|
|
|
6
7
|
//#region src/server/app-page-stream.d.ts
|
|
@@ -143,14 +144,6 @@ type AppPageRscErrorTracker = {
|
|
|
143
144
|
};
|
|
144
145
|
declare function createAppPageFontData(options: CreateAppPageFontDataOptions): AppPageFontData;
|
|
145
146
|
declare function renderAppPageHtmlStream(options: RenderAppPageHtmlStreamOptions): Promise<AppSsrRenderResult>;
|
|
146
|
-
/**
|
|
147
|
-
* Wraps a stream so that `onFlush` is called when the last byte has been read
|
|
148
|
-
* by the downstream consumer (i.e. when the HTTP layer finishes draining the
|
|
149
|
-
* response body). This is the correct place to clear per-request context,
|
|
150
|
-
* because the RSC/SSR pipeline is lazy — components execute while the stream
|
|
151
|
-
* is being consumed, not when the stream handle is first obtained.
|
|
152
|
-
*/
|
|
153
|
-
declare function deferUntilStreamConsumed(stream: ReadableStream<Uint8Array>, onFlush: () => void): ReadableStream<Uint8Array>;
|
|
154
147
|
declare function renderAppPageHtmlResponse(options: RenderAppPageHtmlResponseOptions): Promise<Response>;
|
|
155
148
|
declare function renderAppPageHtmlStreamWithRecovery<TSpecialError>(options: RenderAppPageHtmlStreamWithRecoveryOptions<TSpecialError>): Promise<AppPageHtmlStreamRecoveryResult>;
|
|
156
149
|
declare function createAppPageRscErrorTracker(baseOnError: (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown): AppPageRscErrorTracker;
|