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
|
@@ -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, () => {
|
|
@@ -5,7 +5,9 @@ type PagesEntry = {
|
|
|
5
5
|
handleApiRoute?: (request: Request, url: string) => Promise<Response> | Response;
|
|
6
6
|
matchApiRoute?: (url: string, request: Request) => PagesRouteMatch | null;
|
|
7
7
|
matchPageRoute?: (url: string, request: Request) => PagesRouteMatch | null;
|
|
8
|
-
renderPage?: (request: Request, url: string, query: Record<string, unknown>, parsedUrl: unknown, middlewareRequestHeaders?: Headers | null
|
|
8
|
+
renderPage?: (request: Request, url: string, query: Record<string, unknown>, parsedUrl: unknown, middlewareRequestHeaders?: Headers | null, options?: {
|
|
9
|
+
isDataReq?: boolean;
|
|
10
|
+
}) => Promise<Response> | Response;
|
|
9
11
|
};
|
|
10
12
|
type PagesRouteMatch = {
|
|
11
13
|
route: {
|
|
@@ -44,10 +46,12 @@ type RenderPagesFallbackDependencies = {
|
|
|
44
46
|
type RenderPagesFallbackOptions = {
|
|
45
47
|
allowRscDocumentFallback?: boolean;
|
|
46
48
|
appRouteMatch?: AppRouteMatch | null;
|
|
49
|
+
isDataRequest?: boolean;
|
|
47
50
|
isRscRequest: boolean;
|
|
48
51
|
matchKind?: "dynamic" | "static";
|
|
49
52
|
middlewareContext: AppMiddlewareContext;
|
|
50
53
|
pathname?: string;
|
|
54
|
+
pagesDataRequest?: Request | null;
|
|
51
55
|
request: Request;
|
|
52
56
|
url: URL;
|
|
53
57
|
};
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
+
import { cloneRequestWithHeaders, cloneRequestWithUrl } from "./request-pipeline.js";
|
|
1
2
|
import { pagesRouteHasPriorityOverAppRoute } from "./hybrid-route-priority.js";
|
|
2
3
|
//#region src/server/app-pages-bridge.ts
|
|
3
4
|
/**
|
|
4
5
|
* Fallback handler to route App Router requests to the Pages Router when no App Router route matches.
|
|
5
6
|
*/
|
|
6
7
|
async function renderPagesFallback(options, dependencies) {
|
|
7
|
-
const { allowRscDocumentFallback = false, appRouteMatch = null, isRscRequest, matchKind, middlewareContext, pathname = options.url.pathname, request, url } = options;
|
|
8
|
+
const { allowRscDocumentFallback = false, appRouteMatch = null, isDataRequest = false, isRscRequest, matchKind, middlewareContext, pathname = options.url.pathname, pagesDataRequest = null, request, url } = options;
|
|
8
9
|
const { loadPagesEntry, buildRequestHeaders, decodePathParams, applyRouteHandlerMiddlewareContext, getDraftModeCookieHeader } = dependencies;
|
|
9
10
|
if (isRscRequest && !allowRscDocumentFallback) return null;
|
|
10
11
|
const pagesEntry = await loadPagesEntry();
|
|
11
12
|
const pagesRequestHeaders = middlewareContext.requestHeaders ? buildRequestHeaders(request.headers, middlewareContext.requestHeaders) : null;
|
|
12
13
|
let pagesRequest = request;
|
|
13
|
-
if (pagesRequestHeaders)
|
|
14
|
-
const pagesRequestInit = {
|
|
15
|
-
method: request.method,
|
|
16
|
-
headers: pagesRequestHeaders
|
|
17
|
-
};
|
|
18
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
19
|
-
pagesRequestInit.body = request.body;
|
|
20
|
-
pagesRequestInit.duplex = "half";
|
|
21
|
-
}
|
|
22
|
-
pagesRequest = new Request(request.url, pagesRequestInit);
|
|
23
|
-
}
|
|
14
|
+
if (pagesRequestHeaders) pagesRequest = cloneRequestWithHeaders(request, pagesRequestHeaders);
|
|
24
15
|
const queryIndex = pathname.indexOf("?");
|
|
25
16
|
const pagesPathname = queryIndex === -1 ? pathname : pathname.slice(0, queryIndex);
|
|
26
17
|
const pagesSearch = queryIndex === -1 ? url.search || "" : pathname.slice(queryIndex);
|
|
@@ -46,7 +37,8 @@ async function renderPagesFallback(options, dependencies) {
|
|
|
46
37
|
if (pageMatch !== null && matchKind === "static" && pageMatch.route.isDynamic) return null;
|
|
47
38
|
if (pageMatch !== null && matchKind === "dynamic" && !pageMatch.route.isDynamic) return null;
|
|
48
39
|
if (appRouteMatch !== null && (pageMatch === null || !pagesRouteHasPriorityOverAppRoute(pageMatch.route, appRouteMatch.route))) return null;
|
|
49
|
-
const
|
|
40
|
+
const renderRequest = pagesDataRequest ? cloneRequestWithUrl(pagesRequest, pagesDataRequest.url) : pagesRequest;
|
|
41
|
+
const pagesRes = isDataRequest ? await pagesEntry.renderPage(renderRequest, pagesUrl, {}, void 0, middlewareContext.requestHeaders, { isDataReq: true }) : await pagesEntry.renderPage(renderRequest, pagesUrl, {}, void 0, middlewareContext.requestHeaders);
|
|
50
42
|
if (pagesRes.status === 404 && pageMatch === null) return null;
|
|
51
43
|
return applyDraftModeCookie(pagesRes, getDraftModeCookieHeader());
|
|
52
44
|
}
|
|
@@ -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";
|
|
@@ -130,10 +130,12 @@ type RenderPagesFallbackOptions = {
|
|
|
130
130
|
pattern: string;
|
|
131
131
|
};
|
|
132
132
|
} | null;
|
|
133
|
+
isDataRequest?: boolean;
|
|
133
134
|
isRscRequest: boolean;
|
|
134
135
|
matchKind?: "dynamic" | "static";
|
|
135
136
|
middlewareContext: AppRscMiddlewareContext;
|
|
136
137
|
pathname?: string;
|
|
138
|
+
pagesDataRequest?: Request | null;
|
|
137
139
|
request: Request;
|
|
138
140
|
url: URL;
|
|
139
141
|
};
|
|
@@ -144,6 +146,7 @@ type NavigationContextValue = {
|
|
|
144
146
|
};
|
|
145
147
|
type CreateAppRscHandlerOptions<TRoute extends AppRscHandlerRoute> = {
|
|
146
148
|
basePath: string;
|
|
149
|
+
buildId: string | null;
|
|
147
150
|
cacheComponents?: boolean;
|
|
148
151
|
clearRequestContext: () => void;
|
|
149
152
|
configHeaders: NextHeader[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequestContext, runWithRequestContext } from "../shims/unified-request-context.js";
|
|
2
|
-
import { hasBasePath } from "../utils/base-path.js";
|
|
2
|
+
import { addBasePathToPathname, hasBasePath, stripBasePath } from "../utils/base-path.js";
|
|
3
3
|
import { getRequestExecutionContext } from "../shims/request-context.js";
|
|
4
4
|
import { ACTION_REVALIDATED_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "./headers.js";
|
|
5
5
|
import { isExternalUrl, matchRedirect, matchRewrite, preserveRedirectDestinationQuery, proxyExternalRequest, requestContextFromRequest, sanitizeDestination } from "../config/config-matchers.js";
|
|
@@ -8,20 +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
|
-
import {
|
|
17
|
+
import { buildNextDataNotFoundResponse, normalizePagesDataRequest } from "./pages-data-route.js";
|
|
18
18
|
import { matchPrerenderRouteParamsPayload, readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
|
|
19
19
|
import { getRenderedConcreteUrlPathsForRoute } from "./pregenerated-concrete-paths.js";
|
|
20
|
-
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
21
20
|
import { flattenErrorCauses } from "../utils/error-cause.js";
|
|
22
|
-
import { applyAppMiddleware } from "./app-middleware.js";
|
|
23
21
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
24
22
|
import { buildPostMwRequestContext } from "./app-post-middleware-context.js";
|
|
23
|
+
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
25
24
|
import { handleAppPrerenderEndpoint } from "./app-prerender-endpoints.js";
|
|
26
25
|
import { finalizeAppRscResponse } from "./app-rsc-response-finalizer.js";
|
|
27
26
|
import { normalizeRscRequest } from "./app-rsc-request-normalization.js";
|
|
@@ -108,7 +107,7 @@ function requestWithoutRscSuffix(request) {
|
|
|
108
107
|
url.pathname = pathname;
|
|
109
108
|
return cloneRequestWithUrl(request.body ? request.clone() : request, url.toString());
|
|
110
109
|
}
|
|
111
|
-
async function handleAppRscRequest(options, request, preMiddlewareRequestContext, isDataRequest) {
|
|
110
|
+
async function handleAppRscRequest(options, request, preMiddlewareRequestContext, isDataRequest, pagesDataRequest) {
|
|
112
111
|
const handlerStart = process.env.NODE_ENV !== "production" ? performance.now() : 0;
|
|
113
112
|
if (process.env.NODE_ENV !== "production") {
|
|
114
113
|
const originBlock = options.validateDevRequestOrigin?.(request);
|
|
@@ -119,6 +118,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
119
118
|
const { url, isRscRequest, interceptionContextHeader, mountedSlotsHeader, renderMode, clientReuseManifest } = normalized;
|
|
120
119
|
let { pathname, cleanPathname } = normalized;
|
|
121
120
|
let resolvedUrl = cleanPathname + url.search;
|
|
121
|
+
const originalResolvedUrl = resolvedUrl;
|
|
122
122
|
const getResolvedSearchParams = () => new URL(resolvedUrl, url).searchParams;
|
|
123
123
|
const canonicalPathname = cleanPathname;
|
|
124
124
|
const basePathState = {
|
|
@@ -142,6 +142,10 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
142
142
|
if (redirect) {
|
|
143
143
|
const destination = sanitizeDestination(redirectDestinationWithBasePath(redirect.destination, options.basePath));
|
|
144
144
|
const location = isRscRequest && request.headers.get("RSC") === "1" ? await createRscRedirectLocation(destination, request) : preserveRedirectDestinationQuery(destination, url.search);
|
|
145
|
+
if (isDataRequest) return new Response(null, {
|
|
146
|
+
status: 200,
|
|
147
|
+
headers: { "x-nextjs-redirect": location }
|
|
148
|
+
});
|
|
145
149
|
return new Response(null, {
|
|
146
150
|
status: redirect.permanent ? 308 : 307,
|
|
147
151
|
headers: { Location: location }
|
|
@@ -161,6 +165,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
161
165
|
};
|
|
162
166
|
let didMiddlewareRewrite = false;
|
|
163
167
|
if (options.middlewareModule) {
|
|
168
|
+
const { applyAppMiddleware } = await import("./app-middleware.js");
|
|
164
169
|
const middlewareResult = await applyAppMiddleware({
|
|
165
170
|
basePath: options.basePath,
|
|
166
171
|
cleanPathname,
|
|
@@ -243,7 +248,9 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
243
248
|
if (preActionMatch) setRootParams(pickRootParams(preActionMatch.params, preActionMatch.route.rootParamNames));
|
|
244
249
|
const actionId = request.headers.get("x-rsc-action") ?? request.headers.get("next-action");
|
|
245
250
|
const contentType = request.headers.get("content-type") || "";
|
|
246
|
-
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({
|
|
247
254
|
actionId,
|
|
248
255
|
cleanPathname,
|
|
249
256
|
contentType,
|
|
@@ -251,12 +258,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
251
258
|
request
|
|
252
259
|
});
|
|
253
260
|
if (progressiveActionResult instanceof Response) return progressiveActionResult;
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
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;
|
|
257
265
|
const actionFailed = failedProgressiveActionResult !== null;
|
|
258
266
|
const actionError = failedProgressiveActionResult?.actionError;
|
|
259
|
-
const serverActionResponse = await options.handleServerActionRequest({
|
|
267
|
+
const serverActionResponse = isPostRequest && actionId ? await options.handleServerActionRequest({
|
|
260
268
|
actionId,
|
|
261
269
|
cleanPathname,
|
|
262
270
|
contentType,
|
|
@@ -266,19 +274,31 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
266
274
|
mountedSlotsHeader,
|
|
267
275
|
request,
|
|
268
276
|
searchParams: getResolvedSearchParams()
|
|
269
|
-
});
|
|
277
|
+
}) : null;
|
|
270
278
|
if (serverActionResponse) return serverActionResponse;
|
|
271
279
|
let match = preActionMatch;
|
|
272
|
-
const renderPagesForMatchKind = async (matchKind) =>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
const renderPagesForMatchKind = async (matchKind) => {
|
|
281
|
+
const response = match === null || match.route.isDynamic ? await options.renderPagesFallback?.({
|
|
282
|
+
appRouteMatch: match ?? null,
|
|
283
|
+
allowRscDocumentFallback: didMiddlewareRewrite,
|
|
284
|
+
isDataRequest,
|
|
285
|
+
isRscRequest,
|
|
286
|
+
matchKind,
|
|
287
|
+
middlewareContext,
|
|
288
|
+
pathname: resolvedUrl,
|
|
289
|
+
pagesDataRequest,
|
|
290
|
+
request,
|
|
291
|
+
url
|
|
292
|
+
}) ?? null : null;
|
|
293
|
+
if (!response || !pagesDataRequest || resolvedUrl === originalResolvedUrl) return response;
|
|
294
|
+
const headers = new Headers(response.headers);
|
|
295
|
+
headers.set("x-nextjs-rewrite", resolvedUrl);
|
|
296
|
+
return new Response(response.body, {
|
|
297
|
+
headers,
|
|
298
|
+
status: response.status,
|
|
299
|
+
statusText: response.statusText
|
|
300
|
+
});
|
|
301
|
+
};
|
|
282
302
|
const staticPagesFallbackResponse = await renderPagesForMatchKind("static");
|
|
283
303
|
if (staticPagesFallbackResponse) {
|
|
284
304
|
options.clearRequestContext();
|
|
@@ -339,6 +359,10 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
339
359
|
}
|
|
340
360
|
if (match) break;
|
|
341
361
|
}
|
|
362
|
+
if (pagesDataRequest) {
|
|
363
|
+
options.clearRequestContext();
|
|
364
|
+
return buildNextDataNotFoundResponse();
|
|
365
|
+
}
|
|
342
366
|
if (!match) {
|
|
343
367
|
if (process.env.NODE_ENV !== "production" && canonicalPathname === "/favicon.ico") {
|
|
344
368
|
options.clearRequestContext();
|
|
@@ -364,11 +388,15 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
364
388
|
const isPrerenderFallbackShell = prerenderRouteParamsMatch?.kind === "fallback-shell";
|
|
365
389
|
const renderParams = prerenderRouteParams ?? params;
|
|
366
390
|
const resolvedSearchParams = getResolvedSearchParams();
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
+
}
|
|
372
400
|
options.setNavigationContext({
|
|
373
401
|
pathname: canonicalPathname,
|
|
374
402
|
searchParams: resolvedSearchParams,
|
|
@@ -421,7 +449,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
421
449
|
searchParams: resolvedSearchParams,
|
|
422
450
|
renderMode
|
|
423
451
|
});
|
|
424
|
-
if (isProgressiveActionRender) return applyProgressiveActionSideEffects(pageResponse,
|
|
452
|
+
if (isProgressiveActionRender) return applyProgressiveActionSideEffects(pageResponse, progressiveActionFormState);
|
|
425
453
|
return pageResponse;
|
|
426
454
|
}
|
|
427
455
|
/**
|
|
@@ -461,13 +489,27 @@ function createAppRscHandler(options) {
|
|
|
461
489
|
options.registerCacheAdapters();
|
|
462
490
|
await options.ensureInstrumentation?.();
|
|
463
491
|
const mwCtx = rawRequest.headers.get(VINEXT_MW_CTX_HEADER);
|
|
464
|
-
const
|
|
492
|
+
const hasDataRequestHeader = rawRequest.headers.get("x-nextjs-data") === "1";
|
|
493
|
+
const pagesDataUrl = new URL(rawRequest.url);
|
|
494
|
+
const pagesDataInScope = !options.basePath || hasBasePath(pagesDataUrl.pathname, options.basePath);
|
|
495
|
+
if (pagesDataInScope) pagesDataUrl.pathname = stripBasePath(pagesDataUrl.pathname, options.basePath);
|
|
496
|
+
const pagesDataCandidate = pagesDataInScope ? cloneRequestWithUrl(rawRequest, pagesDataUrl.toString()) : null;
|
|
497
|
+
const pagesDataNormalization = options.renderPagesFallback && pagesDataCandidate ? normalizePagesDataRequest(pagesDataCandidate, options.buildId) : null;
|
|
498
|
+
if (pagesDataNormalization?.notFoundResponse) return pagesDataNormalization.notFoundResponse;
|
|
499
|
+
const isDataRequest = hasDataRequestHeader || pagesDataNormalization?.isDataReq === true;
|
|
465
500
|
const prerenderRouteParamsPayload = readTrustedPrerenderRouteParams(rawRequest);
|
|
466
501
|
const filteredHeaders = filterInternalHeaders(rawRequest.headers);
|
|
467
502
|
if (mwCtx !== null) filteredHeaders.set(VINEXT_MW_CTX_HEADER, mwCtx);
|
|
468
503
|
const prerenderRouteParamsHeader = serializePrerenderRouteParamsHeader(prerenderRouteParamsPayload);
|
|
469
504
|
if (prerenderRouteParamsHeader !== null) filteredHeaders.set(VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, prerenderRouteParamsHeader);
|
|
470
|
-
|
|
505
|
+
let appRequest = rawRequest;
|
|
506
|
+
if (pagesDataNormalization?.isDataReq) {
|
|
507
|
+
const appRequestUrl = new URL(pagesDataNormalization.request.url);
|
|
508
|
+
appRequestUrl.pathname = addBasePathToPathname(appRequestUrl.pathname, options.basePath);
|
|
509
|
+
appRequest = cloneRequestWithUrl(pagesDataCandidate, appRequestUrl.toString());
|
|
510
|
+
}
|
|
511
|
+
const request = cloneRequestWithHeaders(appRequest, filteredHeaders);
|
|
512
|
+
const pagesDataRequest = pagesDataNormalization?.isDataReq ? cloneRequestWithHeaders(pagesDataCandidate, filteredHeaders) : null;
|
|
471
513
|
const executionContext = isExecutionContextLike(ctx) ? ctx : getRequestExecutionContext() ?? null;
|
|
472
514
|
return runWithRequestContext(createRequestContext({
|
|
473
515
|
headersContext: headersContextFromRequest(request, { draftModeSecret: options.draftModeSecret }),
|
|
@@ -478,7 +520,7 @@ function createAppRscHandler(options) {
|
|
|
478
520
|
const preMiddlewareRequestContext = requestContextFromRequest(request);
|
|
479
521
|
let response;
|
|
480
522
|
try {
|
|
481
|
-
response = await handleAppRscRequest(options, request, preMiddlewareRequestContext, isDataRequest);
|
|
523
|
+
response = await handleAppRscRequest(options, request, preMiddlewareRequestContext, isDataRequest, pagesDataRequest);
|
|
482
524
|
} catch (error) {
|
|
483
525
|
if (process.env.NODE_ENV !== "production") flattenErrorCauses(error);
|
|
484
526
|
throw error;
|
|
@@ -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
|
/**
|
|
@@ -18,6 +18,7 @@ function appRscPathnameParts(pathname) {
|
|
|
18
18
|
function createAppRscRouteMatcher(routes) {
|
|
19
19
|
const routeTrie = buildRouteTrie(routes);
|
|
20
20
|
const interceptLookup = createInterceptLookup(routes);
|
|
21
|
+
const routeIndexes = new Map(routes.map((route, index) => [route, index]));
|
|
21
22
|
return {
|
|
22
23
|
matchRoute(url) {
|
|
23
24
|
return trieMatch(routeTrie, appRscPathnameParts(url));
|
|
@@ -26,16 +27,19 @@ function createAppRscRouteMatcher(routes) {
|
|
|
26
27
|
if (sourcePathname === null) return null;
|
|
27
28
|
const urlParts = appRscPathnameParts(pathname);
|
|
28
29
|
const sourceParts = appRscPathnameParts(sourcePathname);
|
|
30
|
+
const matchedSourceRoute = trieMatch(routeTrie, sourceParts);
|
|
29
31
|
for (const entry of interceptLookup) {
|
|
30
32
|
if (!matchInterceptSource(sourceParts, entry)) continue;
|
|
31
33
|
const params = matchAppRscRoutePattern(urlParts, entry.targetPatternParts);
|
|
32
34
|
if (params === null) continue;
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
+
const concreteSourceRouteIndex = matchedSourceRoute && entry.sourceMatchPatternParts !== null ? routeIndexes.get(matchedSourceRoute.route) ?? entry.sourceRouteIndex : entry.sourceRouteIndex;
|
|
36
|
+
const sourceRoute = routes[concreteSourceRouteIndex];
|
|
37
|
+
const matchedSourceParams = matchedSourceRoute && entry.sourceMatchPatternParts !== null ? matchedSourceRoute.params : sourceRoute ? matchAppRscRoutePattern(sourceParts, sourceRoute.patternParts) : null;
|
|
35
38
|
if (matchedSourceParams === null && entry.sourceMatchPatternParts === null) continue;
|
|
36
39
|
const sourceParams = matchedSourceParams ?? createRouteParams();
|
|
37
40
|
return {
|
|
38
41
|
...entry,
|
|
42
|
+
sourceRouteIndex: concreteSourceRouteIndex,
|
|
39
43
|
matchedParams: mergeMatchedParams(sourceParams, params)
|
|
40
44
|
};
|
|
41
45
|
}
|
|
@@ -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";
|
|
@@ -177,7 +178,7 @@ async function readActionFormDataWithLimit(request, maxBytes) {
|
|
|
177
178
|
if (result.done) break;
|
|
178
179
|
totalSize += result.value.byteLength;
|
|
179
180
|
if (totalSize > maxBytes) {
|
|
180
|
-
|
|
181
|
+
reader.cancel();
|
|
181
182
|
throw new Error("Request body too large");
|
|
182
183
|
}
|
|
183
184
|
chunks.push(result.value);
|
|
@@ -485,7 +486,10 @@ async function handleServerActionRscRequest(options) {
|
|
|
485
486
|
if (options.request.method.toUpperCase() !== "POST" || !options.actionId) return null;
|
|
486
487
|
const csrfResponse = validateCsrfOrigin(options.request, options.allowedOrigins);
|
|
487
488
|
if (csrfResponse) return csrfResponse;
|
|
488
|
-
if (parseInt(options.request.headers.get("content-length") || "0", 10) > options.maxActionBodySize)
|
|
489
|
+
if (parseInt(options.request.headers.get("content-length") || "0", 10) > options.maxActionBodySize) {
|
|
490
|
+
if (options.request.body) options.request.body.cancel().catch(() => {});
|
|
491
|
+
return renderFetchActionBodyExceededResponse(options);
|
|
492
|
+
}
|
|
489
493
|
try {
|
|
490
494
|
let action;
|
|
491
495
|
if (options.contentType.startsWith("multipart/form-data")) {
|
|
@@ -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";
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import "./server-globals.js";
|
|
2
2
|
import { notFoundResponse } from "./http-error-responses.js";
|
|
3
|
-
import { isOpenRedirectShaped } from "./
|
|
4
|
-
import { isPprFallbackShellAbortError } from "../shims/ppr-fallback-shell.js";
|
|
3
|
+
import { isOpenRedirectShaped } from "./open-redirect.js";
|
|
5
4
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
6
5
|
import "./app-elements.js";
|
|
6
|
+
import { isPprFallbackShellAbortError } from "../shims/ppr-fallback-shell.js";
|
|
7
7
|
import { AppRouterContext } from "../shims/internal/app-router-context.js";
|
|
8
8
|
import { appendAssetDeploymentIdQuery } from "../utils/deployment-id.js";
|
|
9
|
-
import { ServerInsertedHTMLContext,
|
|
9
|
+
import { ServerInsertedHTMLContext, clearServerInsertedHTML, getBfcacheIdMapContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
10
|
+
import "../shims/navigation-server.js";
|
|
10
11
|
import { runWithNavigationContext } from "../shims/navigation-state.js";
|
|
11
12
|
import { withScriptNonce } from "../shims/script-nonce-context.js";
|
|
12
13
|
import { createInlineScriptTag, createNonceAttribute, escapeHtmlAttr, safeJsonStringify } from "./html.js";
|
|
@@ -15,13 +16,15 @@ import DefaultGlobalError from "../shims/default-global-error.js";
|
|
|
15
16
|
import { BfcacheStateKeyMapContext, ElementsContext, Slot } from "../shims/slot.js";
|
|
16
17
|
import { createSsrErrorMetaRenderer } from "./app-ssr-error-meta.js";
|
|
17
18
|
import { createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform } from "./app-ssr-stream.js";
|
|
18
|
-
import {
|
|
19
|
-
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
20
|
-
import { createBfcacheSegmentStateKeyMap, createInitialBfcacheIdMap } from "./app-browser-state.js";
|
|
19
|
+
import { createBfcacheSegmentStateKeyMap, createInitialBfcacheIdMap } from "./app-bfcache-identity.js";
|
|
21
20
|
import { RSC_FORM_STATE_GLOBAL } from "./app-browser-hydration.js";
|
|
22
21
|
import { createClientReferencePreloader } from "./app-client-reference-preloader.js";
|
|
23
|
-
import { deferUntilStreamConsumed } from "./
|
|
22
|
+
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
23
|
+
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
24
|
+
import { BeforeInteractiveContext } from "../shims/before-interactive-context.js";
|
|
25
|
+
import { renderBeforeInteractiveInlineScripts } from "./before-interactive-head.js";
|
|
24
26
|
import { createInitialDevServerErrorScript } from "./dev-initial-server-error.js";
|
|
27
|
+
import { ssrAppRouterInstance } from "./app-ssr-router-instance.js";
|
|
25
28
|
import { Fragment, createElement, use } from "react";
|
|
26
29
|
import { renderToReadableStream, renderToStaticMarkup } from "react-dom/server.edge";
|
|
27
30
|
import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
@@ -107,35 +110,6 @@ function renderInsertedHtml(insertedElements) {
|
|
|
107
110
|
} catch {}
|
|
108
111
|
return insertedHTML;
|
|
109
112
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Render captured `<Script strategy="beforeInteractive">` inline scripts to
|
|
112
|
-
* HTML, ready to splice immediately after `<head ...>` opens. Each entry has
|
|
113
|
-
* already had its inline content escaped via `escapeInlineContent(..., "script")`
|
|
114
|
-
* inside the Script shim, so this function only quotes the attributes that
|
|
115
|
-
* actually go on the tag (id, nonce, plus the residual passthroughs).
|
|
116
|
-
*
|
|
117
|
-
* Keeping this function colocated with the rest of the head-injection
|
|
118
|
-
* helpers makes it obvious where the boundary is: anything passed through
|
|
119
|
-
* here is being concatenated directly into HTML; treat the inputs
|
|
120
|
-
* accordingly.
|
|
121
|
-
*/
|
|
122
|
-
const VALID_ATTR_NAME = /^[a-zA-Z][\w.-]*$/;
|
|
123
|
-
function renderBeforeInteractiveInlineScripts(scripts) {
|
|
124
|
-
if (scripts.length === 0) return "";
|
|
125
|
-
let html = "";
|
|
126
|
-
for (const script of scripts) {
|
|
127
|
-
let attrs = "";
|
|
128
|
-
if (script.id) attrs += ` id="${escapeHtmlAttr(script.id)}"`;
|
|
129
|
-
attrs += createNonceAttribute(script.nonce);
|
|
130
|
-
if (script.attributes) for (const [key, value] of Object.entries(script.attributes)) {
|
|
131
|
-
if (!VALID_ATTR_NAME.test(key)) continue;
|
|
132
|
-
if (value === true) attrs += ` ${key}`;
|
|
133
|
-
else if (typeof value === "string") attrs += ` ${key}="${escapeHtmlAttr(value)}"`;
|
|
134
|
-
}
|
|
135
|
-
html += `<script${attrs}>${script.innerHTML}<\/script>`;
|
|
136
|
-
}
|
|
137
|
-
return html;
|
|
138
|
-
}
|
|
139
113
|
function renderFontHtml(fontData, nonce, options = {}) {
|
|
140
114
|
if (!fontData) return "";
|
|
141
115
|
let fontHTML = "";
|
|
@@ -220,8 +194,8 @@ async function handleSsr(rscStream, navContext, fontData, options) {
|
|
|
220
194
|
return BfcacheIdMapContext ? createElement(BfcacheIdMapContext.Provider, { value: createInitialBfcacheIdMap(elements) }, stateKeyTree) : stateKeyTree;
|
|
221
195
|
}
|
|
222
196
|
const flightRootElement = createElement(VinextFlightRoot);
|
|
223
|
-
const root = AppRouterContext ? createElement(AppRouterContext.Provider, { value:
|
|
224
|
-
const ssrTree = ServerInsertedHTMLContext ? createElement(ServerInsertedHTMLContext.Provider, { value:
|
|
197
|
+
const root = AppRouterContext ? createElement(AppRouterContext.Provider, { value: ssrAppRouterInstance }, flightRootElement) : flightRootElement;
|
|
198
|
+
const ssrTree = ServerInsertedHTMLContext ? createElement(ServerInsertedHTMLContext.Provider, { value: registerServerInsertedHTMLCallback }, root) : root;
|
|
225
199
|
const beforeInteractiveInlineScripts = [];
|
|
226
200
|
const registerBeforeInteractiveInlineScript = (script) => {
|
|
227
201
|
beforeInteractiveInlineScripts.push(script);
|