vinext 0.0.50 → 0.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/google-fonts/fallback-metrics-data.js +14031 -0
- package/dist/build/google-fonts/fallback-metrics-data.js.map +1 -0
- package/dist/build/google-fonts/fallback-metrics.d.ts +13 -0
- package/dist/build/google-fonts/fallback-metrics.js +46 -0
- package/dist/build/google-fonts/fallback-metrics.js.map +1 -0
- package/dist/build/precompress.d.ts +13 -2
- package/dist/build/precompress.js +12 -3
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +1 -1
- package/dist/build/prerender.js +44 -14
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/report.d.ts +5 -4
- package/dist/build/report.js +196 -348
- package/dist/build/report.js.map +1 -1
- package/dist/check.js +1 -0
- package/dist/check.js.map +1 -1
- package/dist/cli.js +60 -3
- package/dist/cli.js.map +1 -1
- package/dist/client/window-next.d.ts +3 -1
- package/dist/client/window-next.js.map +1 -1
- package/dist/config/dotenv.d.ts +11 -1
- package/dist/config/dotenv.js.map +1 -1
- package/dist/config/next-config.d.ts +87 -3
- package/dist/config/next-config.js +222 -6
- package/dist/config/next-config.js.map +1 -1
- package/dist/config/tsconfig-paths.d.ts +13 -0
- package/dist/config/tsconfig-paths.js +117 -0
- package/dist/config/tsconfig-paths.js.map +1 -0
- package/dist/deploy.js +3 -2
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +2 -2
- package/dist/entries/app-browser-entry.js +26 -1
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +19 -1
- package/dist/entries/app-rsc-entry.js +38 -12
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +9 -0
- package/dist/entries/app-rsc-manifest.js +4 -1
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/pages-client-entry.js +3 -5
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +19 -1
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.js +130 -37
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-reference-dedup.d.ts +15 -2
- package/dist/plugins/client-reference-dedup.js +138 -16
- package/dist/plugins/client-reference-dedup.js.map +1 -1
- package/dist/plugins/fonts.d.ts +2 -2
- package/dist/plugins/fonts.js +15 -6
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/sass.d.ts +34 -0
- package/dist/plugins/sass.js +22 -0
- package/dist/plugins/sass.js.map +1 -0
- package/dist/routing/app-route-graph.d.ts +31 -2
- package/dist/routing/app-route-graph.js +82 -10
- package/dist/routing/app-route-graph.js.map +1 -1
- package/dist/routing/route-pattern.d.ts +56 -1
- package/dist/routing/route-pattern.js +60 -1
- package/dist/routing/route-pattern.js.map +1 -1
- package/dist/server/app-browser-action-result.d.ts +27 -2
- package/dist/server/app-browser-action-result.js +63 -2
- package/dist/server/app-browser-action-result.js.map +1 -1
- package/dist/server/app-browser-entry.js +262 -108
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-hydration.d.ts +13 -1
- package/dist/server/app-browser-hydration.js +9 -1
- package/dist/server/app-browser-hydration.js.map +1 -1
- package/dist/server/app-browser-navigation-controller.d.ts +14 -1
- package/dist/server/app-browser-navigation-controller.js +28 -9
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-browser-popstate.d.ts +16 -0
- package/dist/server/app-browser-popstate.js +17 -0
- package/dist/server/app-browser-popstate.js.map +1 -0
- package/dist/server/app-browser-rsc-redirect.d.ts +28 -0
- package/dist/server/app-browser-rsc-redirect.js +37 -0
- package/dist/server/app-browser-rsc-redirect.js.map +1 -0
- package/dist/server/app-browser-state.d.ts +11 -7
- package/dist/server/app-browser-state.js +45 -27
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +5 -4
- package/dist/server/app-browser-stream.js +5 -6
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +5 -0
- package/dist/server/app-browser-visible-commit.js +38 -5
- package/dist/server/app-browser-visible-commit.js.map +1 -1
- package/dist/server/app-elements-wire.d.ts +38 -6
- package/dist/server/app-elements-wire.js +106 -6
- package/dist/server/app-elements-wire.js.map +1 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +2 -2
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +10 -1
- package/dist/server/app-fallback-renderer.js +37 -1
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-history-state.d.ts +26 -0
- package/dist/server/app-history-state.js +53 -0
- package/dist/server/app-history-state.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +10 -1
- package/dist/server/app-page-boundary-render.js +13 -6
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.js +3 -2
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +13 -0
- package/dist/server/app-page-cache.js +25 -8
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +5 -0
- package/dist/server/app-page-dispatch.js +68 -11
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +7 -0
- package/dist/server/app-page-element-builder.js +32 -4
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.js +2 -3
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.d.ts +7 -0
- package/dist/server/app-page-head.js +2 -1
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +23 -1
- package/dist/server/app-page-probe.js +29 -1
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render-observation.d.ts +35 -0
- package/dist/server/app-page-render-observation.js +68 -0
- package/dist/server/app-page-render-observation.js.map +1 -0
- package/dist/server/app-page-render.d.ts +5 -1
- package/dist/server/app-page-render.js +79 -3
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +1 -0
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.js +3 -2
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +3 -1
- package/dist/server/app-page-route-wiring.js +42 -14
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +2 -0
- package/dist/server/app-page-stream.js +1 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-router-entry.js +1 -13
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +19 -1
- package/dist/server/app-rsc-cache-busting.js +36 -1
- package/dist/server/app-rsc-cache-busting.js.map +1 -1
- package/dist/server/app-rsc-embedded-chunks.d.ts +9 -0
- package/dist/server/app-rsc-embedded-chunks.js +34 -0
- package/dist/server/app-rsc-embedded-chunks.js.map +1 -0
- package/dist/server/app-rsc-errors.d.ts +4 -1
- package/dist/server/app-rsc-errors.js +1 -1
- package/dist/server/app-rsc-errors.js.map +1 -1
- package/dist/server/app-rsc-handler.d.ts +12 -4
- package/dist/server/app-rsc-handler.js +6 -1
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-route-matching.d.ts +23 -0
- package/dist/server/app-rsc-route-matching.js +45 -23
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +35 -3
- package/dist/server/app-server-action-execution.js +87 -33
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.d.ts +1 -0
- package/dist/server/app-ssr-entry.js +37 -13
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-error-meta.d.ts +14 -0
- package/dist/server/app-ssr-error-meta.js +50 -0
- package/dist/server/app-ssr-error-meta.js.map +1 -0
- package/dist/server/app-ssr-stream.d.ts +1 -1
- package/dist/server/app-ssr-stream.js +9 -12
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +12 -2
- package/dist/server/artifact-compatibility.js +12 -8
- package/dist/server/artifact-compatibility.js.map +1 -1
- package/dist/server/cache-proof.d.ts +124 -5
- package/dist/server/cache-proof.js +416 -18
- package/dist/server/cache-proof.js.map +1 -1
- package/dist/server/dev-lockfile.d.ts +110 -0
- package/dist/server/dev-lockfile.js +180 -0
- package/dist/server/dev-lockfile.js.map +1 -0
- package/dist/server/dev-server.js +15 -5
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/file-based-metadata.d.ts +13 -0
- package/dist/server/file-based-metadata.js +49 -2
- package/dist/server/file-based-metadata.js.map +1 -1
- package/dist/server/headers.d.ts +3 -1
- package/dist/server/headers.js +5 -2
- package/dist/server/headers.js.map +1 -1
- package/dist/server/html.js +1 -1
- package/dist/server/html.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +10 -0
- package/dist/server/http-error-responses.js +11 -1
- package/dist/server/http-error-responses.js.map +1 -1
- package/dist/server/isr-cache.d.ts +2 -1
- package/dist/server/isr-cache.js +4 -2
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-route-response.js +22 -5
- package/dist/server/metadata-route-response.js.map +1 -1
- package/dist/server/metadata-routes.js +27 -8
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-runtime.js +1 -0
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/middleware.d.ts +12 -0
- package/dist/server/middleware.js +12 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/navigation-planner.d.ts +19 -5
- package/dist/server/navigation-planner.js +278 -17
- package/dist/server/navigation-planner.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +8 -1
- package/dist/server/navigation-trace.js +7 -0
- package/dist/server/navigation-trace.js.map +1 -1
- package/dist/server/normalize-path.d.ts +2 -1
- package/dist/server/normalize-path.js +4 -1
- package/dist/server/normalize-path.js.map +1 -1
- package/dist/server/pages-api-route.js +1 -0
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +3 -2
- package/dist/server/pages-page-data.js +22 -3
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/prod-server.d.ts +28 -1
- package/dist/server/prod-server.js +62 -9
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/server-action-not-found.d.ts +16 -3
- package/dist/server/server-action-not-found.js +19 -1
- package/dist/server/server-action-not-found.js.map +1 -1
- package/dist/server/server-globals.d.ts +5 -0
- package/dist/server/server-globals.js +37 -0
- package/dist/server/server-globals.js.map +1 -0
- package/dist/server/static-file-cache.js +1 -1
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/shims/cache-runtime.d.ts +19 -2
- package/dist/shims/cache-runtime.js +67 -11
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +5 -18
- package/dist/shims/cache.js +2 -0
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/error-boundary.js +6 -8
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/error.d.ts +18 -1
- package/dist/shims/error.js +56 -1
- package/dist/shims/error.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +4 -1
- package/dist/shims/fetch-cache.js +40 -5
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +22 -8
- package/dist/shims/font-google-base.js +41 -71
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/font-local.d.ts +3 -20
- package/dist/shims/font-local.js +23 -75
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/font-utils.d.ts +51 -0
- package/dist/shims/font-utils.js +97 -0
- package/dist/shims/font-utils.js.map +1 -0
- package/dist/shims/hash-scroll.d.ts +7 -0
- package/dist/shims/hash-scroll.js +30 -0
- package/dist/shims/hash-scroll.js.map +1 -0
- package/dist/shims/headers.d.ts +8 -11
- package/dist/shims/headers.js +22 -2
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.d.ts +1 -0
- package/dist/shims/image.js +144 -78
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/app-router-context.d.ts +6 -6
- package/dist/shims/internal/app-router-context.js +17 -6
- package/dist/shims/internal/app-router-context.js.map +1 -1
- package/dist/shims/link-prefetch.d.ts +9 -1
- package/dist/shims/link-prefetch.js +11 -6
- package/dist/shims/link-prefetch.js.map +1 -1
- package/dist/shims/link.d.ts +12 -2
- package/dist/shims/link.js +78 -32
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +16 -30
- package/dist/shims/metadata.js +87 -28
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +158 -17
- package/dist/shims/navigation.js +324 -74
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/navigation.react-server.d.ts +3 -2
- package/dist/shims/navigation.react-server.js +5 -2
- package/dist/shims/navigation.react-server.js.map +1 -1
- package/dist/shims/pages-router-runtime.d.ts +7 -0
- package/dist/shims/pages-router-runtime.js +16 -0
- package/dist/shims/pages-router-runtime.js.map +1 -0
- package/dist/shims/router.d.ts +32 -6
- package/dist/shims/router.js +197 -242
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.js +110 -32
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.js +2 -1
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.d.ts +1 -0
- package/dist/shims/slot.js +41 -1
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/unrecognized-action-error.d.ts +35 -0
- package/dist/shims/unrecognized-action-error.js +41 -0
- package/dist/shims/unrecognized-action-error.js.map +1 -0
- package/dist/shims/url-utils.d.ts +21 -1
- package/dist/shims/url-utils.js +67 -3
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/utils/asset-prefix.d.ts +69 -0
- package/dist/utils/asset-prefix.js +91 -0
- package/dist/utils/asset-prefix.js.map +1 -0
- package/dist/utils/base-path.d.ts +7 -1
- package/dist/utils/base-path.js +10 -1
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/navigation-signal.d.ts +1 -2
- package/dist/utils/navigation-signal.js +1 -1
- package/dist/utils/navigation-signal.js.map +1 -1
- package/dist/utils/sorted-array.d.ts +9 -0
- package/dist/utils/sorted-array.js +22 -0
- package/dist/utils/sorted-array.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,25 +1,31 @@
|
|
|
1
|
+
import { stripBasePath } from "../utils/base-path.js";
|
|
1
2
|
import { ACTION_REDIRECT_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_PARAMS_HEADER } from "./headers.js";
|
|
2
3
|
import { DANGEROUS_URL_BLOCK_MESSAGE, isDangerousScheme } from "../shims/url-safety.js";
|
|
3
4
|
import { APP_RSC_RENDER_MODE_REFRESH_PRESERVE_UI } from "./app-rsc-render-mode.js";
|
|
4
5
|
import { installWindowNext } from "../client/window-next.js";
|
|
6
|
+
import { scrollToHashTargetOnNextFrame } from "../shims/hash-scroll.js";
|
|
5
7
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
6
8
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
7
9
|
import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
+
import { createHistoryStateWithNavigationMetadata, createHistoryStateWithPreviousNextUrl, readHistoryStatePreviousNextUrl, readHistoryStateTraversalIndex, resolveHistoryTraversalIntent } from "./app-history-state.js";
|
|
11
|
+
import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, getVinextRscCompatibilityId, resolveHardNavigationTargetFromRscResponse, resolveRscCompatibilityNavigationDecision } from "./app-rsc-cache-busting.js";
|
|
12
|
+
import { AppRouterContext } from "../shims/internal/app-router-context.js";
|
|
13
|
+
import { __basePath, appRouterInstance, commitClientNavigationState, consumePrefetchResponse, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, getClientNavigationRenderContext, getCurrentInterceptionContext, getCurrentNextUrl, invalidatePrefetchCache, pushHistoryStateWithoutNotify, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, restoreRscResponse, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname } from "../shims/navigation.js";
|
|
10
14
|
import { DevRecoveryBoundary, RedirectBoundary } from "../shims/error-boundary.js";
|
|
11
15
|
import { ElementsContext, Slot } from "../shims/slot.js";
|
|
12
16
|
import "../client/instrumentation-client.js";
|
|
13
|
-
import { isServerActionResult, shouldClearClientNavigationCachesForServerActionResult } from "./app-browser-action-result.js";
|
|
17
|
+
import { createDiscardedServerActionRefreshScheduler, createServerActionInitiationSnapshot, isServerActionResult, parseServerActionRevalidationHeader, shouldClearClientNavigationCachesForServerActionResult } from "./app-browser-action-result.js";
|
|
14
18
|
import { chunksToReadableStream, createProgressiveRscStream, getVinextBrowserGlobal } from "./app-browser-stream.js";
|
|
15
|
-
import {
|
|
19
|
+
import { resolveInterceptionContextFromPreviousNextUrl, resolveServerActionRequestState } from "./app-browser-state.js";
|
|
16
20
|
import { clearHardNavigationLoopGuard, createAppBrowserNavigationController } from "./app-browser-navigation-controller.js";
|
|
17
|
-
import { consumeInitialFormState, createVinextHydrateRootOptions } from "./app-browser-hydration.js";
|
|
21
|
+
import { consumeInitialFormState, createVinextHydrateRootOptions, hydrateRootInTransition } from "./app-browser-hydration.js";
|
|
22
|
+
import { createPopstateRestoreHandler } from "./app-browser-popstate.js";
|
|
18
23
|
import { createOnUncaughtError } from "./app-browser-error.js";
|
|
19
24
|
import { dismissOverlay } from "./dev-error-overlay-store.js";
|
|
20
25
|
import { devOnCaughtError, devOnUncaughtError, installDevErrorOverlay } from "./dev-error-overlay.js";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
26
|
+
import { throwOnServerActionNotFound } from "./server-action-not-found.js";
|
|
27
|
+
import { resolveRscRedirectLifecycleHop } from "./app-browser-rsc-redirect.js";
|
|
28
|
+
import { createElement, startTransition, use, useLayoutEffect, useRef, useState } from "react";
|
|
23
29
|
import { createFromFetch, createFromReadableStream, createTemporaryReferenceSet, encodeReply, setServerCallback } from "@vitejs/plugin-rsc/browser";
|
|
24
30
|
import { hydrateRoot } from "react-dom/client";
|
|
25
31
|
//#region src/server/app-browser-entry.ts
|
|
@@ -37,7 +43,20 @@ function toOperationLane(kind) {
|
|
|
37
43
|
const MAX_VISITED_RESPONSE_CACHE_SIZE = 50;
|
|
38
44
|
const VISITED_RESPONSE_CACHE_TTL = 5 * 6e4;
|
|
39
45
|
const MAX_TRAVERSAL_CACHE_TTL = 30 * 6e4;
|
|
40
|
-
const
|
|
46
|
+
const CLIENT_RSC_COMPATIBILITY_ID = getVinextRscCompatibilityId();
|
|
47
|
+
function getBrowserRouteManifest() {
|
|
48
|
+
return window.__VINEXT_ROUTE_MANIFEST__ ?? null;
|
|
49
|
+
}
|
|
50
|
+
const browserNavigationController = createAppBrowserNavigationController({
|
|
51
|
+
getRouteManifest: getBrowserRouteManifest,
|
|
52
|
+
syncHistoryStatePreviousNextUrl: syncCurrentHistoryStatePreviousNextUrl
|
|
53
|
+
});
|
|
54
|
+
const discardedServerActionRefreshScheduler = createDiscardedServerActionRefreshScheduler({ runRefresh() {
|
|
55
|
+
clearClientNavigationCaches();
|
|
56
|
+
const rscNavigate = window.__VINEXT_RSC_NAVIGATE__;
|
|
57
|
+
if (typeof rscNavigate !== "function") return;
|
|
58
|
+
rscNavigate(window.location.href, 0, "refresh", void 0, void 0, true);
|
|
59
|
+
} });
|
|
41
60
|
const NavigationCommitSignal = browserNavigationController.NavigationCommitSignal;
|
|
42
61
|
function parseEncodedJsonHeader(value) {
|
|
43
62
|
if (!value) return null;
|
|
@@ -54,6 +73,47 @@ let latestClientParams = {};
|
|
|
54
73
|
const visitedResponseCache = /* @__PURE__ */ new Map();
|
|
55
74
|
let browserRouterStateHasEverCommitted = false;
|
|
56
75
|
let pendingNavigationRecoveryHref = null;
|
|
76
|
+
let currentHistoryTraversalIndex = readHistoryStateTraversalIndex(window.history.state) ?? 0;
|
|
77
|
+
let nextHistoryTraversalIndex = currentHistoryTraversalIndex;
|
|
78
|
+
function allocateNavigationHistoryTraversalIndex(historyUpdateMode) {
|
|
79
|
+
switch (historyUpdateMode) {
|
|
80
|
+
case "push": return nextHistoryTraversalIndex + 1;
|
|
81
|
+
case "replace": return currentHistoryTraversalIndex;
|
|
82
|
+
case void 0: return null;
|
|
83
|
+
default: throw new Error("[vinext] Unknown history update mode: " + String(historyUpdateMode));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function commitHistoryTraversalIndex(index) {
|
|
87
|
+
currentHistoryTraversalIndex = index;
|
|
88
|
+
if (index !== null) nextHistoryTraversalIndex = Math.max(nextHistoryTraversalIndex, index);
|
|
89
|
+
}
|
|
90
|
+
function commitHashOnlyNavigation(href, historyUpdateMode, scroll) {
|
|
91
|
+
const navigationHistoryIndex = allocateNavigationHistoryTraversalIndex(historyUpdateMode);
|
|
92
|
+
const previousNextUrl = hasBrowserRouterState() ? getBrowserRouterState().previousNextUrl : readHistoryStatePreviousNextUrl(window.history.state);
|
|
93
|
+
const historyState = createHistoryStateWithNavigationMetadata(createHashOnlyNavigationBaseHistoryState(historyUpdateMode, scroll), {
|
|
94
|
+
previousNextUrl,
|
|
95
|
+
traversalIndex: navigationHistoryIndex
|
|
96
|
+
});
|
|
97
|
+
if (historyUpdateMode === "replace") replaceHistoryStateWithoutNotify(historyState, "", href);
|
|
98
|
+
else pushHistoryStateWithoutNotify(historyState, "", href);
|
|
99
|
+
commitHistoryTraversalIndex(navigationHistoryIndex);
|
|
100
|
+
}
|
|
101
|
+
function createHashOnlyNavigationBaseHistoryState(historyUpdateMode, scroll) {
|
|
102
|
+
if (historyUpdateMode !== "replace") return null;
|
|
103
|
+
return scroll ? stripVinextScrollState(window.history.state) : window.history.state;
|
|
104
|
+
}
|
|
105
|
+
function stripVinextScrollState(state) {
|
|
106
|
+
if (!state || typeof state !== "object") return state;
|
|
107
|
+
const nextState = {};
|
|
108
|
+
for (const [key, value] of Object.entries(state)) {
|
|
109
|
+
if (key === "__vinext_scrollX" || key === "__vinext_scrollY") continue;
|
|
110
|
+
nextState[key] = value;
|
|
111
|
+
}
|
|
112
|
+
return Object.keys(nextState).length > 0 ? nextState : null;
|
|
113
|
+
}
|
|
114
|
+
function commitTraversalIndexFromHistoryState(historyState) {
|
|
115
|
+
commitHistoryTraversalIndex(readHistoryStateTraversalIndex(historyState));
|
|
116
|
+
}
|
|
57
117
|
function getBrowserRouterState() {
|
|
58
118
|
return browserNavigationController.getBrowserRouterState();
|
|
59
119
|
}
|
|
@@ -78,30 +138,63 @@ function clearVisitedResponseCache() {
|
|
|
78
138
|
visitedResponseCache.clear();
|
|
79
139
|
}
|
|
80
140
|
function clearPrefetchState() {
|
|
81
|
-
|
|
82
|
-
getPrefetchedUrls().clear();
|
|
141
|
+
invalidatePrefetchCache();
|
|
83
142
|
}
|
|
84
143
|
function clearClientNavigationCaches() {
|
|
85
144
|
clearVisitedResponseCache();
|
|
86
145
|
clearPrefetchState();
|
|
87
146
|
}
|
|
147
|
+
function syncCurrentHistoryStatePreviousNextUrl(previousNextUrl) {
|
|
148
|
+
if (readHistoryStatePreviousNextUrl(window.history.state) === previousNextUrl) return;
|
|
149
|
+
const nextHistoryState = createHistoryStateWithPreviousNextUrl(window.history.state, previousNextUrl);
|
|
150
|
+
replaceHistoryStateWithoutNotify(nextHistoryState, "", window.location.href);
|
|
151
|
+
if (readHistoryStatePreviousNextUrl(window.history.state) === previousNextUrl) return;
|
|
152
|
+
window.history.replaceState(nextHistoryState, "", window.location.href);
|
|
153
|
+
}
|
|
154
|
+
function createActionInitiationSnapshot() {
|
|
155
|
+
const routerState = getBrowserRouterState();
|
|
156
|
+
return createServerActionInitiationSnapshot({
|
|
157
|
+
href: window.location.href,
|
|
158
|
+
navigationId: browserNavigationController.getActiveNavigationId(),
|
|
159
|
+
routerState
|
|
160
|
+
});
|
|
161
|
+
}
|
|
88
162
|
function createNavigationCommitEffect(options) {
|
|
89
|
-
const { href, historyUpdateMode, navId, params, previousNextUrl } = options;
|
|
163
|
+
const { href, historyUpdateMode, navId, params, previousNextUrl, targetHistoryIndex } = options;
|
|
90
164
|
return () => {
|
|
91
165
|
if (!browserNavigationController.isCurrentNavigation(navId)) {
|
|
92
166
|
commitClientNavigationState(void 0, { releaseSnapshot: true });
|
|
93
167
|
return;
|
|
94
168
|
}
|
|
95
169
|
const targetHref = new URL(href, window.location.origin).href;
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
170
|
+
const preserveExistingState = historyUpdateMode === "replace";
|
|
171
|
+
const navigationHistoryIndex = targetHistoryIndex !== void 0 ? targetHistoryIndex : allocateNavigationHistoryTraversalIndex(historyUpdateMode);
|
|
172
|
+
const historyState = createHistoryStateWithNavigationMetadata(preserveExistingState ? window.history.state : null, {
|
|
173
|
+
previousNextUrl,
|
|
174
|
+
traversalIndex: navigationHistoryIndex
|
|
175
|
+
});
|
|
176
|
+
let wroteHistoryState = false;
|
|
177
|
+
if (historyUpdateMode === "replace" && window.location.href !== targetHref) {
|
|
178
|
+
stageClientParams(params);
|
|
179
|
+
replaceHistoryStateWithoutNotify(historyState, "", href);
|
|
180
|
+
wroteHistoryState = true;
|
|
181
|
+
commitHistoryTraversalIndex(navigationHistoryIndex);
|
|
182
|
+
} else if (historyUpdateMode === "push" && window.location.href !== targetHref) {
|
|
183
|
+
stageClientParams(params);
|
|
184
|
+
pushHistoryStateWithoutNotify(historyState, "", href);
|
|
185
|
+
wroteHistoryState = true;
|
|
186
|
+
commitHistoryTraversalIndex(navigationHistoryIndex);
|
|
187
|
+
}
|
|
188
|
+
if (!wroteHistoryState) {
|
|
189
|
+
syncCurrentHistoryStatePreviousNextUrl(previousNextUrl);
|
|
190
|
+
stageClientParams(params);
|
|
191
|
+
if (targetHistoryIndex !== void 0) commitHistoryTraversalIndex(targetHistoryIndex);
|
|
192
|
+
}
|
|
100
193
|
pendingNavigationRecoveryHref = null;
|
|
101
194
|
commitClientNavigationState(navId);
|
|
102
195
|
};
|
|
103
196
|
}
|
|
104
|
-
async function renderNavigationPayload(payload, navigationSnapshot, targetHref, navId, historyUpdateMode, params, previousNextUrl, pendingRouterState, actionType = "navigate", operationLane = "navigation") {
|
|
197
|
+
async function renderNavigationPayload(payload, navigationSnapshot, targetHref, navId, historyUpdateMode, params, previousNextUrl, pendingRouterState, actionType = "navigate", operationLane = "navigation", traversalIntent = null) {
|
|
105
198
|
try {
|
|
106
199
|
return await browserNavigationController.renderNavigationPayload({
|
|
107
200
|
actionType,
|
|
@@ -116,6 +209,7 @@ async function renderNavigationPayload(payload, navigationSnapshot, targetHref,
|
|
|
116
209
|
params,
|
|
117
210
|
pendingRouterState,
|
|
118
211
|
previousNextUrl,
|
|
212
|
+
targetHistoryIndex: traversalIntent === null ? void 0 : traversalIntent.targetHistoryIndex,
|
|
119
213
|
targetHref,
|
|
120
214
|
navId
|
|
121
215
|
});
|
|
@@ -124,9 +218,16 @@ async function renderNavigationPayload(payload, navigationSnapshot, targetHref,
|
|
|
124
218
|
throw error;
|
|
125
219
|
}
|
|
126
220
|
}
|
|
127
|
-
async function commitSameUrlNavigatePayload(nextElements, returnValue,
|
|
128
|
-
const navigationSnapshot = createClientNavigationRenderSnapshot(
|
|
129
|
-
return browserNavigationController.commitSameUrlNavigatePayload(nextElements, navigationSnapshot, returnValue,
|
|
221
|
+
async function commitSameUrlNavigatePayload(nextElements, actionInitiation, returnValue, revalidation = "none") {
|
|
222
|
+
const navigationSnapshot = createClientNavigationRenderSnapshot(actionInitiation.href, actionInitiation.routerState.navigationSnapshot.params);
|
|
223
|
+
return browserNavigationController.commitSameUrlNavigatePayload(nextElements, navigationSnapshot, returnValue, actionInitiation.routerState, {
|
|
224
|
+
onDiscardedRevalidation() {
|
|
225
|
+
discardedServerActionRefreshScheduler.schedule();
|
|
226
|
+
},
|
|
227
|
+
revalidation,
|
|
228
|
+
startedNavigationId: actionInitiation.navigationId,
|
|
229
|
+
targetHref: actionInitiation.href
|
|
230
|
+
});
|
|
130
231
|
}
|
|
131
232
|
function evictVisitedResponseCacheIfNeeded() {
|
|
132
233
|
while (visitedResponseCache.size >= MAX_VISITED_RESPONSE_CACHE_SIZE) {
|
|
@@ -173,18 +274,25 @@ function storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, par
|
|
|
173
274
|
response: snapshot
|
|
174
275
|
});
|
|
175
276
|
}
|
|
176
|
-
function getRequestState(navigationKind, previousNextUrlOverride) {
|
|
277
|
+
function getRequestState(navigationKind, previousNextUrlOverride, traverseHistoryState) {
|
|
177
278
|
if (previousNextUrlOverride !== void 0) return {
|
|
178
279
|
interceptionContext: resolveInterceptionContextFromPreviousNextUrl(previousNextUrlOverride, __basePath),
|
|
179
280
|
previousNextUrl: previousNextUrlOverride
|
|
180
281
|
};
|
|
181
282
|
switch (navigationKind) {
|
|
182
|
-
case "navigate":
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
283
|
+
case "navigate": {
|
|
284
|
+
const currentPreviousNextUrl = getBrowserRouterState().previousNextUrl;
|
|
285
|
+
if (currentPreviousNextUrl !== null) return {
|
|
286
|
+
interceptionContext: resolveInterceptionContextFromPreviousNextUrl(currentPreviousNextUrl, __basePath),
|
|
287
|
+
previousNextUrl: currentPreviousNextUrl
|
|
288
|
+
};
|
|
289
|
+
return {
|
|
290
|
+
interceptionContext: getCurrentInterceptionContext(),
|
|
291
|
+
previousNextUrl: getCurrentNextUrl()
|
|
292
|
+
};
|
|
293
|
+
}
|
|
186
294
|
case "traverse": {
|
|
187
|
-
const previousNextUrl = readHistoryStatePreviousNextUrl(window.history.state);
|
|
295
|
+
const previousNextUrl = readHistoryStatePreviousNextUrl(traverseHistoryState ?? window.history.state);
|
|
188
296
|
return {
|
|
189
297
|
interceptionContext: resolveInterceptionContextFromPreviousNextUrl(previousNextUrl, __basePath),
|
|
190
298
|
previousNextUrl
|
|
@@ -212,6 +320,7 @@ function BrowserRoot({ initialElements, initialNavigationSnapshot }) {
|
|
|
212
320
|
const [treeStateValue, setTreeStateValue] = useState({
|
|
213
321
|
activeOperation: null,
|
|
214
322
|
elements: resolvedElements,
|
|
323
|
+
interception: initialMetadata.interception,
|
|
215
324
|
interceptionContext: initialMetadata.interceptionContext,
|
|
216
325
|
layoutIds: initialMetadata.layoutIds,
|
|
217
326
|
layoutFlags: initialMetadata.layoutFlags,
|
|
@@ -220,6 +329,7 @@ function BrowserRoot({ initialElements, initialNavigationSnapshot }) {
|
|
|
220
329
|
renderId: 0,
|
|
221
330
|
rootLayoutTreePath: initialMetadata.rootLayoutTreePath,
|
|
222
331
|
routeId: initialMetadata.routeId,
|
|
332
|
+
slotBindings: initialMetadata.slotBindings,
|
|
223
333
|
visibleCommitVersion: 0
|
|
224
334
|
});
|
|
225
335
|
const treeState = isRouterStatePromise(treeStateValue) ? use(treeStateValue) : treeStateValue;
|
|
@@ -228,6 +338,7 @@ function BrowserRoot({ initialElements, initialNavigationSnapshot }) {
|
|
|
228
338
|
useLayoutEffect(() => {
|
|
229
339
|
const detach = browserNavigationController.attachBrowserRouterState(setTreeStateValue, stateRef);
|
|
230
340
|
browserRouterStateHasEverCommitted = true;
|
|
341
|
+
window.__VINEXT_HYDRATED_AT = performance.now();
|
|
231
342
|
return () => {
|
|
232
343
|
detach();
|
|
233
344
|
setMountedSlotsHeader(null);
|
|
@@ -235,12 +346,17 @@ function BrowserRoot({ initialElements, initialNavigationSnapshot }) {
|
|
|
235
346
|
}, [setTreeStateValue]);
|
|
236
347
|
useLayoutEffect(() => {
|
|
237
348
|
setMountedSlotsHeader(getMountedSlotIdsHeader(stateRef.current.elements));
|
|
349
|
+
window.__VINEXT_PING_VISIBLE_LINKS__?.();
|
|
238
350
|
}, [treeState.elements]);
|
|
239
351
|
useLayoutEffect(() => {
|
|
240
352
|
if (treeState.renderId !== 0) return;
|
|
241
|
-
replaceHistoryStateWithoutNotify(
|
|
353
|
+
replaceHistoryStateWithoutNotify(createHistoryStateWithNavigationMetadata(window.history.state, {
|
|
354
|
+
previousNextUrl: treeState.previousNextUrl,
|
|
355
|
+
traversalIndex: currentHistoryTraversalIndex
|
|
356
|
+
}), "", window.location.href);
|
|
242
357
|
}, [treeState.previousNextUrl, treeState.renderId]);
|
|
243
|
-
const
|
|
358
|
+
const routeTree = createElement(RedirectBoundary, null, createElement(NavigationCommitSignal, { renderId: treeState.renderId }, createElement(ElementsContext.Provider, { value: treeState.elements }, createElement(Slot, { id: treeState.routeId }))));
|
|
359
|
+
const innerTree = AppRouterContext ? createElement(AppRouterContext.Provider, { value: appRouterInstance }, routeTree) : routeTree;
|
|
244
360
|
const committedTree = import.meta.env.DEV ? createElement(DevRecoveryBoundary, {
|
|
245
361
|
resetKey: treeState.renderId,
|
|
246
362
|
onCatch: handleDevRecoveryBoundaryCatch
|
|
@@ -256,31 +372,9 @@ function restoreHydrationNavigationContext(pathname, searchParams, params) {
|
|
|
256
372
|
params
|
|
257
373
|
});
|
|
258
374
|
}
|
|
259
|
-
function decodeHashFragment(fragment) {
|
|
260
|
-
try {
|
|
261
|
-
return decodeURIComponent(fragment);
|
|
262
|
-
} catch {
|
|
263
|
-
return fragment;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function scrollToHashTarget(hash) {
|
|
267
|
-
const fragment = decodeHashFragment(hash.startsWith("#") ? hash.slice(1) : hash);
|
|
268
|
-
requestAnimationFrame(() => {
|
|
269
|
-
if (fragment === "" || fragment === "top") {
|
|
270
|
-
window.scrollTo(0, 0);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const idElement = document.getElementById(fragment);
|
|
274
|
-
if (idElement) {
|
|
275
|
-
idElement.scrollIntoView({ behavior: "auto" });
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
document.getElementsByName(fragment)[0]?.scrollIntoView({ behavior: "auto" });
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
375
|
function restorePopstateScrollPosition(state) {
|
|
282
376
|
if (!(state && typeof state === "object" && "__vinext_scrollY" in state)) {
|
|
283
|
-
if (window.location.hash)
|
|
377
|
+
if (window.location.hash) scrollToHashTargetOnNextFrame(window.location.hash);
|
|
284
378
|
return;
|
|
285
379
|
}
|
|
286
380
|
const y = Number(state.__vinext_scrollY);
|
|
@@ -289,6 +383,15 @@ function restorePopstateScrollPosition(state) {
|
|
|
289
383
|
window.scrollTo(x, y);
|
|
290
384
|
});
|
|
291
385
|
}
|
|
386
|
+
function isSameAppRoutePopstateTarget(href) {
|
|
387
|
+
if (!hasBrowserRouterState()) return false;
|
|
388
|
+
const target = new URL(href, window.location.origin);
|
|
389
|
+
const routerState = getBrowserRouterState();
|
|
390
|
+
const targetPathname = stripBasePath(target.pathname, __basePath);
|
|
391
|
+
const targetSearch = new URLSearchParams(target.search).toString();
|
|
392
|
+
const currentSearch = routerState.navigationSnapshot.searchParams.toString();
|
|
393
|
+
return targetPathname === routerState.navigationSnapshot.pathname && targetSearch === currentSearch;
|
|
394
|
+
}
|
|
292
395
|
let isPageUnloading = false;
|
|
293
396
|
const RSC_RELOAD_KEY = "__vinext_rsc_initial_reload__";
|
|
294
397
|
function readReloadFlag() {
|
|
@@ -364,20 +467,21 @@ async function readInitialRscStream() {
|
|
|
364
467
|
function registerServerActionCallback() {
|
|
365
468
|
setServerCallback(async (id, args) => {
|
|
366
469
|
const temporaryReferences = createTemporaryReferenceSet();
|
|
470
|
+
const actionInitiation = createActionInitiationSnapshot();
|
|
471
|
+
syncCurrentHistoryStatePreviousNextUrl(actionInitiation.routerState.previousNextUrl);
|
|
367
472
|
const body = await encodeReply(args, { temporaryReferences });
|
|
368
|
-
const currentState = getBrowserRouterState();
|
|
369
473
|
const { headers } = resolveServerActionRequestState({
|
|
370
474
|
actionId: id,
|
|
371
475
|
basePath: __basePath,
|
|
372
|
-
elements:
|
|
373
|
-
previousNextUrl:
|
|
476
|
+
elements: actionInitiation.routerState.elements,
|
|
477
|
+
previousNextUrl: actionInitiation.routerState.previousNextUrl
|
|
374
478
|
});
|
|
375
|
-
const fetchResponse = await fetch(await createRscRequestUrl(
|
|
479
|
+
const fetchResponse = await fetch(await createRscRequestUrl(actionInitiation.path, headers), {
|
|
376
480
|
method: "POST",
|
|
377
481
|
headers,
|
|
378
482
|
body
|
|
379
483
|
});
|
|
380
|
-
|
|
484
|
+
throwOnServerActionNotFound(fetchResponse, id);
|
|
381
485
|
const actionRedirect = fetchResponse.headers.get(ACTION_REDIRECT_HEADER);
|
|
382
486
|
if (actionRedirect) {
|
|
383
487
|
if (isDangerousScheme(actionRedirect)) {
|
|
@@ -395,17 +499,28 @@ function registerServerActionCallback() {
|
|
|
395
499
|
else window.location.replace(actionRedirect);
|
|
396
500
|
return;
|
|
397
501
|
}
|
|
502
|
+
if (resolveRscCompatibilityNavigationDecision({
|
|
503
|
+
clientCompatibilityId: CLIENT_RSC_COMPATIBILITY_ID,
|
|
504
|
+
currentHref: actionInitiation.href,
|
|
505
|
+
origin: window.location.origin,
|
|
506
|
+
responseCompatibilityId: fetchResponse.headers.get("X-Vinext-RSC-Compatibility-Id"),
|
|
507
|
+
responseUrl: fetchResponse.url
|
|
508
|
+
}).kind === "hard-navigate") {
|
|
509
|
+
window.location.reload();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const revalidation = parseServerActionRevalidationHeader(fetchResponse.headers);
|
|
398
513
|
const result = await createFromFetch(Promise.resolve(fetchResponse), { temporaryReferences });
|
|
399
|
-
if (shouldClearClientNavigationCachesForServerActionResult(result)) clearClientNavigationCaches();
|
|
514
|
+
if (shouldClearClientNavigationCachesForServerActionResult(result, revalidation)) clearClientNavigationCaches();
|
|
400
515
|
if (isServerActionResult(result)) {
|
|
401
|
-
if (result.root !== void 0) return commitSameUrlNavigatePayload(Promise.resolve(AppElementsWire.decode(result.root)), result.returnValue,
|
|
516
|
+
if (result.root !== void 0) return commitSameUrlNavigatePayload(Promise.resolve(AppElementsWire.decode(result.root)), actionInitiation, result.returnValue, revalidation);
|
|
402
517
|
if (result.returnValue) {
|
|
403
518
|
if (!result.returnValue.ok) throw result.returnValue.data;
|
|
404
519
|
return result.returnValue.data;
|
|
405
520
|
}
|
|
406
521
|
return;
|
|
407
522
|
}
|
|
408
|
-
return commitSameUrlNavigatePayload(Promise.resolve(AppElementsWire.decode(result)), void 0,
|
|
523
|
+
return commitSameUrlNavigatePayload(Promise.resolve(AppElementsWire.decode(result)), actionInitiation, void 0, revalidation);
|
|
409
524
|
});
|
|
410
525
|
}
|
|
411
526
|
async function main() {
|
|
@@ -418,7 +533,10 @@ function bootstrapHydration(rscStream) {
|
|
|
418
533
|
if (import.meta.env.DEV) installDevErrorOverlay();
|
|
419
534
|
const root = decodeAppElementsPromise(createFromReadableStream(rscStream));
|
|
420
535
|
const initialNavigationSnapshot = createClientNavigationRenderSnapshot(window.location.href, latestClientParams);
|
|
421
|
-
replaceHistoryStateWithoutNotify(
|
|
536
|
+
replaceHistoryStateWithoutNotify(createHistoryStateWithNavigationMetadata(window.history.state, {
|
|
537
|
+
previousNextUrl: null,
|
|
538
|
+
traversalIndex: currentHistoryTraversalIndex
|
|
539
|
+
}), "", window.location.href);
|
|
422
540
|
const onUncaughtError = import.meta.env.DEV ? devOnUncaughtError : createOnUncaughtError(() => pendingNavigationRecoveryHref);
|
|
423
541
|
const formState = consumeInitialFormState(getVinextBrowserGlobal());
|
|
424
542
|
const hydrateRootOptions = import.meta.env.DEV ? createVinextHydrateRootOptions({
|
|
@@ -429,21 +547,32 @@ function bootstrapHydration(rscStream) {
|
|
|
429
547
|
formState,
|
|
430
548
|
onUncaughtError
|
|
431
549
|
});
|
|
432
|
-
window.__VINEXT_RSC_ROOT__ =
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
550
|
+
window.__VINEXT_RSC_ROOT__ = hydrateRootInTransition({
|
|
551
|
+
children: createElement(BrowserRoot, {
|
|
552
|
+
initialElements: root,
|
|
553
|
+
initialNavigationSnapshot
|
|
554
|
+
}),
|
|
555
|
+
container: document,
|
|
556
|
+
hydrateRoot,
|
|
557
|
+
options: hydrateRootOptions,
|
|
558
|
+
startTransition
|
|
559
|
+
});
|
|
437
560
|
window.__VINEXT_CLEAR_NAV_CACHES__ = clearClientNavigationCaches;
|
|
438
|
-
window.
|
|
561
|
+
window.__VINEXT_RSC_COMMIT_HASH_NAVIGATION__ = commitHashOnlyNavigation;
|
|
562
|
+
window.__VINEXT_RSC_NAVIGATE__ = async function navigateRsc(href, redirectDepth = 0, navigationKind = "navigate", historyUpdateMode, previousNextUrlOverride, programmaticTransition = false, traversalIntent) {
|
|
439
563
|
let pendingRouterState = null;
|
|
440
564
|
const navId = browserNavigationController.beginNavigation();
|
|
565
|
+
discardedServerActionRefreshScheduler.markNavigationStart();
|
|
441
566
|
let currentHref = href;
|
|
442
567
|
let currentHistoryMode = historyUpdateMode;
|
|
443
568
|
let currentPrevNextUrl = previousNextUrlOverride;
|
|
444
569
|
let redirectCount = redirectDepth;
|
|
570
|
+
const activeTraversalIntent = navigationKind === "traverse" ? traversalIntent ?? resolveHistoryTraversalIntent({
|
|
571
|
+
currentHistoryIndex: currentHistoryTraversalIndex,
|
|
572
|
+
historyState: window.history.state
|
|
573
|
+
}) : null;
|
|
445
574
|
try {
|
|
446
|
-
const shouldUsePendingRouterState = programmaticTransition
|
|
575
|
+
const shouldUsePendingRouterState = programmaticTransition;
|
|
447
576
|
if (shouldUsePendingRouterState && hasBrowserRouterState()) pendingRouterState = beginPendingBrowserRouterState();
|
|
448
577
|
else {
|
|
449
578
|
await waitForBrowserRouterStateReady();
|
|
@@ -451,15 +580,11 @@ function bootstrapHydration(rscStream) {
|
|
|
451
580
|
if (shouldUsePendingRouterState) pendingRouterState = beginPendingBrowserRouterState();
|
|
452
581
|
}
|
|
453
582
|
while (true) {
|
|
454
|
-
if (redirectCount > 10) {
|
|
455
|
-
console.error("[vinext] Too many RSC redirects — aborting navigation to prevent infinite loop.");
|
|
456
|
-
window.location.href = currentHref;
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
583
|
const url = new URL(currentHref, window.location.origin);
|
|
460
|
-
const requestState = getRequestState(navigationKind, currentPrevNextUrl);
|
|
584
|
+
const requestState = getRequestState(navigationKind, currentPrevNextUrl, activeTraversalIntent?.historyState);
|
|
461
585
|
const requestInterceptionContext = requestState.interceptionContext;
|
|
462
586
|
const requestPreviousNextUrl = requestState.previousNextUrl;
|
|
587
|
+
if (navigationKind === "refresh") syncCurrentHistoryStatePreviousNextUrl(requestPreviousNextUrl);
|
|
463
588
|
setPendingPathname(url.pathname, navId);
|
|
464
589
|
const elementsAtNavStart = getBrowserRouterState().elements;
|
|
465
590
|
const mountedSlotsHeader = getMountedSlotIdsHeader(elementsAtNavStart);
|
|
@@ -471,12 +596,23 @@ function bootstrapHydration(rscStream) {
|
|
|
471
596
|
const rscUrl = await createRscRequestUrl(url.pathname + url.search, requestHeaders);
|
|
472
597
|
const cachedRoute = getVisitedResponse(rscUrl, requestInterceptionContext, mountedSlotsHeader, navigationKind);
|
|
473
598
|
if (cachedRoute) {
|
|
599
|
+
const compatibilityDecision = resolveRscCompatibilityNavigationDecision({
|
|
600
|
+
clientCompatibilityId: CLIENT_RSC_COMPATIBILITY_ID,
|
|
601
|
+
currentHref,
|
|
602
|
+
origin: window.location.origin,
|
|
603
|
+
responseCompatibilityId: cachedRoute.response.compatibilityIdHeader,
|
|
604
|
+
responseUrl: cachedRoute.response.url
|
|
605
|
+
});
|
|
606
|
+
if (compatibilityDecision.kind === "hard-navigate") {
|
|
607
|
+
window.location.href = compatibilityDecision.hardNavigationTarget;
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
474
610
|
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
475
611
|
const cachedParams = cachedRoute.params;
|
|
476
612
|
const cachedNavigationSnapshot = createClientNavigationRenderSnapshot(currentHref, cachedParams);
|
|
477
613
|
const cachedPayload = decodeAppElementsPromise(createFromFetch(Promise.resolve(restoreRscResponse(cachedRoute.response))));
|
|
478
614
|
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
479
|
-
await renderNavigationPayload(cachedPayload, cachedNavigationSnapshot, currentHref, navId, currentHistoryMode, cachedParams, requestPreviousNextUrl, pendingRouterState, toActionType(navigationKind), toOperationLane(navigationKind));
|
|
615
|
+
await renderNavigationPayload(cachedPayload, cachedNavigationSnapshot, currentHref, navId, currentHistoryMode, cachedParams, requestPreviousNextUrl, pendingRouterState, toActionType(navigationKind), toOperationLane(navigationKind), activeTraversalIntent);
|
|
480
616
|
return;
|
|
481
617
|
}
|
|
482
618
|
let navResponse;
|
|
@@ -496,29 +632,38 @@ function bootstrapHydration(rscStream) {
|
|
|
496
632
|
const isRscResponse = (navResponse.headers.get("content-type") ?? "").startsWith("text/x-component");
|
|
497
633
|
if (!navResponse.ok || !isRscResponse || !navResponse.body) {
|
|
498
634
|
const responseUrl = navResponseUrl ?? navResponse.url;
|
|
499
|
-
|
|
500
|
-
if (responseUrl) {
|
|
501
|
-
const parsed = new URL(responseUrl, window.location.origin);
|
|
502
|
-
stripRscCacheBustingSearchParam(parsed);
|
|
503
|
-
const origUrl = new URL(currentHref, window.location.origin);
|
|
504
|
-
let pathname = stripRscSuffix(parsed.pathname);
|
|
505
|
-
if (origUrl.pathname.length > 1 && origUrl.pathname.endsWith("/") && !pathname.endsWith("/")) pathname += "/";
|
|
506
|
-
hardNavTarget = pathname + parsed.search;
|
|
507
|
-
if (origUrl.hash) hardNavTarget += origUrl.hash;
|
|
508
|
-
}
|
|
509
|
-
window.location.href = hardNavTarget;
|
|
635
|
+
window.location.href = resolveHardNavigationTargetFromRscResponse(responseUrl, currentHref, window.location.origin);
|
|
510
636
|
return;
|
|
511
637
|
}
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
638
|
+
const compatibilityDecision = resolveRscCompatibilityNavigationDecision({
|
|
639
|
+
clientCompatibilityId: CLIENT_RSC_COMPATIBILITY_ID,
|
|
640
|
+
currentHref,
|
|
641
|
+
origin: window.location.origin,
|
|
642
|
+
responseCompatibilityId: navResponse.headers.get(VINEXT_RSC_COMPATIBILITY_ID_HEADER),
|
|
643
|
+
responseUrl: navResponseUrl ?? navResponse.url
|
|
644
|
+
});
|
|
645
|
+
if (compatibilityDecision.kind === "hard-navigate") {
|
|
646
|
+
window.location.href = compatibilityDecision.hardNavigationTarget;
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const redirectDecision = resolveRscRedirectLifecycleHop({
|
|
650
|
+
currentHref,
|
|
651
|
+
historyUpdateMode: currentHistoryMode ?? "replace",
|
|
652
|
+
origin: window.location.origin,
|
|
653
|
+
redirectDepth: redirectCount,
|
|
654
|
+
requestPreviousNextUrl,
|
|
655
|
+
responseUrl: navResponseUrl ?? navResponse.url
|
|
656
|
+
});
|
|
657
|
+
if (redirectDecision.kind === "terminal-hard-navigation") {
|
|
658
|
+
if (redirectDecision.reason === "maxRedirectsExceeded") console.error("[vinext] Too many RSC redirects — aborting navigation to prevent infinite loop.");
|
|
659
|
+
window.location.href = redirectDecision.href;
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
if (redirectDecision.kind === "follow") {
|
|
663
|
+
currentHref = redirectDecision.href;
|
|
664
|
+
currentHistoryMode = redirectDecision.historyUpdateMode;
|
|
665
|
+
currentPrevNextUrl = redirectDecision.previousNextUrl;
|
|
666
|
+
redirectCount = redirectDecision.redirectDepth;
|
|
522
667
|
continue;
|
|
523
668
|
}
|
|
524
669
|
const navParams = parseEncodedJsonHeader(navResponse.headers.get("X-Vinext-Params")) ?? {};
|
|
@@ -534,18 +679,12 @@ function bootstrapHydration(rscStream) {
|
|
|
534
679
|
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
535
680
|
const rscPayload = decodeAppElementsPromise(createFromFetch(Promise.resolve(reactResponse)));
|
|
536
681
|
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
537
|
-
if (await renderNavigationPayload(rscPayload, navigationSnapshot, currentHref, navId, currentHistoryMode, navParams, requestPreviousNextUrl, pendingRouterState, toActionType(navigationKind), toOperationLane(navigationKind)) !== "committed") return;
|
|
682
|
+
if (await renderNavigationPayload(rscPayload, navigationSnapshot, currentHref, navId, currentHistoryMode, navParams, requestPreviousNextUrl, pendingRouterState, toActionType(navigationKind), toOperationLane(navigationKind), activeTraversalIntent) !== "committed") return;
|
|
538
683
|
if (!browserNavigationController.isCurrentNavigation(navId)) return;
|
|
539
684
|
const resolvedElements = await rscPayload;
|
|
540
685
|
const metadata = AppElementsWire.readMetadata(resolvedElements);
|
|
541
686
|
const cacheBuffer = await cacheBufferPromise;
|
|
542
|
-
storeVisitedResponseSnapshot(rscUrl, resolveVisitedResponseInterceptionContext(requestInterceptionContext, metadata.interceptionContext),
|
|
543
|
-
buffer: cacheBuffer,
|
|
544
|
-
contentType: navResponse.headers.get("content-type") ?? "text/x-component",
|
|
545
|
-
mountedSlotsHeader: navResponse.headers.get(VINEXT_MOUNTED_SLOTS_HEADER),
|
|
546
|
-
paramsHeader: navResponse.headers.get(VINEXT_PARAMS_HEADER),
|
|
547
|
-
url: navResponse.url
|
|
548
|
-
}, navParams);
|
|
687
|
+
storeVisitedResponseSnapshot(rscUrl, resolveVisitedResponseInterceptionContext(requestInterceptionContext, metadata.interceptionContext), createCachedRscResponseSnapshot(navResponse, cacheBuffer, navResponseUrl), navParams);
|
|
549
688
|
return;
|
|
550
689
|
}
|
|
551
690
|
} catch (error) {
|
|
@@ -554,17 +693,32 @@ function bootstrapHydration(rscStream) {
|
|
|
554
693
|
window.location.href = currentHref;
|
|
555
694
|
} finally {
|
|
556
695
|
browserNavigationController.finalizeNavigation(navId, pendingRouterState);
|
|
696
|
+
discardedServerActionRefreshScheduler.markNavigationSettled();
|
|
557
697
|
}
|
|
558
698
|
};
|
|
559
699
|
if ("scrollRestoration" in history) history.scrollRestoration = "manual";
|
|
700
|
+
const handlePopstate = createPopstateRestoreHandler({
|
|
701
|
+
getActiveNavigationId: browserNavigationController.getActiveNavigationId.bind(browserNavigationController),
|
|
702
|
+
getPendingNavigation: () => window.__VINEXT_RSC_PENDING__,
|
|
703
|
+
getNavigate: () => window.__VINEXT_RSC_NAVIGATE__,
|
|
704
|
+
isCurrentNavigation: browserNavigationController.isCurrentNavigation.bind(browserNavigationController),
|
|
705
|
+
notifyAppRouterTransitionStart: (href) => {
|
|
706
|
+
notifyAppRouterTransitionStart(href, "traverse");
|
|
707
|
+
},
|
|
708
|
+
restorePopstateScrollPosition,
|
|
709
|
+
setPendingNavigation: (pendingNavigation) => {
|
|
710
|
+
window.__VINEXT_RSC_PENDING__ = pendingNavigation;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
560
713
|
window.addEventListener("popstate", (event) => {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
714
|
+
const href = window.location.href;
|
|
715
|
+
if (isSameAppRoutePopstateTarget(href)) {
|
|
716
|
+
notifyAppRouterTransitionStart(href, "traverse");
|
|
717
|
+
commitTraversalIndexFromHistoryState(event.state);
|
|
565
718
|
restorePopstateScrollPosition(event.state);
|
|
566
|
-
|
|
567
|
-
}
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
handlePopstate(event);
|
|
568
722
|
});
|
|
569
723
|
if (import.meta.hot) {
|
|
570
724
|
const handleRscUpdate = async () => {
|