vinext 1.3.1 → 1.4.1
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 +25 -22
- package/THIRD_PARTY_LICENSES.md +47 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -2
- package/dist/build/prerender.js +4 -3
- package/dist/build/report.d.ts +0 -14
- package/dist/build/report.js +1 -51
- package/dist/check.js +4 -7
- package/dist/cli.js +3 -0
- package/dist/client/dev-error-overlay-store.d.ts +1 -0
- package/dist/client/dev-error-overlay.d.ts +2 -0
- package/dist/client/dev-error-overlay.js +20 -4
- package/dist/client/navigation-runtime.d.ts +13 -1
- package/dist/client/navigation-runtime.js +1 -1
- package/dist/config/config-matchers.js +2 -0
- package/dist/config/destination-params.d.ts +2 -1
- package/dist/config/destination-params.js +52 -2
- package/dist/config/next-config.d.ts +25 -0
- package/dist/config/next-config.js +82 -4
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/dbcs-codec.js +327 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/dbcs-data.js +123 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/index.js +29 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/internal.js +134 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/sbcs-codec.js +50 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/sbcs-data-generated.js +455 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/sbcs-data.js +147 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/big5-added.json.js +169 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/cp936.json.js +2584 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/cp949.json.js +2220 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/cp950.json.js +227 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/eucjp.json.js +425 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/gb18030-ranges.json.js +427 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/gbk-added.json.js +229 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/tables/shiftjis.json.js +292 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/utf16.js +106 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/encodings/utf7.js +182 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/lib/bom-handling.js +42 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/lib/extend-node.js +147 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/lib/index.js +94 -0
- package/dist/deps/.pnpm/iconv-lite@0.4.24/deps/iconv-lite/lib/streams.js +95 -0
- package/dist/deps/.pnpm/safer-buffer@2.1.2/deps/safer-buffer/safer.js +45 -0
- package/dist/entries/app-rsc-entry.js +17 -49
- package/dist/entries/app-rsc-manifest.js +3 -4
- package/dist/entries/app-ssr-entry.js +1 -0
- package/dist/entries/pages-server-entry.js +36 -9
- package/dist/index.js +112 -90
- package/dist/init-cloudflare.d.ts +1 -3
- package/dist/init-cloudflare.js +10 -48
- package/dist/init-platform.d.ts +2 -0
- package/dist/init-platform.js +4 -0
- package/dist/plugins/extensionless-dynamic-import.js +6 -2
- package/dist/plugins/next-intl-catalog.d.ts +12 -0
- package/dist/plugins/next-intl-catalog.js +85 -0
- package/dist/plugins/pages-node-externals.d.ts +1 -0
- package/dist/plugins/pages-node-externals.js +1 -1
- package/dist/plugins/strip-server-exports.js +2 -1
- package/dist/plugins/use-cache-callable.d.ts +1 -1
- package/dist/plugins/use-cache-callable.js +136 -94
- package/dist/routing/app-route-graph.d.ts +6 -0
- package/dist/routing/app-route-graph.js +9 -1
- package/dist/server/api-handler.js +21 -5
- package/dist/server/app-bfcache-identity.js +1 -1
- package/dist/server/app-browser-entry.js +86 -66
- package/dist/server/app-browser-history-controller.d.ts +5 -4
- package/dist/server/app-browser-history-controller.js +93 -15
- package/dist/server/app-browser-navigation-controller.d.ts +2 -2
- package/dist/server/app-browser-navigation-controller.js +1 -2
- package/dist/server/app-browser-rsc-redirect.js +7 -7
- package/dist/server/app-browser-server-action-client.d.ts +2 -0
- package/dist/server/app-browser-server-action-client.js +5 -4
- package/dist/server/app-browser-state.d.ts +2 -4
- package/dist/server/app-browser-state.js +9 -4
- package/dist/server/app-browser-supplemental-refresh.js +16 -1
- package/dist/server/app-browser-visible-commit.d.ts +1 -1
- package/dist/server/app-browser-visible-commit.js +4 -14
- package/dist/server/app-elements-wire.d.ts +6 -38
- package/dist/server/app-elements-wire.js +4 -41
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +2 -2
- package/dist/server/app-history-state.d.ts +2 -2
- package/dist/server/app-history-state.js +5 -2
- package/dist/server/app-mounted-layouts.d.ts +21 -0
- package/dist/server/app-mounted-layouts.js +67 -0
- package/dist/server/app-optimistic-routing.d.ts +19 -1
- package/dist/server/app-optimistic-routing.js +43 -4
- package/dist/server/app-page-boundary-render.js +10 -14
- package/dist/server/app-page-boundary.js +2 -2
- package/dist/server/app-page-cache-finalizer.d.ts +12 -1
- package/dist/server/app-page-cache-finalizer.js +70 -29
- package/dist/server/app-page-cache.d.ts +13 -1
- package/dist/server/app-page-cache.js +31 -9
- package/dist/server/app-page-dispatch.d.ts +5 -11
- package/dist/server/app-page-dispatch.js +84 -155
- package/dist/server/app-page-element-builder.d.ts +2 -2
- package/dist/server/app-page-element-builder.js +13 -12
- package/dist/server/app-page-execution.d.ts +17 -52
- package/dist/server/app-page-execution.js +102 -95
- package/dist/server/app-page-head.d.ts +13 -0
- package/dist/server/app-page-head.js +44 -16
- package/dist/server/app-page-http-access-fallback-metadata.d.ts +1 -0
- package/dist/server/app-page-http-access-fallback-metadata.js +2 -2
- package/dist/server/app-page-layout-gate.d.ts +35 -0
- package/dist/server/app-page-layout-gate.js +50 -0
- package/dist/server/app-page-params.d.ts +0 -1
- package/dist/server/app-page-params.js +1 -14
- package/dist/server/app-page-probe.d.ts +3 -21
- package/dist/server/app-page-probe.js +4 -37
- package/dist/server/app-page-render.d.ts +2 -13
- package/dist/server/app-page-render.js +103 -234
- package/dist/server/app-page-request.d.ts +1 -3
- package/dist/server/app-page-request.js +1 -1
- package/dist/server/app-page-response.js +3 -3
- package/dist/server/app-page-route-wiring.d.ts +13 -6
- package/dist/server/app-page-route-wiring.js +86 -63
- package/dist/server/app-page-rsc-render-status.d.ts +27 -1
- package/dist/server/app-page-rsc-render-status.js +121 -13
- package/dist/server/app-page-stream.d.ts +12 -8
- package/dist/server/app-page-stream.js +4 -3
- package/dist/server/app-pages-bridge.d.ts +4 -0
- package/dist/server/app-pages-bridge.js +7 -3
- package/dist/server/app-render-dependency.d.ts +11 -4
- package/dist/server/app-render-dependency.js +86 -38
- package/dist/server/app-request-stage-dispatch.js +1 -1
- package/dist/server/app-request-stage-independent-entry.js +1 -1
- package/dist/server/app-route-handler-cache.js +2 -2
- package/dist/server/app-route-handler-dispatch.js +14 -9
- package/dist/server/app-route-handler-execution.js +11 -5
- package/dist/server/app-route-handler-policy.d.ts +1 -1
- package/dist/server/app-route-handler-policy.js +3 -3
- package/dist/server/app-route-handler-response.js +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +1 -1
- package/dist/server/app-route-handler-runtime.js +28 -11
- package/dist/server/app-router-entry.js +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +12 -12
- package/dist/server/app-rsc-cache-busting.js +31 -72
- package/dist/server/app-rsc-error-handler.d.ts +2 -1
- package/dist/server/app-rsc-error-handler.js +10 -2
- package/dist/server/app-rsc-errors.d.ts +8 -0
- package/dist/server/app-rsc-errors.js +11 -1
- package/dist/server/app-rsc-handler.d.ts +5 -5
- package/dist/server/app-rsc-handler.js +80 -83
- package/dist/server/app-rsc-request-normalization.d.ts +10 -16
- package/dist/server/app-rsc-request-normalization.js +12 -18
- package/dist/server/app-rsc-response-finalizer.js +2 -2
- package/dist/server/app-rsc-response-stage.js +9 -15
- package/dist/server/app-server-action-execution.d.ts +3 -1
- package/dist/server/app-server-action-execution.js +15 -8
- package/dist/server/app-ssr-entry.d.ts +8 -0
- package/dist/server/app-ssr-entry.js +22 -16
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/app-visited-response-cache.d.ts +36 -1
- package/dist/server/app-visited-response-cache.js +46 -5
- package/dist/server/app-worker-stages.d.ts +37 -6
- package/dist/server/app-worker-stages.js +81 -9
- package/dist/server/artifact-compatibility.d.ts +0 -1
- package/dist/server/artifact-compatibility.js +1 -10
- package/dist/server/bfcache-identity.d.ts +7 -0
- package/dist/server/bfcache-identity.js +10 -1
- package/dist/server/cache-proof.d.ts +1 -115
- package/dist/server/cache-proof.js +1 -544
- package/dist/server/cacheability-manifest.js +1 -2
- package/dist/server/cacheability-request.js +13 -8
- package/dist/server/dev-origin-check.d.ts +2 -1
- package/dist/server/dev-origin-check.js +2 -1
- package/dist/server/dev-server.js +6 -4
- package/dist/server/headers.d.ts +6 -3
- package/dist/server/headers.js +9 -5
- package/dist/server/image-optimization.d.ts +5 -0
- package/dist/server/image-optimization.js +6 -1
- package/dist/server/isr-cache.d.ts +8 -2
- package/dist/server/isr-cache.js +30 -2
- package/dist/server/metadata-route-response.js +32 -15
- package/dist/server/middleware-matcher.js +19 -6
- package/dist/server/middleware-runtime.js +6 -2
- package/dist/server/multi-stage.d.ts +57 -12
- package/dist/server/multi-stage.js +13 -1
- package/dist/server/navigation-planner.js +1 -1
- package/dist/server/pages-api-route.js +28 -19
- package/dist/server/pages-media-type.d.ts +21 -1
- package/dist/server/pages-media-type.js +69 -5
- package/dist/server/pages-node-compat.d.ts +1 -1
- package/dist/server/pages-node-compat.js +54 -27
- package/dist/server/pages-page-data.js +2 -1
- package/dist/server/pages-page-handler.js +28 -26
- package/dist/server/pages-page-response.d.ts +9 -0
- package/dist/server/pages-page-response.js +18 -4
- package/dist/server/pages-request-pipeline.d.ts +8 -0
- package/dist/server/pages-request-pipeline.js +2 -2
- package/dist/server/pages-request-stage-entry.js +36 -14
- package/dist/server/pages-response-stage-entry.js +9 -3
- package/dist/server/pages-router-entry.js +3 -2
- package/dist/server/prod-server.d.ts +2 -2
- package/dist/server/prod-server.js +47 -9
- package/dist/server/request-error-log.d.ts +9 -0
- package/dist/server/request-error-log.js +13 -0
- package/dist/server/request-pipeline.d.ts +15 -4
- package/dist/server/request-pipeline.js +43 -15
- package/dist/server/rsc-completion-metadata.js +3 -0
- package/dist/server/shared-cache-identity.d.ts +23 -0
- package/dist/server/shared-cache-identity.js +36 -0
- package/dist/server/static-file-cache.d.ts +9 -0
- package/dist/server/static-file-cache.js +13 -2
- package/dist/server/worker-stages.d.ts +16 -3
- package/dist/server/worker-stages.js +23 -4
- package/dist/shims/cache-handler.js +2 -2
- package/dist/shims/cache-request-state.d.ts +23 -26
- package/dist/shims/cache-request-state.js +22 -57
- package/dist/shims/cache-runtime.d.ts +3 -1
- package/dist/shims/cache-runtime.js +94 -48
- package/dist/shims/cache.d.ts +16 -10
- package/dist/shims/cache.js +47 -36
- package/dist/shims/cacheability-classification.d.ts +2 -0
- package/dist/shims/cdn-cache.d.ts +22 -5
- package/dist/shims/client-hook-error.d.ts +2 -0
- package/dist/shims/client-hook-error.js +16 -1
- package/dist/shims/client-page-root.js +2 -2
- package/dist/shims/dynamic.js +9 -6
- package/dist/shims/error-boundary.js +2 -2
- package/dist/shims/fetch-cache-state.d.ts +5 -1
- package/dist/shims/fetch-cache-state.js +1 -3
- package/dist/shims/fetch-cache.d.ts +2 -1
- package/dist/shims/fetch-cache.js +39 -25
- package/dist/shims/form.js +2 -2
- package/dist/shims/headers.d.ts +10 -24
- package/dist/shims/headers.js +22 -70
- package/dist/shims/internal/cache-context-accessor.d.ts +1 -1
- package/dist/shims/internal/navigation-untracked.js +1 -1
- package/dist/shims/link.js +8 -11
- package/dist/shims/metadata.d.ts +23 -21
- package/dist/shims/metadata.js +62 -24
- package/dist/shims/navigation-server.js +1 -1
- package/dist/shims/navigation.d.ts +74 -7
- package/dist/shims/navigation.js +184 -31
- package/dist/shims/navigation.react-server.js +2 -2
- package/dist/shims/request-state-types.d.ts +3 -2
- package/dist/shims/slot.d.ts +16 -0
- package/dist/shims/slot.js +44 -9
- package/dist/shims/unified-request-context.d.ts +7 -1
- package/dist/shims/unified-request-context.js +3 -3
- package/dist/utils/cache-control-metadata.d.ts +5 -0
- package/dist/utils/cache-control-metadata.js +9 -1
- package/dist/utils/cache-life-profiles.d.ts +33 -0
- package/dist/utils/cache-life-profiles.js +111 -0
- package/dist/utils/middleware-request-headers.d.ts +14 -3
- package/dist/utils/middleware-request-headers.js +54 -7
- package/dist/utils/project.d.ts +2 -2
- package/dist/utils/project.js +3 -16
- package/dist/utils/regex.d.ts +5 -0
- package/dist/utils/regex.js +11 -1
- package/dist/utils/text-stream.d.ts +10 -5
- package/dist/utils/text-stream.js +6 -6
- package/package.json +2 -1
- package/dist/build/layout-classification-types.d.ts +0 -60
- package/dist/build/layout-classification-types.js +0 -1
- package/dist/build/layout-classification.d.ts +0 -62
- package/dist/build/layout-classification.js +0 -98
- package/dist/build/route-classification-injector.d.ts +0 -33
- package/dist/build/route-classification-injector.js +0 -59
- package/dist/build/route-classification-manifest.d.ts +0 -54
- package/dist/build/route-classification-manifest.js +0 -143
- package/dist/server/app-browser-client-reuse-manifest.d.ts +0 -11
- package/dist/server/app-browser-client-reuse-manifest.js +0 -101
- package/dist/server/app-layout-param-observation.d.ts +0 -42
- package/dist/server/app-layout-param-observation.js +0 -168
- package/dist/server/client-reuse-manifest.d.ts +0 -103
- package/dist/server/client-reuse-manifest.js +0 -209
- package/dist/server/skip-cache-proof.d.ts +0 -60
- package/dist/server/skip-cache-proof.js +0 -168
- package/dist/server/static-layout-client-reuse-proof.d.ts +0 -14
- package/dist/server/static-layout-client-reuse-proof.js +0 -33
- package/dist/utils/sorted-array.d.ts +0 -8
- package/dist/utils/sorted-array.js +0 -20
|
@@ -702,6 +702,14 @@ function findSlotConfigLayoutTreePositions(slotDir, layoutPaths) {
|
|
|
702
702
|
return relativeDir ? relativeDir.split(path.sep).filter(Boolean).length : 0;
|
|
703
703
|
});
|
|
704
704
|
}
|
|
705
|
+
/**
|
|
706
|
+
* The tree position of a slot's active page relative to the slot root, in the
|
|
707
|
+
* coordinates of configLayoutTreePositions. Route groups count, unlike in
|
|
708
|
+
* `routeSegments`, since each is its own loader-tree segment.
|
|
709
|
+
*/
|
|
710
|
+
function findSlotPageTreePosition(slot) {
|
|
711
|
+
return slot.pagePath ? findSlotConfigLayoutTreePositions(slot.ownerDir, [slot.pagePath])[0] : null;
|
|
712
|
+
}
|
|
705
713
|
function findSlotLoadingEntries(slotDir, pagePath, matcher) {
|
|
706
714
|
return findSlotSegmentFileEntries(slotDir, pagePath, "loading", matcher);
|
|
707
715
|
}
|
|
@@ -1823,4 +1831,4 @@ function computeAppRouteStaticSiblings(allRoutes, matchedRoute) {
|
|
|
1823
1831
|
return Array.from(siblings);
|
|
1824
1832
|
}
|
|
1825
1833
|
//#endregion
|
|
1826
|
-
export { buildAppRouteGraph, computeAppRouteStaticSiblings, computeRootParamNames, convertSegmentsToRouteParts, findOwnerRouteForDir, isInvisibleSegment, patternsStructurallyEquivalent };
|
|
1834
|
+
export { buildAppRouteGraph, computeAppRouteStaticSiblings, computeRootParamNames, convertSegmentsToRouteParts, findOwnerRouteForDir, findSlotPageTreePosition, isInvisibleSegment, patternsStructurallyEquivalent };
|
|
@@ -4,16 +4,18 @@ import "./server-globals.js";
|
|
|
4
4
|
import { resolveRequestHost, resolveRequestProtocol } from "./proxy-trust.js";
|
|
5
5
|
import { NextRequest } from "../shims/server.js";
|
|
6
6
|
import { importModule, reportRequestError } from "./instrumentation.js";
|
|
7
|
+
import { logRequestError } from "./request-error-log.js";
|
|
7
8
|
import { mergeRouteParamsIntoQuery, parseQueryString, urlQueryToSearchParams } from "../utils/query.js";
|
|
8
9
|
import { tracePagesApiHandler } from "./pages-execution-tracing.js";
|
|
9
10
|
import { DEFAULT_PAGES_API_BODY_SIZE_LIMIT, resolveBodyParserConfig } from "./pages-body-parser-config.js";
|
|
10
|
-
import { PagesBodyParseError,
|
|
11
|
+
import { PagesBodyParseError, createPagesBodyDecoder, isJsonMediaType } from "./pages-media-type.js";
|
|
11
12
|
import { performOnDemandRevalidate } from "./pages-revalidate.js";
|
|
12
13
|
import { attachPagesPreviewApi, attachPagesRequestCookies } from "./pages-node-compat.js";
|
|
13
14
|
import { finalizeEdgeApiResponse, isEdgeApiRuntime } from "./edge-api-runtime.js";
|
|
14
15
|
import { signalFromNodeResponse } from "./node-response-signal.js";
|
|
15
16
|
import { Buffer } from "node:buffer";
|
|
16
17
|
import { decode } from "node:querystring";
|
|
18
|
+
import { Stream } from "node:stream";
|
|
17
19
|
//#region src/server/api-handler.ts
|
|
18
20
|
/**
|
|
19
21
|
* Default request body size (1 MB). Matches Next.js default bodyParser sizeLimit.
|
|
@@ -32,6 +34,8 @@ const MAX_BODY_SIZE = DEFAULT_PAGES_API_BODY_SIZE_LIMIT;
|
|
|
32
34
|
* HMAC signature verification).
|
|
33
35
|
*/
|
|
34
36
|
async function parseBody(req, sizeLimit = MAX_BODY_SIZE) {
|
|
37
|
+
const { mediaType, decoder } = await createPagesBodyDecoder(req.headers["content-type"]);
|
|
38
|
+
if (req.destroyed) throw req.errored ?? /* @__PURE__ */ new Error("Request aborted");
|
|
35
39
|
return new Promise((resolve, reject) => {
|
|
36
40
|
const chunks = [];
|
|
37
41
|
let totalSize = 0;
|
|
@@ -55,10 +59,10 @@ async function parseBody(req, sizeLimit = MAX_BODY_SIZE) {
|
|
|
55
59
|
req.on("end", () => {
|
|
56
60
|
if (settled) return;
|
|
57
61
|
settled = true;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
62
|
+
const body = Buffer.concat(chunks);
|
|
63
|
+
const raw = decoder.decode(body);
|
|
60
64
|
if (!raw) {
|
|
61
|
-
resolve(isJsonMediaType(mediaType) ? {} : mediaType === "application/x-www-form-urlencoded" ? decode(raw) : void 0);
|
|
65
|
+
resolve(isJsonMediaType(mediaType) ? {} : mediaType === "application/x-www-form-urlencoded" ? decode(raw) : body.length > 0 ? raw : void 0);
|
|
62
66
|
return;
|
|
63
67
|
}
|
|
64
68
|
if (isJsonMediaType(mediaType)) try {
|
|
@@ -188,6 +192,18 @@ function enhanceApiObjects(req, res, query, body, trustedRevalidateOrigin, allow
|
|
|
188
192
|
this.end(JSON.stringify(data));
|
|
189
193
|
},
|
|
190
194
|
send(data) {
|
|
195
|
+
if (this.statusCode === 204 || this.statusCode === 304) {
|
|
196
|
+
this.removeHeader("Content-Type");
|
|
197
|
+
this.removeHeader("Content-Length");
|
|
198
|
+
this.removeHeader("Transfer-Encoding");
|
|
199
|
+
this.end();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (data instanceof Stream) {
|
|
203
|
+
if (!this.getHeader("Content-Type")) this.setHeader("Content-Type", "application/octet-stream");
|
|
204
|
+
data.pipe(this);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
191
207
|
if (Buffer.isBuffer(data)) {
|
|
192
208
|
if (!this.getHeader("Content-Type")) this.setHeader("Content-Type", "application/octet-stream");
|
|
193
209
|
this.setHeader("Content-Length", String(data.length));
|
|
@@ -272,7 +288,7 @@ async function handleApiRoute(runner, req, res, url, apiRoutes, nextConfig) {
|
|
|
272
288
|
res.end(e.message);
|
|
273
289
|
return true;
|
|
274
290
|
}
|
|
275
|
-
|
|
291
|
+
logRequestError(e);
|
|
276
292
|
await reportRequestError(e, {
|
|
277
293
|
path: url,
|
|
278
294
|
method: req.method ?? "GET",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
2
2
|
import "./app-elements.js";
|
|
3
|
-
import { isNestedBfcacheSlotSegmentIdFor } from "./bfcache-identity.js";
|
|
4
3
|
import { isBfcacheSegmentId } from "./app-bfcache-id.js";
|
|
4
|
+
import { isNestedBfcacheSlotSegmentIdFor } from "./bfcache-identity.js";
|
|
5
5
|
//#region src/server/app-bfcache-identity.ts
|
|
6
6
|
let nextBfcacheId = 0;
|
|
7
7
|
function rememberBfcacheId(value) {
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import { addBasePathToPathname, stripBasePath } from "../utils/base-path.js";
|
|
2
|
-
import {
|
|
2
|
+
import { VINEXT_MOUNTED_LAYOUTS_HEADER, VINEXT_PARAMS_HEADER, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_REDIRECT_TYPE_HEADER } from "./headers.js";
|
|
3
3
|
import { splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
4
4
|
import { AppRouterContext } from "../shims/internal/app-router-context.js";
|
|
5
5
|
import { matchRoutePattern } from "../routing/route-pattern.js";
|
|
6
6
|
import { installWindowNext, setWindowNextInternalSourcePage } from "../client/window-next.js";
|
|
7
7
|
import { retryScrollTo, scrollToHashTargetOnNextFrame } from "../shims/hash-scroll.js";
|
|
8
|
-
import { AppElementsWire } from "./app-elements-wire.js";
|
|
9
|
-
import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
10
|
-
import { getBfcacheIdMapContext, getNavigationContext, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
11
|
-
import { decodeRedirectError, isRedirectError } from "../shims/navigation-errors.js";
|
|
12
|
-
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
13
|
-
import { clearAppNavigationFailureTarget, installAppNavigationFailureListeners } from "../client/app-nav-failure-handler.js";
|
|
14
|
-
import { DevRecoveryBoundary, GlobalErrorBoundary, RedirectBoundary } from "../shims/error-boundary.js";
|
|
15
|
-
import { beginAppRouterScrollIntent, consumeAppRouterScrollIntent } from "../shims/app-router-scroll-state.js";
|
|
16
|
-
import { AppRouterScrollCommitProvider } from "../shims/app-router-scroll.js";
|
|
17
|
-
import { BfcacheIdentityMapContext, bindAppElementsRenderedSearch, setAppElementsRenderedSearch } from "../shims/slot.js";
|
|
18
8
|
import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, createRscRequestHeaders, createRscRequestUrl, formatRscRequestPath, isRscCompatibilityIdCompatible } from "./app-rsc-cache-busting.js";
|
|
9
|
+
import { clearAppNavigationFailureTarget, installAppNavigationFailureListeners } from "../client/app-nav-failure-handler.js";
|
|
19
10
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
20
11
|
import "../client/instrumentation-client.js";
|
|
21
12
|
import { createNavigationRuntimeRouteManifestLoader, getNavigationRuntime, loadNavigationRuntimeRouteManifest, registerNavigationRuntimeBootstrap, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
|
|
13
|
+
import { AppElementsWire } from "./app-elements-wire.js";
|
|
14
|
+
import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
22
15
|
import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap } from "./app-bfcache-identity.js";
|
|
23
16
|
import { createDiscardedServerActionRefreshScheduler, createServerActionInitiationSnapshot, resolveServerActionOperationLane } from "./app-browser-action-result.js";
|
|
24
|
-
import { createClientReuseManifestHeaderFromVisibleAppState } from "./app-browser-client-reuse-manifest.js";
|
|
25
17
|
import { resolveManifestNavigationInterceptionContext, resolveMiddlewareRewriteNavigationInterceptionContext } from "./app-browser-interception-context.js";
|
|
26
18
|
import { isExternalHistoryState, readHistoryStateActiveRoutePaths, readHistoryStatePreviousNextUrl, resolveActiveRoutePaths } from "./app-history-state.js";
|
|
27
19
|
import { AppBrowserMpaNavigationScheduler } from "./app-browser-mpa-navigation.js";
|
|
28
20
|
import { stripRscCompletionMetadataResponse } from "./rsc-completion-metadata.js";
|
|
29
21
|
import { blockDangerousStreamedRscRedirect } from "./app-browser-rsc-redirect.js";
|
|
30
22
|
import { navigationPlanner } from "./navigation-planner.js";
|
|
31
|
-
import {
|
|
23
|
+
import { decodeRedirectError, isRedirectError } from "../shims/navigation-errors.js";
|
|
24
|
+
import { beginAppRouterScrollIntent, consumeAppRouterScrollIntent } from "../shims/app-router-scroll-state.js";
|
|
25
|
+
import { getBfcacheIdMapContext, getNavigationContext, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
26
|
+
import { DYNAMIC_NAVIGATION_CACHE_TTL, PREFETCH_CACHE_TTL, __basePath, appRouterInstance, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, deletePrefetchResponseSnapshot, disableNavigationResponsePrefetchCacheReuse, getClientNavigationRenderContext, getMountedSlotsHeader, getPrefetchCache, hasPrefetchCacheEntryForNavigation, invalidateDynamicPrefetchCache, invalidatePrefetchCache, invalidateVisitedResponsePrefetches, parseRenderedPathAndSearchHeader, preloadHybridClientRouteOwner, pushHistoryStateWithoutNotify, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setPendingPathname, trackAppRouterNavigationInFlight, useRouter } from "../shims/navigation.js";
|
|
27
|
+
import { AppRouterScrollCommitProvider } from "../shims/app-router-scroll.js";
|
|
32
28
|
import { chunksToReadableStream, createProgressiveRscStream, getVinextBrowserGlobal } from "./app-browser-stream.js";
|
|
29
|
+
import { createMountedLayoutsHeader, holdsSkippedLayouts } from "./app-mounted-layouts.js";
|
|
30
|
+
import { BfcacheIdentityMapContext, bindAppElementsRenderedSearch, setAppElementsRenderedSearch } from "../shims/slot.js";
|
|
33
31
|
import { COMMITTED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN, FRESH_APP_NAVIGATION_PAYLOAD_ORIGIN, VISITED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN, isCacheRestorableAppPayloadMetadata, isCompleteAppPayloadMetadata, resolveInterceptionContextFromPreviousNextUrl } from "./app-browser-state.js";
|
|
34
32
|
import { clearHardNavigationLoopGuard, createAppBrowserNavigationController, createBasePathStrippedPathAndSearch, navigateDocumentDirectly } from "./app-browser-navigation-controller.js";
|
|
35
33
|
import { createAppRouteTree } from "./app-route-tree.js";
|
|
@@ -38,17 +36,19 @@ import { createSupplementalRefreshCoordinator, mergeRefreshedParallelSlot, requi
|
|
|
38
36
|
import { createAppBrowserNavigationAbortCoordinator } from "./app-browser-navigation-abort.js";
|
|
39
37
|
import { consumeInitialFormState, createVinextHydrateRootOptions, hydrateRootInTransition, resolveFetchedHydrationLocation } from "./app-browser-hydration.js";
|
|
40
38
|
import { AppBrowserHistoryController } from "./app-browser-history-controller.js";
|
|
41
|
-
import { createVisitedResponseCacheEntry, deleteAllVisitedResponseCacheEntries,
|
|
39
|
+
import { createVisitedResponseCacheEntry, deleteAllVisitedResponseCacheEntries, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, findVisitedResponseForFullPrefetch, hasNavigationResponseHistoryLifetime, isVisitedResponseCacheEntryFresh, revokeHistoryRestoreNavigationReuse } from "./app-visited-response-cache.js";
|
|
42
40
|
import { createPopstateRestoreHandler, restoreSynchronousPopstateScrollPosition, shouldCommitPopstateUrlWithoutNavigation } from "./app-browser-popstate.js";
|
|
41
|
+
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
42
|
+
import { DevRecoveryBoundary, GlobalErrorBoundary, RedirectBoundary } from "../shims/error-boundary.js";
|
|
43
43
|
import { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, createProdOnRecoverableError } from "./app-browser-error.js";
|
|
44
44
|
import { createHydrationCachePublication } from "./app-hydration-cache-publication.js";
|
|
45
45
|
import { peekSettledPrefetchResponseForNavigation, prepareConsumedPrefetchResponseForPublication, preserveCommittedPrefetchExpiry, resolvePrefetchNavigationResponseUrl } from "./app-browser-prefetch-response.js";
|
|
46
|
-
import { canCommitOptimisticRouteTemplate, createOptimisticRouteTemplate, getOptimisticPrefetchSourceKey, getOptimisticRouteTemplateKey, keepOptimisticStreamingMetadata, resolveOptimisticNavigationParamsForHref, resolveOptimisticNavigationPayload } from "./app-optimistic-routing.js";
|
|
46
|
+
import { canCommitOptimisticRouteTemplate, createOptimisticRouteTemplate, createOptimisticRouteTemplateStore, getOptimisticPrefetchSourceKey, getOptimisticRouteTemplateKey, keepOptimisticStreamingMetadata, resolveOptimisticNavigationParamsForHref, resolveOptimisticNavigationPayload } from "./app-optimistic-routing.js";
|
|
47
47
|
import { removeStylesheetLinksCoveredByInlineCss } from "./app-inline-css-client.js";
|
|
48
|
-
import { createElement, startTransition, use, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
49
|
-
import { flushSync } from "react-dom";
|
|
48
|
+
import { Fragment, createElement, startTransition, use, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
50
49
|
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
51
50
|
import { createFromFetch, createFromReadableStream, setServerCallback } from "@vitejs/plugin-rsc/browser";
|
|
51
|
+
import { flushSync } from "react-dom";
|
|
52
52
|
import { hasServerActions, loadServerActionClient } from "virtual:vinext-app-capabilities";
|
|
53
53
|
//#region src/server/app-browser-entry.ts
|
|
54
54
|
const HAS_CLIENT_REWRITES = process.env.__VINEXT_HAS_CLIENT_REWRITES !== "false";
|
|
@@ -80,9 +80,7 @@ function setClientRscCompatibilityId(compatibilityId) {
|
|
|
80
80
|
if (IS_STATIC_EXPORT || !compatibilityId) return;
|
|
81
81
|
clientRscCompatibilityId = compatibilityId;
|
|
82
82
|
}
|
|
83
|
-
const optimisticRouteTemplates =
|
|
84
|
-
const optimisticRouteTemplateSources = /* @__PURE__ */ new Set();
|
|
85
|
-
const optimisticRouteTemplateLearning = /* @__PURE__ */ new Map();
|
|
83
|
+
const optimisticRouteTemplates = createOptimisticRouteTemplateStore();
|
|
86
84
|
function claimInitialAppRouterBootstrap() {
|
|
87
85
|
if (window.__VINEXT_RSC_ROOT__ || window.__VINEXT_RSC_BOOTSTRAP_STATE__) return false;
|
|
88
86
|
window.__VINEXT_RSC_BOOTSTRAP_STATE__ = "starting";
|
|
@@ -114,8 +112,8 @@ const historyController = new AppBrowserHistoryController({
|
|
|
114
112
|
maxHistoryStateSnapshots: 50,
|
|
115
113
|
readHistoryState: () => window.history.state,
|
|
116
114
|
readCurrentHref: () => window.location.href,
|
|
117
|
-
pushHistoryState: (state, href) => pushHistoryStateWithoutNotify(state, "", href),
|
|
118
|
-
replaceHistoryState: (state, href) => replaceHistoryStateWithoutNotify(state, "", href),
|
|
115
|
+
pushHistoryState: (state, href, land) => pushHistoryStateWithoutNotify(state, "", href, land),
|
|
116
|
+
replaceHistoryState: (state, href, land) => replaceHistoryStateWithoutNotify(state, "", href, land),
|
|
119
117
|
readVisibleNavigationMetadata: () => {
|
|
120
118
|
if (!hasBrowserRouterState()) return null;
|
|
121
119
|
const routerState = getBrowserRouterState();
|
|
@@ -223,7 +221,7 @@ function restoreHistoryStateSnapshot(historyState, navId, onApprovedBeforeCommit
|
|
|
223
221
|
});
|
|
224
222
|
if (!restored) return false;
|
|
225
223
|
clientNavigationCacheGeneration += 1;
|
|
226
|
-
|
|
224
|
+
revokeHistoryRestoreNavigationReuse(visitedResponseCache);
|
|
227
225
|
disableNavigationResponsePrefetchCacheReuse();
|
|
228
226
|
commitClientNavigationState(navId, { releaseSnapshot: false });
|
|
229
227
|
return true;
|
|
@@ -250,17 +248,23 @@ function stageClientParams(params) {
|
|
|
250
248
|
}
|
|
251
249
|
function clearVisitedResponseCache() {
|
|
252
250
|
visitedResponseCache.clear();
|
|
251
|
+
invalidateVisitedResponsePrefetches();
|
|
253
252
|
}
|
|
254
|
-
function clearPrefetchState() {
|
|
255
|
-
invalidatePrefetchCache();
|
|
253
|
+
function clearPrefetchState(options) {
|
|
254
|
+
invalidatePrefetchCache(options);
|
|
256
255
|
optimisticRouteTemplates.clear();
|
|
257
|
-
optimisticRouteTemplateSources.clear();
|
|
258
|
-
optimisticRouteTemplateLearning.clear();
|
|
259
256
|
}
|
|
260
|
-
function clearClientNavigationCaches() {
|
|
257
|
+
function clearClientNavigationCaches(options) {
|
|
258
|
+
clientNavigationCacheGeneration += 1;
|
|
259
|
+
clearVisitedResponseCache();
|
|
260
|
+
clearPrefetchState(options);
|
|
261
|
+
historyController.invalidateRestorableClientState();
|
|
262
|
+
}
|
|
263
|
+
function clearDynamicClientNavigationCaches() {
|
|
261
264
|
clientNavigationCacheGeneration += 1;
|
|
262
265
|
clearVisitedResponseCache();
|
|
263
|
-
|
|
266
|
+
invalidateDynamicPrefetchCache();
|
|
267
|
+
optimisticRouteTemplates.clear();
|
|
264
268
|
historyController.invalidateRestorableClientState();
|
|
265
269
|
}
|
|
266
270
|
function getMatchedUrlPathname(matchedUrl) {
|
|
@@ -343,10 +347,10 @@ function parsePrefetchCacheKey(cacheKey) {
|
|
|
343
347
|
}
|
|
344
348
|
async function learnOptimisticRouteTemplateFromPrefetch(options) {
|
|
345
349
|
const source = parsePrefetchCacheKey(options.cacheKey);
|
|
346
|
-
if (source.interceptionContext !== options.interceptionContext) return
|
|
347
|
-
if (resolvePrefetchCacheEntryMountedSlotsHeader(options.entry) !== options.mountedSlotsHeader) return
|
|
348
|
-
if (options.interceptionContext !== null) return
|
|
349
|
-
if (!isRscResponseCompatible(options.entry.snapshot.compatibilityIdHeader)) return
|
|
350
|
+
if (source.interceptionContext !== options.interceptionContext) return null;
|
|
351
|
+
if (resolvePrefetchCacheEntryMountedSlotsHeader(options.entry) !== options.mountedSlotsHeader) return null;
|
|
352
|
+
if (options.interceptionContext !== null) return null;
|
|
353
|
+
if (!isRscResponseCompatible(options.entry.snapshot.compatibilityIdHeader)) return null;
|
|
350
354
|
const elements = await decodeAppElementsPromise(createFromFetch(Promise.resolve(restoreRscResponse(options.entry.snapshot))));
|
|
351
355
|
const template = createOptimisticRouteTemplate({
|
|
352
356
|
allowLoadingShell: options.entry.optimisticRouteShell === true,
|
|
@@ -357,40 +361,36 @@ async function learnOptimisticRouteTemplateFromPrefetch(options) {
|
|
|
357
361
|
mountedSlotsHeader: options.mountedSlotsHeader,
|
|
358
362
|
routeManifest: options.routeManifest
|
|
359
363
|
});
|
|
360
|
-
if (template === null) return
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
if (template === null) return null;
|
|
365
|
+
return {
|
|
366
|
+
key: getOptimisticRouteTemplateKey({
|
|
367
|
+
interceptionContext: options.interceptionContext,
|
|
368
|
+
mountedSlotsHeader: options.mountedSlotsHeader,
|
|
369
|
+
routeId: template.routeId
|
|
370
|
+
}),
|
|
371
|
+
template
|
|
372
|
+
};
|
|
367
373
|
}
|
|
368
374
|
async function learnOptimisticRouteTemplatesFromPrefetchCache(options) {
|
|
369
|
-
|
|
370
|
-
|
|
375
|
+
const { routeManifest } = options;
|
|
376
|
+
if (routeManifest === null) return;
|
|
377
|
+
const learning = optimisticRouteTemplates.pendingLearning();
|
|
371
378
|
for (const [cacheKey, entry] of getPrefetchCache()) {
|
|
372
379
|
const sourceKey = getOptimisticPrefetchSourceKey({
|
|
373
380
|
cacheKey,
|
|
374
381
|
interceptionContext: options.interceptionContext,
|
|
375
382
|
mountedSlotsHeader: options.mountedSlotsHeader
|
|
376
383
|
});
|
|
377
|
-
if (
|
|
378
|
-
if (optimisticRouteTemplateLearning.has(sourceKey)) continue;
|
|
384
|
+
if (optimisticRouteTemplates.hasSource(sourceKey)) continue;
|
|
379
385
|
if (!isSettledPrefetchCacheEntry(entry)) continue;
|
|
380
386
|
if (entry.prefetchKind === "route-tree") continue;
|
|
381
|
-
|
|
387
|
+
learning.push(optimisticRouteTemplates.learn(sourceKey, () => learnOptimisticRouteTemplateFromPrefetch({
|
|
382
388
|
cacheKey,
|
|
383
389
|
entry,
|
|
384
390
|
interceptionContext: options.interceptionContext,
|
|
385
391
|
mountedSlotsHeader: options.mountedSlotsHeader,
|
|
386
|
-
routeManifest
|
|
387
|
-
})
|
|
388
|
-
if (learned) optimisticRouteTemplateSources.add(sourceKey);
|
|
389
|
-
}).finally(() => {
|
|
390
|
-
optimisticRouteTemplateLearning.delete(sourceKey);
|
|
391
|
-
});
|
|
392
|
-
optimisticRouteTemplateLearning.set(sourceKey, promise);
|
|
393
|
-
learning.push(promise);
|
|
392
|
+
routeManifest
|
|
393
|
+
})));
|
|
394
394
|
}
|
|
395
395
|
if (learning.length === 0) return;
|
|
396
396
|
await Promise.allSettled(learning);
|
|
@@ -533,7 +533,7 @@ function evictVisitedResponseCacheIfNeeded() {
|
|
|
533
533
|
function readVisitedResponseCacheCandidate(rscUrl, interceptionContext, mountedSlotsHeader, navigationKind) {
|
|
534
534
|
const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
|
|
535
535
|
const match = findVisitedResponseCacheEntry(visitedResponseCache, rscUrl, interceptionContext);
|
|
536
|
-
if (!match) return {
|
|
536
|
+
if (!match || match.entry.navigationReuseRevoked) return {
|
|
537
537
|
cacheKey,
|
|
538
538
|
entry: null,
|
|
539
539
|
facts: {
|
|
@@ -568,13 +568,14 @@ function applyVisitedResponseCacheCandidateDecision(candidate, decision) {
|
|
|
568
568
|
function deleteVisitedResponse(rscUrl, interceptionContext) {
|
|
569
569
|
deleteVisitedResponseCacheEntry(visitedResponseCache, rscUrl, interceptionContext);
|
|
570
570
|
}
|
|
571
|
-
function storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, params, prefetchFallbackTtlMs = DYNAMIC_NAVIGATION_CACHE_TTL, requestMountedSlotsHeader = snapshot.mountedSlotsHeader ?? null, elements, seedPrefetchCache = true, prefetchSnapshot = snapshot, reuseAfterHistoryRestore = false) {
|
|
571
|
+
function storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, params, prefetchFallbackTtlMs = DYNAMIC_NAVIGATION_CACHE_TTL, requestMountedSlotsHeader = snapshot.mountedSlotsHeader ?? null, elements, seedPrefetchCache = true, prefetchSnapshot = snapshot, reuseAfterHistoryRestore = false, fromHydration = false) {
|
|
572
572
|
const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
|
|
573
573
|
deleteAllVisitedResponseCacheEntries(visitedResponseCache, rscUrl, interceptionContext);
|
|
574
574
|
evictVisitedResponseCacheIfNeeded();
|
|
575
575
|
const entry = createVisitedResponseCacheEntry({
|
|
576
576
|
fallbackTtlMs: prefetchFallbackTtlMs,
|
|
577
577
|
elements,
|
|
578
|
+
fromHydration,
|
|
578
579
|
now: Date.now(),
|
|
579
580
|
mountedSlotsHeader: requestMountedSlotsHeader,
|
|
580
581
|
params,
|
|
@@ -699,7 +700,6 @@ function BrowserRoot({ hydrationCachePublication, initialElements, initialNaviga
|
|
|
699
700
|
interception: initialMetadata.interception,
|
|
700
701
|
interceptionContext: initialMetadata.interceptionContext,
|
|
701
702
|
layoutIds: initialMetadata.layoutIds,
|
|
702
|
-
layoutFlags: initialMetadata.layoutFlags,
|
|
703
703
|
navigationSnapshot: initialNavigationSnapshot,
|
|
704
704
|
previousNextUrl: null,
|
|
705
705
|
renderId: 0,
|
|
@@ -966,6 +966,7 @@ function registerServerActionCallback() {
|
|
|
966
966
|
return loadServerActionClient().then(({ invokeClientServerAction }) => invokeClientServerAction(id, args, actionInitiation, {
|
|
967
967
|
basePath: __basePath,
|
|
968
968
|
clearClientNavigationCaches,
|
|
969
|
+
clearDynamicClientNavigationCaches,
|
|
969
970
|
clientRscCompatibilityId,
|
|
970
971
|
commitSameUrlNavigatePayload,
|
|
971
972
|
navigationPlanner,
|
|
@@ -999,6 +1000,10 @@ function registerServerActionCallback() {
|
|
|
999
1000
|
})).finally(releaseCacheInvalidationGuard);
|
|
1000
1001
|
});
|
|
1001
1002
|
}
|
|
1003
|
+
function ReplayInitialDevServerErrors({ report }) {
|
|
1004
|
+
useEffect(report, [report]);
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1002
1007
|
async function main() {
|
|
1003
1008
|
if (!claimInitialAppRouterBootstrap()) return;
|
|
1004
1009
|
loadNavigationRuntimeRouteManifest();
|
|
@@ -1010,7 +1015,7 @@ async function main() {
|
|
|
1010
1015
|
devErrorOverlay = await import("../client/dev-error-overlay.js");
|
|
1011
1016
|
devErrorOverlay.installDevErrorOverlay();
|
|
1012
1017
|
devErrorOverlay.installViteHmrErrorHandler(import.meta.hot);
|
|
1013
|
-
devErrorOverlay.reportInitialDevServerErrors();
|
|
1018
|
+
if (document.documentElement.id !== "__next_error__") devErrorOverlay.reportInitialDevServerErrors();
|
|
1014
1019
|
}
|
|
1015
1020
|
const initialRscBootstrap = getNavigationRuntime()?.bootstrap.rsc;
|
|
1016
1021
|
const rscStream = await readInitialRscStream();
|
|
@@ -1059,7 +1064,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1059
1064
|
const fallbackTtlMs = initialRscBootstrap?.initialCacheKind === "static" ? PREFETCH_CACHE_TTL : DYNAMIC_NAVIGATION_CACHE_TTL;
|
|
1060
1065
|
hydrationCachePublication.publish(() => {
|
|
1061
1066
|
if (cacheGeneration !== clientNavigationCacheGeneration) return () => {};
|
|
1062
|
-
return storeVisitedResponseSnapshot(rscUrl, metadata.interceptionContext, snapshot, initialParams, fallbackTtlMs, mountedSlotsHeader, elements, false, snapshot, initialRscBootstrap?.initialCacheKind === "static" || metadata.interceptionContext !== null);
|
|
1067
|
+
return storeVisitedResponseSnapshot(rscUrl, metadata.interceptionContext, snapshot, initialParams, fallbackTtlMs, mountedSlotsHeader, elements, false, snapshot, initialRscBootstrap?.initialCacheKind === "static" || metadata.interceptionContext !== null, true);
|
|
1063
1068
|
});
|
|
1064
1069
|
}).catch(() => {});
|
|
1065
1070
|
historyController.writeBootstrapHistoryMetadata();
|
|
@@ -1097,7 +1102,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1097
1102
|
for (const style of errorShellStyles) style.remove();
|
|
1098
1103
|
startTransition(() => {
|
|
1099
1104
|
const clientRoot = createRoot(document, createRootOptions);
|
|
1100
|
-
clientRoot.render(children);
|
|
1105
|
+
clientRoot.render(import.meta.env.DEV && devErrorOverlay ? createElement(Fragment, null, children, createElement(ReplayInitialDevServerErrors, { report: devErrorOverlay.reportInitialDevServerErrors })) : children);
|
|
1101
1106
|
window.__VINEXT_RSC_ROOT__ = clientRoot;
|
|
1102
1107
|
});
|
|
1103
1108
|
} else window.__VINEXT_RSC_ROOT__ = hydrateRootInTransition({
|
|
@@ -1151,6 +1156,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1151
1156
|
};
|
|
1152
1157
|
let restoredBfcacheIds = navigationKind === "traverse" ? historyController.readCurrentBfcacheVersionHistoryIds(activeTraversalIntent?.historyState ?? window.history.state) : null;
|
|
1153
1158
|
const reuseCurrentBfcacheIds = navigationKind !== "traverse" || !historyController.isCacheInvalidationGuarded() && historyController.isCurrentBfcacheVersion(activeTraversalIntent?.historyState ?? window.history.state);
|
|
1159
|
+
const releaseNavigationInFlight = trackAppRouterNavigationInFlight();
|
|
1154
1160
|
try {
|
|
1155
1161
|
const shouldUsePendingRouterState = programmaticTransition;
|
|
1156
1162
|
if (hasBrowserRouterState()) {
|
|
@@ -1171,6 +1177,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1171
1177
|
}
|
|
1172
1178
|
const navigationInitiationState = getBrowserRouterState();
|
|
1173
1179
|
const mountedSlotsHeader = getMountedSlotIdsHeader(navigationInitiationState.elements);
|
|
1180
|
+
let mountedLayoutsHeader = navigationKind === "navigate" ? createMountedLayoutsHeader(navigationInitiationState.elements, navigationInitiationState.layoutIds) : null;
|
|
1174
1181
|
while (true) {
|
|
1175
1182
|
const url = new URL(currentHref, window.location.origin);
|
|
1176
1183
|
const requestState = getRequestState(navigationKind, url.pathname, currentPrevNextUrl, activeTraversalIntent?.historyState);
|
|
@@ -1380,7 +1387,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1380
1387
|
interceptionContext: requestInterceptionContext,
|
|
1381
1388
|
mountedSlotsHeader,
|
|
1382
1389
|
routeManifest,
|
|
1383
|
-
templates: optimisticRouteTemplates
|
|
1390
|
+
templates: optimisticRouteTemplates.templates
|
|
1384
1391
|
});
|
|
1385
1392
|
if (optimisticPayload !== null && canCommitOptimisticRouteTemplate({
|
|
1386
1393
|
currentElements: navigationInitiationState.elements,
|
|
@@ -1419,13 +1426,16 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1419
1426
|
}
|
|
1420
1427
|
}
|
|
1421
1428
|
}
|
|
1429
|
+
let sentMountedLayouts = false;
|
|
1422
1430
|
if (!navResponse) {
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1431
|
+
let liveRequestHeaders = requestHeaders;
|
|
1432
|
+
if (mountedLayoutsHeader !== null && requestInterceptionContext === null) {
|
|
1433
|
+
liveRequestHeaders = new Headers(requestHeaders);
|
|
1434
|
+
liveRequestHeaders.set(VINEXT_MOUNTED_LAYOUTS_HEADER, mountedLayoutsHeader);
|
|
1435
|
+
sentMountedLayouts = true;
|
|
1426
1436
|
}
|
|
1427
1437
|
navResponse = await fetch(rscUrl, {
|
|
1428
|
-
headers:
|
|
1438
|
+
headers: liveRequestHeaders,
|
|
1429
1439
|
credentials: "include",
|
|
1430
1440
|
priority: "auto",
|
|
1431
1441
|
signal: navigationAbortHandle.signal
|
|
@@ -1508,6 +1518,15 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1508
1518
|
navigationAbortHandle.release();
|
|
1509
1519
|
}).then(requireCompleteSupplementalRefresh);
|
|
1510
1520
|
}
|
|
1521
|
+
if (sentMountedLayouts) {
|
|
1522
|
+
const elements = await rscPayload;
|
|
1523
|
+
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
1524
|
+
if (!holdsSkippedLayouts(navigationInitiationState, elements) || !holdsSkippedLayouts(getBrowserRouterState(), elements)) {
|
|
1525
|
+
mountedLayoutsHeader = null;
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
rscPayload = Promise.resolve(elements);
|
|
1529
|
+
}
|
|
1511
1530
|
if (IS_STATIC_EXPORT) {
|
|
1512
1531
|
const staticExportElements = await rscPayload;
|
|
1513
1532
|
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
@@ -1584,13 +1603,12 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1584
1603
|
const state = committedState;
|
|
1585
1604
|
const committedElements = {
|
|
1586
1605
|
...state.elements,
|
|
1587
|
-
[AppElementsWire.keys.layoutFlags]: state.layoutFlags,
|
|
1588
1606
|
[AppElementsWire.keys.layoutIds]: state.layoutIds,
|
|
1589
1607
|
[AppElementsWire.keys.skippedLayoutIds]: [],
|
|
1590
1608
|
[AppElementsWire.keys.slotBindings]: state.slotBindings
|
|
1591
1609
|
};
|
|
1592
1610
|
if (navigationCacheGeneration !== clientNavigationCacheGeneration) return;
|
|
1593
|
-
storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, navParams, DYNAMIC_NAVIGATION_CACHE_TTL, mountedSlotsHeader, committedElements,
|
|
1611
|
+
storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, navParams, DYNAMIC_NAVIGATION_CACHE_TTL, mountedSlotsHeader, committedElements, isCompleteAppPayloadMetadata(metadata), prefetchSnapshot, interceptionContext !== null || hasNavigationResponseHistoryLifetime(snapshot));
|
|
1594
1612
|
}
|
|
1595
1613
|
} catch {}
|
|
1596
1614
|
return;
|
|
@@ -1603,9 +1621,11 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1603
1621
|
navigationAbortHandle.release();
|
|
1604
1622
|
browserNavigationController.finalizeNavigation(navId, pendingRouterState);
|
|
1605
1623
|
discardedServerActionRefreshScheduler.markNavigationSettled();
|
|
1624
|
+
releaseNavigationInFlight();
|
|
1606
1625
|
if (startedHardNavigation) await waitForMpaNavigationRestore();
|
|
1607
1626
|
}
|
|
1608
1627
|
},
|
|
1628
|
+
readVisitedResponseForFullPrefetch: (rscUrls, interceptionContext, mountedSlotsHeader) => findVisitedResponseForFullPrefetch(visitedResponseCache, rscUrls, interceptionContext, mountedSlotsHeader),
|
|
1609
1629
|
preparePrefetchResponse: (response) => {
|
|
1610
1630
|
if (!isRscResponseCompatible(response.headers.get("X-Vinext-RSC-Compatibility-Id"))) return Promise.reject(/* @__PURE__ */ new Error("[vinext] Prefetched another deployment's payload"));
|
|
1611
1631
|
return decodeAppElementsPromise(createFromFetch(Promise.resolve(response)));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouterHistoryWriteLanding } from "../shims/navigation.js";
|
|
1
2
|
import { BfcacheIdMap, HistoryTraversalIntent } from "./app-history-state.js";
|
|
2
3
|
import { AppRouterState } from "./app-browser-state.js";
|
|
3
4
|
import { HistoryUpdateMode } from "./app-browser-navigation-controller.js";
|
|
@@ -19,10 +20,10 @@ type AppBrowserHistoryControllerDeps = {
|
|
|
19
20
|
readHistoryState: () => unknown;
|
|
20
21
|
/** Reads `window.location.href`. Injected so the controller stays unit-testable. */
|
|
21
22
|
readCurrentHref: () => string;
|
|
22
|
-
/** Wraps `pushHistoryStateWithoutNotify(state, "", href)`. */
|
|
23
|
-
pushHistoryState: (state: unknown, href: string) => void;
|
|
24
|
-
/** Wraps `replaceHistoryStateWithoutNotify(state, "", href)`. */
|
|
25
|
-
replaceHistoryState: (state: unknown, href?: string) => void;
|
|
23
|
+
/** Wraps `pushHistoryStateWithoutNotify(state, "", href, land)`. */
|
|
24
|
+
pushHistoryState: (state: unknown, href: string, land?: RouterHistoryWriteLanding) => void;
|
|
25
|
+
/** Wraps `replaceHistoryStateWithoutNotify(state, "", href, land)`. */
|
|
26
|
+
replaceHistoryState: (state: unknown, href?: string, land?: RouterHistoryWriteLanding) => void;
|
|
26
27
|
readVisibleNavigationMetadata: () => VisibleNavigationMetadata | null;
|
|
27
28
|
};
|
|
28
29
|
/**
|