vinext 1.0.0-beta.6 → 1.0.0-beta.8
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 +47 -3
- package/dist/build/action-owner-manifest.d.ts +42 -0
- package/dist/build/action-owner-manifest.js +110 -0
- package/dist/build/clean-output.js +1 -4
- package/dist/build/client-build-config.js +10 -11
- package/dist/build/prerender.d.ts +1 -1
- package/dist/build/prerender.js +12 -6
- package/dist/build/report.d.ts +1 -1
- package/dist/build/route-classification-manifest.d.ts +1 -1
- package/dist/build/static-export.d.ts +1 -1
- package/dist/client/app-nav-failure-handler.js +1 -0
- package/dist/client/navigation-runtime.d.ts +5 -3
- package/dist/client/navigation-runtime.js +4 -8
- package/dist/entries/app-browser-entry.d.ts +1 -1
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +111 -8
- package/dist/entries/pages-client-entry.d.ts +1 -1
- package/dist/entries/pages-server-entry.d.ts +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +119 -26
- package/dist/plugins/action-owner-manifest.d.ts +14 -0
- package/dist/plugins/action-owner-manifest.js +84 -0
- package/dist/plugins/ast-utils.d.ts +30 -1
- package/dist/plugins/ast-utils.js +76 -1
- package/dist/plugins/css-module-imports.d.ts +2 -2
- package/dist/plugins/css-module-imports.js +5 -13
- package/dist/plugins/dynamic-preload-metadata.js +13 -34
- package/dist/plugins/environment.d.ts +11 -0
- package/dist/plugins/environment.js +7 -0
- package/dist/plugins/extensionless-dynamic-import.js +11 -35
- package/dist/plugins/fonts.js +8 -12
- package/dist/plugins/ignore-dynamic-requests.d.ts +2 -4
- package/dist/plugins/ignore-dynamic-requests.js +29 -59
- package/dist/plugins/import-meta-url.d.ts +15 -9
- package/dist/plugins/import-meta-url.js +310 -85
- package/dist/plugins/instrumentation-client.js +4 -5
- package/dist/plugins/middleware-export-validation.js +5 -17
- package/dist/plugins/middleware-server-only.js +2 -2
- package/dist/plugins/og-asset-ownership.js +18 -26
- package/dist/plugins/og-assets.js +2 -4
- package/dist/plugins/optimize-imports.js +2 -4
- package/dist/plugins/pages-node-externals.js +13 -40
- package/dist/plugins/remove-console.js +2 -4
- package/dist/plugins/require-condition-resolution.d.ts +16 -0
- package/dist/plugins/require-condition-resolution.js +167 -0
- package/dist/plugins/require-context.js +11 -46
- package/dist/plugins/sass.js +1 -1
- package/dist/plugins/server-externals-manifest.js +1 -23
- package/dist/plugins/strip-server-exports.js +13 -19
- package/dist/plugins/styled-jsx.js +17 -19
- package/dist/plugins/transform-result.d.ts +10 -0
- package/dist/plugins/transform-result.js +10 -0
- package/dist/plugins/transitive-externals.js +7 -21
- package/dist/plugins/typeof-window.d.ts +3 -8
- package/dist/plugins/typeof-window.js +5 -15
- package/dist/plugins/use-cache-callable.js +12 -22
- package/dist/plugins/wasm-module-import.js +1 -1
- package/dist/plugins/worker-image-imports.d.ts +12 -0
- package/dist/plugins/worker-image-imports.js +136 -0
- package/dist/routing/app-route-graph.d.ts +3 -2
- package/dist/routing/app-route-graph.js +1 -1
- package/dist/routing/route-pattern.d.ts +8 -1
- package/dist/routing/route-pattern.js +28 -1
- package/dist/routing/route-validation.js +7 -1
- package/dist/server/accept-encoding.d.ts +1 -2
- package/dist/server/accept-encoding.js +1 -4
- package/dist/server/app-action-forwarding.d.ts +18 -0
- package/dist/server/app-action-forwarding.js +140 -0
- package/dist/server/app-browser-entry.js +231 -50
- package/dist/server/app-browser-error.d.ts +1 -2
- package/dist/server/app-browser-error.js +1 -5
- package/dist/server/app-browser-history-controller.d.ts +16 -1
- package/dist/server/app-browser-history-controller.js +135 -18
- package/dist/server/app-browser-navigation-abort.d.ts +16 -0
- package/dist/server/app-browser-navigation-abort.js +29 -0
- package/dist/server/app-browser-navigation-controller.d.ts +4 -0
- package/dist/server/app-browser-navigation-controller.js +22 -6
- package/dist/server/app-browser-navigation-response.d.ts +11 -0
- package/dist/server/app-browser-navigation-response.js +8 -0
- package/dist/server/app-browser-popstate.d.ts +6 -1
- package/dist/server/app-browser-popstate.js +6 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-browser-state.d.ts +2 -2
- package/dist/server/app-browser-state.js +3 -3
- package/dist/server/app-browser-stream.d.ts +0 -2
- package/dist/server/app-browser-supplemental-refresh.d.ts +49 -0
- package/dist/server/app-browser-supplemental-refresh.js +190 -0
- package/dist/server/app-browser-visible-commit.js +23 -12
- package/dist/server/app-elements-wire.d.ts +2 -0
- package/dist/server/app-elements-wire.js +7 -0
- package/dist/server/app-history-state.d.ts +22 -1
- package/dist/server/app-history-state.js +93 -9
- package/dist/server/app-optimistic-routing.d.ts +22 -1
- package/dist/server/app-optimistic-routing.js +137 -12
- package/dist/server/app-page-cache-finalizer.d.ts +3 -1
- package/dist/server/app-page-cache-finalizer.js +6 -6
- package/dist/server/app-page-cache.d.ts +2 -1
- package/dist/server/app-page-cache.js +2 -2
- package/dist/server/app-page-dispatch.d.ts +4 -1
- package/dist/server/app-page-dispatch.js +10 -1
- package/dist/server/app-page-element-builder.d.ts +1 -0
- package/dist/server/app-page-element-builder.js +1 -0
- package/dist/server/app-page-ppr-runtime.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -1
- package/dist/server/app-page-render.js +6 -3
- package/dist/server/app-page-request.d.ts +2 -33
- package/dist/server/app-page-request.js +1 -27
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +4 -0
- package/dist/server/app-page-segment-state.d.ts +2 -2
- package/dist/server/app-page-segment-state.js +14 -8
- package/dist/server/app-ppr-fallback-shell.d.ts +2 -2
- package/dist/server/app-ppr-fallback-shell.js +3 -6
- package/dist/server/app-route-handler-dispatch.js +4 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +34 -8
- package/dist/server/app-rsc-handler.d.ts +4 -2
- package/dist/server/app-rsc-handler.js +57 -9
- package/dist/server/app-rsc-request-normalization.d.ts +2 -0
- package/dist/server/app-rsc-request-normalization.js +5 -1
- package/dist/server/app-rsc-route-matching.d.ts +4 -3
- package/dist/server/app-rsc-route-matching.js +14 -42
- package/dist/server/app-server-action-execution.d.ts +3 -0
- package/dist/server/app-server-action-execution.js +77 -2
- package/dist/server/app-ssr-entry.js +6 -6
- package/dist/server/app-ssr-stream.d.ts +1 -1
- package/dist/server/app-ssr-stream.js +2 -2
- package/dist/server/app-visited-response-cache.d.ts +6 -1
- package/dist/server/app-visited-response-cache.js +18 -2
- package/dist/server/dev-route-files.js +2 -5
- package/dist/server/dev-server.d.ts +5 -13
- package/dist/server/dev-server.js +22 -22
- package/dist/server/dev-stack-sourcemap.d.ts +1 -2
- package/dist/server/dev-stack-sourcemap.js +1 -4
- package/dist/server/headers.d.ts +5 -1
- package/dist/server/headers.js +5 -1
- package/dist/server/isr-cache.d.ts +6 -14
- package/dist/server/isr-cache.js +6 -27
- package/dist/server/middleware.d.ts +3 -16
- package/dist/server/middleware.js +2 -19
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +57 -9
- package/dist/server/navigation-trace.d.ts +1 -0
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/pages-data-route.d.ts +1 -10
- package/dist/server/pages-data-route.js +1 -12
- package/dist/server/pages-node-compat.d.ts +1 -4
- package/dist/server/pages-node-compat.js +1 -7
- package/dist/server/pages-readiness.js +4 -4
- package/dist/server/prerender-route-params.d.ts +1 -2
- package/dist/server/prerender-route-params.js +1 -4
- package/dist/server/prod-server.js +3 -1
- package/dist/shims/cache-runtime.js +39 -22
- package/dist/shims/cache.d.ts +1 -1
- package/dist/shims/dynamic.d.ts +3 -3
- package/dist/shims/dynamic.js +4 -6
- package/dist/shims/error.js +1 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +23 -4
- package/dist/shims/internal/app-route-prefetch-policy.d.ts +6 -7
- package/dist/shims/internal/app-route-prefetch-policy.js +5 -4
- package/dist/shims/link.js +1 -1
- package/dist/shims/navigation.d.ts +12 -3
- package/dist/shims/navigation.js +46 -11
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router.js +75 -4
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/utils/built-asset-url.d.ts +1 -1
- package/dist/utils/built-asset-url.js +4 -2
- package/dist/utils/package-name.d.ts +11 -0
- package/dist/utils/package-name.js +18 -0
- package/dist/utils/path.d.ts +8 -1
- package/dist/utils/path.js +21 -1
- package/dist/utils/react-compiler-support.d.ts +20 -0
- package/dist/utils/react-compiler-support.js +29 -0
- package/package.json +3 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { decodeMatchedParams, splitPathSegments, splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
2
2
|
import { buildRouteTrie, trieMatchRaw } from "../routing/route-trie.js";
|
|
3
|
-
import {
|
|
3
|
+
import { createAppRouteGraphInterceptionId } from "../routing/app-route-graph.js";
|
|
4
|
+
import { extractRawRoutePatternParams, matchRoutePatternPrefix, matchRoutePatternRaw } from "../routing/route-pattern.js";
|
|
5
|
+
import { canonicalizeAppPageParams } from "./app-page-segment-state.js";
|
|
4
6
|
//#region src/server/app-rsc-route-matching.ts
|
|
5
7
|
/**
|
|
6
8
|
* Sentinel slot key used for sibling-style interception entries.
|
|
@@ -26,19 +28,6 @@ function appRscInterceptionSourcePathnameParts(pathname) {
|
|
|
26
28
|
}
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
|
-
function canonicalizeAppPageParam(value) {
|
|
30
|
-
try {
|
|
31
|
-
return encodeURIComponent(decodeURIComponent(value));
|
|
32
|
-
} catch {
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function canonicalizeAppPageParams(params) {
|
|
37
|
-
for (const key of Object.keys(params)) {
|
|
38
|
-
const value = params[key];
|
|
39
|
-
params[key] = Array.isArray(value) ? value.map(canonicalizeAppPageParam) : canonicalizeAppPageParam(value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
31
|
function isAppRouteHandlerRoute(route) {
|
|
43
32
|
return route.routeHandler != null || typeof route.__loadRouteHandler === "function";
|
|
44
33
|
}
|
|
@@ -46,37 +35,20 @@ function normalizeMatchedParamsForRoute(result) {
|
|
|
46
35
|
if (isAppRouteHandlerRoute(result.route)) decodeMatchedParams(result.params);
|
|
47
36
|
else canonicalizeAppPageParams(result.params);
|
|
48
37
|
}
|
|
49
|
-
function extractRawParamsForMatchedRoute(patternParts, pathnameParts) {
|
|
50
|
-
const params = createRouteParams();
|
|
51
|
-
let pathnameIndex = 0;
|
|
52
|
-
for (const part of patternParts) {
|
|
53
|
-
if (!part.startsWith(":")) {
|
|
54
|
-
pathnameIndex += 1;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
const isCatchAll = part.endsWith("+") || part.endsWith("*");
|
|
58
|
-
const paramName = part.slice(1, isCatchAll ? -1 : void 0);
|
|
59
|
-
if (isCatchAll) {
|
|
60
|
-
const remaining = pathnameParts.slice(pathnameIndex);
|
|
61
|
-
if (remaining.length > 0) params[paramName] = [...remaining];
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
const value = pathnameParts[pathnameIndex];
|
|
65
|
-
if (value !== void 0) params[paramName] = value;
|
|
66
|
-
pathnameIndex += 1;
|
|
67
|
-
}
|
|
68
|
-
return params;
|
|
69
|
-
}
|
|
70
38
|
function createAppRscRouteMatcher(routes) {
|
|
71
39
|
const routeTrie = buildRouteTrie(routes);
|
|
72
40
|
const interceptLookup = createInterceptLookup(routes);
|
|
41
|
+
const interceptionIds = new Set(interceptLookup.flatMap((entry) => entry.interceptionId === null ? [] : [entry.interceptionId]));
|
|
73
42
|
const routeIndexes = new Map(routes.map((route, index) => [route, index]));
|
|
74
43
|
return {
|
|
44
|
+
hasInterceptionId(interceptionId) {
|
|
45
|
+
return interceptionIds.has(interceptionId);
|
|
46
|
+
},
|
|
75
47
|
matchRoute(url) {
|
|
76
48
|
const rawParts = appRscPathnameParts(url, true);
|
|
77
49
|
const result = trieMatchRaw(routeTrie, appRscPathnameParts(url, false));
|
|
78
50
|
if (!result) return null;
|
|
79
|
-
result.params =
|
|
51
|
+
result.params = extractRawRoutePatternParams(result.route.patternParts, rawParts);
|
|
80
52
|
normalizeMatchedParamsForRoute(result);
|
|
81
53
|
return result;
|
|
82
54
|
},
|
|
@@ -86,12 +58,13 @@ function createAppRscRouteMatcher(routes) {
|
|
|
86
58
|
normalizeMatchedParamsForRoute(result);
|
|
87
59
|
return result;
|
|
88
60
|
},
|
|
89
|
-
findIntercept(pathname, sourcePathname = null) {
|
|
61
|
+
findIntercept(pathname, sourcePathname = null, interceptionId = null) {
|
|
90
62
|
if (sourcePathname === null) return null;
|
|
91
63
|
const urlParts = appRscPathnameParts(pathname, true);
|
|
92
64
|
const sourceParts = appRscInterceptionSourcePathnameParts(sourcePathname);
|
|
93
65
|
const matchedSourceRoute = trieMatchRaw(routeTrie, sourceParts);
|
|
94
66
|
for (const entry of interceptLookup) {
|
|
67
|
+
if (interceptionId !== null && entry.interceptionId !== interceptionId) continue;
|
|
95
68
|
if (!matchInterceptSource(sourceParts, entry)) continue;
|
|
96
69
|
const params = matchRoutePatternRaw(urlParts, entry.targetPatternParts);
|
|
97
70
|
if (params === null) continue;
|
|
@@ -130,7 +103,7 @@ function matchSlotOwnerSourceParams(sourceParts, patternParts, descendantsAllowe
|
|
|
130
103
|
const exact = matchRoutePatternRaw(sourceParts, patternParts);
|
|
131
104
|
if (exact !== null) return exact;
|
|
132
105
|
if (!descendantsAllowed || !matchRoutePatternPrefix(sourceParts, patternParts)) return null;
|
|
133
|
-
return
|
|
106
|
+
return extractRawRoutePatternParams(patternParts, sourceParts);
|
|
134
107
|
}
|
|
135
108
|
/**
|
|
136
109
|
* Check whether the request's source pathname (Next-URL / interception
|
|
@@ -200,6 +173,7 @@ function createInterceptLookup(routes) {
|
|
|
200
173
|
const sourceMatchPatternParts = sourceMatchPattern ? sourceMatchPattern.split("/").filter(Boolean) : null;
|
|
201
174
|
const ownerRouteIndex = sourceMatchPattern !== null ? patternToIndex.get(sourceMatchPattern) ?? routeIndex : routeIndex;
|
|
202
175
|
interceptLookup.push({
|
|
176
|
+
interceptionId: typeof slotModule.id === "string" && sourceMatchPattern !== null ? createAppRouteGraphInterceptionId(slotModule.id, sourceMatchPattern, intercept.targetPattern) : null,
|
|
203
177
|
interceptionGraphId: null,
|
|
204
178
|
sourceRouteIndex: ownerRouteIndex,
|
|
205
179
|
slotKey,
|
|
@@ -238,6 +212,7 @@ function createInterceptLookup(routes) {
|
|
|
238
212
|
const sourceMatchPattern = intercept.sourceMatchPattern ?? null;
|
|
239
213
|
const sourceMatchPatternParts = sourceMatchPattern ? sourceMatchPattern.split("/").filter(Boolean) : null;
|
|
240
214
|
interceptLookup.push({
|
|
215
|
+
interceptionId: typeof intercept.id === "string" ? intercept.id : null,
|
|
241
216
|
interceptionGraphId: typeof intercept.id === "string" ? intercept.id : null,
|
|
242
217
|
sourceRouteIndex: routeIndex,
|
|
243
218
|
slotKey: SIBLING_PAGE_INTERCEPT_SLOT_KEY,
|
|
@@ -274,9 +249,6 @@ function createInterceptLookup(routes) {
|
|
|
274
249
|
}
|
|
275
250
|
return interceptLookup.sort(compareInterceptTargetPatterns);
|
|
276
251
|
}
|
|
277
|
-
function matchAppRscRoutePattern(urlParts, patternParts) {
|
|
278
|
-
return matchRoutePattern(urlParts, patternParts);
|
|
279
|
-
}
|
|
280
252
|
function mergeMatchedParams(sourceParams, targetParams) {
|
|
281
253
|
return Object.assign(createRouteParams(), sourceParams, targetParams);
|
|
282
254
|
}
|
|
@@ -291,4 +263,4 @@ function pickPatternParams(params, patternParts) {
|
|
|
291
263
|
return picked;
|
|
292
264
|
}
|
|
293
265
|
//#endregion
|
|
294
|
-
export { SIBLING_PAGE_INTERCEPT_SLOT_KEY, createAppRscRouteMatcher
|
|
266
|
+
export { SIBLING_PAGE_INTERCEPT_SLOT_KEY, createAppRscRouteMatcher };
|
|
@@ -134,6 +134,8 @@ type HandleProgressiveServerActionRequestOptions = {
|
|
|
134
134
|
decodeFormState: AppServerActionFormStateDecoder;
|
|
135
135
|
getAndClearPendingCookies: () => string[];
|
|
136
136
|
getDraftModeCookieHeader: () => string | null | undefined;
|
|
137
|
+
forwardAction?: (actionId: string) => Promise<Response | null>;
|
|
138
|
+
validateActionReferences?: (actionIds: readonly string[]) => boolean;
|
|
137
139
|
/**
|
|
138
140
|
* Whether the posted-to route resolves to an App Router *page* (as opposed to
|
|
139
141
|
* a route handler or no match). Multipart form POSTs to a page are always
|
|
@@ -213,6 +215,7 @@ type HandleServerActionRscRequestOptions<TElement, TRoute extends AppServerActio
|
|
|
213
215
|
renderToReadableStream: (model: AppServerActionRscModel<TElement>, options: RenderServerActionRscStreamOptions<TTemporaryReferences>) => BodyInit | null | Promise<BodyInit | null>;
|
|
214
216
|
reportRequestError: AppServerActionErrorReporter;
|
|
215
217
|
resolveRouteFetchCacheMode?: (route: TRoute) => FetchCacheMode | null;
|
|
218
|
+
resolveRouteRevalidateSeconds?: (route: TRoute) => number | null;
|
|
216
219
|
resolveRouteDynamicConfig?: (route: TRoute) => string | null | undefined;
|
|
217
220
|
resolveRouteRuntime?: (route: TRoute) => AppServerActionRouteRuntime;
|
|
218
221
|
request: Request;
|
|
@@ -10,7 +10,7 @@ import { attachRequestCfMetadata, validateCsrfOrigin, validateServerActionPayloa
|
|
|
10
10
|
import { APP_RSC_RENDER_MODE_NAVIGATION } from "./app-rsc-render-mode.js";
|
|
11
11
|
import { isDraftModeRequest, setHeadersContext } from "../shims/headers.js";
|
|
12
12
|
import { _drainPendingRevalidations, getAndClearActionRevalidationKind } from "../shims/cache-request-state.js";
|
|
13
|
-
import { setCurrentFetchCacheMode, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault } from "../shims/fetch-cache.js";
|
|
13
|
+
import { setCurrentFetchCacheMode, setCurrentFetchRevalidate, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault } from "../shims/fetch-cache.js";
|
|
14
14
|
import { readStreamAsTextWithLimit } from "../utils/text-stream.js";
|
|
15
15
|
import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader, createRscRequestUrl, stripRscCacheBustingSearchParam } from "./app-rsc-cache-busting.js";
|
|
16
16
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
@@ -18,15 +18,56 @@ import { applyEdgeRuntimeHeader } from "./app-page-response.js";
|
|
|
18
18
|
import { getNextErrorDigest, parseNextHttpErrorDigest, parseNextRedirectDigest } from "./next-error-digest.js";
|
|
19
19
|
import { buildAppPageTags } from "./implicit-tags.js";
|
|
20
20
|
import { getSetCookieName } from "./cookie-utils.js";
|
|
21
|
+
import { createRootParamsUsageController, runWithRootParamsUsage } from "../shims/root-params.js";
|
|
21
22
|
import { createServerActionNotFoundResponse, getServerActionNotFoundMessage, isServerActionNotFoundError } from "./server-action-not-found.js";
|
|
22
23
|
import { resolveAppPageNavigationParams } from "./app-page-element-builder.js";
|
|
23
24
|
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
24
25
|
import "./app-page-stream.js";
|
|
25
26
|
import { resolveAppPageActionRerenderTarget } from "./app-page-request.js";
|
|
26
|
-
import { createRootParamsUsageController, runWithRootParamsUsage } from "../shims/root-params.js";
|
|
27
27
|
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
28
28
|
import { markAppRscResponseConfigHeadersApplied } from "./app-rsc-response-finalizer.js";
|
|
29
29
|
//#region src/server/app-server-action-execution.ts
|
|
30
|
+
function parseBoundProgressiveActionReference(body, referencePrefix) {
|
|
31
|
+
const fieldPrefix = `$ACTION_${referencePrefix}:`;
|
|
32
|
+
const chunks = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const [key, value] of body) {
|
|
34
|
+
if (!key.startsWith(fieldPrefix) || typeof value !== "string") continue;
|
|
35
|
+
const chunkId = key.slice(fieldPrefix.length);
|
|
36
|
+
if (chunks.has(chunkId)) return null;
|
|
37
|
+
try {
|
|
38
|
+
chunks.set(chunkId, JSON.parse(value));
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const rootMetadata = chunks.get("0");
|
|
44
|
+
if (typeof rootMetadata !== "object" || rootMetadata === null || typeof Reflect.get(rootMetadata, "id") !== "string") return null;
|
|
45
|
+
const actionId = Reflect.get(rootMetadata, "id");
|
|
46
|
+
const referencedActionIds = /* @__PURE__ */ new Set([actionId]);
|
|
47
|
+
for (const chunk of chunks.values()) {
|
|
48
|
+
const values = [chunk];
|
|
49
|
+
while (values.length > 0) {
|
|
50
|
+
const value = values.pop();
|
|
51
|
+
if (typeof value === "string") {
|
|
52
|
+
if (!value.startsWith("$h")) continue;
|
|
53
|
+
const [encodedChunkId, ...path] = value.slice(2).split(":");
|
|
54
|
+
const chunkId = Number.parseInt(encodedChunkId, 16);
|
|
55
|
+
if (!Number.isSafeInteger(chunkId) || chunkId < 0) return null;
|
|
56
|
+
let metadata = chunks.get(String(chunkId));
|
|
57
|
+
for (const segment of path) {
|
|
58
|
+
if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, segment)) return null;
|
|
59
|
+
metadata = Reflect.get(metadata, segment);
|
|
60
|
+
}
|
|
61
|
+
if (typeof metadata !== "object" || metadata === null || typeof Reflect.get(metadata, "id") !== "string") return null;
|
|
62
|
+
referencedActionIds.add(Reflect.get(metadata, "id"));
|
|
63
|
+
} else if (typeof value === "object" && value !== null) values.push(...Object.values(value));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
actionId,
|
|
68
|
+
referencedActionIds: [...referencedActionIds]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
30
71
|
function prepareActionPageRerenderContext(options) {
|
|
31
72
|
if (options.dynamicConfig === "force-static" || options.dynamicConfig === "error") setHeadersContext(createStaticGenerationHeadersContext({
|
|
32
73
|
draftModeEnabled: isDraftModeRequest(createActionRerenderRequest({
|
|
@@ -462,6 +503,34 @@ async function handleProgressiveServerActionRequest(options) {
|
|
|
462
503
|
options.clearRequestContext();
|
|
463
504
|
return payloadResponse;
|
|
464
505
|
}
|
|
506
|
+
let actionKey = null;
|
|
507
|
+
for (const key of body.keys()) if (key.startsWith("$ACTION_ID_") || key.startsWith("$ACTION_REF_")) actionKey = key;
|
|
508
|
+
let directActionId = null;
|
|
509
|
+
let referencedActionIds = [];
|
|
510
|
+
let invalidDirectActionReference = false;
|
|
511
|
+
if (actionKey?.startsWith("$ACTION_ID_")) {
|
|
512
|
+
directActionId = actionKey.slice(11);
|
|
513
|
+
referencedActionIds = [directActionId];
|
|
514
|
+
} else if (actionKey?.startsWith("$ACTION_REF_")) {
|
|
515
|
+
const referencePrefix = actionKey.slice(12);
|
|
516
|
+
const reference = parseBoundProgressiveActionReference(body, referencePrefix);
|
|
517
|
+
if (reference) {
|
|
518
|
+
directActionId = reference.actionId;
|
|
519
|
+
referencedActionIds = reference.referencedActionIds;
|
|
520
|
+
} else invalidDirectActionReference = true;
|
|
521
|
+
}
|
|
522
|
+
if (invalidDirectActionReference) return createActionNotFoundResponse(null, {
|
|
523
|
+
clearRequestContext: options.clearRequestContext,
|
|
524
|
+
getAndClearPendingCookies: options.getAndClearPendingCookies
|
|
525
|
+
});
|
|
526
|
+
if (directActionId && options.forwardAction) {
|
|
527
|
+
const forwardResponse = await options.forwardAction(directActionId);
|
|
528
|
+
if (forwardResponse) return forwardResponse;
|
|
529
|
+
}
|
|
530
|
+
if (options.validateActionReferences && !options.validateActionReferences(referencedActionIds)) return createActionNotFoundResponse(directActionId, {
|
|
531
|
+
clearRequestContext: options.clearRequestContext,
|
|
532
|
+
getAndClearPendingCookies: options.getAndClearPendingCookies
|
|
533
|
+
});
|
|
465
534
|
const action = await options.decodeAction(body);
|
|
466
535
|
if (!isAppServerActionFunction(action)) {
|
|
467
536
|
if (options.hasPageRoute) return createActionNotFoundResponse(null, {
|
|
@@ -470,6 +539,11 @@ async function handleProgressiveServerActionRequest(options) {
|
|
|
470
539
|
});
|
|
471
540
|
return null;
|
|
472
541
|
}
|
|
542
|
+
const decodedActionId = Reflect.get(action, "$$id");
|
|
543
|
+
if (typeof decodedActionId === "string" && decodedActionId !== directActionId && options.forwardAction) {
|
|
544
|
+
const forwardResponse = await options.forwardAction(decodedActionId);
|
|
545
|
+
if (forwardResponse) return forwardResponse;
|
|
546
|
+
}
|
|
473
547
|
let actionRedirect = null;
|
|
474
548
|
let actionError = void 0;
|
|
475
549
|
let actionFailed = false;
|
|
@@ -847,6 +921,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
847
921
|
params: resolvedActionNavigationParams
|
|
848
922
|
});
|
|
849
923
|
setCurrentFetchCacheMode(options.resolveRouteFetchCacheMode?.(actionRerenderTarget.route) ?? null);
|
|
924
|
+
setCurrentFetchRevalidate(options.resolveRouteRevalidateSeconds?.(actionRerenderTarget.route) ?? null);
|
|
850
925
|
setCurrentForceDynamicFetchDefault(actionRerenderDynamicConfig === "force-dynamic");
|
|
851
926
|
setCurrentFetchSoftTags(buildServerActionPageTags(actionRerenderTarget.route, options.cleanPathname));
|
|
852
927
|
const buildActionRerenderElement = () => options.buildPageElement({
|
|
@@ -16,13 +16,13 @@ import DefaultGlobalError from "../shims/default-global-error.js";
|
|
|
16
16
|
import { BfcacheIdentityMapContext, ElementsContext, Slot } from "../shims/slot.js";
|
|
17
17
|
import { createSsrErrorMetaRenderer } from "./app-ssr-error-meta.js";
|
|
18
18
|
import { createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform, waitAtLeastOneReactRenderTask } from "./app-ssr-stream.js";
|
|
19
|
+
import { BeforeInteractiveContext } from "../shims/before-interactive-context.js";
|
|
20
|
+
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
21
|
+
import { runWithNavigationContext } from "../shims/navigation-state.js";
|
|
19
22
|
import { createInitialBfcacheMaps } from "./app-bfcache-identity.js";
|
|
20
23
|
import { RSC_FORM_STATE_GLOBAL } from "./app-browser-hydration.js";
|
|
21
24
|
import { createClientReferencePreloader } from "./app-client-reference-preloader.js";
|
|
22
25
|
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
23
|
-
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
24
|
-
import { runWithNavigationContext } from "../shims/navigation-state.js";
|
|
25
|
-
import { BeforeInteractiveContext } from "../shims/before-interactive-context.js";
|
|
26
26
|
import { renderBeforeInteractiveInlineScripts } from "./before-interactive-head.js";
|
|
27
27
|
import { createInitialDevServerErrorScript } from "./dev-initial-server-error.js";
|
|
28
28
|
import { ssrAppRouterInstance } from "./app-ssr-router-instance.js";
|
|
@@ -153,12 +153,12 @@ function buildModulePreloadHtml(bootstrapModuleUrl, nonce) {
|
|
|
153
153
|
if (!bootstrapModuleUrl) return "";
|
|
154
154
|
return `<link rel="modulepreload"${createNonceAttribute(nonce)} href="${escapeHtmlAttr(bootstrapModuleUrl)}" />\n`;
|
|
155
155
|
}
|
|
156
|
-
function buildHeadInjectionHtml(navContext, bootstrapModuleUrl, formState, insertedHTML, fontHTML, dynamicStaleTimeSeconds, scriptNonce) {
|
|
156
|
+
function buildHeadInjectionHtml(navContext, bootstrapModuleUrl, formState, insertedHTML, fontHTML, dynamicStaleTimeSeconds, searchParamsFromBrowser, scriptNonce) {
|
|
157
157
|
const navPayload = {
|
|
158
158
|
pathname: navContext.pathname,
|
|
159
159
|
searchParams: [...navContext.searchParams.entries()]
|
|
160
160
|
};
|
|
161
|
-
return createInlineScriptTag(createNavigationRuntimeRscMetadataScript(navContext.params, navPayload, dynamicStaleTimeSeconds), scriptNonce) + (formState === null ? "" : createInlineScriptTag("self[" + safeJsonStringify(RSC_FORM_STATE_GLOBAL) + "]=" + safeJsonStringify(formState), scriptNonce)) + buildModulePreloadHtml(bootstrapModuleUrl, scriptNonce) + insertedHTML + fontHTML;
|
|
161
|
+
return createInlineScriptTag(createNavigationRuntimeRscMetadataScript(navContext.params, navPayload, dynamicStaleTimeSeconds, searchParamsFromBrowser), scriptNonce) + (formState === null ? "" : createInlineScriptTag("self[" + safeJsonStringify(RSC_FORM_STATE_GLOBAL) + "]=" + safeJsonStringify(formState), scriptNonce)) + buildModulePreloadHtml(bootstrapModuleUrl, scriptNonce) + insertedHTML + fontHTML;
|
|
162
162
|
}
|
|
163
163
|
function requireNavigationContext(navContext) {
|
|
164
164
|
if (!navContext) throw new Error("App SSR requires navigation context for BFCache state keys");
|
|
@@ -291,7 +291,7 @@ async function handleSsr(rscStream, navContext, fontData, options) {
|
|
|
291
291
|
const initialDevServerErrorHTML = createInitialDevServerErrorScript(options?.initialDevServerError, options?.scriptNonce);
|
|
292
292
|
if (didInjectHeadHTML) return insertedHTML + errorMetaHTML;
|
|
293
293
|
didInjectHeadHTML = true;
|
|
294
|
-
return buildHeadInjectionHtml(ssrNavigationContext, bootstrapModuleUrl, options?.formState ?? null, insertedHTML + errorMetaHTML + getTraceMetaHTML() + initialDevServerErrorHTML, fontHTML, options?.dynamicStaleTimeSeconds, options?.scriptNonce);
|
|
294
|
+
return buildHeadInjectionHtml(ssrNavigationContext, bootstrapModuleUrl, options?.formState ?? null, insertedHTML + errorMetaHTML + getTraceMetaHTML() + initialDevServerErrorHTML, fontHTML, options?.dynamicStaleTimeSeconds, options?.isStaticGeneration === true ? options.isForceStatic !== true : void 0, options?.scriptNonce);
|
|
295
295
|
};
|
|
296
296
|
const getBeforeInteractiveHeadHTML = () => renderBeforeInteractiveInlineScripts(beforeInteractiveInlineScripts);
|
|
297
297
|
if (shouldDelayInitialHtmlPull) await waitAtLeastOneReactRenderTask();
|
|
@@ -26,7 +26,7 @@ declare function navigationRuntimeRscBootstrapExpression(): string;
|
|
|
26
26
|
declare function createNavigationRuntimeRscMetadataScript(params: Record<string, string | string[]>, nav: {
|
|
27
27
|
pathname: string;
|
|
28
28
|
searchParams: [string, string][];
|
|
29
|
-
}, dynamicStaleTimeSeconds?: number): string;
|
|
29
|
+
}, dynamicStaleTimeSeconds?: number, searchParamsFromBrowser?: boolean): string;
|
|
30
30
|
/**
|
|
31
31
|
* Create a helper that progressively embeds RSC chunks as inline <script> tags.
|
|
32
32
|
* The browser entry turns the embedded chunks back into Uint8Array data.
|
|
@@ -9,8 +9,8 @@ const NAVIGATION_RUNTIME_REFERENCE = `self[Symbol.for(${safeJsonStringify(NAVIGA
|
|
|
9
9
|
function navigationRuntimeRscBootstrapExpression() {
|
|
10
10
|
return `((${NAVIGATION_RUNTIME_REFERENCE}??={bootstrap:{routeManifest:null},functions:{}}).bootstrap.rsc??={rsc:[]})`;
|
|
11
11
|
}
|
|
12
|
-
function createNavigationRuntimeRscMetadataScript(params, nav, dynamicStaleTimeSeconds) {
|
|
13
|
-
return "Object.assign(" + navigationRuntimeRscBootstrapExpression() + ",{params:" + safeJsonStringify(params) + ",nav:" + safeJsonStringify(nav) + (dynamicStaleTimeSeconds === void 0 ? "" : ",dynamicStaleTimeSeconds:" + safeJsonStringify(dynamicStaleTimeSeconds)) + "})";
|
|
12
|
+
function createNavigationRuntimeRscMetadataScript(params, nav, dynamicStaleTimeSeconds, searchParamsFromBrowser) {
|
|
13
|
+
return "Object.assign(" + navigationRuntimeRscBootstrapExpression() + ",{params:" + safeJsonStringify(params) + ",nav:" + safeJsonStringify(nav) + (searchParamsFromBrowser === void 0 ? "" : ",searchParamsFromBrowser:" + safeJsonStringify(searchParamsFromBrowser)) + (dynamicStaleTimeSeconds === void 0 ? "" : ",dynamicStaleTimeSeconds:" + safeJsonStringify(dynamicStaleTimeSeconds)) + "})";
|
|
14
14
|
}
|
|
15
15
|
function createNavigationRuntimeRscChunkScript(chunk) {
|
|
16
16
|
return navigationRuntimeRscBootstrapExpression() + ".rsc.push(" + safeJsonStringify(chunk) + ")";
|
|
@@ -10,9 +10,11 @@ type VisitedResponseCacheEntry = {
|
|
|
10
10
|
mountedSlotsHeader: string | null;
|
|
11
11
|
params: Record<string, string | string[]>;
|
|
12
12
|
response: CachedRscResponse;
|
|
13
|
+
reuseAfterHistoryRestore: boolean;
|
|
13
14
|
};
|
|
14
15
|
declare const VISITED_RESPONSE_CACHE_TTL: number;
|
|
15
16
|
declare const MAX_TRAVERSAL_CACHE_TTL: number;
|
|
17
|
+
declare function hasNavigationResponseHistoryLifetime(snapshot: CachedRscResponse): boolean;
|
|
16
18
|
declare function createVisitedResponseCacheEntry(options: {
|
|
17
19
|
elements?: AppElements;
|
|
18
20
|
fallbackTtlMs?: number;
|
|
@@ -20,6 +22,7 @@ declare function createVisitedResponseCacheEntry(options: {
|
|
|
20
22
|
mountedSlotsHeader?: string | null;
|
|
21
23
|
params: Record<string, string | string[]>;
|
|
22
24
|
response: CachedRscResponse;
|
|
25
|
+
reuseAfterHistoryRestore?: boolean;
|
|
23
26
|
}): VisitedResponseCacheEntry;
|
|
24
27
|
declare function isVisitedResponseCacheEntryFresh(entry: VisitedResponseCacheEntry, options: {
|
|
25
28
|
navigationKind: VisitedResponseCacheNavigationKind;
|
|
@@ -30,5 +33,7 @@ declare function findVisitedResponseCacheEntry(cache: Map<string, VisitedRespons
|
|
|
30
33
|
entry: VisitedResponseCacheEntry;
|
|
31
34
|
} | null;
|
|
32
35
|
declare function deleteVisitedResponseCacheEntry(cache: Map<string, VisitedResponseCacheEntry>, rscUrl: string, interceptionContext: string | null): boolean;
|
|
36
|
+
declare function deleteAllVisitedResponseCacheEntries(cache: Map<string, VisitedResponseCacheEntry>, rscUrl: string, interceptionContext: string | null): number;
|
|
37
|
+
declare function deleteInvalidatedHistoryRestoreEntries(cache: Map<string, VisitedResponseCacheEntry>): void;
|
|
33
38
|
//#endregion
|
|
34
|
-
export { MAX_TRAVERSAL_CACHE_TTL, VISITED_RESPONSE_CACHE_TTL, VisitedResponseCacheEntry, createVisitedResponseCacheEntry, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, isVisitedResponseCacheEntryFresh };
|
|
39
|
+
export { MAX_TRAVERSAL_CACHE_TTL, VISITED_RESPONSE_CACHE_TTL, VisitedResponseCacheEntry, createVisitedResponseCacheEntry, deleteAllVisitedResponseCacheEntries, deleteInvalidatedHistoryRestoreEntries, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, hasNavigationResponseHistoryLifetime, isVisitedResponseCacheEntryFresh };
|
|
@@ -5,6 +5,10 @@ import { resolveCachedRscResponseExpiresAt } from "../shims/navigation.js";
|
|
|
5
5
|
//#region src/server/app-visited-response-cache.ts
|
|
6
6
|
const VISITED_RESPONSE_CACHE_TTL = 5 * 6e4;
|
|
7
7
|
const MAX_TRAVERSAL_CACHE_TTL = 30 * 6e4;
|
|
8
|
+
function hasNavigationResponseHistoryLifetime(snapshot) {
|
|
9
|
+
const dynamicStaleTime = snapshot.completedDynamicStaleTimeSeconds ?? snapshot.dynamicStaleTimeSeconds;
|
|
10
|
+
return dynamicStaleTime !== void 0 ? dynamicStaleTime > 0 : snapshot.serverStaleTime !== void 0;
|
|
11
|
+
}
|
|
8
12
|
function createVisitedResponseCacheEntry(options) {
|
|
9
13
|
return {
|
|
10
14
|
createdAt: options.now,
|
|
@@ -12,7 +16,8 @@ function createVisitedResponseCacheEntry(options) {
|
|
|
12
16
|
expiresAt: resolveCachedRscResponseExpiresAt(options.now, options.response, options.fallbackTtlMs ?? 3e5),
|
|
13
17
|
mountedSlotsHeader: options.mountedSlotsHeader ?? null,
|
|
14
18
|
params: options.params,
|
|
15
|
-
response: options.response
|
|
19
|
+
response: options.response,
|
|
20
|
+
reuseAfterHistoryRestore: options.reuseAfterHistoryRestore === true
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
23
|
function isVisitedResponseCacheEntryFresh(entry, options) {
|
|
@@ -65,5 +70,16 @@ function deleteVisitedResponseCacheEntry(cache, rscUrl, interceptionContext) {
|
|
|
65
70
|
if (!match) return false;
|
|
66
71
|
return cache.delete(match.cacheKey);
|
|
67
72
|
}
|
|
73
|
+
function deleteAllVisitedResponseCacheEntries(cache, rscUrl, interceptionContext) {
|
|
74
|
+
let deleted = 0;
|
|
75
|
+
while (deleteVisitedResponseCacheEntry(cache, rscUrl, interceptionContext)) deleted++;
|
|
76
|
+
return deleted;
|
|
77
|
+
}
|
|
78
|
+
function deleteInvalidatedHistoryRestoreEntries(cache) {
|
|
79
|
+
for (const [cacheKey, entry] of cache) {
|
|
80
|
+
if (entry.reuseAfterHistoryRestore) continue;
|
|
81
|
+
cache.delete(cacheKey);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
68
84
|
//#endregion
|
|
69
|
-
export { MAX_TRAVERSAL_CACHE_TTL, VISITED_RESPONSE_CACHE_TTL, createVisitedResponseCacheEntry, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, isVisitedResponseCacheEntryFresh };
|
|
85
|
+
export { MAX_TRAVERSAL_CACHE_TTL, VISITED_RESPONSE_CACHE_TTL, createVisitedResponseCacheEntry, deleteAllVisitedResponseCacheEntries, deleteInvalidatedHistoryRestoreEntries, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, hasNavigationResponseHistoryLifetime, isVisitedResponseCacheEntryFresh };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
|
+
import { isPathInside } from "../utils/path.js";
|
|
2
3
|
import { METADATA_FILE_MAP, matchMetadataFileBaseName } from "./metadata-routes.js";
|
|
3
4
|
//#region src/server/dev-route-files.ts
|
|
4
5
|
const APP_ROUTER_STRUCTURE_FILES = [
|
|
@@ -13,10 +14,6 @@ const APP_ROUTER_STRUCTURE_FILES = [
|
|
|
13
14
|
"forbidden",
|
|
14
15
|
"unauthorized"
|
|
15
16
|
];
|
|
16
|
-
function isInsideDirectory(dir, filePath) {
|
|
17
|
-
const relativePath = path.relative(dir, filePath);
|
|
18
|
-
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
19
|
-
}
|
|
20
17
|
function relativeParts(dir, filePath) {
|
|
21
18
|
return path.relative(dir, filePath).split(path.sep).filter(Boolean);
|
|
22
19
|
}
|
|
@@ -64,7 +61,7 @@ function isMetadataRouteFile(parts) {
|
|
|
64
61
|
return false;
|
|
65
62
|
}
|
|
66
63
|
function shouldInvalidateAppRouteFile(appDir, filePath, matcher) {
|
|
67
|
-
if (!
|
|
64
|
+
if (!isPathInside(appDir, filePath)) return false;
|
|
68
65
|
const parts = relativeParts(appDir, filePath);
|
|
69
66
|
if (parts.length === 0 || isPrivateAppPath(parts)) return false;
|
|
70
67
|
const fileName = parts[parts.length - 1];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NextI18nConfig } from "../config/next-config.js";
|
|
2
1
|
import { ValidFileMatcher } from "../routing/file-matcher.js";
|
|
2
|
+
import { NextI18nConfig } from "../config/next-config.js";
|
|
3
3
|
import { Route } from "../routing/pages-router.js";
|
|
4
4
|
import { ModuleImporter } from "./instrumentation.js";
|
|
5
5
|
import { ViteDevServer } from "vite";
|
|
@@ -15,16 +15,6 @@ declare function extractLocaleFromUrl(url: string, i18nConfig: NextI18nConfig):
|
|
|
15
15
|
url: string;
|
|
16
16
|
hadPrefix: boolean;
|
|
17
17
|
};
|
|
18
|
-
/**
|
|
19
|
-
* Detect the preferred locale from the Accept-Language header.
|
|
20
|
-
* Returns the best matching locale or null.
|
|
21
|
-
*/
|
|
22
|
-
declare function detectLocaleFromHeaders(req: IncomingMessage, i18nConfig: NextI18nConfig): string | null;
|
|
23
|
-
/**
|
|
24
|
-
* Parse the NEXT_LOCALE cookie from a request.
|
|
25
|
-
* Returns the cookie value if it matches a configured locale, otherwise null.
|
|
26
|
-
*/
|
|
27
|
-
declare function parseCookieLocale(req: IncomingMessage, i18nConfig: NextI18nConfig): string | null;
|
|
28
18
|
/**
|
|
29
19
|
* Create an SSR request handler for the Pages Router.
|
|
30
20
|
*
|
|
@@ -52,7 +42,9 @@ clientTraceMetadata?: readonly string[], htmlLimitedBots?: string,
|
|
|
52
42
|
*/
|
|
53
43
|
reactStrictMode?: boolean,
|
|
54
44
|
/** Next.js `expireTime`, used when formatting terminal GSP responses. */
|
|
55
|
-
expireTime?: number, crossOrigin?: string
|
|
45
|
+
expireTime?: number, crossOrigin?: string,
|
|
46
|
+
/** Resolved Pages Router build ID shared with the dev data-route parser. */
|
|
47
|
+
buildId?: string): (req: IncomingMessage, res: ServerResponse, url: string,
|
|
56
48
|
/** Status code override — propagated from middleware rewrite status. */
|
|
57
49
|
statusCode?: number,
|
|
58
50
|
/**
|
|
@@ -63,4 +55,4 @@ statusCode?: number,
|
|
|
63
55
|
*/
|
|
64
56
|
isDataReq?: boolean, originalUrl?: string) => Promise<void>;
|
|
65
57
|
//#endregion
|
|
66
|
-
export { createSSRHandler,
|
|
58
|
+
export { createSSRHandler, extractLocaleFromUrl };
|
|
@@ -6,7 +6,7 @@ import { PRERENDER_REVALIDATE_HEADER } from "../utils/protocol-headers.js";
|
|
|
6
6
|
import { NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
|
|
7
7
|
import { isDangerousScheme } from "../shims/url-safety.js";
|
|
8
8
|
import { sanitizeDestination } from "../config/config-matchers.js";
|
|
9
|
-
import {
|
|
9
|
+
import { extractLocaleFromUrl as extractLocaleFromUrl$1, resolvePagesI18nRequest } from "./pages-i18n.js";
|
|
10
10
|
import { importModule, reportRequestError } from "./instrumentation.js";
|
|
11
11
|
import { NEVER_CACHE_CONTROL } from "./cache-control.js";
|
|
12
12
|
import { buildMissIsrCacheControl } from "./isr-decision.js";
|
|
@@ -273,20 +273,6 @@ function extractLocaleFromUrl(url, i18nConfig) {
|
|
|
273
273
|
return extractLocaleFromUrl$1(url, i18nConfig);
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
|
-
* Detect the preferred locale from the Accept-Language header.
|
|
277
|
-
* Returns the best matching locale or null.
|
|
278
|
-
*/
|
|
279
|
-
function detectLocaleFromHeaders(req, i18nConfig) {
|
|
280
|
-
return detectLocaleFromAcceptLanguage(req.headers["accept-language"], i18nConfig);
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Parse the NEXT_LOCALE cookie from a request.
|
|
284
|
-
* Returns the cookie value if it matches a configured locale, otherwise null.
|
|
285
|
-
*/
|
|
286
|
-
function parseCookieLocale(req, i18nConfig) {
|
|
287
|
-
return parseCookieLocaleFromHeader(req.headers.cookie, i18nConfig);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
276
|
* Create an SSR request handler for the Pages Router.
|
|
291
277
|
*
|
|
292
278
|
* For each request:
|
|
@@ -296,7 +282,7 @@ function parseCookieLocale(req, i18nConfig) {
|
|
|
296
282
|
* 4. Render the component to HTML
|
|
297
283
|
* 5. Wrap in _document shell and send response
|
|
298
284
|
*/
|
|
299
|
-
function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatcher, basePath = "", trailingSlash = false, hasMiddleware = false, hasRewrites = false, clientTraceMetadata, htmlLimitedBots, reactStrictMode = false, expireTime = PAGES_CACHE_ONE_YEAR_SECONDS, crossOrigin) {
|
|
285
|
+
function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatcher, basePath = "", trailingSlash = false, hasMiddleware = false, hasRewrites = false, clientTraceMetadata, htmlLimitedBots, reactStrictMode = false, expireTime = PAGES_CACHE_ONE_YEAR_SECONDS, crossOrigin, buildId = process.env.__VINEXT_BUILD_ID ?? "development") {
|
|
300
286
|
const matcher = fileMatcher ?? createValidFileMatcher();
|
|
301
287
|
const pagePatterns = routes.map((r) => patternToNextFormat(r.pattern));
|
|
302
288
|
const _alsRegistration = Promise.all([runner.import("vinext/head-state"), runner.import("vinext/router-state")]);
|
|
@@ -336,6 +322,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
336
322
|
}
|
|
337
323
|
const errorPageContext = {
|
|
338
324
|
basePath,
|
|
325
|
+
buildId,
|
|
339
326
|
clientTraceMetadata,
|
|
340
327
|
locale: locale ?? currentDefaultLocale,
|
|
341
328
|
locales: i18nConfig?.locales,
|
|
@@ -581,7 +568,10 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
581
568
|
res.end("{\"notFound\":true}");
|
|
582
569
|
return;
|
|
583
570
|
}
|
|
584
|
-
await renderErrorPage(server, runner, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, void 0, void 0, reactStrictMode,
|
|
571
|
+
await renderErrorPage(server, runner, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, void 0, void 0, reactStrictMode, {
|
|
572
|
+
...errorPageContext,
|
|
573
|
+
notFoundSrcPage: patternToNextFormat(route.pattern)
|
|
574
|
+
});
|
|
585
575
|
return;
|
|
586
576
|
}
|
|
587
577
|
if (result && "props" in result) isSerializableProps(patternToNextFormat(route.pattern), "getServerSideProps", pageProps);
|
|
@@ -655,7 +645,10 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
655
645
|
res.end("{\"notFound\":true}");
|
|
656
646
|
return;
|
|
657
647
|
}
|
|
658
|
-
await renderErrorPage(server, runner, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, void 0, void 0, reactStrictMode,
|
|
648
|
+
await renderErrorPage(server, runner, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, void 0, void 0, reactStrictMode, {
|
|
649
|
+
...errorPageContext,
|
|
650
|
+
notFoundSrcPage: patternToNextFormat(route.pattern)
|
|
651
|
+
});
|
|
659
652
|
return;
|
|
660
653
|
}
|
|
661
654
|
if (result && "props" in result) isSerializableProps(routePattern, "getStaticProps", pageProps);
|
|
@@ -775,7 +768,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
775
768
|
props: renderProps,
|
|
776
769
|
page: patternToNextFormat(route.pattern),
|
|
777
770
|
query: isFallbackRender ? {} : params,
|
|
778
|
-
buildId
|
|
771
|
+
buildId,
|
|
779
772
|
isFallback: isFallbackRender,
|
|
780
773
|
locale: locale ?? currentDefaultLocale,
|
|
781
774
|
locales: i18nConfig?.locales,
|
|
@@ -987,14 +980,21 @@ async function renderErrorPage(server, runner, req, res, url, pagesDir, statusCo
|
|
|
987
980
|
const scriptNonce = getScriptNonceFromNodeHeaderSources(req.headers, responseHeaders);
|
|
988
981
|
const nonceAttr = createNonceAttribute(scriptNonce);
|
|
989
982
|
const assetHeadHTML = await collectPagesDevInitialStylesheetHeadHTML(server, runner, [appAssetPath, errorAssetPath], nonceAttr);
|
|
983
|
+
const errorModuleUrl = errorAssetPath ? createPagesDevModuleUrl(server.config.root, errorAssetPath, server.config.base) : null;
|
|
990
984
|
const errorModuleSource = errorAssetPath ? createPagesDevModuleUrl(server.config.root, errorAssetPath, "/") : "next/error";
|
|
985
|
+
const appModuleUrl = appAssetPath ? createPagesDevModuleUrl(server.config.root, appAssetPath, server.config.base) : null;
|
|
991
986
|
const appModuleSource = appAssetPath ? createPagesDevModuleUrl(server.config.root, appAssetPath, "/") : null;
|
|
992
987
|
const errorScripts = `${`<script id="__NEXT_DATA__" type="application/json"${nonceAttr}>${safeJsonStringify({
|
|
993
988
|
props: renderProps,
|
|
994
989
|
page: errorPage,
|
|
995
990
|
query: parseQueryString(url),
|
|
996
|
-
buildId: process.env.__VINEXT_BUILD_ID,
|
|
997
|
-
isFallback: false
|
|
991
|
+
buildId: context.buildId ?? process.env.__VINEXT_BUILD_ID ?? "development",
|
|
992
|
+
isFallback: false,
|
|
993
|
+
notFoundSrcPage: context.notFoundSrcPage,
|
|
994
|
+
__vinext: {
|
|
995
|
+
pageModuleUrl: errorModuleUrl ?? void 0,
|
|
996
|
+
appModuleUrl: appModuleUrl ?? void 0
|
|
997
|
+
}
|
|
998
998
|
})}<\/script>`}\n${createPagesDevHydrationScript({
|
|
999
999
|
appModuleSource,
|
|
1000
1000
|
forceRouterReady: true,
|
|
@@ -1083,4 +1083,4 @@ async function renderErrorPage(server, runner, req, res, url, pagesDir, statusCo
|
|
|
1083
1083
|
res.end(`${statusCode} - Internal Server Error`);
|
|
1084
1084
|
}
|
|
1085
1085
|
//#endregion
|
|
1086
|
-
export { createSSRHandler,
|
|
1086
|
+
export { createSSRHandler, extractLocaleFromUrl };
|
|
@@ -33,10 +33,9 @@ type MappedStackLine = {
|
|
|
33
33
|
codeFrame?: StackCodeFramePayload;
|
|
34
34
|
};
|
|
35
35
|
declare function installDevStackSourcemapMiddleware(server: ViteDevServer): void;
|
|
36
|
-
declare function mapStackLine(server: ViteDevServer, line: string, requestHost: string | undefined, sourceMapCache: Map<string, Promise<SourceMapPayload | null>>): Promise<string>;
|
|
37
36
|
declare function mapStackLineWithMetadata(server: ViteDevServer, line: string, requestHost: string | undefined, sourceMapCache: Map<string, Promise<SourceMapPayload | null>>): Promise<MappedStackLine>;
|
|
38
37
|
declare function originalPositionFor(sourceMap: SourceMapPayload, generatedLine: number, generatedColumn: number): SourceMapPosition | null;
|
|
39
38
|
declare function decodeVlqSegment(segment: string): number[];
|
|
40
39
|
declare function resolveSourceFile(source: string, sourceMap: SourceMapPayload, generatedUrl: URL): string;
|
|
41
40
|
//#endregion
|
|
42
|
-
export { SourceMapPayload, VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT, decodeVlqSegment, installDevStackSourcemapMiddleware,
|
|
41
|
+
export { SourceMapPayload, VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT, decodeVlqSegment, installDevStackSourcemapMiddleware, mapStackLineWithMetadata, originalPositionFor, resolveSourceFile };
|
|
@@ -104,9 +104,6 @@ async function resolveDevServerStackTrace(server, stack, requestHost) {
|
|
|
104
104
|
...codeFrame ? { codeFrame } : {}
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
-
async function mapStackLine(server, line, requestHost, sourceMapCache) {
|
|
108
|
-
return (await mapStackLineWithMetadata(server, line, requestHost, sourceMapCache)).line;
|
|
109
|
-
}
|
|
110
107
|
async function mapStackLineWithMetadata(server, line, requestHost, sourceMapCache) {
|
|
111
108
|
const v8Paren = line.match(V8_PAREN_STACK_LINE);
|
|
112
109
|
if (v8Paren) {
|
|
@@ -441,4 +438,4 @@ function resolveSourceFile(source, sourceMap, generatedUrl) {
|
|
|
441
438
|
}
|
|
442
439
|
}
|
|
443
440
|
//#endregion
|
|
444
|
-
export { VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT, decodeVlqSegment, installDevStackSourcemapMiddleware,
|
|
441
|
+
export { VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT, decodeVlqSegment, installDevStackSourcemapMiddleware, mapStackLineWithMetadata, originalPositionFor, resolveSourceFile };
|
package/dist/server/headers.d.ts
CHANGED
|
@@ -42,10 +42,14 @@ declare const VINEXT_RSC_COMPLETION_METADATA_HEADER = "X-Vinext-Rsc-Completion-M
|
|
|
42
42
|
declare const VINEXT_RENDERED_PATH_AND_SEARCH_HEADER = "X-Vinext-Rendered-Path-And-Search";
|
|
43
43
|
/** Prerender-only JSON side channel carrying request cacheLife metadata. */
|
|
44
44
|
declare const VINEXT_PRERENDER_CACHE_LIFE_HEADER = "x-vinext-prerender-cache-life";
|
|
45
|
+
/** Marks a local prerender-server 500 that originated from a thrown render error. */
|
|
46
|
+
declare const VINEXT_PRERENDER_RENDER_ERROR_HEADER = "x-vinext-prerender-render-error";
|
|
45
47
|
/** Internal marker persisted only inside metadata-route APP_ROUTE cache values. */
|
|
46
48
|
declare const VINEXT_METADATA_ROUTE_CACHE_HEADER = "x-vinext-metadata-route-cache";
|
|
47
49
|
/** Route interception context for parallel/intercepting routes. */
|
|
48
50
|
declare const VINEXT_INTERCEPTION_CONTEXT_HEADER = "X-Vinext-Interception-Context";
|
|
51
|
+
/** Exact interception declaration requested by supplemental refreshes. */
|
|
52
|
+
declare const VINEXT_INTERCEPTION_ID_HEADER = "X-Vinext-Interception-Id";
|
|
49
53
|
/** RSC render mode (e.g. "navigation", "prefetch"). */
|
|
50
54
|
declare const VINEXT_RSC_RENDER_MODE_HEADER = "X-Vinext-Rsc-Render-Mode";
|
|
51
55
|
/** Stable visible-router-state variant for RSC cache busting. */
|
|
@@ -128,4 +132,4 @@ declare const INTERNAL_HEADERS: string[];
|
|
|
128
132
|
/** Vinext-only internal headers stripped alongside Next.js protocol internals. */
|
|
129
133
|
declare const VINEXT_INTERNAL_HEADERS: string[];
|
|
130
134
|
//#endregion
|
|
131
|
-
export { ACTION_FORWARDED_HEADER, ACTION_REDIRECT_HEADER, ACTION_REDIRECT_STATUS_HEADER, ACTION_REDIRECT_TYPE_HEADER, ACTION_REVALIDATED_HEADER, FLIGHT_HEADERS, INTERNAL_HEADERS, MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_NEXT_HEADER, MIDDLEWARE_REWRITE_HEADER, MIDDLEWARE_SET_COOKIE_HEADER, MIDDLEWARE_SKIP_HEADER, NEXTJS_ACTION_NOT_FOUND_HEADER, NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER, NEXT_ACTION_HEADER, NEXT_CACHE_TAGS_HEADER, NEXT_HTML_REQUEST_ID_HEADER, NEXT_REQUEST_ID_HEADER, NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, NEXT_ROUTER_STALE_TIME_HEADER, NEXT_ROUTER_STATE_TREE_HEADER, NEXT_URL_HEADER, RSC_ACTION_HEADER, RSC_HEADER, VINEXT_CACHE_HEADER, VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_INTERCEPTION_CONTEXT_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_METADATA_ROUTE_CACHE_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PARAMS_HEADER, VINEXT_PRERENDER_CACHE_LIFE_HEADER, VINEXT_PRERENDER_METADATA_ROUTES_PATH, VINEXT_PRERENDER_PAGES_STATIC_PATHS_PATH, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_PRERENDER_SPECULATIVE_HEADER, VINEXT_PRERENDER_STATIC_PARAMS_PATH, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_REVALIDATE_HEADER, VINEXT_REVALIDATE_HOST_HEADER, VINEXT_RSC_COMPLETION_METADATA_HEADER, VINEXT_RSC_MARKER_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_REDIRECT_TYPE_HEADER, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_RSC_STATE_FINGERPRINT_HEADER, VINEXT_STALE_TIME_PENDING_HEADER, VINEXT_STATIC_FILE_HEADER, VINEXT_TIMING_HEADER };
|
|
135
|
+
export { ACTION_FORWARDED_HEADER, ACTION_REDIRECT_HEADER, ACTION_REDIRECT_STATUS_HEADER, ACTION_REDIRECT_TYPE_HEADER, ACTION_REVALIDATED_HEADER, FLIGHT_HEADERS, INTERNAL_HEADERS, MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_NEXT_HEADER, MIDDLEWARE_REWRITE_HEADER, MIDDLEWARE_SET_COOKIE_HEADER, MIDDLEWARE_SKIP_HEADER, NEXTJS_ACTION_NOT_FOUND_HEADER, NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER, NEXT_ACTION_HEADER, NEXT_CACHE_TAGS_HEADER, NEXT_HTML_REQUEST_ID_HEADER, NEXT_REQUEST_ID_HEADER, NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, NEXT_ROUTER_STALE_TIME_HEADER, NEXT_ROUTER_STATE_TREE_HEADER, NEXT_URL_HEADER, RSC_ACTION_HEADER, RSC_HEADER, VINEXT_CACHE_HEADER, VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_INTERCEPTION_CONTEXT_HEADER, VINEXT_INTERCEPTION_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_METADATA_ROUTE_CACHE_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PARAMS_HEADER, VINEXT_PRERENDER_CACHE_LIFE_HEADER, VINEXT_PRERENDER_METADATA_ROUTES_PATH, VINEXT_PRERENDER_PAGES_STATIC_PATHS_PATH, VINEXT_PRERENDER_RENDER_ERROR_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_PRERENDER_SPECULATIVE_HEADER, VINEXT_PRERENDER_STATIC_PARAMS_PATH, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_REVALIDATE_HEADER, VINEXT_REVALIDATE_HOST_HEADER, VINEXT_RSC_COMPLETION_METADATA_HEADER, VINEXT_RSC_MARKER_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_REDIRECT_TYPE_HEADER, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_RSC_STATE_FINGERPRINT_HEADER, VINEXT_STALE_TIME_PENDING_HEADER, VINEXT_STATIC_FILE_HEADER, VINEXT_TIMING_HEADER };
|