vinext 0.1.8 → 0.2.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 +51 -30
- package/dist/build/css-url-assets.d.ts +3 -1
- package/dist/build/css-url-assets.js +18 -1
- package/dist/build/inject-pregenerated-paths.d.ts +7 -0
- package/dist/build/inject-pregenerated-paths.js +21 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender-server-entry.d.ts +1 -0
- package/dist/build/prerender-server-entry.js +49 -0
- package/dist/build/prerender-server-pool.d.ts +44 -0
- package/dist/build/prerender-server-pool.js +194 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +98 -27
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +12 -2
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +4 -6
- package/dist/check.js +48 -11
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +112 -96
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/vinext-next-data.d.ts +4 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/config/config-matchers.js +45 -19
- package/dist/config/next-config.d.ts +41 -9
- package/dist/config/next-config.js +60 -3
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-browser-entry.js +5 -1
- package/dist/entries/app-rsc-entry.d.ts +5 -3
- package/dist/entries/app-rsc-entry.js +44 -10
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +28 -3
- package/dist/entries/pages-server-entry.js +23 -6
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +482 -120
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +209 -99
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +9 -2
- package/dist/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +272 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +44 -20
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/og-assets.js +2 -1
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
- package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
- package/dist/plugins/sass.d.ts +17 -1
- package/dist/plugins/sass.js +74 -1
- package/dist/plugins/styled-jsx.d.ts +16 -0
- package/dist/plugins/styled-jsx.js +149 -0
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +23 -2
- package/dist/routing/app-route-graph.js +138 -38
- package/dist/routing/file-matcher.d.ts +11 -1
- package/dist/routing/file-matcher.js +18 -3
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +198 -57
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +1 -1
- package/dist/server/app-browser-server-action-client.js +8 -7
- package/dist/server/app-browser-state.d.ts +12 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +42 -24
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +2 -1
- package/dist/server/app-fallback-renderer.js +10 -6
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +5 -4
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +27 -7
- package/dist/server/app-page-dispatch.d.ts +1 -0
- package/dist/server/app-page-dispatch.js +26 -8
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +59 -4
- package/dist/server/app-page-execution.js +2 -1
- package/dist/server/app-page-probe.js +5 -0
- package/dist/server/app-page-render-identity.d.ts +2 -0
- package/dist/server/app-page-render-identity.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +85 -16
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -4
- package/dist/server/app-page-response.d.ts +7 -0
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-route-wiring.d.ts +8 -1
- package/dist/server/app-page-route-wiring.js +32 -18
- package/dist/server/app-page-segment-state.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +7 -1
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-route-handler-execution.js +5 -1
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-tree-prefetch.d.ts +43 -0
- package/dist/server/app-route-tree-prefetch.js +187 -0
- package/dist/server/app-router-entry.js +9 -2
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +9 -4
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +148 -39
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.d.ts +6 -6
- package/dist/server/app-rsc-request-normalization.js +10 -8
- package/dist/server/app-segment-config.d.ts +11 -0
- package/dist/server/app-segment-config.js +62 -6
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +61 -30
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +13 -5
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/cache-control.d.ts +3 -1
- package/dist/server/cache-control.js +13 -1
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-route-files.js +4 -0
- package/dist/server/dev-server.d.ts +11 -1
- package/dist/server/dev-server.js +94 -35
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +11 -18
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +3 -2
- package/dist/server/isr-cache.js +9 -5
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-api-route.js +2 -2
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-data-route.d.ts +4 -2
- package/dist/server/pages-data-route.js +18 -4
- package/dist/server/pages-dev-module-url.d.ts +2 -1
- package/dist/server/pages-dev-module-url.js +6 -3
- package/dist/server/pages-node-compat.d.ts +19 -1
- package/dist/server/pages-node-compat.js +81 -4
- package/dist/server/pages-page-data.d.ts +33 -1
- package/dist/server/pages-page-data.js +62 -33
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +38 -19
- package/dist/server/pages-page-response.d.ts +8 -0
- package/dist/server/pages-page-response.js +7 -3
- package/dist/server/pages-request-pipeline.d.ts +9 -5
- package/dist/server/pages-request-pipeline.js +55 -7
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +5 -3
- package/dist/server/prod-server.js +68 -39
- package/dist/server/request-pipeline.js +2 -1
- package/dist/server/seed-cache.js +4 -4
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache-handler.js +8 -1
- package/dist/shims/cache.js +22 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +77 -52
- package/dist/shims/form.d.ts +4 -2
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +7 -1
- package/dist/shims/headers.js +17 -3
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
- package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +40 -58
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +10 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +84 -14
- package/dist/shims/internal/pages-data-target.d.ts +18 -12
- package/dist/shims/internal/pages-data-target.js +97 -13
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.d.ts +1 -1
- package/dist/shims/link.js +224 -58
- package/dist/shims/navigation.d.ts +19 -3
- package/dist/shims/navigation.js +245 -47
- package/dist/shims/request-context.js +18 -0
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +387 -102
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/typegen.js +1 -1
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +3 -3
- package/dist/utils/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- package/dist/utils/protocol-headers.d.ts +23 -0
- package/dist/utils/protocol-headers.js +23 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/dist/utils/vite-version.d.ts +2 -0
- package/dist/utils/vite-version.js +11 -1
- package/package.json +47 -2
- package/dist/deploy.d.ts +0 -197
- package/dist/deploy.js +0 -1040
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
package/dist/shims/router.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { splitPathSegments } from "../routing/utils.js";
|
|
2
|
-
import { removeTrailingSlash, stripBasePath } from "../utils/base-path.js";
|
|
2
|
+
import { hasBasePath, removeTrailingSlash, stripBasePath } from "../utils/base-path.js";
|
|
3
|
+
import { parseCookieHeader } from "../utils/parse-cookie.js";
|
|
3
4
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
4
|
-
import { fillRoutePatternSegments, matchRoutePattern, routePatternParts } from "../routing/route-pattern.js";
|
|
5
5
|
import { isUnknownRecord } from "../utils/record.js";
|
|
6
6
|
import { AppRouterContext } from "./internal/app-router-context.js";
|
|
7
7
|
import { RouterContext } from "./internal/router-context.js";
|
|
8
8
|
import { applyVinextLocaleGlobals, extractVinextNextDataJson, parseVinextNextDataJson } from "../client/vinext-next-data.js";
|
|
9
9
|
import { isValidModulePath } from "../client/validate-module-path.js";
|
|
10
10
|
import { addLocalePrefix, getDomainLocaleUrl, getLocalePathPrefix } from "../utils/domain-locale.js";
|
|
11
|
-
import {
|
|
11
|
+
import { fillRoutePatternSegments, matchRoutePattern, routePatternParts } from "../routing/route-pattern.js";
|
|
12
12
|
import { NEXT_DEPLOYMENT_ID_HEADER, getDeploymentId } from "../utils/deployment-id.js";
|
|
13
|
-
import { dedupedPagesDataFetch } from "./internal/pages-data-fetch-dedup.js";
|
|
14
|
-
import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
13
|
+
import { dedupedPagesDataFetch, evictPagesDataCache, fetchCachedPagesData, fetchStaticPagesData, getPagesStaticDataCache } from "./internal/pages-data-fetch-dedup.js";
|
|
14
|
+
import { getPagesMiddlewareDataHref, prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
15
|
+
import { getPagesRouterComponentsMap } from "./internal/pages-router-components.js";
|
|
16
|
+
import { markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.js";
|
|
17
|
+
import { resolveDirectHybridClientRouteOwner } from "./internal/hybrid-client-route-owner-direct.js";
|
|
18
18
|
import { installWindowNext } from "../client/window-next.js";
|
|
19
19
|
import { getWindowOrigin, isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
20
|
+
import { addQueryParam, appendSearchParamsToUrl, mergeRewriteQuery, mergeRouteParamsIntoQuery, parseQueryString, urlQueryToSearchParams } from "../utils/query.js";
|
|
20
21
|
import { scrollToHashTarget } from "./hash-scroll.js";
|
|
21
22
|
import { installPagesRouterRuntime, setPagesRouterPopStateHandler, setStampInitialHistoryState } from "./pages-router-runtime.js";
|
|
22
23
|
import { interpolateDynamicRouteHref } from "./internal/interpolate-as.js";
|
|
23
24
|
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
24
|
-
import { Component, Fragment, createElement, useContext, useEffect, useLayoutEffect, useMemo, useState } from "react";
|
|
25
|
+
import { Component, Fragment, StrictMode, createElement, useContext, useEffect, useLayoutEffect, useMemo, useState } from "react";
|
|
25
26
|
//#region src/shims/router.ts
|
|
26
27
|
/**
|
|
27
28
|
* next/router shim
|
|
@@ -841,31 +842,188 @@ function resolveLocalRedirectUrl(location) {
|
|
|
841
842
|
if (appPath === null) return null;
|
|
842
843
|
return normalizePathTrailingSlash(toBrowserNavigationHref(stripLocalePrefixForApiRedirect(appPath), window.location.href, __basePath), __trailingSlash);
|
|
843
844
|
}
|
|
844
|
-
function
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
return isUnknownRecord(vinext) && vinext.hasMiddleware === true;
|
|
845
|
+
function hasClientRewriteRules() {
|
|
846
|
+
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
847
|
+
return Boolean(rewrites && (rewrites.beforeFiles.length > 0 || rewrites.afterFiles.length > 0 || rewrites.fallback.length > 0));
|
|
848
848
|
}
|
|
849
|
-
function
|
|
850
|
-
const
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
849
|
+
function hasClientRedirectRules() {
|
|
850
|
+
const redirects = window.__VINEXT_CLIENT_REDIRECTS__;
|
|
851
|
+
return Array.isArray(redirects) && redirects.length > 0;
|
|
852
|
+
}
|
|
853
|
+
function hasClientAppRouteManifest() {
|
|
854
|
+
const routes = window.__VINEXT_LINK_PREFETCH_ROUTES__;
|
|
855
|
+
return Array.isArray(routes) && routes.length > 0;
|
|
856
|
+
}
|
|
857
|
+
function getClientConfigRouteContext(href) {
|
|
854
858
|
let parsed;
|
|
855
859
|
try {
|
|
856
|
-
parsed = new URL(
|
|
860
|
+
parsed = new URL(href, window.location.href);
|
|
857
861
|
} catch {
|
|
858
862
|
return null;
|
|
859
863
|
}
|
|
860
864
|
if (parsed.origin !== getWindowOrigin()) return null;
|
|
861
|
-
|
|
865
|
+
const hadBasePath = __basePath ? hasBasePath(parsed.pathname, __basePath) : true;
|
|
866
|
+
const pathname = hadBasePath ? stripBasePath(parsed.pathname, __basePath) : parsed.pathname;
|
|
867
|
+
const headers = new Headers({ "user-agent": globalThis.navigator?.userAgent ?? "" });
|
|
868
|
+
return {
|
|
869
|
+
basePathState: {
|
|
870
|
+
basePath: __basePath,
|
|
871
|
+
hadBasePath
|
|
872
|
+
},
|
|
873
|
+
context: {
|
|
874
|
+
cookies: parseCookieHeader(globalThis.document?.cookie ?? ""),
|
|
875
|
+
headers,
|
|
876
|
+
host: parsed.hostname,
|
|
877
|
+
query: parsed.searchParams
|
|
878
|
+
},
|
|
879
|
+
pathname,
|
|
880
|
+
search: parsed.search
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
async function resolveClientConfigRedirect(href) {
|
|
884
|
+
const redirects = window.__VINEXT_CLIENT_REDIRECTS__;
|
|
885
|
+
if (!redirects || redirects.length === 0) return null;
|
|
886
|
+
const routeContext = getClientConfigRouteContext(href);
|
|
887
|
+
if (!routeContext) return null;
|
|
888
|
+
const { isExternalUrl, matchRedirect, preserveRedirectDestinationQuery } = await import("../config/config-matchers.js");
|
|
889
|
+
const redirect = matchRedirect(routeContext.pathname, redirects, routeContext.context, routeContext.basePathState);
|
|
890
|
+
if (!redirect) return null;
|
|
891
|
+
return preserveRedirectDestinationQuery(__basePath && routeContext.basePathState.hadBasePath && !isExternalUrl(redirect.destination) && !hasBasePath(redirect.destination, __basePath) ? __basePath + redirect.destination : redirect.destination, routeContext.search);
|
|
892
|
+
}
|
|
893
|
+
async function applyClientConfigRewrite(href, rewrite) {
|
|
894
|
+
const routeContext = getClientConfigRouteContext(href);
|
|
895
|
+
if (!routeContext) return null;
|
|
896
|
+
const { isExternalUrl, matchRewrite } = await import("../config/config-matchers.js");
|
|
897
|
+
const rewritten = matchRewrite(routeContext.pathname, [rewrite], routeContext.context, routeContext.basePathState);
|
|
898
|
+
if (rewritten === null) return null;
|
|
899
|
+
if (isExternalUrl(rewritten)) return { kind: "document" };
|
|
900
|
+
return {
|
|
901
|
+
href: mergeRewriteQuery(href, rewritten),
|
|
902
|
+
kind: "rewrite"
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
function shouldEvaluateClientConfigRule(ruleBasePath, state) {
|
|
906
|
+
if (!state.basePath) return true;
|
|
907
|
+
return ruleBasePath === false ? !state.hadBasePath : state.hadBasePath;
|
|
862
908
|
}
|
|
863
|
-
|
|
864
|
-
|
|
909
|
+
function matchSimpleClientConfigPattern(pathname, source) {
|
|
910
|
+
if (source.includes("(") || source.includes("\\") || /:[\w-]+[*+][^/]/.test(source)) return;
|
|
911
|
+
const sourceParts = removeTrailingSlash(source).split("/");
|
|
912
|
+
const pathParts = removeTrailingSlash(pathname).split("/");
|
|
913
|
+
const params = {};
|
|
914
|
+
let pathIndex = 0;
|
|
915
|
+
for (let sourceIndex = 0; sourceIndex < sourceParts.length; sourceIndex++) {
|
|
916
|
+
const sourcePart = sourceParts[sourceIndex];
|
|
917
|
+
const pathPart = pathParts[pathIndex];
|
|
918
|
+
if (sourcePart.startsWith(":")) {
|
|
919
|
+
const catchAll = sourcePart.match(/^:([\w-]+)([*+])$/);
|
|
920
|
+
if (catchAll) {
|
|
921
|
+
const rest = pathParts.slice(pathIndex).join("/");
|
|
922
|
+
if (catchAll[2] === "+" && rest === "") return null;
|
|
923
|
+
params[catchAll[1]] = rest;
|
|
924
|
+
return sourceIndex === sourceParts.length - 1 ? params : void 0;
|
|
925
|
+
}
|
|
926
|
+
if (pathPart === void 0) return null;
|
|
927
|
+
params[sourcePart.slice(1)] = pathPart;
|
|
928
|
+
pathIndex++;
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
if (pathPart !== sourcePart) return null;
|
|
932
|
+
pathIndex++;
|
|
933
|
+
}
|
|
934
|
+
return pathIndex === pathParts.length ? params : null;
|
|
935
|
+
}
|
|
936
|
+
function simpleClientConfigSourceCouldMatch(pathname, source) {
|
|
937
|
+
const wildcardIndex = source.search(/[:(\\*+?]/);
|
|
938
|
+
const normalizedPrefix = removeTrailingSlash(wildcardIndex === -1 ? source : source.slice(0, wildcardIndex));
|
|
939
|
+
if (!normalizedPrefix || normalizedPrefix === "/") return true;
|
|
940
|
+
const normalizedPathname = removeTrailingSlash(pathname);
|
|
941
|
+
return normalizedPathname === normalizedPrefix || normalizedPathname.startsWith(`${normalizedPrefix}/`);
|
|
942
|
+
}
|
|
943
|
+
function substituteSimpleClientConfigDestination(destination, params) {
|
|
944
|
+
const keys = Object.keys(params);
|
|
945
|
+
if (keys.length === 0) return destination;
|
|
946
|
+
const alternation = keys.sort((a, b) => b.length - a.length).map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
947
|
+
return destination.replace(new RegExp(`:(${alternation})([+*])?(?![A-Za-z0-9_])`, "g"), (_token, key) => params[key] ?? _token);
|
|
948
|
+
}
|
|
949
|
+
function isExternalClientConfigUrl(url) {
|
|
950
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("//");
|
|
951
|
+
}
|
|
952
|
+
function clientConfigRedirectCouldMatch(href) {
|
|
953
|
+
const redirects = window.__VINEXT_CLIENT_REDIRECTS__;
|
|
954
|
+
if (!redirects || redirects.length === 0) return false;
|
|
955
|
+
const routeContext = getClientConfigRouteContext(href);
|
|
956
|
+
if (!routeContext) return false;
|
|
957
|
+
for (const redirect of redirects) {
|
|
958
|
+
if (!shouldEvaluateClientConfigRule(redirect.basePath, routeContext.basePathState)) continue;
|
|
959
|
+
if (!simpleClientConfigSourceCouldMatch(routeContext.pathname, redirect.source)) continue;
|
|
960
|
+
if (matchSimpleClientConfigPattern(routeContext.pathname, redirect.source) !== null) return true;
|
|
961
|
+
}
|
|
962
|
+
return false;
|
|
963
|
+
}
|
|
964
|
+
function resolveClientConfigRewriteSync(href) {
|
|
965
|
+
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
966
|
+
if (!rewrites) return null;
|
|
967
|
+
let currentHref = href;
|
|
968
|
+
let matched = false;
|
|
969
|
+
for (const rewrite of rewrites.beforeFiles) {
|
|
970
|
+
const routeContext = getClientConfigRouteContext(currentHref);
|
|
971
|
+
if (!routeContext) return null;
|
|
972
|
+
if (!shouldEvaluateClientConfigRule(rewrite.basePath, routeContext.basePathState)) continue;
|
|
973
|
+
if (!simpleClientConfigSourceCouldMatch(routeContext.pathname, rewrite.source)) continue;
|
|
974
|
+
if (rewrite.has || rewrite.missing) return void 0;
|
|
975
|
+
const params = matchSimpleClientConfigPattern(routeContext.pathname, rewrite.source);
|
|
976
|
+
if (params === void 0) return void 0;
|
|
977
|
+
if (params === null) continue;
|
|
978
|
+
const rewritten = substituteSimpleClientConfigDestination(rewrite.destination, params);
|
|
979
|
+
if (isExternalClientConfigUrl(rewritten)) return { kind: "document" };
|
|
980
|
+
currentHref = mergeRewriteQuery(currentHref, rewritten);
|
|
981
|
+
matched = true;
|
|
982
|
+
}
|
|
983
|
+
return matched ? {
|
|
984
|
+
href: currentHref,
|
|
985
|
+
kind: "rewrite"
|
|
986
|
+
} : null;
|
|
987
|
+
}
|
|
988
|
+
async function resolveClientConfigRewrite(href) {
|
|
989
|
+
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
990
|
+
if (!rewrites) return null;
|
|
991
|
+
let currentHref = href;
|
|
992
|
+
let matched = false;
|
|
993
|
+
for (const rewrite of rewrites.beforeFiles) {
|
|
994
|
+
const result = await applyClientConfigRewrite(currentHref, rewrite);
|
|
995
|
+
if (result?.kind === "document") return result;
|
|
996
|
+
if (result?.kind !== "rewrite") continue;
|
|
997
|
+
currentHref = result.href;
|
|
998
|
+
matched = true;
|
|
999
|
+
}
|
|
1000
|
+
return matched ? {
|
|
1001
|
+
href: currentHref,
|
|
1002
|
+
kind: "rewrite"
|
|
1003
|
+
} : null;
|
|
1004
|
+
}
|
|
1005
|
+
function getMiddlewarePagesDataFetchUrl(browserUrl, dataTarget) {
|
|
1006
|
+
const middlewareDataHref = getPagesMiddlewareDataHref(browserUrl, __basePath);
|
|
1007
|
+
if (!middlewareDataHref) return null;
|
|
1008
|
+
if (dataTarget?.dataKind === "static" && dataTarget.middlewareDataHref === middlewareDataHref && dataTarget.prefetchDataHref) return dataTarget.prefetchDataHref;
|
|
1009
|
+
return middlewareDataHref;
|
|
1010
|
+
}
|
|
1011
|
+
function getPagesDataCacheHref(dataHref) {
|
|
1012
|
+
try {
|
|
1013
|
+
return new URL(dataHref, window.location.href).href;
|
|
1014
|
+
} catch {
|
|
1015
|
+
return dataHref;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function shouldEvictMiddlewareDataCache(middlewareEffect, dataTarget) {
|
|
1019
|
+
return middlewareEffect?.redirectLocation != null || dataTarget?.dataKind !== "static";
|
|
1020
|
+
}
|
|
1021
|
+
async function resolveMiddlewareDataEffect(browserUrl, signal, dataTarget) {
|
|
1022
|
+
const dataUrl = getMiddlewarePagesDataFetchUrl(browserUrl, dataTarget);
|
|
865
1023
|
if (!dataUrl) return null;
|
|
866
1024
|
if (signal.aborted) throw new DOMException("Aborted", "AbortError");
|
|
867
1025
|
try {
|
|
868
|
-
const res = await
|
|
1026
|
+
const res = await fetchCachedPagesData(dataUrl, {
|
|
869
1027
|
headers: {
|
|
870
1028
|
Accept: "application/json",
|
|
871
1029
|
"x-nextjs-data": "1"
|
|
@@ -873,6 +1031,7 @@ async function resolveMiddlewareDataEffect(browserUrl, signal) {
|
|
|
873
1031
|
signal
|
|
874
1032
|
});
|
|
875
1033
|
return {
|
|
1034
|
+
dataHref: getPagesDataCacheHref(dataUrl),
|
|
876
1035
|
redirectLocation: res.headers.get("x-nextjs-redirect"),
|
|
877
1036
|
rewriteTarget: res.headers.get("x-nextjs-rewrite"),
|
|
878
1037
|
response: res
|
|
@@ -900,6 +1059,110 @@ function handleDataRedirect(destination, redirectBasePath, mode = "push") {
|
|
|
900
1059
|
if (!(destination.startsWith("/") && redirectBasePath !== false)) scheduleHardNavigationAndThrow(destination, "Navigation redirected externally");
|
|
901
1060
|
performNavigation(destination, void 0, { locale: false }, mode);
|
|
902
1061
|
}
|
|
1062
|
+
async function loadTargetPageModule(target, url, failurePrefix) {
|
|
1063
|
+
try {
|
|
1064
|
+
return await target.loader();
|
|
1065
|
+
} catch (err) {
|
|
1066
|
+
console.error("[vinext] Page loader threw during navigation:", err);
|
|
1067
|
+
scheduleHardNavigationAndThrow(url, `${failurePrefix}: page loader threw`);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
async function loadPagesAppComponent() {
|
|
1071
|
+
let AppComponent = window.__VINEXT_APP__;
|
|
1072
|
+
if (!AppComponent && typeof window.__VINEXT_APP_LOADER__ === "function") try {
|
|
1073
|
+
const appModule = await window.__VINEXT_APP_LOADER__();
|
|
1074
|
+
AppComponent = isAppComponent(appModule.default) ? appModule.default : void 0;
|
|
1075
|
+
if (AppComponent) window.__VINEXT_APP__ = AppComponent;
|
|
1076
|
+
} catch {}
|
|
1077
|
+
return AppComponent;
|
|
1078
|
+
}
|
|
1079
|
+
function buildPagesNavigationNextData(target, props) {
|
|
1080
|
+
const mergedQuery = mergeRouteParamsIntoQuery(parseQueryString(target.search), target.params);
|
|
1081
|
+
const prev = window.__NEXT_DATA__;
|
|
1082
|
+
const nextLocale = (window.__VINEXT_LOCALES__?.length ?? 0) > 0 ? target.locale ?? window.__VINEXT_DEFAULT_LOCALE__ : prev?.locale;
|
|
1083
|
+
return {
|
|
1084
|
+
...prev,
|
|
1085
|
+
props,
|
|
1086
|
+
page: target.pattern,
|
|
1087
|
+
query: mergedQuery,
|
|
1088
|
+
buildId: target.buildId,
|
|
1089
|
+
isFallback: false,
|
|
1090
|
+
...nextLocale !== void 0 ? { locale: nextLocale } : {}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
function propsObject(value) {
|
|
1094
|
+
return isUnknownRecord(value) ? value : {};
|
|
1095
|
+
}
|
|
1096
|
+
async function loadComponentOnlyProps(PageComponent, AppComponent, target, asPath) {
|
|
1097
|
+
const query = mergeRouteParamsIntoQuery(parseQueryString(target.search), target.params);
|
|
1098
|
+
const ctx = {
|
|
1099
|
+
pathname: target.pattern,
|
|
1100
|
+
query,
|
|
1101
|
+
asPath,
|
|
1102
|
+
locale: target.locale ?? window.__VINEXT_LOCALE__,
|
|
1103
|
+
locales: window.__VINEXT_LOCALES__,
|
|
1104
|
+
defaultLocale: window.__VINEXT_DEFAULT_LOCALE__
|
|
1105
|
+
};
|
|
1106
|
+
if (typeof AppComponent?.getInitialProps === "function") {
|
|
1107
|
+
const AppTree = (appProps) => createElement(AppComponent, {
|
|
1108
|
+
...appProps,
|
|
1109
|
+
Component: PageComponent,
|
|
1110
|
+
router: Router
|
|
1111
|
+
});
|
|
1112
|
+
return propsObject(await AppComponent.getInitialProps({
|
|
1113
|
+
Component: PageComponent,
|
|
1114
|
+
AppTree,
|
|
1115
|
+
ctx,
|
|
1116
|
+
router: Router
|
|
1117
|
+
}));
|
|
1118
|
+
}
|
|
1119
|
+
if (typeof PageComponent.getInitialProps === "function") return { pageProps: propsObject(await PageComponent.getInitialProps(ctx)) };
|
|
1120
|
+
return { pageProps: {} };
|
|
1121
|
+
}
|
|
1122
|
+
async function renderPagesNavigationTarget(url, target, props, options, assertStillCurrent, preloaded) {
|
|
1123
|
+
const pageModule = preloaded?.pageModule ?? await loadTargetPageModule(target, url, "Navigation failed");
|
|
1124
|
+
assertStillCurrent();
|
|
1125
|
+
const PageComponent = pageModule.default;
|
|
1126
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(url, "Navigation failed: page module default export is not a component");
|
|
1127
|
+
const AppComponent = preloaded?.appComponent ?? await loadPagesAppComponent();
|
|
1128
|
+
assertStillCurrent();
|
|
1129
|
+
const React = (await import("react")).default;
|
|
1130
|
+
assertStillCurrent();
|
|
1131
|
+
const rawPageProps = props.pageProps;
|
|
1132
|
+
const pageProps = isUnknownRecord(rawPageProps) ? rawPageProps : {};
|
|
1133
|
+
let element;
|
|
1134
|
+
if (AppComponent) element = React.createElement(AppComponent, {
|
|
1135
|
+
...props,
|
|
1136
|
+
Component: PageComponent,
|
|
1137
|
+
pageProps: rawPageProps,
|
|
1138
|
+
router: Router
|
|
1139
|
+
});
|
|
1140
|
+
else element = React.createElement(PageComponent, pageProps);
|
|
1141
|
+
const nextData = buildPagesNavigationNextData(target, props);
|
|
1142
|
+
window.__NEXT_DATA__ = nextData;
|
|
1143
|
+
applyVinextLocaleGlobals(window, nextData);
|
|
1144
|
+
await renderPagesRouterElement(element, options.scroll);
|
|
1145
|
+
assertStillCurrent();
|
|
1146
|
+
}
|
|
1147
|
+
async function navigateClientNoData(url, target, controller, assertStillCurrent, options = {}) {
|
|
1148
|
+
if (!window.__VINEXT_ROOT__) {
|
|
1149
|
+
window.location.href = url;
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
if (controller.signal.aborted) throw new NavigationCancelledError(url);
|
|
1153
|
+
const pageModule = await loadTargetPageModule(target, url, "Navigation failed");
|
|
1154
|
+
assertStillCurrent();
|
|
1155
|
+
const PageComponent = pageModule.default;
|
|
1156
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(url, "Navigation failed: page module default export is not a component");
|
|
1157
|
+
const AppComponent = await loadPagesAppComponent();
|
|
1158
|
+
assertStillCurrent();
|
|
1159
|
+
const props = await loadComponentOnlyProps(PageComponent, AppComponent, target, url);
|
|
1160
|
+
assertStillCurrent();
|
|
1161
|
+
await renderPagesNavigationTarget(url, target, props, options, assertStillCurrent, {
|
|
1162
|
+
appComponent: AppComponent,
|
|
1163
|
+
pageModule
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
903
1166
|
/**
|
|
904
1167
|
* Perform client-side navigation via the `/_next/data/<id>/<page>.json`
|
|
905
1168
|
* endpoint. Used when `__VINEXT_PAGE_LOADERS__` has a matching code-split
|
|
@@ -927,7 +1190,7 @@ async function navigateClientData(url, initialTarget, controller, navId, assertS
|
|
|
927
1190
|
};
|
|
928
1191
|
const deploymentId = getDeploymentId();
|
|
929
1192
|
if (deploymentId) headers[NEXT_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
930
|
-
res = await dedupedPagesDataFetch(initialTarget.dataHref, {
|
|
1193
|
+
res = await (initialTarget.dataKind === "static" ? fetchStaticPagesData : dedupedPagesDataFetch)(initialTarget.dataHref, {
|
|
931
1194
|
headers,
|
|
932
1195
|
signal: controller.signal
|
|
933
1196
|
});
|
|
@@ -936,6 +1199,9 @@ async function navigateClientData(url, initialTarget, controller, navId, assertS
|
|
|
936
1199
|
throw err;
|
|
937
1200
|
}
|
|
938
1201
|
assertStillCurrent();
|
|
1202
|
+
const responseDeploymentId = res.headers.get("x-nextjs-deployment-id");
|
|
1203
|
+
const currentDeploymentId = getDeploymentId() ?? null;
|
|
1204
|
+
if (responseDeploymentId !== null && responseDeploymentId !== currentDeploymentId) scheduleHardNavigationAndThrow(url, "Loaded static props were from an outdated deployment");
|
|
939
1205
|
const softRedirect = res.headers.get("x-nextjs-redirect");
|
|
940
1206
|
if (softRedirect) {
|
|
941
1207
|
const redirectedUrl = resolveLocalRedirectUrl(softRedirect);
|
|
@@ -946,68 +1212,31 @@ async function navigateClientData(url, initialTarget, controller, navId, assertS
|
|
|
946
1212
|
await navigateClientHtml(redirectedUrl, redirectedUrl, controller, navId, assertStillCurrent);
|
|
947
1213
|
return;
|
|
948
1214
|
}
|
|
949
|
-
if (!res.ok)
|
|
1215
|
+
if (!res.ok) {
|
|
1216
|
+
if (options.isHydrationQueryUpdate) return;
|
|
1217
|
+
scheduleHardNavigationAndThrow(url, `Data navigation failed: ${res.status} ${res.statusText}`);
|
|
1218
|
+
}
|
|
950
1219
|
const rewriteTarget = res.headers.get("x-nextjs-rewrite");
|
|
951
|
-
const target = rewriteTarget ? resolvePagesDataNavigationTarget(rewriteTarget, __basePath) : initialTarget;
|
|
1220
|
+
const target = rewriteTarget ? resolvePagesDataNavigationTarget(rewriteTarget, __basePath, { locale: initialTarget.prefetchLocale }) : initialTarget;
|
|
952
1221
|
if (!target) scheduleHardNavigationAndThrow(url, "Data navigation failed: rewrite target has no page loader");
|
|
953
1222
|
let body;
|
|
954
1223
|
try {
|
|
955
1224
|
body = await res.json();
|
|
956
1225
|
} catch {
|
|
1226
|
+
if (options.isHydrationQueryUpdate) return;
|
|
957
1227
|
scheduleHardNavigationAndThrow(url, "Data navigation failed: invalid JSON response");
|
|
958
1228
|
}
|
|
959
1229
|
assertStillCurrent();
|
|
960
1230
|
const props = isUnknownRecord(body) ? body : {};
|
|
961
1231
|
const rawPageProps = props.pageProps;
|
|
962
1232
|
const pageProps = isUnknownRecord(rawPageProps) ? rawPageProps : {};
|
|
1233
|
+
if (initialTarget.dataKind === "server") evictPagesDataCache(initialTarget.dataHref);
|
|
963
1234
|
const redirectDestination = pageProps.__N_REDIRECT;
|
|
964
1235
|
if (typeof redirectDestination === "string") {
|
|
965
1236
|
handleDataRedirect(redirectDestination, pageProps.__N_REDIRECT_BASE_PATH, options.mode);
|
|
966
1237
|
throw new NavigationCancelledError(url);
|
|
967
1238
|
}
|
|
968
|
-
|
|
969
|
-
try {
|
|
970
|
-
pageModule = await target.loader();
|
|
971
|
-
} catch (err) {
|
|
972
|
-
console.error("[vinext] Page loader threw during navigation:", err);
|
|
973
|
-
scheduleHardNavigationAndThrow(url, "Data navigation failed: page loader threw");
|
|
974
|
-
}
|
|
975
|
-
assertStillCurrent();
|
|
976
|
-
const PageComponent = pageModule.default;
|
|
977
|
-
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(url, "Data navigation failed: page module default export is not a component");
|
|
978
|
-
let AppComponent = window.__VINEXT_APP__;
|
|
979
|
-
if (!AppComponent && typeof window.__VINEXT_APP_LOADER__ === "function") try {
|
|
980
|
-
const appModule = await window.__VINEXT_APP_LOADER__();
|
|
981
|
-
AppComponent = isAppComponent(appModule.default) ? appModule.default : void 0;
|
|
982
|
-
if (AppComponent) window.__VINEXT_APP__ = AppComponent;
|
|
983
|
-
} catch {}
|
|
984
|
-
assertStillCurrent();
|
|
985
|
-
const React = (await import("react")).default;
|
|
986
|
-
assertStillCurrent();
|
|
987
|
-
let element;
|
|
988
|
-
if (AppComponent) element = React.createElement(AppComponent, {
|
|
989
|
-
...props,
|
|
990
|
-
Component: PageComponent,
|
|
991
|
-
pageProps: rawPageProps,
|
|
992
|
-
router: Router
|
|
993
|
-
});
|
|
994
|
-
else element = React.createElement(PageComponent, pageProps);
|
|
995
|
-
const mergedQuery = mergeRouteParamsIntoQuery(parseQueryString(target.search), target.params);
|
|
996
|
-
const prev = window.__NEXT_DATA__;
|
|
997
|
-
const nextLocale = (window.__VINEXT_LOCALES__?.length ?? 0) > 0 ? target.locale ?? window.__VINEXT_DEFAULT_LOCALE__ : prev?.locale;
|
|
998
|
-
const nextData = {
|
|
999
|
-
...prev,
|
|
1000
|
-
props,
|
|
1001
|
-
page: target.pattern,
|
|
1002
|
-
query: mergedQuery,
|
|
1003
|
-
buildId: target.buildId,
|
|
1004
|
-
isFallback: false,
|
|
1005
|
-
...nextLocale !== void 0 ? { locale: nextLocale } : {}
|
|
1006
|
-
};
|
|
1007
|
-
window.__NEXT_DATA__ = nextData;
|
|
1008
|
-
applyVinextLocaleGlobals(window, nextData);
|
|
1009
|
-
await renderPagesRouterElement(element, options.scroll);
|
|
1010
|
-
assertStillCurrent();
|
|
1239
|
+
await renderPagesNavigationTarget(url, target, props, options, assertStillCurrent);
|
|
1011
1240
|
}
|
|
1012
1241
|
/**
|
|
1013
1242
|
* Perform client-side navigation by fetching the page's full HTML and
|
|
@@ -1130,6 +1359,7 @@ async function navigateClient(url, fetchUrl = url, options = {}, routeUrl = url)
|
|
|
1130
1359
|
const controller = new AbortController();
|
|
1131
1360
|
routerRuntimeState.activeAbortController = controller;
|
|
1132
1361
|
const navId = ++routerRuntimeState.navigationId;
|
|
1362
|
+
let middlewareDataCacheEvictHref = null;
|
|
1133
1363
|
/** Check if this navigation is still the active one. If not, throw. */
|
|
1134
1364
|
function assertStillCurrent() {
|
|
1135
1365
|
if (navId !== routerRuntimeState.navigationId) throw new NavigationCancelledError(url);
|
|
@@ -1139,36 +1369,73 @@ async function navigateClient(url, fetchUrl = url, options = {}, routeUrl = url)
|
|
|
1139
1369
|
else {
|
|
1140
1370
|
let browserUrl = url;
|
|
1141
1371
|
let htmlFetchUrl = fetchUrl;
|
|
1142
|
-
|
|
1372
|
+
const configRedirect = hasClientRedirectRules() && clientConfigRedirectCouldMatch(browserUrl) ? await resolveClientConfigRedirect(browserUrl) : null;
|
|
1373
|
+
if (configRedirect) {
|
|
1374
|
+
const redirectedUrl = resolveLocalRedirectUrl(configRedirect);
|
|
1375
|
+
if (!redirectedUrl) scheduleHardNavigationAndThrow(configRedirect, "Navigation redirected externally");
|
|
1376
|
+
window.history.replaceState(window.history.state ?? {}, "", redirectedUrl);
|
|
1377
|
+
routerRuntimeState.lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
1378
|
+
routerRuntimeState.lastHash = window.location.hash;
|
|
1379
|
+
browserUrl = redirectedUrl;
|
|
1380
|
+
htmlFetchUrl = redirectedUrl;
|
|
1381
|
+
}
|
|
1382
|
+
let routeLookupUrl = configRedirect ? browserUrl : routeUrl;
|
|
1383
|
+
if (routeUrl === url && hasClientRewriteRules()) {
|
|
1384
|
+
const syncConfigRewrite = hasClientAppRouteManifest() ? void 0 : resolveClientConfigRewriteSync(browserUrl);
|
|
1385
|
+
const configRewrite = syncConfigRewrite === void 0 ? await resolveClientConfigRewrite(browserUrl) : syncConfigRewrite;
|
|
1386
|
+
if (configRewrite?.kind === "document") scheduleHardNavigationAndThrow(browserUrl, "Navigation rewritten to a document route");
|
|
1387
|
+
else if (configRewrite?.kind === "rewrite") {
|
|
1388
|
+
routeLookupUrl = configRewrite.href;
|
|
1389
|
+
htmlFetchUrl = configRewrite.href;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
const pagesDataTargetOptions = { locale: options.locale };
|
|
1393
|
+
let dataTarget = resolvePagesDataNavigationTarget(routeLookupUrl, __basePath, pagesDataTargetOptions);
|
|
1143
1394
|
let middlewareDataResponse;
|
|
1144
|
-
|
|
1145
|
-
|
|
1395
|
+
let middlewareEffect = null;
|
|
1396
|
+
let middlewareRewrittenTarget;
|
|
1397
|
+
const middlewareProbeDataHref = getMiddlewarePagesDataFetchUrl(browserUrl, dataTarget);
|
|
1398
|
+
if (middlewareProbeDataHref !== null) {
|
|
1399
|
+
middlewareDataCacheEvictHref = getPagesDataCacheHref(middlewareProbeDataHref);
|
|
1146
1400
|
try {
|
|
1147
|
-
middlewareEffect = await resolveMiddlewareDataEffect(browserUrl, controller.signal);
|
|
1401
|
+
middlewareEffect = await resolveMiddlewareDataEffect(browserUrl, controller.signal, dataTarget);
|
|
1148
1402
|
} catch (err) {
|
|
1149
1403
|
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(browserUrl);
|
|
1150
1404
|
throw err;
|
|
1151
1405
|
}
|
|
1406
|
+
if (middlewareEffect?.rewriteTarget) middlewareRewrittenTarget = resolvePagesDataNavigationTarget(middlewareEffect.rewriteTarget, __basePath, pagesDataTargetOptions);
|
|
1407
|
+
if (middlewareEffect) if (shouldEvictMiddlewareDataCache(middlewareEffect, middlewareRewrittenTarget !== void 0 ? middlewareRewrittenTarget : dataTarget)) middlewareDataCacheEvictHref = middlewareEffect.dataHref;
|
|
1408
|
+
else middlewareDataCacheEvictHref = null;
|
|
1152
1409
|
assertStillCurrent();
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1410
|
+
}
|
|
1411
|
+
const redirectLocation = middlewareEffect?.redirectLocation ?? null;
|
|
1412
|
+
if (redirectLocation) {
|
|
1413
|
+
const redirectedUrl = resolveLocalRedirectUrl(redirectLocation);
|
|
1414
|
+
if (!redirectedUrl) scheduleHardNavigationAndThrow(redirectLocation, "Navigation redirected externally");
|
|
1415
|
+
window.history.replaceState(window.history.state ?? {}, "", redirectedUrl);
|
|
1416
|
+
routerRuntimeState.lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
1417
|
+
routerRuntimeState.lastHash = window.location.hash;
|
|
1418
|
+
browserUrl = redirectedUrl;
|
|
1419
|
+
htmlFetchUrl = redirectedUrl;
|
|
1420
|
+
} else if (middlewareEffect) {
|
|
1421
|
+
if (middlewareEffect.rewriteTarget || routeUrl === url) middlewareDataResponse = middlewareEffect.response;
|
|
1422
|
+
if (middlewareEffect.rewriteTarget) {
|
|
1423
|
+
const rewrittenOwner = resolveDirectHybridClientRouteOwner(middlewareEffect.rewriteTarget, __basePath);
|
|
1424
|
+
if (rewrittenOwner === "app" || rewrittenOwner === "document") scheduleHardNavigationAndThrow(browserUrl, "Navigation rewritten to a non-Pages route");
|
|
1425
|
+
const rewrittenTarget = middlewareRewrittenTarget ?? resolvePagesDataNavigationTarget(middlewareEffect.rewriteTarget, __basePath, pagesDataTargetOptions);
|
|
1426
|
+
if (!rewrittenTarget) scheduleHardNavigationAndThrow(browserUrl, "Navigation rewritten to a non-Pages route");
|
|
1427
|
+
dataTarget = rewrittenTarget;
|
|
1165
1428
|
}
|
|
1166
1429
|
}
|
|
1167
|
-
if (
|
|
1430
|
+
if (middlewareEffect && shouldEvictMiddlewareDataCache(middlewareEffect, dataTarget)) middlewareDataCacheEvictHref = middlewareEffect.dataHref;
|
|
1431
|
+
else if (middlewareEffect) middlewareDataCacheEvictHref = null;
|
|
1432
|
+
if (dataTarget?.dataKind === "static" || dataTarget?.dataKind === "server") await navigateClientData(browserUrl, dataTarget, controller, navId, assertStillCurrent, options, middlewareDataResponse);
|
|
1433
|
+
else if (dataTarget) await navigateClientNoData(browserUrl, dataTarget, controller, assertStillCurrent, options);
|
|
1168
1434
|
else await navigateClientHtml(browserUrl, htmlFetchUrl, controller, navId, assertStillCurrent, options);
|
|
1169
1435
|
}
|
|
1170
1436
|
} finally {
|
|
1171
1437
|
if (navId === routerRuntimeState.navigationId) routerRuntimeState.activeAbortController = null;
|
|
1438
|
+
if (middlewareDataCacheEvictHref !== null) evictPagesDataCache(middlewareDataCacheEvictHref);
|
|
1172
1439
|
}
|
|
1173
1440
|
}
|
|
1174
1441
|
/**
|
|
@@ -1361,11 +1628,15 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
1361
1628
|
} : null;
|
|
1362
1629
|
const navigateOptions = errorRouteHtmlFetchUrl ? {
|
|
1363
1630
|
allowNotFoundResponse: true,
|
|
1631
|
+
locale: navigationLocale,
|
|
1364
1632
|
mode,
|
|
1365
|
-
scroll: scrollTarget
|
|
1633
|
+
scroll: scrollTarget,
|
|
1634
|
+
isHydrationQueryUpdate: options?._h === 1
|
|
1366
1635
|
} : {
|
|
1636
|
+
locale: navigationLocale,
|
|
1367
1637
|
mode,
|
|
1368
|
-
scroll: scrollTarget
|
|
1638
|
+
scroll: scrollTarget,
|
|
1639
|
+
isHydrationQueryUpdate: options?._h === 1
|
|
1369
1640
|
};
|
|
1370
1641
|
const currentLocale = getCurrentUrlLocale();
|
|
1371
1642
|
if (mode === "push" && interpolatedRoute !== resolved && stripHash(full) === routerRuntimeState.lastPathnameAndSearch && navigationLocale === currentLocale) mode = "replace";
|
|
@@ -1391,7 +1662,14 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
1391
1662
|
const appPath = getLocalPathname(resolved);
|
|
1392
1663
|
const appPathNorm = appPath !== null ? removeTrailingSlash(appPath) : null;
|
|
1393
1664
|
const appPathEntry = appPathNorm !== null ? getPagesRouterComponentsMap()[appPathNorm] : void 0;
|
|
1394
|
-
if (appPathEntry !== void 0 && "__appRouter" in appPathEntry && appPathEntry.__appRouter
|
|
1665
|
+
if (appPathEntry !== void 0 && "__appRouter" in appPathEntry && appPathEntry.__appRouter) {
|
|
1666
|
+
if (mode === "push") window.location.assign(full);
|
|
1667
|
+
else window.location.replace(full);
|
|
1668
|
+
return new Promise(() => {});
|
|
1669
|
+
}
|
|
1670
|
+
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
1671
|
+
const hybridOwner = rewrites && (rewrites.beforeFiles.length > 0 || rewrites.afterFiles.length > 0 || rewrites.fallback.length > 0) && hasClientAppRouteManifest() ? (await import("./internal/hybrid-client-route-owner.js")).resolveHybridClientRouteOwner(resolved, __basePath) : resolveDirectHybridClientRouteOwner(resolved, __basePath);
|
|
1672
|
+
if (["app", "document"].includes(hybridOwner ?? "")) {
|
|
1395
1673
|
if (mode === "push") window.location.assign(full);
|
|
1396
1674
|
else window.location.replace(full);
|
|
1397
1675
|
return new Promise(() => {});
|
|
@@ -1417,12 +1695,11 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
1417
1695
|
* Prefetch the resources needed for a future Pages Router navigation.
|
|
1418
1696
|
*
|
|
1419
1697
|
* When the client has a registered code-split loader for the target route
|
|
1420
|
-
* (the prod hot path), we
|
|
1421
|
-
*
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
* the returned Promise is intentionally discarded.
|
|
1698
|
+
* (the prod hot path), we warm the page's JS chunk by invoking the loader
|
|
1699
|
+
* thunk now. Vite's dynamic `import()` machinery is responsible for fetching
|
|
1700
|
+
* and caching it; the returned Promise is intentionally discarded. SSG routes
|
|
1701
|
+
* also prefetch their `/_next/data/<buildId>/<page>.json` payload, matching
|
|
1702
|
+
* Next.js's Pages Router `_isSsg(route)` gate.
|
|
1426
1703
|
*
|
|
1427
1704
|
* When no loader is registered (dev server, or an unmapped route), we fall
|
|
1428
1705
|
* back to the legacy `<link rel="prefetch" as="document">` hint, which lets
|
|
@@ -1432,17 +1709,22 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
1432
1709
|
* Ported from Next.js: `packages/next/src/client/page-loader.ts` `prefetch`
|
|
1433
1710
|
* (the data + chunk parallel prefetch shape).
|
|
1434
1711
|
*/
|
|
1435
|
-
async function prefetchUrl(url) {
|
|
1712
|
+
async function prefetchUrl(url, as) {
|
|
1436
1713
|
if (typeof document === "undefined") return;
|
|
1714
|
+
const displayUrl = as ?? url;
|
|
1437
1715
|
const dataTarget = resolvePagesDataNavigationTarget(url, __basePath);
|
|
1438
1716
|
if (dataTarget) {
|
|
1439
|
-
|
|
1717
|
+
const middlewareDataHref = displayUrl === url ? dataTarget.middlewareDataHref : getPagesMiddlewareDataHref(displayUrl, __basePath) ?? void 0;
|
|
1718
|
+
prefetchPagesData({
|
|
1719
|
+
...dataTarget,
|
|
1720
|
+
middlewareDataHref
|
|
1721
|
+
});
|
|
1440
1722
|
return;
|
|
1441
1723
|
}
|
|
1442
|
-
markAppRouteDetectedOnPrefetch(
|
|
1724
|
+
await markAppRouteDetectedOnPrefetch(displayUrl, __basePath);
|
|
1443
1725
|
const link = document.createElement("link");
|
|
1444
1726
|
link.rel = "prefetch";
|
|
1445
|
-
link.href =
|
|
1727
|
+
link.href = displayUrl;
|
|
1446
1728
|
link.as = "document";
|
|
1447
1729
|
document.head.appendChild(link);
|
|
1448
1730
|
}
|
|
@@ -1614,10 +1896,12 @@ setPagesRouterPopStateHandler(handlePagesRouterPopState);
|
|
|
1614
1896
|
*/
|
|
1615
1897
|
function wrapWithRouterContext(element, onCommit = noopCommit, onError = noopCommit) {
|
|
1616
1898
|
const { CommitBoundary, Provider } = getPagesRouterRuntimeComponents();
|
|
1899
|
+
let inner = createElement(Provider, null, element);
|
|
1900
|
+
if (typeof window !== "undefined" && window.__VINEXT_REACT_STRICT_MODE__ === true) inner = createElement(StrictMode, null, inner);
|
|
1617
1901
|
return createElement(CommitBoundary, {
|
|
1618
1902
|
onCommit,
|
|
1619
1903
|
onError
|
|
1620
|
-
},
|
|
1904
|
+
}, inner);
|
|
1621
1905
|
}
|
|
1622
1906
|
/**
|
|
1623
1907
|
* Higher-order component that injects the Pages Router `router` instance as
|
|
@@ -1654,6 +1938,7 @@ function withRouter(ComposedComponent) {
|
|
|
1654
1938
|
const RouterMethods = {
|
|
1655
1939
|
/** See `_components` comment above for the dual role this map plays. */
|
|
1656
1940
|
components: getPagesRouterComponentsMap(),
|
|
1941
|
+
sdc: getPagesStaticDataCache(),
|
|
1657
1942
|
push: (url, as, options) => {
|
|
1658
1943
|
if (typeof window === "undefined") throwNoRouterInstance();
|
|
1659
1944
|
assertSafeNavigationUrl(resolveUrl(url));
|
|
@@ -1674,9 +1959,9 @@ const RouterMethods = {
|
|
|
1674
1959
|
if (typeof window === "undefined") throwNoRouterInstance();
|
|
1675
1960
|
window.location.reload();
|
|
1676
1961
|
},
|
|
1677
|
-
prefetch: (url) => {
|
|
1962
|
+
prefetch: (url, as) => {
|
|
1678
1963
|
if (typeof window === "undefined") throwNoRouterInstance();
|
|
1679
|
-
return prefetchUrl(url);
|
|
1964
|
+
return prefetchUrl(url, as);
|
|
1680
1965
|
},
|
|
1681
1966
|
beforePopState: (cb) => {
|
|
1682
1967
|
if (typeof window === "undefined") throwNoRouterInstance();
|