vinext 0.1.4 → 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/css-url-assets.d.ts +1 -1
- package/dist/build/css-url-assets.js +9 -7
- package/dist/build/prerender.js +2 -1
- package/dist/cache/cache-adapters-virtual.js +1 -1
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
- package/dist/entries/app-rsc-entry.js +24 -20
- package/dist/entries/pages-server-entry.js +2 -1
- package/dist/index.js +187 -146
- package/dist/plugins/css-data-url.js +30 -26
- package/dist/plugins/extensionless-dynamic-import.js +27 -24
- 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 +7 -1
- package/dist/plugins/strip-server-exports.js +4 -1
- package/dist/server/app-bfcache-identity.d.ts +26 -0
- package/dist/server/app-bfcache-identity.js +127 -0
- package/dist/server/app-browser-entry.js +14 -11
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.d.ts +2 -21
- package/dist/server/app-browser-state.js +4 -128
- package/dist/server/app-browser-stream.js +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-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.js +22 -16
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-server-action-execution.d.ts +1 -1
- package/dist/server/app-server-action-execution.js +5 -4
- package/dist/server/app-ssr-entry.d.ts +1 -1
- package/dist/server/app-ssr-entry.js +11 -9
- 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/client-reuse-manifest.js +1 -1
- 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 +1 -1
- 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 +8 -6
- package/dist/server/middleware-runtime.js +2 -2
- package/dist/server/open-redirect.d.ts +12 -0
- package/dist/server/open-redirect.js +21 -0
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-response.d.ts +1 -1
- package/dist/server/pages-page-response.js +2 -2
- package/dist/server/prod-server.js +2 -1
- 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/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/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 +67 -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/layout-segment-context.d.ts +1 -1
- package/dist/shims/layout-segment-context.js +2 -1
- package/dist/shims/link.js +2 -2
- 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 +14 -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/script.js +1 -1
- package/dist/shims/slot.js +3 -1
- package/dist/shims/unified-request-context.d.ts +2 -2
- package/dist/utils/virtual-module.d.ts +5 -0
- package/dist/utils/virtual-module.js +0 -0
- package/package.json +5 -1
|
@@ -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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VINEXT_RSC_VARY_HEADER } from "./app-rsc-cache-busting.js";
|
|
2
2
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
3
3
|
import { applyEdgeRuntimeHeader } from "./app-page-response.js";
|
|
4
|
+
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
4
5
|
//#region src/server/app-page-stream.ts
|
|
5
6
|
function isAppSsrRenderResult(value) {
|
|
6
7
|
return typeof value === "object" && value !== null && "htmlStream" in value && "metadataReady" in value;
|
|
@@ -70,41 +71,6 @@ async function renderAppPageHtmlStream(options) {
|
|
|
70
71
|
};
|
|
71
72
|
return normalizeAppSsrRenderResult(await options.ssrHandler.handleSsr(options.rscStream, options.navigationContext, options.fontData, ssrOptions), options.capturedRscDataRef?.value ?? null);
|
|
72
73
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Wraps a stream so that `onFlush` is called when the last byte has been read
|
|
75
|
-
* by the downstream consumer (i.e. when the HTTP layer finishes draining the
|
|
76
|
-
* response body). This is the correct place to clear per-request context,
|
|
77
|
-
* because the RSC/SSR pipeline is lazy — components execute while the stream
|
|
78
|
-
* is being consumed, not when the stream handle is first obtained.
|
|
79
|
-
*/
|
|
80
|
-
function deferUntilStreamConsumed(stream, onFlush) {
|
|
81
|
-
let called = false;
|
|
82
|
-
const once = () => {
|
|
83
|
-
if (!called) {
|
|
84
|
-
called = true;
|
|
85
|
-
onFlush();
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const cleanup = new TransformStream({ flush() {
|
|
89
|
-
once();
|
|
90
|
-
} });
|
|
91
|
-
const reader = stream.pipeThrough(cleanup).getReader();
|
|
92
|
-
return new ReadableStream({
|
|
93
|
-
pull(controller) {
|
|
94
|
-
return reader.read().then(({ done, value }) => {
|
|
95
|
-
if (done) controller.close();
|
|
96
|
-
else controller.enqueue(value);
|
|
97
|
-
}, (error) => {
|
|
98
|
-
once();
|
|
99
|
-
controller.error(error);
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
cancel(reason) {
|
|
103
|
-
once();
|
|
104
|
-
return reader.cancel(reason);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
74
|
async function renderAppPageHtmlResponse(options) {
|
|
109
75
|
const { htmlStream } = await renderAppPageHtmlStream(options);
|
|
110
76
|
const safeStream = deferUntilStreamConsumed(htmlStream, () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { setHeadersContext } from "../shims/headers.js";
|
|
2
|
-
import { setNavigationContext } from "../shims/navigation.js";
|
|
2
|
+
import { setNavigationContext } from "../shims/navigation-context-state.js";
|
|
3
|
+
import "../shims/navigation-server.js";
|
|
3
4
|
import { setRootParams } from "../shims/root-params.js";
|
|
4
5
|
//#region src/server/app-request-context.ts
|
|
5
6
|
/**
|
|
@@ -3,13 +3,14 @@ import { getRequestExecutionContext } from "../shims/request-context.js";
|
|
|
3
3
|
import { reportRequestError } from "./instrumentation.js";
|
|
4
4
|
import { consumeDynamicUsage, getAndClearPendingCookies, getDraftModeCookieHeader, markDynamicUsage, setHeadersAccessPhase } from "../shims/headers.js";
|
|
5
5
|
import { ensureFetchPatch, getCollectedFetchTags, setCurrentFetchCacheMode, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault } from "../shims/fetch-cache.js";
|
|
6
|
-
import { setNavigationContext } from "../shims/navigation.js";
|
|
6
|
+
import { setNavigationContext } from "../shims/navigation-context-state.js";
|
|
7
7
|
import { makeThenableParams } from "../shims/thenable-params.js";
|
|
8
|
+
import "../shims/navigation.js";
|
|
8
9
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
9
10
|
import { isKnownDynamicAppRoute, isValidHTTPMethod } from "./app-route-handler-runtime.js";
|
|
10
11
|
import { getAppRouteHandlerRevalidateSeconds, hasAppRouteHandlerDefaultExport, resolveAppRouteHandlerMethod, shouldReadAppRouteHandlerCache } from "./app-route-handler-policy.js";
|
|
11
|
-
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
12
12
|
import { applyRouteHandlerMiddlewareContext } from "./app-route-handler-response.js";
|
|
13
|
+
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
13
14
|
import { executeAppRouteHandler } from "./app-route-handler-execution.js";
|
|
14
15
|
import { readAppRouteHandlerCacheResponse } from "./app-route-handler-cache.js";
|
|
15
16
|
import { resolveAppRouteHandlerFetchCacheMode } from "./app-segment-config.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextI18nConfig } from "../config/next-config.js";
|
|
2
|
+
import { CachedRouteValue } from "../shims/cache-handler.js";
|
|
2
3
|
import { ExecutionContextLike } from "../shims/request-context.js";
|
|
3
|
-
import { CachedRouteValue } from "../shims/cache.js";
|
|
4
4
|
import { NextRequest } from "../shims/server.js";
|
|
5
5
|
import { HeadersAccessPhase } from "../shims/headers.js";
|
|
6
6
|
import { RouteHandlerMiddlewareContext } from "./app-route-handler-response.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { setHeadersContext } from "../shims/headers.js";
|
|
2
2
|
import { createTrackedAppRouteRequest, markKnownDynamicAppRoute } from "./app-route-handler-runtime.js";
|
|
3
3
|
import { isPossibleAppRouteActionRequest, resolveAppRouteHandlerSpecialError, shouldApplyAppRouteHandlerRevalidateHeader, shouldWriteAppRouteHandlerCache } from "./app-route-handler-policy.js";
|
|
4
|
-
import { createStaticGenerationHeadersContext, getAppRouteStaticGenerationErrorMessage } from "./app-static-generation.js";
|
|
5
4
|
import { applyRouteHandlerMiddlewareContext, applyRouteHandlerRevalidateHeader, assertSupportedAppRouteHandlerResponse, buildAppRouteCacheValue, finalizeRouteHandlerResponse, markRouteHandlerCacheMiss } from "./app-route-handler-response.js";
|
|
5
|
+
import { createStaticGenerationHeadersContext, getAppRouteStaticGenerationErrorMessage } from "./app-static-generation.js";
|
|
6
6
|
//#region src/server/app-route-handler-execution.ts
|
|
7
7
|
function configureAppRouteStaticGenerationContext(options) {
|
|
8
8
|
if (options.dynamicConfig === "force-static" || options.dynamicConfig === "error") {
|
|
@@ -2,7 +2,8 @@ import "./server-globals.js";
|
|
|
2
2
|
import { runWithExecutionContext } from "../shims/request-context.js";
|
|
3
3
|
import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "./headers.js";
|
|
4
4
|
import { badRequestResponse, notFoundResponse, notFoundStaticAssetResponse } from "./http-error-responses.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isOpenRedirectShaped } from "./open-redirect.js";
|
|
6
|
+
import { cloneRequestWithHeaders, filterInternalHeaders } from "./request-pipeline.js";
|
|
6
7
|
import { assetPrefixPathname, isNextStaticPath } from "../utils/asset-prefix.js";
|
|
7
8
|
import { resolveStaticAssetSignal } from "./worker-utils.js";
|
|
8
9
|
import { readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
|
|
@@ -8,21 +8,19 @@ import { applyConfigHeadersToResponse, cloneRequestWithHeaders, cloneRequestWith
|
|
|
8
8
|
import { headersContextFromRequest } from "../shims/headers.js";
|
|
9
9
|
import { ensureFetchPatch, setCurrentFetchSoftTags } from "../shims/fetch-cache.js";
|
|
10
10
|
import { mergeRewriteQuery } from "../utils/query.js";
|
|
11
|
-
import { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, createRscRedirectLocation, hasRscCacheBustingSearchParam, resolveInvalidRscCacheBustingRequest, stripRscCacheBustingSearchParam, stripRscSuffix } from "./app-rsc-cache-busting.js";
|
|
12
11
|
import { getScriptNonceFromHeaderSources } from "./csp.js";
|
|
13
12
|
import { normalizeDefaultLocalePathname } from "./pages-i18n.js";
|
|
14
13
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./image-optimization.js";
|
|
14
|
+
import { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, createRscRedirectLocation, hasRscCacheBustingSearchParam, resolveInvalidRscCacheBustingRequest, stripRscCacheBustingSearchParam, stripRscSuffix } from "./app-rsc-cache-busting.js";
|
|
15
15
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
16
16
|
import "./app-page-response.js";
|
|
17
17
|
import { buildNextDataNotFoundResponse, normalizePagesDataRequest } from "./pages-data-route.js";
|
|
18
|
-
import { createAppPprFallbackShells } from "./app-ppr-fallback-shell.js";
|
|
19
18
|
import { matchPrerenderRouteParamsPayload, readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
|
|
20
19
|
import { getRenderedConcreteUrlPathsForRoute } from "./pregenerated-concrete-paths.js";
|
|
21
|
-
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
22
20
|
import { flattenErrorCauses } from "../utils/error-cause.js";
|
|
23
|
-
import { applyAppMiddleware } from "./app-middleware.js";
|
|
24
21
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
25
22
|
import { buildPostMwRequestContext } from "./app-post-middleware-context.js";
|
|
23
|
+
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
26
24
|
import { handleAppPrerenderEndpoint } from "./app-prerender-endpoints.js";
|
|
27
25
|
import { finalizeAppRscResponse } from "./app-rsc-response-finalizer.js";
|
|
28
26
|
import { normalizeRscRequest } from "./app-rsc-request-normalization.js";
|
|
@@ -167,6 +165,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
167
165
|
};
|
|
168
166
|
let didMiddlewareRewrite = false;
|
|
169
167
|
if (options.middlewareModule) {
|
|
168
|
+
const { applyAppMiddleware } = await import("./app-middleware.js");
|
|
170
169
|
const middlewareResult = await applyAppMiddleware({
|
|
171
170
|
basePath: options.basePath,
|
|
172
171
|
cleanPathname,
|
|
@@ -249,7 +248,9 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
249
248
|
if (preActionMatch) setRootParams(pickRootParams(preActionMatch.params, preActionMatch.route.rootParamNames));
|
|
250
249
|
const actionId = request.headers.get("x-rsc-action") ?? request.headers.get("next-action");
|
|
251
250
|
const contentType = request.headers.get("content-type") || "";
|
|
252
|
-
const
|
|
251
|
+
const isPostRequest = request.method.toUpperCase() === "POST";
|
|
252
|
+
let progressiveActionResult = null;
|
|
253
|
+
if (isPostRequest && contentType.startsWith("multipart/form-data") && !actionId) progressiveActionResult = await options.handleProgressiveActionRequest({
|
|
253
254
|
actionId,
|
|
254
255
|
cleanPathname,
|
|
255
256
|
contentType,
|
|
@@ -257,12 +258,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
257
258
|
request
|
|
258
259
|
});
|
|
259
260
|
if (progressiveActionResult instanceof Response) return progressiveActionResult;
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
const
|
|
261
|
+
const progressiveActionFormState = progressiveActionResult?.kind === "form-state" ? progressiveActionResult : null;
|
|
262
|
+
const isProgressiveActionRender = progressiveActionFormState !== null;
|
|
263
|
+
const formState = progressiveActionFormState?.formState ?? null;
|
|
264
|
+
const failedProgressiveActionResult = progressiveActionFormState && "actionError" in progressiveActionFormState ? progressiveActionFormState : null;
|
|
263
265
|
const actionFailed = failedProgressiveActionResult !== null;
|
|
264
266
|
const actionError = failedProgressiveActionResult?.actionError;
|
|
265
|
-
const serverActionResponse = await options.handleServerActionRequest({
|
|
267
|
+
const serverActionResponse = isPostRequest && actionId ? await options.handleServerActionRequest({
|
|
266
268
|
actionId,
|
|
267
269
|
cleanPathname,
|
|
268
270
|
contentType,
|
|
@@ -272,7 +274,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
272
274
|
mountedSlotsHeader,
|
|
273
275
|
request,
|
|
274
276
|
searchParams: getResolvedSearchParams()
|
|
275
|
-
});
|
|
277
|
+
}) : null;
|
|
276
278
|
if (serverActionResponse) return serverActionResponse;
|
|
277
279
|
let match = preActionMatch;
|
|
278
280
|
const renderPagesForMatchKind = async (matchKind) => {
|
|
@@ -386,11 +388,15 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
386
388
|
const isPrerenderFallbackShell = prerenderRouteParamsMatch?.kind === "fallback-shell";
|
|
387
389
|
const renderParams = prerenderRouteParams ?? params;
|
|
388
390
|
const resolvedSearchParams = getResolvedSearchParams();
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
let runtimeFallbackShells = [];
|
|
392
|
+
if (options.cacheComponents === true && request.method === "GET" && !isRscRequest && !isPrerenderFallbackShell && route.params) {
|
|
393
|
+
const { createAppPprFallbackShells } = await import("./app-ppr-fallback-shell.js");
|
|
394
|
+
runtimeFallbackShells = createAppPprFallbackShells({
|
|
395
|
+
params: route.params,
|
|
396
|
+
pattern: route.pattern,
|
|
397
|
+
rootParamNames: route.rootParamNames
|
|
398
|
+
}, params);
|
|
399
|
+
}
|
|
394
400
|
options.setNavigationContext({
|
|
395
401
|
pathname: canonicalPathname,
|
|
396
402
|
searchParams: resolvedSearchParams,
|
|
@@ -443,7 +449,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
443
449
|
searchParams: resolvedSearchParams,
|
|
444
450
|
renderMode
|
|
445
451
|
});
|
|
446
|
-
if (isProgressiveActionRender) return applyProgressiveActionSideEffects(pageResponse,
|
|
452
|
+
if (isProgressiveActionRender) return applyProgressiveActionSideEffects(pageResponse, progressiveActionFormState);
|
|
447
453
|
return pageResponse;
|
|
448
454
|
}
|
|
449
455
|
/**
|
|
@@ -4,8 +4,8 @@ import "./headers.js";
|
|
|
4
4
|
import { normalizePath } from "./normalize-path.js";
|
|
5
5
|
import { applyConfigHeadersToResponse } from "./request-pipeline.js";
|
|
6
6
|
import { applyCdnResponseHeaders } from "./cache-control.js";
|
|
7
|
-
import { VINEXT_RSC_VARY_HEADER } from "./app-rsc-cache-busting.js";
|
|
8
7
|
import { normalizeDefaultLocalePathname } from "./pages-i18n.js";
|
|
8
|
+
import { VINEXT_RSC_VARY_HEADER } from "./app-rsc-cache-busting.js";
|
|
9
9
|
import { mergeVaryHeader } from "./middleware-response-headers.js";
|
|
10
10
|
//#region src/server/app-rsc-response-finalizer.ts
|
|
11
11
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionRevalidationKind } from "../shims/cache.js";
|
|
1
|
+
import { ActionRevalidationKind } from "../shims/cache-request-state.js";
|
|
2
2
|
import { AppRscRenderMode } from "./app-rsc-render-mode.js";
|
|
3
3
|
import { FetchCacheMode } from "../shims/fetch-cache.js";
|
|
4
4
|
import { HeadersAccessPhase } from "../shims/headers.js";
|
|
@@ -4,17 +4,18 @@ import { ACTION_FORWARDED_HEADER, ACTION_REDIRECT_HEADER, ACTION_REDIRECT_STATUS
|
|
|
4
4
|
import { isExternalUrl } from "../config/config-matchers.js";
|
|
5
5
|
import { internalServerErrorResponse, payloadTooLargeResponse } from "./http-error-responses.js";
|
|
6
6
|
import { validateCsrfOrigin, validateServerActionPayload } from "./request-pipeline.js";
|
|
7
|
-
import { headersContextFromRequest, setHeadersContext } from "../shims/headers.js";
|
|
8
|
-
import { getAndClearActionRevalidationKind } from "../shims/cache.js";
|
|
9
7
|
import { APP_RSC_RENDER_MODE_ACTION_RERENDER_PRESERVE_UI } from "./app-rsc-render-mode.js";
|
|
8
|
+
import { headersContextFromRequest, setHeadersContext } from "../shims/headers.js";
|
|
9
|
+
import { getAndClearActionRevalidationKind } from "../shims/cache-request-state.js";
|
|
10
10
|
import { setCurrentFetchCacheMode, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault } from "../shims/fetch-cache.js";
|
|
11
|
-
import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader } from "./app-rsc-cache-busting.js";
|
|
12
11
|
import { readStreamAsTextWithLimit } from "../utils/text-stream.js";
|
|
12
|
+
import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader } from "./app-rsc-cache-busting.js";
|
|
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
16
|
import { createServerActionNotFoundResponse, getServerActionNotFoundMessage, isServerActionNotFoundError } from "./server-action-not-found.js";
|
|
17
|
-
import { deferUntilStreamConsumed } from "./
|
|
17
|
+
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
18
|
+
import "./app-page-stream.js";
|
|
18
19
|
import { buildAppPageTags } from "./implicit-tags.js";
|
|
19
20
|
import { resolveAppPageNavigationParams } from "./app-page-element-builder.js";
|
|
20
21
|
import { resolveAppPageActionRerenderTarget } from "./app-page-request.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NavigationContext } from "../shims/navigation.js";
|
|
1
|
+
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
2
2
|
import { RootParams } from "../shims/root-params.js";
|
|
3
3
|
import { AppSsrRenderResult } from "./app-page-stream.js";
|
|
4
4
|
import { ReactFormState } from "react-dom/client";
|