vinext 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -30
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +13 -6
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +113 -97
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/config/config-matchers.js +14 -10
- package/dist/config/next-config.d.ts +6 -3
- package/dist/config/next-config.js +47 -1
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +89 -15
- package/dist/entries/app-rsc-manifest.js +10 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +16 -1
- package/dist/entries/pages-server-entry.js +6 -2
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +211 -118
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +208 -97
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
- package/dist/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +276 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +18 -15
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/middleware-server-only.d.ts +8 -6
- package/dist/plugins/middleware-server-only.js +8 -7
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +29 -4
- package/dist/routing/app-route-graph.js +182 -40
- package/dist/routing/app-router.d.ts +5 -0
- package/dist/routing/app-router.js +5 -0
- package/dist/routing/file-matcher.d.ts +8 -0
- package/dist/routing/file-matcher.js +10 -1
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +194 -190
- package/dist/server/app-browser-history-controller.d.ts +2 -1
- package/dist/server/app-browser-history-controller.js +6 -2
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +32 -0
- package/dist/server/app-browser-server-action-client.js +127 -0
- package/dist/server/app-browser-state.d.ts +11 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +43 -25
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +5 -2
- package/dist/server/app-fallback-renderer.js +15 -7
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-boundary-render.d.ts +3 -0
- package/dist/server/app-page-boundary-render.js +14 -3
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +10 -3
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +5 -2
- package/dist/server/app-page-dispatch.d.ts +33 -4
- package/dist/server/app-page-dispatch.js +63 -90
- package/dist/server/app-page-element-builder.d.ts +9 -2
- package/dist/server/app-page-element-builder.js +114 -23
- package/dist/server/app-page-head.d.ts +16 -1
- package/dist/server/app-page-head.js +44 -22
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-ppr-runtime.d.ts +7 -0
- package/dist/server/app-page-ppr-runtime.js +70 -0
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +6 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.d.ts +4 -1
- package/dist/server/app-page-render.js +26 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +92 -15
- package/dist/server/app-page-route-wiring.d.ts +14 -2
- package/dist/server/app-page-route-wiring.js +61 -25
- package/dist/server/app-page-search-params-observation.d.ts +4 -2
- package/dist/server/app-page-search-params-observation.js +11 -7
- package/dist/server/app-page-segment-state.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +5 -0
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-ppr-fallback-shell-render.d.ts +4 -3
- package/dist/server/app-route-handler-dispatch.js +1 -0
- package/dist/server/app-route-handler-execution.js +7 -2
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-module-loader.d.ts +2 -0
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-router-entry.js +16 -8
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.d.ts +3 -1
- package/dist/server/app-rsc-handler.js +67 -39
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +6 -3
- package/dist/server/app-rsc-route-matching.d.ts +7 -0
- package/dist/server/app-rsc-route-matching.js +36 -3
- package/dist/server/app-segment-config.d.ts +12 -0
- package/dist/server/app-segment-config.js +91 -5
- package/dist/server/app-server-action-execution.d.ts +5 -0
- package/dist/server/app-server-action-execution.js +94 -33
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +19 -8
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-route-files.js +4 -0
- package/dist/server/dev-server.js +19 -18
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +5 -15
- package/dist/server/headers.js +4 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-api-route.js +2 -2
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-node-compat.d.ts +8 -1
- package/dist/server/pages-node-compat.js +32 -4
- package/dist/server/pages-page-data.d.ts +24 -1
- package/dist/server/pages-page-data.js +45 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +19 -12
- package/dist/server/pages-page-response.d.ts +7 -0
- package/dist/server/pages-page-response.js +4 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +48 -26
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/server/worker-utils.d.ts +2 -1
- package/dist/server/worker-utils.js +7 -1
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/error-boundary.d.ts +19 -1
- package/dist/shims/error-boundary.js +11 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +9 -1
- package/dist/shims/headers.js +31 -6
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +9 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +73 -14
- package/dist/shims/internal/pages-data-target.d.ts +10 -9
- package/dist/shims/internal/pages-data-target.js +91 -12
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.js +70 -37
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.d.ts +5 -1
- package/dist/shims/navigation.js +45 -10
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +374 -94
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/typegen.js +6 -5
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +2 -2
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/project.d.ts +52 -2
- package/dist/utils/project.js +230 -5
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +53 -4
- package/dist/deploy.d.ts +0 -190
- package/dist/deploy.js +0 -1033
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isCatchAllSegment, isOptionalCatchAllSegment } from "../routing/utils.js";
|
|
2
2
|
//#region src/server/app-page-segment-state.ts
|
|
3
|
+
const APP_PAGE_SEGMENT_KEY = "__PAGE__";
|
|
3
4
|
function isDynamicSegment(segment) {
|
|
4
5
|
return segment.startsWith("[") && segment.endsWith("]") && !segment.includes(".");
|
|
5
6
|
}
|
|
@@ -58,6 +59,7 @@ function resolveAppPageChildSegments(routeSegments, treePosition, params) {
|
|
|
58
59
|
}
|
|
59
60
|
resolvedSegments.push(segment);
|
|
60
61
|
}
|
|
62
|
+
resolvedSegments.push(APP_PAGE_SEGMENT_KEY);
|
|
61
63
|
return resolvedSegments;
|
|
62
64
|
}
|
|
63
65
|
function resolveAppPageSegmentStateKey(routeSegments, treePosition, params) {
|
|
@@ -77,4 +79,4 @@ function resolveAppPageLeafSegmentStateKey(routeSegments, params) {
|
|
|
77
79
|
return "";
|
|
78
80
|
}
|
|
79
81
|
//#endregion
|
|
80
|
-
export { resolveAppPageChildSegments, resolveAppPageLeafSegmentStateKey, resolveAppPageRouteStateKey, resolveAppPageSegmentStateKey };
|
|
82
|
+
export { APP_PAGE_SEGMENT_KEY, resolveAppPageChildSegments, resolveAppPageLeafSegmentStateKey, resolveAppPageRouteStateKey, resolveAppPageSegmentStateKey };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
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 { InitialNavigationCacheMetadata } from "./app-ssr-stream.js";
|
|
4
5
|
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
5
6
|
import { ReactFormState } from "react-dom/client";
|
|
6
7
|
|
|
@@ -72,9 +73,13 @@ type AppPageSsrHandler = {
|
|
|
72
73
|
* default `__next_error__` error-document shell (with the original
|
|
73
74
|
* flight payload and bootstrap) instead of rejecting. See handleSsr. */
|
|
74
75
|
fallbackToErrorDocumentOnShellError?: boolean;
|
|
76
|
+
dynamicStaleTimeSeconds?: number;
|
|
77
|
+
getInitialNavigationCacheMetadata?: () => InitialNavigationCacheMetadata;
|
|
75
78
|
}) => Promise<ReadableStream<Uint8Array> | AppSsrRenderResult>;
|
|
76
79
|
};
|
|
77
80
|
type RenderAppPageHtmlStreamOptions = {
|
|
81
|
+
dynamicStaleTimeSeconds?: number;
|
|
82
|
+
getInitialNavigationCacheMetadata?: () => InitialNavigationCacheMetadata;
|
|
78
83
|
fontData: AppPageFontData;
|
|
79
84
|
formState?: ReactFormState | null;
|
|
80
85
|
navigationContext: NavigationContext | null;
|
|
@@ -68,7 +68,9 @@ async function renderAppPageHtmlStream(options) {
|
|
|
68
68
|
pprFallbackShellSignal: options.pprFallbackShellSignal,
|
|
69
69
|
waitForAllReady: options.waitForAllReady,
|
|
70
70
|
initialDevServerError: options.initialDevServerError,
|
|
71
|
-
fallbackToErrorDocumentOnShellError: options.waitForAllReady !== true && options.hasCustomGlobalError === false
|
|
71
|
+
fallbackToErrorDocumentOnShellError: options.waitForAllReady !== true && options.hasCustomGlobalError === false,
|
|
72
|
+
dynamicStaleTimeSeconds: options.dynamicStaleTimeSeconds,
|
|
73
|
+
getInitialNavigationCacheMetadata: options.getInitialNavigationCacheMetadata
|
|
72
74
|
};
|
|
73
75
|
return normalizeAppSsrRenderResult(await options.ssrHandler.handleSsr(options.rscStream, options.navigationContext, options.fontData, ssrOptions), options.capturedRscDataRef?.value ?? null);
|
|
74
76
|
}
|
|
@@ -4,7 +4,7 @@ import { ReactNode } from "react";
|
|
|
4
4
|
//#region src/server/app-ppr-fallback-shell-render.d.ts
|
|
5
5
|
type AppPageBoundaryOnError = (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown;
|
|
6
6
|
type AppPageRenderableElement = ReactNode | Record<string, ReactNode>;
|
|
7
|
-
|
|
7
|
+
type WarmPprFallbackShellCachesOptions = {
|
|
8
8
|
element: AppPageRenderableElement;
|
|
9
9
|
onError: AppPageBoundaryOnError;
|
|
10
10
|
renderToReadableStream: (element: AppPageRenderableElement, options: {
|
|
@@ -12,6 +12,7 @@ declare function warmPprFallbackShellCaches(options: {
|
|
|
12
12
|
signal?: AbortSignal;
|
|
13
13
|
}) => ReadableStream<Uint8Array>;
|
|
14
14
|
state: PprFallbackShellState;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
|
+
declare function warmPprFallbackShellCaches(options: WarmPprFallbackShellCachesOptions): Promise<void>;
|
|
16
17
|
//#endregion
|
|
17
|
-
export { warmPprFallbackShellCaches };
|
|
18
|
+
export { WarmPprFallbackShellCachesOptions, warmPprFallbackShellCaches };
|
|
@@ -24,6 +24,7 @@ function buildRouteHandlerPageCacheTags(pathname, extraTags, routeSegments) {
|
|
|
24
24
|
async function runInRouteHandlerRevalidationContext(options, renderFn) {
|
|
25
25
|
await runWithRequestContext(createRequestContext({
|
|
26
26
|
headersContext: createStaticGenerationHeadersContext({
|
|
27
|
+
draftModeEnabled: false,
|
|
27
28
|
draftModeSecret: options.draftModeSecret,
|
|
28
29
|
dynamicConfig: options.dynamicConfig,
|
|
29
30
|
routeKind: "route",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { setHeadersContext } from "../shims/headers.js";
|
|
1
|
+
import { isDraftModeRequest, setHeadersContext } from "../shims/headers.js";
|
|
2
2
|
import { isPossibleAppRouteActionRequest } from "./app-action-request.js";
|
|
3
|
+
import { runWithRootParamsUsage } from "../shims/root-params.js";
|
|
3
4
|
import { applyRouteHandlerMiddlewareContext, applyRouteHandlerRevalidateHeader, assertSupportedAppRouteHandlerResponse, buildAppRouteCacheValue, finalizeRouteHandlerResponse, markRouteHandlerCacheMiss } from "./app-route-handler-response.js";
|
|
4
5
|
import { createTrackedAppRouteRequest, markKnownDynamicAppRoute } from "./app-route-handler-runtime.js";
|
|
5
6
|
import { createStaticGenerationHeadersContext, getAppRouteStaticGenerationErrorMessage } from "./app-static-generation.js";
|
|
@@ -8,6 +9,7 @@ import { resolveAppRouteHandlerSpecialError, shouldApplyAppRouteHandlerRevalidat
|
|
|
8
9
|
function configureAppRouteStaticGenerationContext(options) {
|
|
9
10
|
if (options.dynamicConfig === "force-static" || options.dynamicConfig === "error") {
|
|
10
11
|
setHeadersContext(createStaticGenerationHeadersContext({
|
|
12
|
+
draftModeEnabled: options.draftModeSecret !== void 0 && isDraftModeRequest(options.request, options.draftModeSecret),
|
|
11
13
|
draftModeSecret: options.draftModeSecret,
|
|
12
14
|
dynamicConfig: options.dynamicConfig,
|
|
13
15
|
routeKind: "route",
|
|
@@ -32,7 +34,10 @@ async function runAppRouteHandler(options) {
|
|
|
32
34
|
return getAppRouteStaticGenerationErrorMessage(options.routePattern, expression);
|
|
33
35
|
}
|
|
34
36
|
});
|
|
35
|
-
const response = await
|
|
37
|
+
const response = await runWithRootParamsUsage({
|
|
38
|
+
kind: "route-handler",
|
|
39
|
+
routePattern: options.routePattern ?? new URL(options.request.url).pathname
|
|
40
|
+
}, () => options.handlerFn(trackedRequest.request, { params: options.params }));
|
|
36
41
|
return {
|
|
37
42
|
dynamicUsedInHandler: options.consumeDynamicUsage(),
|
|
38
43
|
response
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { addBasePathToPathname } from "../utils/base-path.js";
|
|
2
|
-
import { buildRequestHeadersFromMiddlewareResponse } from "
|
|
2
|
+
import { buildRequestHeadersFromMiddlewareResponse } from "../utils/middleware-request-headers.js";
|
|
3
3
|
import { NextRequest, RequestCookies, sealRequestCookies, sealRequestHeaders } from "../shims/server.js";
|
|
4
4
|
//#region src/server/app-route-handler-runtime.ts
|
|
5
5
|
const ROUTE_HANDLER_HTTP_METHODS = [
|
|
@@ -36,11 +36,13 @@ type LazyLoadableSlot = {
|
|
|
36
36
|
page?: unknown;
|
|
37
37
|
default?: unknown;
|
|
38
38
|
layout?: unknown;
|
|
39
|
+
configLayouts?: readonly unknown[];
|
|
39
40
|
loading?: unknown;
|
|
40
41
|
error?: unknown;
|
|
41
42
|
__loadPage?: LazyModuleThunk | null;
|
|
42
43
|
__loadDefault?: LazyModuleThunk | null;
|
|
43
44
|
__loadLayout?: LazyModuleThunk | null;
|
|
45
|
+
__loadConfigLayouts?: LazyModuleLoaderArray | null;
|
|
44
46
|
__loadLoading?: LazyModuleThunk | null;
|
|
45
47
|
__loadError?: LazyModuleThunk | null; /** Hydrated only after an intercept matches, not with the slot's base modules. */
|
|
46
48
|
intercepts?: LazyLoadableIntercept[];
|
|
@@ -61,6 +61,7 @@ function ensureAppRouteModulesLoaded(route) {
|
|
|
61
61
|
pushFieldLoad(loads, slot, "page", slot.__loadPage);
|
|
62
62
|
pushFieldLoad(loads, slot, "default", slot.__loadDefault);
|
|
63
63
|
pushFieldLoad(loads, slot, "layout", slot.__loadLayout);
|
|
64
|
+
pushArrayLoads(loads, slot.configLayouts, slot.__loadConfigLayouts);
|
|
64
65
|
pushFieldLoad(loads, slot, "loading", slot.__loadLoading);
|
|
65
66
|
pushFieldLoad(loads, slot, "error", slot.__loadError);
|
|
66
67
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import "./server-globals.js";
|
|
2
2
|
import { runWithExecutionContext } from "../shims/request-context.js";
|
|
3
|
-
import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "
|
|
3
|
+
import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "../utils/protocol-headers.js";
|
|
4
4
|
import { badRequestResponse, notFoundResponse, notFoundStaticAssetResponse } from "./http-error-responses.js";
|
|
5
5
|
import { isOpenRedirectShaped } from "./open-redirect.js";
|
|
6
6
|
import { cloneRequestWithHeaders, filterInternalHeaders } from "./request-pipeline.js";
|
|
7
|
+
import { getImageOptimizer, handleConfiguredImageOptimization, isImageOptimizationPath } from "./image-optimization.js";
|
|
7
8
|
import { assetPrefixPathname, isNextStaticPath } from "../utils/asset-prefix.js";
|
|
8
|
-
import { resolveStaticAssetSignal } from "./worker-utils.js";
|
|
9
|
+
import { finalizeMissingStaticAssetResponse, resolveStaticAssetSignal } from "./worker-utils.js";
|
|
9
10
|
import { readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
|
|
10
|
-
import rscHandler, { __assetPrefix, __basePath } from "virtual:vinext-rsc-entry";
|
|
11
|
+
import rscHandler, { __assetPrefix, __basePath, __imageAllowedWidths, __imageConfig } from "virtual:vinext-rsc-entry";
|
|
11
12
|
import { registerConfiguredCacheAdapters } from "virtual:vinext-cache-adapters";
|
|
13
|
+
import { registerConfiguredImageOptimizer } from "virtual:vinext-image-adapters";
|
|
12
14
|
//#region src/server/app-router-entry.ts
|
|
13
15
|
const __workerBasePath = typeof __basePath === "string" ? __basePath : "";
|
|
14
16
|
const __workerAssetPathPrefix = assetPrefixPathname(typeof __assetPrefix === "string" ? __assetPrefix : "");
|
|
@@ -17,14 +19,19 @@ var app_router_entry_default = { async fetch(request, env, ctx) {
|
|
|
17
19
|
} };
|
|
18
20
|
async function handleRequest(request, env, ctx) {
|
|
19
21
|
registerConfiguredCacheAdapters(env);
|
|
22
|
+
registerConfiguredImageOptimizer(env);
|
|
20
23
|
const url = new URL(request.url);
|
|
24
|
+
if (isImageOptimizationPath(url.pathname) && env?.ASSETS && getImageOptimizer()) {
|
|
25
|
+
const assetFetcher = env.ASSETS;
|
|
26
|
+
return handleConfiguredImageOptimization(request, (assetPath) => Promise.resolve(assetFetcher.fetch(new Request(new URL(assetPath, request.url)))), __imageAllowedWidths, __imageConfig);
|
|
27
|
+
}
|
|
21
28
|
if (isOpenRedirectShaped(url.pathname)) return notFoundResponse();
|
|
22
29
|
try {
|
|
23
30
|
decodeURIComponent(url.pathname);
|
|
24
31
|
} catch {
|
|
25
32
|
return badRequestResponse();
|
|
26
33
|
}
|
|
27
|
-
|
|
34
|
+
const missingBuildAsset = isNextStaticPath(url.pathname, __workerBasePath, __workerAssetPathPrefix);
|
|
28
35
|
{
|
|
29
36
|
const prerenderRouteParamsPayload = readTrustedPrerenderRouteParams(request);
|
|
30
37
|
const filteredHeaders = filterInternalHeaders(request.headers);
|
|
@@ -35,14 +42,15 @@ async function handleRequest(request, env, ctx) {
|
|
|
35
42
|
const handleFn = () => rscHandler(request, ctx);
|
|
36
43
|
const result = await (ctx ? runWithExecutionContext(ctx, handleFn) : handleFn());
|
|
37
44
|
if (result instanceof Response) {
|
|
45
|
+
let response = result;
|
|
38
46
|
if (env?.ASSETS) {
|
|
39
47
|
const assetFetcher = env.ASSETS;
|
|
40
|
-
const assetResponse = await resolveStaticAssetSignal(
|
|
41
|
-
if (assetResponse)
|
|
48
|
+
const assetResponse = await resolveStaticAssetSignal(response, { fetchAsset: (path) => Promise.resolve(assetFetcher.fetch(new Request(new URL(path, request.url)))) });
|
|
49
|
+
if (assetResponse) response = assetResponse;
|
|
42
50
|
}
|
|
43
|
-
return
|
|
51
|
+
return finalizeMissingStaticAssetResponse(response, missingBuildAsset);
|
|
44
52
|
}
|
|
45
|
-
if (result === null || result === void 0) return notFoundResponse();
|
|
53
|
+
if (result === null || result === void 0) return missingBuildAsset ? notFoundStaticAssetResponse() : notFoundResponse();
|
|
46
54
|
return new Response(String(result), { status: 200 });
|
|
47
55
|
}
|
|
48
56
|
//#endregion
|
|
@@ -53,7 +53,13 @@ function createRscOnErrorHandler(options) {
|
|
|
53
53
|
}
|
|
54
54
|
if (options.requestInfo && options.errorContext && error) options.reportRequestError(error instanceof Error ? error : new Error(getThrownValueMessage(error)), options.requestInfo, options.errorContext);
|
|
55
55
|
if (hasDigest(error)) return String(error.digest);
|
|
56
|
-
if (
|
|
56
|
+
if (error) {
|
|
57
|
+
const digest = errorDigest(getThrownValueMessage(error) + getThrownValueStack(error));
|
|
58
|
+
if (error instanceof Error) try {
|
|
59
|
+
Object.assign(error, { digest });
|
|
60
|
+
} catch {}
|
|
61
|
+
return digest;
|
|
62
|
+
}
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
65
|
//#endregion
|
|
@@ -4,6 +4,7 @@ import { ClientReuseManifestParseResult } from "./client-reuse-manifest.js";
|
|
|
4
4
|
import { RootParams } from "../shims/root-params.js";
|
|
5
5
|
import { AppMiddlewareContext, ApplyAppMiddlewareResult } from "./app-middleware.js";
|
|
6
6
|
import { AppRscRenderMode } from "./app-rsc-render-mode.js";
|
|
7
|
+
import { AppPagePprFallbackCacheShell } from "./app-ppr-fallback-shell.js";
|
|
7
8
|
import { AppPrerenderRootParamNamesMap, AppPrerenderStaticParamsMap } from "./app-prerender-endpoints.js";
|
|
8
9
|
import { ReactFormState } from "react-dom/client";
|
|
9
10
|
|
|
@@ -15,6 +16,7 @@ type AppRscMiddlewareContext = AppMiddlewareContext;
|
|
|
15
16
|
type RunAppMiddlewareOptions = {
|
|
16
17
|
cleanPathname: string;
|
|
17
18
|
context: AppRscMiddlewareContext;
|
|
19
|
+
hadBasePath: boolean;
|
|
18
20
|
isDataRequest: boolean;
|
|
19
21
|
request: Request;
|
|
20
22
|
};
|
|
@@ -151,7 +153,6 @@ type NavigationContextValue = {
|
|
|
151
153
|
type CreateAppRscHandlerOptions<TRoute extends AppRscHandlerRoute> = {
|
|
152
154
|
basePath: string;
|
|
153
155
|
buildId: string | null;
|
|
154
|
-
cacheComponents?: boolean;
|
|
155
156
|
clearRequestContext: () => void;
|
|
156
157
|
configHeaders: NextHeader[];
|
|
157
158
|
configRedirects: NextRedirect[];
|
|
@@ -179,6 +180,7 @@ type CreateAppRscHandlerOptions<TRoute extends AppRscHandlerRoute> = {
|
|
|
179
180
|
registerCacheAdapters: (env?: Record<string, unknown>) => void;
|
|
180
181
|
handleProgressiveActionRequest?: (options: HandleProgressiveActionRequestOptions) => Promise<Response | ProgressiveActionFormStateResult | null>;
|
|
181
182
|
handleMetadataRouteRequest?: (cleanPathname: string) => Promise<Response | null>;
|
|
183
|
+
createPprFallbackShells?: (route: Pick<AppRscHandlerRoute, "params" | "pattern" | "rootParamNames">, params: AppPageParams) => AppPagePprFallbackCacheShell[];
|
|
182
184
|
handleServerActionRequest?: (options: HandleServerActionRequestOptions) => Promise<Response | null>;
|
|
183
185
|
i18nConfig: NextI18nConfig | null;
|
|
184
186
|
imageConfig?: ImageConfig;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createRequestContext, runWithRequestContext } from "../shims/unified-request-context.js";
|
|
2
2
|
import { addBasePathToPathname, hasBasePath, stripBasePath } from "../utils/base-path.js";
|
|
3
3
|
import { getRequestExecutionContext } from "../shims/request-context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "../utils/protocol-headers.js";
|
|
5
|
+
import { ACTION_REVALIDATED_HEADER } from "./headers.js";
|
|
5
6
|
import { isExternalUrl, matchRedirect, matchRewrite, preserveRedirectDestinationQuery, proxyExternalRequest, requestContextFromRequest, sanitizeDestination } from "../config/config-matchers.js";
|
|
6
7
|
import { notFoundResponse } from "./http-error-responses.js";
|
|
7
8
|
import { applyConfigHeadersToResponse, cloneRequestWithHeaders, cloneRequestWithUrl, filterInternalHeaders, normalizeTrailingSlash, resolvePublicFileRoute } from "./request-pipeline.js";
|
|
@@ -10,18 +11,19 @@ import { ensureFetchPatch, setCurrentFetchSoftTags } from "../shims/fetch-cache.
|
|
|
10
11
|
import { mergeRewriteQuery } from "../utils/query.js";
|
|
11
12
|
import { getScriptNonceFromHeaderSources } from "./csp.js";
|
|
12
13
|
import { normalizeDefaultLocalePathname } from "./pages-i18n.js";
|
|
14
|
+
import { buildNextDataNotFoundResponse, normalizePagesDataRequest } from "./pages-data-route.js";
|
|
13
15
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./image-optimization.js";
|
|
14
16
|
import { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, createRscRedirectLocation, hasRscCacheBustingSearchParam, resolveInvalidRscCacheBustingRequest, stripRscCacheBustingSearchParam, stripRscSuffix } from "./app-rsc-cache-busting.js";
|
|
15
17
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
16
18
|
import "./app-page-response.js";
|
|
17
|
-
import {
|
|
19
|
+
import { parseNextHttpErrorDigest } from "./next-error-digest.js";
|
|
18
20
|
import { matchPrerenderRouteParamsPayload, readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
|
|
19
21
|
import { getRenderedConcreteUrlPathsForRoute } from "./pregenerated-concrete-paths.js";
|
|
20
|
-
import { flattenErrorCauses } from "../utils/error-cause.js";
|
|
21
|
-
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
22
22
|
import { createServerActionNotFoundResponse, getServerActionNotFoundMessage } from "./server-action-not-found.js";
|
|
23
23
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
24
24
|
import { buildPostMwRequestContext } from "./app-post-middleware-context.js";
|
|
25
|
+
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
26
|
+
import { flattenErrorCauses } from "../utils/error-cause.js";
|
|
25
27
|
import { finalizeAppRscResponse } from "./app-rsc-response-finalizer.js";
|
|
26
28
|
import { normalizeRscRequest } from "./app-rsc-request-normalization.js";
|
|
27
29
|
import { runWithPrerenderWorkUnit } from "./prerender-work-unit-setup.js";
|
|
@@ -53,8 +55,8 @@ function createMissingServerActionResponse(options, actionId) {
|
|
|
53
55
|
options.clearRequestContext();
|
|
54
56
|
return createServerActionNotFoundResponse();
|
|
55
57
|
}
|
|
56
|
-
function redirectDestinationWithBasePath(destination, basePath) {
|
|
57
|
-
if (!basePath || isExternalUrl(destination) || hasBasePath(destination, basePath)) return destination;
|
|
58
|
+
function redirectDestinationWithBasePath(destination, basePath, hadBasePath) {
|
|
59
|
+
if (!basePath || !hadBasePath || isExternalUrl(destination) || hasBasePath(destination, basePath)) return destination;
|
|
58
60
|
return basePath + destination;
|
|
59
61
|
}
|
|
60
62
|
async function applyRewrite(options, cleanPathname) {
|
|
@@ -111,15 +113,22 @@ function requestWithoutRscSuffix(request) {
|
|
|
111
113
|
url.pathname = pathname;
|
|
112
114
|
return cloneRequestWithUrl(request.body ? request.clone() : request, url.toString());
|
|
113
115
|
}
|
|
114
|
-
async function handleAppRscRequest(options, request, preMiddlewareRequestContext, isDataRequest, pagesDataRequest) {
|
|
116
|
+
async function handleAppRscRequest(options, request, preMiddlewareRequestContext, isDataRequest, isMiddlewareDataRequest, pagesDataRequest) {
|
|
115
117
|
const handlerStart = process.env.NODE_ENV !== "production" ? performance.now() : 0;
|
|
116
118
|
if (process.env.NODE_ENV !== "production") {
|
|
117
119
|
const originBlock = options.validateDevRequestOrigin?.(request);
|
|
118
120
|
if (originBlock) return originBlock;
|
|
119
121
|
}
|
|
120
|
-
const
|
|
122
|
+
const canHandleOutsideBasePath = Boolean(options.runMiddleware) || [
|
|
123
|
+
...options.configRedirects,
|
|
124
|
+
...options.configRewrites.beforeFiles,
|
|
125
|
+
...options.configRewrites.afterFiles,
|
|
126
|
+
...options.configRewrites.fallback,
|
|
127
|
+
...options.configHeaders
|
|
128
|
+
].some((rule) => rule.basePath === false);
|
|
129
|
+
const normalized = normalizeRscRequest(request, options.basePath, canHandleOutsideBasePath);
|
|
121
130
|
if (normalized instanceof Response) return normalized;
|
|
122
|
-
const { url, isRscRequest, interceptionContextHeader, mountedSlotsHeader, renderMode, clientReuseManifest } = normalized;
|
|
131
|
+
const { url, isRscRequest, interceptionContextHeader, mountedSlotsHeader, renderMode, clientReuseManifest, hadBasePath } = normalized;
|
|
123
132
|
let { pathname, cleanPathname } = normalized;
|
|
124
133
|
let resolvedUrl = cleanPathname + url.search;
|
|
125
134
|
const originalResolvedUrl = resolvedUrl;
|
|
@@ -127,7 +136,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
127
136
|
const canonicalPathname = cleanPathname;
|
|
128
137
|
const basePathState = {
|
|
129
138
|
basePath: options.basePath,
|
|
130
|
-
hadBasePath
|
|
139
|
+
hadBasePath
|
|
131
140
|
};
|
|
132
141
|
if (pathname === "/__vinext/prerender/static-params" || pathname === "/__vinext/prerender/pages-static-paths") {
|
|
133
142
|
const { handleAppPrerenderEndpoint } = await import("./app-prerender-endpoints.js");
|
|
@@ -142,17 +151,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
142
151
|
});
|
|
143
152
|
if (prerenderEndpointResponse) return prerenderEndpointResponse;
|
|
144
153
|
}
|
|
145
|
-
const trailingSlashRedirect = normalizeTrailingSlash(pathname, options.basePath, options.trailingSlash, url.search);
|
|
154
|
+
const trailingSlashRedirect = normalizeTrailingSlash(pathname, hadBasePath ? options.basePath : "", options.trailingSlash, url.search);
|
|
146
155
|
if (trailingSlashRedirect) return trailingSlashRedirect;
|
|
147
156
|
const matchPathname = (p) => normalizeDefaultLocalePathname(p, options.i18nConfig, { hostname: url.hostname });
|
|
148
157
|
const redirect = matchRedirect(matchPathname(stripRscSuffix(pathname)), options.configRedirects, preMiddlewareRequestContext, basePathState);
|
|
149
158
|
if (redirect) {
|
|
150
|
-
const destination = sanitizeDestination(redirectDestinationWithBasePath(redirect.destination, options.basePath));
|
|
159
|
+
const destination = sanitizeDestination(redirectDestinationWithBasePath(redirect.destination, options.basePath, hadBasePath));
|
|
151
160
|
const location = isRscRequest && request.headers.get("RSC") === "1" ? await createRscRedirectLocation(destination, request) : preserveRedirectDestinationQuery(destination, url.search);
|
|
152
|
-
if (isDataRequest) return new Response(null, {
|
|
153
|
-
status: 200,
|
|
154
|
-
headers: { "x-nextjs-redirect": location }
|
|
155
|
-
});
|
|
156
161
|
return new Response(null, {
|
|
157
162
|
status: redirect.permanent ? 308 : 307,
|
|
158
163
|
headers: { Location: location }
|
|
@@ -171,11 +176,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
171
176
|
status: null
|
|
172
177
|
};
|
|
173
178
|
let didMiddlewareRewrite = false;
|
|
179
|
+
let didMiddlewareRewritePathname = false;
|
|
174
180
|
if (options.runMiddleware) {
|
|
175
181
|
const middlewareResult = await options.runMiddleware({
|
|
176
182
|
cleanPathname,
|
|
177
183
|
context: middlewareContext,
|
|
178
|
-
|
|
184
|
+
hadBasePath,
|
|
185
|
+
isDataRequest: isMiddlewareDataRequest,
|
|
179
186
|
request: userlandRequest
|
|
180
187
|
});
|
|
181
188
|
if (middlewareResult.kind === "response") return applyConfigHeadersToMiddlewareRedirect(middlewareResult.response, {
|
|
@@ -185,12 +192,14 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
185
192
|
requestContext: preMiddlewareRequestContext
|
|
186
193
|
});
|
|
187
194
|
cleanPathname = middlewareResult.cleanPathname;
|
|
188
|
-
didMiddlewareRewrite =
|
|
195
|
+
didMiddlewareRewrite = middlewareResult.rewritten;
|
|
196
|
+
didMiddlewareRewritePathname = cleanPathname !== normalized.cleanPathname;
|
|
189
197
|
if (middlewareResult.search !== null) url.search = middlewareResult.search;
|
|
190
198
|
resolvedUrl = cleanPathname + url.search;
|
|
191
199
|
}
|
|
192
200
|
const scriptNonce = getScriptNonceFromHeaderSources(request.headers, middlewareContext.headers);
|
|
193
201
|
const postMiddlewareRequestContext = buildPostMwRequestContext(userlandRequest);
|
|
202
|
+
let filesystemRouteEligible = hadBasePath || didMiddlewareRewrite;
|
|
194
203
|
for (const rewrite of options.configRewrites.beforeFiles) {
|
|
195
204
|
const beforeFilesRewrite = await applyRewrite({
|
|
196
205
|
basePathState,
|
|
@@ -203,14 +212,15 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
203
212
|
if (beforeFilesRewrite) {
|
|
204
213
|
resolvedUrl = mergeRewriteQuery(resolvedUrl, beforeFilesRewrite);
|
|
205
214
|
cleanPathname = pathnameForResolvedUrl(resolvedUrl);
|
|
215
|
+
filesystemRouteEligible = true;
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
|
-
if (isImageOptimizationPath(cleanPathname)) {
|
|
218
|
+
if (filesystemRouteEligible && isImageOptimizationPath(cleanPathname)) {
|
|
209
219
|
const imageRedirect = resolveDevImageRedirect(url, [...options.imageConfig?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...options.imageConfig?.imageSizes ?? DEFAULT_IMAGE_SIZES], options.imageConfig?.qualities, { isDev: options.isDev });
|
|
210
220
|
if (!imageRedirect) return new Response("Invalid image optimization parameters", { status: 400 });
|
|
211
221
|
return Response.redirect(new URL(imageRedirect, url.origin).href, 302);
|
|
212
222
|
}
|
|
213
|
-
if (options.handleMetadataRouteRequest) {
|
|
223
|
+
if (filesystemRouteEligible && options.handleMetadataRouteRequest) {
|
|
214
224
|
const metadataRouteResponse = await options.handleMetadataRouteRequest(cleanPathname);
|
|
215
225
|
if (metadataRouteResponse) {
|
|
216
226
|
applyConfigHeadersToResponse(metadataRouteResponse.headers, {
|
|
@@ -223,13 +233,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
223
233
|
return applyMiddlewareContextToResponse(metadataRouteResponse, middlewareContext);
|
|
224
234
|
}
|
|
225
235
|
}
|
|
226
|
-
const publicFileResponse = resolvePublicFileRoute({
|
|
236
|
+
const publicFileResponse = filesystemRouteEligible ? resolvePublicFileRoute({
|
|
227
237
|
cleanPathname,
|
|
228
238
|
middlewareContext,
|
|
229
239
|
pathname,
|
|
230
240
|
publicFiles: options.publicFiles,
|
|
231
241
|
request
|
|
232
|
-
});
|
|
242
|
+
}) : null;
|
|
233
243
|
if (publicFileResponse) {
|
|
234
244
|
options.clearRequestContext();
|
|
235
245
|
return publicFileResponse;
|
|
@@ -243,13 +253,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
243
253
|
searchParams: getResolvedSearchParams(),
|
|
244
254
|
params: {}
|
|
245
255
|
});
|
|
246
|
-
const preActionMatch = options.matchRoute(cleanPathname);
|
|
256
|
+
const preActionMatch = filesystemRouteEligible ? options.matchRoute(cleanPathname) : null;
|
|
247
257
|
if (preActionMatch) setRootParams(pickRootParams(preActionMatch.params, preActionMatch.route.rootParamNames));
|
|
248
258
|
const actionId = request.headers.get("x-rsc-action") ?? request.headers.get("next-action");
|
|
249
259
|
const contentType = request.headers.get("content-type") || "";
|
|
250
260
|
const isPostRequest = request.method.toUpperCase() === "POST";
|
|
251
261
|
let progressiveActionResult = null;
|
|
252
|
-
if (isPostRequest && contentType.startsWith("multipart/form-data") && !actionId) {
|
|
262
|
+
if (filesystemRouteEligible && isPostRequest && contentType.startsWith("multipart/form-data") && !actionId) {
|
|
253
263
|
if (options.handleProgressiveActionRequest) progressiveActionResult = await options.handleProgressiveActionRequest({
|
|
254
264
|
actionId,
|
|
255
265
|
cleanPathname,
|
|
@@ -266,7 +276,11 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
266
276
|
const failedProgressiveActionResult = progressiveActionFormState && "actionError" in progressiveActionFormState ? progressiveActionFormState : null;
|
|
267
277
|
const actionFailed = failedProgressiveActionResult !== null;
|
|
268
278
|
const actionError = failedProgressiveActionResult?.actionError;
|
|
269
|
-
const
|
|
279
|
+
const actionErrorDigest = actionError && typeof actionError === "object" && "digest" in actionError ? String(actionError.digest) : null;
|
|
280
|
+
const actionHttpFallbackStatus = actionErrorDigest ? parseNextHttpErrorDigest(actionErrorDigest)?.status ?? null : null;
|
|
281
|
+
const normalizedProgressiveActionError = actionHttpFallbackStatus === null || actionHttpFallbackStatus === 404 ? actionError : { digest: "NEXT_NOT_FOUND" };
|
|
282
|
+
if (actionFailed && middlewareContext.status === null && actionHttpFallbackStatus === null) middlewareContext.status = 500;
|
|
283
|
+
const serverActionResponse = filesystemRouteEligible && isPostRequest && actionId && options.handleServerActionRequest ? await options.handleServerActionRequest({
|
|
270
284
|
actionId,
|
|
271
285
|
cleanPathname,
|
|
272
286
|
contentType,
|
|
@@ -278,12 +292,13 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
278
292
|
searchParams: getResolvedSearchParams()
|
|
279
293
|
}) : null;
|
|
280
294
|
if (serverActionResponse) return serverActionResponse;
|
|
281
|
-
if (isPostRequest && actionId && !options.handleServerActionRequest) return createMissingServerActionResponse(options, actionId);
|
|
295
|
+
if (filesystemRouteEligible && isPostRequest && actionId && !options.handleServerActionRequest) return createMissingServerActionResponse(options, actionId);
|
|
282
296
|
let match = preActionMatch;
|
|
283
297
|
const renderPagesForMatchKind = async (matchKind) => {
|
|
298
|
+
if (!filesystemRouteEligible) return null;
|
|
284
299
|
const response = match === null || match.route.isDynamic ? await options.renderPagesFallback?.({
|
|
285
300
|
appRouteMatch: match ?? null,
|
|
286
|
-
allowRscDocumentFallback:
|
|
301
|
+
allowRscDocumentFallback: didMiddlewareRewritePathname,
|
|
287
302
|
isDataRequest,
|
|
288
303
|
isRscRequest,
|
|
289
304
|
matchKind,
|
|
@@ -319,6 +334,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
319
334
|
if (!afterFilesRewrite) continue;
|
|
320
335
|
resolvedUrl = mergeRewriteQuery(resolvedUrl, afterFilesRewrite);
|
|
321
336
|
cleanPathname = pathnameForResolvedUrl(resolvedUrl);
|
|
337
|
+
filesystemRouteEligible = true;
|
|
322
338
|
match = options.matchRoute(cleanPathname);
|
|
323
339
|
const rewrittenStaticPagesResponse = await renderPagesForMatchKind("static");
|
|
324
340
|
if (rewrittenStaticPagesResponse) {
|
|
@@ -349,6 +365,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
349
365
|
if (!fallbackRewrite) continue;
|
|
350
366
|
resolvedUrl = mergeRewriteQuery(resolvedUrl, fallbackRewrite);
|
|
351
367
|
cleanPathname = pathnameForResolvedUrl(resolvedUrl);
|
|
368
|
+
filesystemRouteEligible = true;
|
|
352
369
|
match = options.matchRoute(cleanPathname);
|
|
353
370
|
const rewrittenStaticPagesResponse = await renderPagesForMatchKind("static");
|
|
354
371
|
if (rewrittenStaticPagesResponse) {
|
|
@@ -362,8 +379,23 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
362
379
|
}
|
|
363
380
|
if (match) break;
|
|
364
381
|
}
|
|
382
|
+
if (!filesystemRouteEligible) {
|
|
383
|
+
options.clearRequestContext();
|
|
384
|
+
const headers = new Headers();
|
|
385
|
+
mergeMiddlewareResponseHeaders(headers, middlewareContext.headers);
|
|
386
|
+
return notFoundResponse({ headers });
|
|
387
|
+
}
|
|
365
388
|
if (pagesDataRequest) {
|
|
366
389
|
options.clearRequestContext();
|
|
390
|
+
if (options.runMiddleware && (middlewareContext.status === null || middlewareContext.status === 200 || middlewareContext.status === 404)) {
|
|
391
|
+
const response = buildNextDataNotFoundResponse();
|
|
392
|
+
const headers = new Headers(response.headers);
|
|
393
|
+
headers.set("x-nextjs-matched-path", matchPathname(canonicalPathname));
|
|
394
|
+
return new Response("{}", {
|
|
395
|
+
status: 200,
|
|
396
|
+
headers
|
|
397
|
+
});
|
|
398
|
+
}
|
|
367
399
|
return buildNextDataNotFoundResponse();
|
|
368
400
|
}
|
|
369
401
|
if (!match) {
|
|
@@ -392,14 +424,11 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
392
424
|
const renderParams = prerenderRouteParams ?? params;
|
|
393
425
|
const resolvedSearchParams = getResolvedSearchParams();
|
|
394
426
|
let runtimeFallbackShells = [];
|
|
395
|
-
if (options.
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
rootParamNames: route.rootParamNames
|
|
401
|
-
}, params);
|
|
402
|
-
}
|
|
427
|
+
if (options.createPprFallbackShells && request.method === "GET" && !isRscRequest && !isPrerenderFallbackShell && route.params) runtimeFallbackShells = options.createPprFallbackShells({
|
|
428
|
+
params: route.params,
|
|
429
|
+
pattern: route.pattern,
|
|
430
|
+
rootParamNames: route.rootParamNames
|
|
431
|
+
}, params);
|
|
403
432
|
options.setNavigationContext({
|
|
404
433
|
pathname: canonicalPathname,
|
|
405
434
|
searchParams: resolvedSearchParams,
|
|
@@ -428,7 +457,7 @@ async function handleAppRscRequest(options, request, preMiddlewareRequestContext
|
|
|
428
457
|
cleanPathname,
|
|
429
458
|
displayPathname: canonicalPathname,
|
|
430
459
|
formState,
|
|
431
|
-
actionError,
|
|
460
|
+
actionError: normalizedProgressiveActionError,
|
|
432
461
|
actionFailed,
|
|
433
462
|
handlerStart,
|
|
434
463
|
interceptionContext: interceptionContextHeader,
|
|
@@ -492,14 +521,13 @@ function createAppRscHandler(options) {
|
|
|
492
521
|
options.registerCacheAdapters();
|
|
493
522
|
await options.ensureInstrumentation?.();
|
|
494
523
|
const mwCtx = rawRequest.headers.get(VINEXT_MW_CTX_HEADER);
|
|
495
|
-
const hasDataRequestHeader = rawRequest.headers.get("x-nextjs-data") === "1";
|
|
496
524
|
const pagesDataUrl = new URL(rawRequest.url);
|
|
497
525
|
const pagesDataInScope = !options.basePath || hasBasePath(pagesDataUrl.pathname, options.basePath);
|
|
498
526
|
if (pagesDataInScope) pagesDataUrl.pathname = stripBasePath(pagesDataUrl.pathname, options.basePath);
|
|
499
527
|
const pagesDataCandidate = pagesDataInScope ? cloneRequestWithUrl(rawRequest, pagesDataUrl.toString()) : null;
|
|
500
528
|
const pagesDataNormalization = options.renderPagesFallback && pagesDataCandidate ? normalizePagesDataRequest(pagesDataCandidate, options.buildId) : null;
|
|
501
529
|
if (pagesDataNormalization?.notFoundResponse) return pagesDataNormalization.notFoundResponse;
|
|
502
|
-
const
|
|
530
|
+
const isPagesDataRequest = pagesDataNormalization?.isDataReq === true;
|
|
503
531
|
const prerenderRouteParamsPayload = readTrustedPrerenderRouteParams(rawRequest);
|
|
504
532
|
const filteredHeaders = filterInternalHeaders(rawRequest.headers);
|
|
505
533
|
if (mwCtx !== null) filteredHeaders.set(VINEXT_MW_CTX_HEADER, mwCtx);
|
|
@@ -523,7 +551,7 @@ function createAppRscHandler(options) {
|
|
|
523
551
|
const preMiddlewareRequestContext = requestContextFromRequest(request);
|
|
524
552
|
let response;
|
|
525
553
|
try {
|
|
526
|
-
response = await handleAppRscRequest(options, request, preMiddlewareRequestContext,
|
|
554
|
+
response = await handleAppRscRequest(options, request, preMiddlewareRequestContext, isPagesDataRequest, isPagesDataRequest, pagesDataRequest);
|
|
527
555
|
} catch (error) {
|
|
528
556
|
if (process.env.NODE_ENV !== "production") flattenErrorCauses(error);
|
|
529
557
|
throw error;
|
|
@@ -11,7 +11,8 @@ type NormalizedRscRequest = {
|
|
|
11
11
|
interceptionContextHeader: string | null; /** Normalized x-vinext-mounted-slots header (deduplicated, sorted). null when absent or blank. */
|
|
12
12
|
mountedSlotsHeader: string | null; /** Semantic RSC payload mode. HTML requests always normalize to "navigation". */
|
|
13
13
|
renderMode: AppRscRenderMode; /** Parsed ClientReuseManifest hint. Verification and skip authorization happen later. */
|
|
14
|
-
clientReuseManifest: ClientReuseManifestParseResult;
|
|
14
|
+
clientReuseManifest: ClientReuseManifestParseResult; /** Whether the incoming pathname included the configured basePath. */
|
|
15
|
+
hadBasePath: boolean;
|
|
15
16
|
};
|
|
16
17
|
/**
|
|
17
18
|
* Normalize an App Router RSC request.
|
|
@@ -43,6 +44,6 @@ type NormalizedRscRequest = {
|
|
|
43
44
|
* @returns A 400 or 404 Response for invalid or out-of-scope inputs,
|
|
44
45
|
* or a NormalizedRscRequest for valid requests.
|
|
45
46
|
*/
|
|
46
|
-
declare function normalizeRscRequest(request: Request, basePath: string): Response | NormalizedRscRequest;
|
|
47
|
+
declare function normalizeRscRequest(request: Request, basePath: string, allowOutsideBasePath?: boolean): Response | NormalizedRscRequest;
|
|
47
48
|
//#endregion
|
|
48
49
|
export { NormalizedRscRequest, normalizeMountedSlotsHeader, normalizeRscRequest };
|
|
@@ -40,7 +40,7 @@ import { normalizeInterceptionContextHeader } from "./app-interception-context-h
|
|
|
40
40
|
* @returns A 400 or 404 Response for invalid or out-of-scope inputs,
|
|
41
41
|
* or a NormalizedRscRequest for valid requests.
|
|
42
42
|
*/
|
|
43
|
-
function normalizeRscRequest(request, basePath) {
|
|
43
|
+
function normalizeRscRequest(request, basePath, allowOutsideBasePath = false) {
|
|
44
44
|
const url = new URL(request.url);
|
|
45
45
|
const protoGuard = guardProtocolRelativeUrl(url.pathname);
|
|
46
46
|
if (protoGuard) return protoGuard;
|
|
@@ -51,9 +51,11 @@ function normalizeRscRequest(request, basePath) {
|
|
|
51
51
|
return badRequestResponse();
|
|
52
52
|
}
|
|
53
53
|
let pathname = normalizePath(decoded);
|
|
54
|
+
let hadBasePath = true;
|
|
54
55
|
if (basePath) {
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
hadBasePath = hasBasePath(pathname, basePath);
|
|
57
|
+
if (!hadBasePath && !pathname.startsWith("/__vinext/") && !allowOutsideBasePath) return notFoundResponse();
|
|
58
|
+
if (hadBasePath) pathname = stripBasePath(pathname, basePath);
|
|
57
59
|
}
|
|
58
60
|
const isRscRequest = pathname.endsWith(".rsc") || request.headers.get("RSC") === "1" && url.searchParams.has("_rsc");
|
|
59
61
|
const cleanPathname = stripRscSuffix(pathname);
|
|
@@ -62,6 +64,7 @@ function normalizeRscRequest(request, basePath) {
|
|
|
62
64
|
const renderMode = isRscRequest ? parseAppRscRenderMode(request.headers.get(VINEXT_RSC_RENDER_MODE_HEADER)) : APP_RSC_RENDER_MODE_NAVIGATION;
|
|
63
65
|
return {
|
|
64
66
|
clientReuseManifest: isRscRequest ? parseClientReuseManifestHeader(request.headers.get(VINEXT_CLIENT_REUSE_MANIFEST_HEADER)) : { kind: "absent" },
|
|
67
|
+
hadBasePath,
|
|
65
68
|
url,
|
|
66
69
|
pathname,
|
|
67
70
|
cleanPathname,
|