vinext 0.0.52 → 0.0.54
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 +1 -1
- package/dist/build/clean-output.d.ts +14 -0
- package/dist/build/clean-output.js +36 -0
- package/dist/build/clean-output.js.map +1 -0
- package/dist/build/inline-css.d.ts +7 -0
- package/dist/build/inline-css.js +50 -0
- package/dist/build/inline-css.js.map +1 -0
- package/dist/build/prerender.d.ts +6 -2
- package/dist/build/prerender.js +51 -12
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/static-export.d.ts +5 -0
- package/dist/build/static-export.js +8 -3
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.js +4 -0
- package/dist/check.js.map +1 -1
- package/dist/cli.js +19 -4
- package/dist/cli.js.map +1 -1
- package/dist/client/instrumentation-client-inject.d.ts +34 -0
- package/dist/client/instrumentation-client-inject.js +57 -0
- package/dist/client/instrumentation-client-inject.js.map +1 -0
- package/dist/client/navigation-runtime.d.ts +16 -2
- package/dist/client/navigation-runtime.js +16 -1
- package/dist/client/navigation-runtime.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +2 -1
- package/dist/client/vinext-next-data.js.map +1 -1
- package/dist/client/window-next.d.ts +17 -2
- package/dist/client/window-next.js.map +1 -1
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.js +2 -1
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +95 -4
- package/dist/config/next-config.js +173 -14
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +42 -7
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +11 -1
- package/dist/entries/app-browser-entry.js +16 -6
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +12 -3
- package/dist/entries/app-rsc-entry.js +41 -8
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +21 -1
- package/dist/entries/app-rsc-manifest.js +6 -4
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/pages-client-entry.d.ts +4 -1
- package/dist/entries/pages-client-entry.js +40 -3
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +292 -34
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +1 -10
- package/dist/entries/runtime-entry-module.js +2 -12
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +91 -10
- package/dist/index.js.map +1 -1
- package/dist/plugins/fonts.js +25 -2
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/remove-console.d.ts +16 -0
- package/dist/plugins/remove-console.js +176 -0
- package/dist/plugins/remove-console.js.map +1 -0
- package/dist/routing/app-route-graph.d.ts +24 -1
- package/dist/routing/app-route-graph.js +52 -4
- package/dist/routing/app-route-graph.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -2
- package/dist/routing/app-router.js +2 -2
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +21 -1
- package/dist/routing/file-matcher.js +39 -1
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.d.ts +1 -1
- package/dist/routing/pages-router.js +10 -3
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-trie.js +13 -18
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/utils.d.ts +11 -1
- package/dist/routing/utils.js +15 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +19 -10
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-action-result.d.ts +16 -1
- package/dist/server/app-browser-action-result.js +15 -1
- package/dist/server/app-browser-action-result.js.map +1 -1
- package/dist/server/app-browser-entry.js +47 -28
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +4 -0
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-elements-wire.d.ts +13 -4
- package/dist/server/app-elements-wire.js +10 -1
- 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 +27 -8
- package/dist/server/app-fallback-renderer.js +19 -8
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-history-state.js +6 -2
- package/dist/server/app-history-state.js.map +1 -1
- package/dist/server/app-inline-css-client.d.ts +7 -0
- package/dist/server/app-inline-css-client.js +37 -0
- package/dist/server/app-inline-css-client.js.map +1 -0
- package/dist/server/app-interception-context-header.d.ts +33 -0
- package/dist/server/app-interception-context-header.js +44 -0
- package/dist/server/app-interception-context-header.js.map +1 -0
- package/dist/server/app-mounted-slots-header.d.ts +19 -0
- package/dist/server/app-mounted-slots-header.js +40 -1
- package/dist/server/app-mounted-slots-header.js.map +1 -1
- package/dist/server/app-optimistic-routing.js +26 -18
- package/dist/server/app-optimistic-routing.js.map +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +2 -0
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +22 -1
- package/dist/server/app-page-boundary.js +30 -3
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +9 -3
- package/dist/server/app-page-cache.js +14 -8
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +13 -1
- package/dist/server/app-page-dispatch.js +136 -82
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +17 -30
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +1 -0
- package/dist/server/app-page-execution.js +2 -0
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.d.ts +1 -0
- package/dist/server/app-page-head.js +8 -0
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-render-identity.d.ts +22 -0
- package/dist/server/app-page-render-identity.js +42 -0
- package/dist/server/app-page-render-identity.js.map +1 -0
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +9 -1
- package/dist/server/app-page-render.js +8 -2
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +6 -3
- package/dist/server/app-page-request.js +5 -2
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.d.ts +11 -1
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +16 -0
- package/dist/server/app-page-route-wiring.js +25 -10
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +12 -0
- package/dist/server/app-page-stream.js +3 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +3 -0
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-response.js +38 -6
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-rsc-handler.d.ts +16 -3
- package/dist/server/app-rsc-handler.js +60 -11
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.d.ts +2 -1
- package/dist/server/app-rsc-request-normalization.js +6 -4
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-segment-config.d.ts +4 -1
- package/dist/server/app-segment-config.js +6 -1
- package/dist/server/app-segment-config.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +22 -3
- package/dist/server/app-server-action-execution.js +46 -7
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.d.ts +6 -0
- package/dist/server/app-ssr-entry.js +57 -6
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-error-meta.js +3 -3
- package/dist/server/app-ssr-error-meta.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +25 -1
- package/dist/server/app-ssr-stream.js +237 -19
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +2 -1
- package/dist/server/app-static-generation.js.map +1 -1
- package/dist/server/client-trace-metadata.d.ts +31 -0
- package/dist/server/client-trace-metadata.js +83 -0
- package/dist/server/client-trace-metadata.js.map +1 -0
- package/dist/server/cookie-utils.d.ts +13 -0
- package/dist/server/cookie-utils.js +20 -0
- package/dist/server/cookie-utils.js.map +1 -0
- package/dist/server/default-not-found-module.d.ts +20 -0
- package/dist/server/default-not-found-module.js +20 -0
- package/dist/server/default-not-found-module.js.map +1 -0
- package/dist/server/dev-server.d.ts +8 -1
- package/dist/server/dev-server.js +56 -11
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/headers.d.ts +5 -1
- package/dist/server/headers.js +5 -1
- package/dist/server/headers.js.map +1 -1
- package/dist/server/html.d.ts +2 -1
- package/dist/server/html.js +6 -1
- package/dist/server/html.js.map +1 -1
- package/dist/server/image-optimization.d.ts +13 -4
- package/dist/server/image-optimization.js +15 -4
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/isr-cache.d.ts +7 -5
- package/dist/server/isr-cache.js +17 -6
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/middleware-runtime.js +1 -2
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/middleware.js +1 -1
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +18 -0
- package/dist/server/pages-api-route.js +3 -1
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-body-parser-config.d.ts +60 -0
- package/dist/server/pages-body-parser-config.js +79 -0
- package/dist/server/pages-body-parser-config.js.map +1 -0
- package/dist/server/pages-data-route.js +1 -0
- package/dist/server/pages-data-route.js.map +1 -1
- package/dist/server/pages-default-404.d.ts +31 -0
- package/dist/server/pages-default-404.js +40 -0
- package/dist/server/pages-default-404.js.map +1 -0
- package/dist/server/pages-document-initial-props.d.ts +7 -0
- package/dist/server/pages-document-initial-props.js +14 -0
- package/dist/server/pages-document-initial-props.js.map +1 -0
- package/dist/server/pages-node-compat.d.ts +10 -0
- package/dist/server/pages-node-compat.js +12 -1
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +40 -0
- package/dist/server/pages-page-data.js +19 -14
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-method.d.ts +48 -0
- package/dist/server/pages-page-method.js +19 -0
- package/dist/server/pages-page-method.js.map +1 -0
- package/dist/server/pages-page-response.d.ts +8 -0
- package/dist/server/pages-page-response.js +21 -11
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/pages-serializable-props.d.ts +25 -0
- package/dist/server/pages-serializable-props.js +69 -0
- package/dist/server/pages-serializable-props.js.map +1 -0
- package/dist/server/prerender-route-params.d.ts +14 -0
- package/dist/server/prerender-route-params.js +94 -0
- package/dist/server/prerender-route-params.js.map +1 -0
- package/dist/server/prod-server.d.ts +3 -23
- package/dist/server/prod-server.js +43 -57
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/proxy-trust.d.ts +41 -0
- package/dist/server/proxy-trust.js +70 -0
- package/dist/server/proxy-trust.js.map +1 -0
- package/dist/server/request-pipeline.d.ts +3 -3
- package/dist/server/request-pipeline.js +5 -4
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/seed-cache.js +12 -6
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/server-action-not-found.js +3 -2
- package/dist/server/server-action-not-found.js.map +1 -1
- package/dist/server/static-file-cache.js +2 -1
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/server/streaming-metadata.d.ts +5 -0
- package/dist/server/streaming-metadata.js +10 -0
- package/dist/server/streaming-metadata.js.map +1 -0
- package/dist/shims/app-router-scroll-state.d.ts +14 -0
- package/dist/shims/app-router-scroll-state.js +51 -0
- package/dist/shims/app-router-scroll-state.js.map +1 -0
- package/dist/shims/app-router-scroll.d.ts +28 -0
- package/dist/shims/app-router-scroll.js +115 -0
- package/dist/shims/app-router-scroll.js.map +1 -0
- package/dist/shims/before-interactive-context.d.ts +30 -0
- package/dist/shims/before-interactive-context.js +10 -0
- package/dist/shims/before-interactive-context.js.map +1 -0
- package/dist/shims/cache-runtime.d.ts +1 -1
- package/dist/shims/cache-runtime.js +14 -1
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +6 -0
- package/dist/shims/cache.js +7 -0
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/default-not-found.d.ts +12 -0
- package/dist/shims/default-not-found.js +61 -0
- package/dist/shims/default-not-found.js.map +1 -0
- package/dist/shims/error.js +3 -0
- package/dist/shims/error.js.map +1 -1
- package/dist/shims/font-local.d.ts +5 -0
- package/dist/shims/font-local.js +6 -2
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/head.js +4 -4
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +13 -2
- package/dist/shims/headers.js +73 -22
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.d.ts +1 -1
- package/dist/shims/image.js +4 -4
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/app-route-detection.d.ts +37 -0
- package/dist/shims/internal/app-route-detection.js +69 -0
- package/dist/shims/internal/app-route-detection.js.map +1 -0
- package/dist/shims/internal/pages-data-target.d.ts +58 -0
- package/dist/shims/internal/pages-data-target.js +91 -0
- package/dist/shims/internal/pages-data-target.js.map +1 -0
- package/dist/shims/internal/pages-data-url.d.ts +42 -0
- package/dist/shims/internal/pages-data-url.js +73 -0
- package/dist/shims/internal/pages-data-url.js.map +1 -0
- package/dist/shims/link.d.ts +18 -2
- package/dist/shims/link.js +129 -15
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +9 -7
- package/dist/shims/metadata.js +70 -7
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +1 -2
- package/dist/shims/navigation.js +94 -20
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/router.d.ts +5 -0
- package/dist/shims/router.js +389 -80
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.d.ts +11 -1
- package/dist/shims/script.js +158 -15
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.js +1 -0
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/url-utils.d.ts +2 -1
- package/dist/shims/url-utils.js +15 -4
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/utils/html-limited-bots.d.ts +5 -0
- package/dist/utils/html-limited-bots.js +15 -0
- package/dist/utils/html-limited-bots.js.map +1 -0
- package/dist/utils/path.d.ts +13 -0
- package/dist/utils/path.js +16 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/query.d.ts +6 -0
- package/dist/utils/query.js +10 -1
- package/dist/utils/query.js.map +1 -1
- package/package.json +1 -1
package/dist/shims/router.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
2
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
3
|
-
import { addQueryParam, appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
4
3
|
import { matchRoutePattern, routePatternParts } from "../routing/route-pattern.js";
|
|
4
|
+
import { isUnknownRecord } from "../utils/record.js";
|
|
5
5
|
import { RouterContext } from "./internal/router-context.js";
|
|
6
6
|
import { applyVinextLocaleGlobals, extractVinextNextDataJson, parseVinextNextDataJson } from "../client/vinext-next-data.js";
|
|
7
7
|
import { isValidModulePath } from "../client/validate-module-path.js";
|
|
8
|
-
import { installWindowNext } from "../client/window-next.js";
|
|
9
|
-
import { isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
10
8
|
import { addLocalePrefix, getDomainLocaleUrl, getLocalePathPrefix } from "../utils/domain-locale.js";
|
|
9
|
+
import { buildPagesDataHref } from "./internal/pages-data-url.js";
|
|
10
|
+
import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
11
|
+
import { getPagesRouterComponentsMap, markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.js";
|
|
12
|
+
import { installWindowNext } from "../client/window-next.js";
|
|
13
|
+
import { getWindowOrigin, isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
14
|
+
import { addQueryParam, appendSearchParamsToUrl, mergeRouteParamsIntoQuery, parseQueryString, urlQueryToSearchParams } from "../utils/query.js";
|
|
11
15
|
import { scrollToHashTarget } from "./hash-scroll.js";
|
|
12
16
|
import { setPagesRouterPopStateHandler } from "./pages-router-runtime.js";
|
|
13
17
|
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
@@ -55,6 +59,8 @@ function resolveUrl(url) {
|
|
|
55
59
|
* data fetching, as for the browser URL). We collapse them because vinext's
|
|
56
60
|
* navigateClient() fetches HTML from the target URL, so `as` must be a
|
|
57
61
|
* server-resolvable path. Purely decorative `as` values are not supported.
|
|
62
|
+
* Pages error routes are handled as a narrow exception below because Next.js
|
|
63
|
+
* treats their href as the component route while preserving `as` in history.
|
|
58
64
|
*/
|
|
59
65
|
function resolveNavigationTarget(url, as, locale) {
|
|
60
66
|
return applyNavigationLocale(as ?? resolveUrl(url), locale);
|
|
@@ -66,6 +72,40 @@ function getCurrentUrlLocale() {
|
|
|
66
72
|
hostname: getCurrentHostname()
|
|
67
73
|
});
|
|
68
74
|
}
|
|
75
|
+
function getLocalPathname(url) {
|
|
76
|
+
if (typeof window === "undefined") return null;
|
|
77
|
+
if (isAbsoluteOrProtocolRelativeUrl(url)) {
|
|
78
|
+
const localPath = toSameOriginAppPath(url, __basePath);
|
|
79
|
+
if (localPath == null) return null;
|
|
80
|
+
return stripBasePath(new URL(localPath, window.location.href).pathname, __basePath);
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return stripBasePath(new URL(url, window.location.href).pathname, __basePath);
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function resolvePagesErrorHtmlFetchUrl(url, locale) {
|
|
89
|
+
const href = resolveUrl(url);
|
|
90
|
+
const errorRoutePathname = getLocalPathname(href);
|
|
91
|
+
if (errorRoutePathname !== "/404" && errorRoutePathname !== "/_error") return null;
|
|
92
|
+
const resolvedUrl = applyNavigationLocale(errorRoutePathname === "/_error" ? replaceUrlPathname(href, "/404") : href, locale);
|
|
93
|
+
let parsed;
|
|
94
|
+
try {
|
|
95
|
+
parsed = new URL(resolvedUrl, window.location.href);
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(`${stripBasePath(parsed.pathname, __basePath)}${parsed.search}${parsed.hash}`, window.location.href, __basePath), __trailingSlash);
|
|
100
|
+
}
|
|
101
|
+
function replaceUrlPathname(url, pathname) {
|
|
102
|
+
try {
|
|
103
|
+
const parsed = new URL(url, window.location.href);
|
|
104
|
+
return `${pathname}${parsed.search}${parsed.hash}`;
|
|
105
|
+
} catch {
|
|
106
|
+
return pathname;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
69
109
|
function resolveTransitionLocale(locale) {
|
|
70
110
|
if (typeof window === "undefined") return void 0;
|
|
71
111
|
if (locale === false) return window.__VINEXT_DEFAULT_LOCALE__;
|
|
@@ -179,6 +219,7 @@ function _buildClientPagesNavigationContext(routePattern, resolvedPath, searchSt
|
|
|
179
219
|
_cachedClientPagesNavCtxKey = cacheKey;
|
|
180
220
|
return ctx;
|
|
181
221
|
}
|
|
222
|
+
const _ssrPagesNavCtxCache = /* @__PURE__ */ new WeakMap();
|
|
182
223
|
/**
|
|
183
224
|
* Cross-router compat shim source for `next/navigation` hooks.
|
|
184
225
|
*
|
|
@@ -199,6 +240,8 @@ function getPagesNavigationContext() {
|
|
|
199
240
|
if (typeof window === "undefined") {
|
|
200
241
|
const ssrCtx = _getSSRContext();
|
|
201
242
|
if (!ssrCtx) return null;
|
|
243
|
+
const cached = _ssrPagesNavCtxCache.get(ssrCtx);
|
|
244
|
+
if (cached) return cached;
|
|
202
245
|
let searchParams;
|
|
203
246
|
let resolvedPath;
|
|
204
247
|
try {
|
|
@@ -210,11 +253,13 @@ function getPagesNavigationContext() {
|
|
|
210
253
|
resolvedPath = ssrCtx.pathname;
|
|
211
254
|
}
|
|
212
255
|
const params = extractRouteParamsFromPath(ssrCtx.pathname, resolvedPath) ?? {};
|
|
213
|
-
|
|
256
|
+
const ctx = {
|
|
214
257
|
pathname: resolvedPath,
|
|
215
258
|
searchParams,
|
|
216
259
|
params
|
|
217
260
|
};
|
|
261
|
+
_ssrPagesNavCtxCache.set(ssrCtx, ctx);
|
|
262
|
+
return ctx;
|
|
218
263
|
}
|
|
219
264
|
const resolvedPath = stripBasePath(window.location.pathname, __basePath);
|
|
220
265
|
return _buildClientPagesNavigationContext(window.__NEXT_DATA__?.page ?? "", resolvedPath, window.location.search);
|
|
@@ -329,21 +374,286 @@ function scheduleHardNavigationAndThrow(url, message) {
|
|
|
329
374
|
window.location.href = url;
|
|
330
375
|
throw new HardNavigationScheduledError(message);
|
|
331
376
|
}
|
|
377
|
+
function isPageComponent(value) {
|
|
378
|
+
if (typeof value === "function") return true;
|
|
379
|
+
if (!isUnknownRecord(value)) return false;
|
|
380
|
+
return value.$$typeof === Symbol.for("react.forward_ref") || value.$$typeof === Symbol.for("react.memo");
|
|
381
|
+
}
|
|
382
|
+
function isAppComponent(value) {
|
|
383
|
+
return isPageComponent(value);
|
|
384
|
+
}
|
|
385
|
+
function resolveSameOriginRedirectedUrl(responseUrl) {
|
|
386
|
+
const appPath = toSameOriginAppPath(responseUrl, __basePath);
|
|
387
|
+
if (appPath === null) return null;
|
|
388
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(appPath, window.location.href, __basePath), __trailingSlash);
|
|
389
|
+
}
|
|
390
|
+
function stripLocalePrefixForApiRedirect(appPath) {
|
|
391
|
+
const locales = window.__VINEXT_LOCALES__;
|
|
392
|
+
if (!locales || locales.length === 0) return appPath;
|
|
393
|
+
try {
|
|
394
|
+
const parsed = new URL(appPath, "http://vinext.local");
|
|
395
|
+
const pathname = stripBasePath(parsed.pathname, __basePath);
|
|
396
|
+
const firstSegment = pathname.split("/")[1];
|
|
397
|
+
if (!firstSegment || !locales.includes(firstSegment)) return appPath;
|
|
398
|
+
const withoutLocale = pathname.slice(firstSegment.length + 1) || "/";
|
|
399
|
+
if (withoutLocale !== "/api" && !withoutLocale.startsWith("/api/")) return appPath;
|
|
400
|
+
return `${withoutLocale}${parsed.search}${parsed.hash}`;
|
|
401
|
+
} catch {
|
|
402
|
+
return appPath;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function resolveLocalRedirectUrl(location) {
|
|
406
|
+
let appPath;
|
|
407
|
+
if (location.startsWith("/") && !location.startsWith("//")) try {
|
|
408
|
+
const parsed = new URL(location, "http://vinext.local");
|
|
409
|
+
appPath = stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;
|
|
410
|
+
} catch {
|
|
411
|
+
appPath = location;
|
|
412
|
+
}
|
|
413
|
+
else appPath = toSameOriginAppPath(location, __basePath);
|
|
414
|
+
if (appPath === null) return null;
|
|
415
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(stripLocalePrefixForApiRedirect(appPath), window.location.href, __basePath), __trailingSlash);
|
|
416
|
+
}
|
|
417
|
+
function hasVinextMiddleware(nextData) {
|
|
418
|
+
if (!isUnknownRecord(nextData)) return false;
|
|
419
|
+
const vinext = nextData.__vinext;
|
|
420
|
+
return isUnknownRecord(vinext) && vinext.hasMiddleware === true;
|
|
421
|
+
}
|
|
422
|
+
function getMiddlewarePagesDataFetchUrl(browserUrl) {
|
|
423
|
+
const nextData = window.__NEXT_DATA__;
|
|
424
|
+
if (!nextData || !hasVinextMiddleware(nextData)) return null;
|
|
425
|
+
const buildId = nextData.buildId;
|
|
426
|
+
if (typeof buildId !== "string" || buildId.length === 0) return null;
|
|
427
|
+
let parsed;
|
|
428
|
+
try {
|
|
429
|
+
parsed = new URL(browserUrl, window.location.href);
|
|
430
|
+
} catch {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
if (parsed.origin !== getWindowOrigin()) return null;
|
|
434
|
+
return buildPagesDataHref(__basePath, buildId, stripBasePath(parsed.pathname, __basePath), parsed.search);
|
|
435
|
+
}
|
|
436
|
+
async function resolveMiddlewareDataRedirect(browserUrl, signal) {
|
|
437
|
+
const dataUrl = getMiddlewarePagesDataFetchUrl(browserUrl);
|
|
438
|
+
if (!dataUrl) return null;
|
|
439
|
+
try {
|
|
440
|
+
return (await fetch(dataUrl, {
|
|
441
|
+
headers: {
|
|
442
|
+
Accept: "application/json",
|
|
443
|
+
"x-nextjs-data": "1"
|
|
444
|
+
},
|
|
445
|
+
signal
|
|
446
|
+
})).headers.get("x-nextjs-redirect");
|
|
447
|
+
} catch (err) {
|
|
448
|
+
if (err instanceof DOMException && err.name === "AbortError") throw err;
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
332
452
|
/**
|
|
333
|
-
* Perform client-side navigation
|
|
334
|
-
*
|
|
453
|
+
* Perform client-side navigation via the `/_next/data/<id>/<page>.json`
|
|
454
|
+
* endpoint. Used when `__VINEXT_PAGE_LOADERS__` has a matching code-split
|
|
455
|
+
* loader for the target pattern (the prod hot path). Falls back to the
|
|
456
|
+
* HTML extraction path (`navigateClientHtml`) when this returns `null`.
|
|
457
|
+
*
|
|
458
|
+
* Failure modes (404, 5xx, network, parse, missing loader, soft redirect)
|
|
459
|
+
* all queue a hard navigation and throw `HardNavigationScheduledError`,
|
|
460
|
+
* mirroring the existing HTML-path failure protocol. The hard reload is
|
|
461
|
+
* the deploy-skew safety net: when the server's buildId has rotated, the
|
|
462
|
+
* data endpoint returns 404 and the client lands on the new build via a
|
|
463
|
+
* full document load.
|
|
464
|
+
*/
|
|
465
|
+
async function navigateClientData(url, target, controller, navId, assertStillCurrent) {
|
|
466
|
+
const root = window.__VINEXT_ROOT__;
|
|
467
|
+
if (!root) {
|
|
468
|
+
window.location.href = url;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
let res;
|
|
472
|
+
try {
|
|
473
|
+
res = await fetch(target.dataHref, {
|
|
474
|
+
headers: {
|
|
475
|
+
Accept: "application/json",
|
|
476
|
+
"x-nextjs-data": "1"
|
|
477
|
+
},
|
|
478
|
+
signal: controller.signal
|
|
479
|
+
});
|
|
480
|
+
} catch (err) {
|
|
481
|
+
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(url);
|
|
482
|
+
throw err;
|
|
483
|
+
}
|
|
484
|
+
assertStillCurrent();
|
|
485
|
+
const softRedirect = res.headers.get("x-nextjs-redirect");
|
|
486
|
+
if (softRedirect) {
|
|
487
|
+
const redirectedUrl = resolveLocalRedirectUrl(softRedirect);
|
|
488
|
+
if (!redirectedUrl) scheduleHardNavigationAndThrow(softRedirect, "Navigation redirected externally");
|
|
489
|
+
window.history.replaceState(window.history.state ?? {}, "", redirectedUrl);
|
|
490
|
+
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
491
|
+
await navigateClientHtml(redirectedUrl, redirectedUrl, controller, navId, assertStillCurrent);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (!res.ok) scheduleHardNavigationAndThrow(url, `Data navigation failed: ${res.status} ${res.statusText}`);
|
|
495
|
+
let body;
|
|
496
|
+
try {
|
|
497
|
+
body = await res.json();
|
|
498
|
+
} catch {
|
|
499
|
+
scheduleHardNavigationAndThrow(url, "Data navigation failed: invalid JSON response");
|
|
500
|
+
}
|
|
501
|
+
assertStillCurrent();
|
|
502
|
+
const pageProps = body.pageProps && typeof body.pageProps === "object" ? body.pageProps : {};
|
|
503
|
+
let pageModule;
|
|
504
|
+
try {
|
|
505
|
+
pageModule = await target.loader();
|
|
506
|
+
} catch (err) {
|
|
507
|
+
console.error("[vinext] Page loader threw during navigation:", err);
|
|
508
|
+
scheduleHardNavigationAndThrow(url, "Data navigation failed: page loader threw");
|
|
509
|
+
}
|
|
510
|
+
assertStillCurrent();
|
|
511
|
+
const PageComponent = pageModule.default;
|
|
512
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(url, "Data navigation failed: page module default export is not a component");
|
|
513
|
+
let AppComponent = window.__VINEXT_APP__;
|
|
514
|
+
if (!AppComponent && typeof window.__VINEXT_APP_LOADER__ === "function") try {
|
|
515
|
+
const appModule = await window.__VINEXT_APP_LOADER__();
|
|
516
|
+
AppComponent = isAppComponent(appModule.default) ? appModule.default : void 0;
|
|
517
|
+
if (AppComponent) window.__VINEXT_APP__ = AppComponent;
|
|
518
|
+
} catch {}
|
|
519
|
+
assertStillCurrent();
|
|
520
|
+
const React = (await import("react")).default;
|
|
521
|
+
assertStillCurrent();
|
|
522
|
+
let element;
|
|
523
|
+
if (AppComponent) element = React.createElement(AppComponent, {
|
|
524
|
+
Component: PageComponent,
|
|
525
|
+
pageProps
|
|
526
|
+
});
|
|
527
|
+
else element = React.createElement(PageComponent, pageProps);
|
|
528
|
+
element = wrapWithRouterContext(element);
|
|
529
|
+
const mergedQuery = mergeRouteParamsIntoQuery(parseQueryString(target.search), target.params);
|
|
530
|
+
const prev = window.__NEXT_DATA__;
|
|
531
|
+
const nextLocale = (window.__VINEXT_LOCALES__?.length ?? 0) > 0 ? target.locale ?? window.__VINEXT_DEFAULT_LOCALE__ : prev?.locale;
|
|
532
|
+
const nextData = {
|
|
533
|
+
...prev,
|
|
534
|
+
props: { pageProps },
|
|
535
|
+
page: target.pattern,
|
|
536
|
+
query: mergedQuery,
|
|
537
|
+
buildId: target.buildId,
|
|
538
|
+
isFallback: false,
|
|
539
|
+
...nextLocale !== void 0 ? { locale: nextLocale } : {}
|
|
540
|
+
};
|
|
541
|
+
window.__NEXT_DATA__ = nextData;
|
|
542
|
+
applyVinextLocaleGlobals(window, nextData);
|
|
543
|
+
root.render(element);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Perform client-side navigation by fetching the page's full HTML and
|
|
547
|
+
* extracting `__NEXT_DATA__` plus the page module URL. Used in dev (where
|
|
548
|
+
* the per-page inline hydration script does not populate the loader map) and
|
|
549
|
+
* as a generic fallback when the data path is not available.
|
|
335
550
|
*
|
|
336
551
|
* Throws NavigationCancelledError if a newer navigation supersedes this one.
|
|
337
552
|
* Throws on hard-navigation failures (non-OK response, missing data) so the
|
|
338
553
|
* caller can distinguish success from failure for event emission.
|
|
339
554
|
*/
|
|
340
|
-
async function
|
|
341
|
-
|
|
555
|
+
async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillCurrent, options = {}) {
|
|
556
|
+
let browserUrl = url;
|
|
557
|
+
let pendingRedirectHistoryUrl = fetchUrl === url ? null : url;
|
|
342
558
|
const root = window.__VINEXT_ROOT__;
|
|
343
559
|
if (!root) {
|
|
344
|
-
window.location.href =
|
|
560
|
+
window.location.href = browserUrl;
|
|
345
561
|
return;
|
|
346
562
|
}
|
|
563
|
+
let res;
|
|
564
|
+
try {
|
|
565
|
+
res = await fetch(fetchUrl, {
|
|
566
|
+
headers: { Accept: "text/html" },
|
|
567
|
+
signal: controller.signal
|
|
568
|
+
});
|
|
569
|
+
} catch (err) {
|
|
570
|
+
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(url);
|
|
571
|
+
throw err;
|
|
572
|
+
}
|
|
573
|
+
assertStillCurrent();
|
|
574
|
+
if (res.redirected && res.url) {
|
|
575
|
+
const redirectedUrl = resolveSameOriginRedirectedUrl(res.url);
|
|
576
|
+
if (redirectedUrl) {
|
|
577
|
+
browserUrl = redirectedUrl;
|
|
578
|
+
pendingRedirectHistoryUrl = redirectedUrl;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (!res.ok && !(options.allowNotFoundResponse === true && res.status === 404)) scheduleHardNavigationAndThrow(browserUrl, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
582
|
+
const html = await res.text();
|
|
583
|
+
assertStillCurrent();
|
|
584
|
+
const nextDataJson = extractVinextNextDataJson(html);
|
|
585
|
+
if (!nextDataJson) scheduleHardNavigationAndThrow(url, "Navigation failed: missing __NEXT_DATA__ in response");
|
|
586
|
+
const nextData = parseVinextNextDataJson(nextDataJson);
|
|
587
|
+
const { pageProps } = nextData.props;
|
|
588
|
+
let pageModuleUrl = nextData.__vinext?.pageModuleUrl;
|
|
589
|
+
if (!pageModuleUrl) {
|
|
590
|
+
const moduleMatch = html.match(/import\("([^"]+)"\);\s*\n\s*const PageComponent/);
|
|
591
|
+
const altMatch = html.match(/await import\("([^"]+pages\/[^"]+)"\)/);
|
|
592
|
+
pageModuleUrl = moduleMatch?.[1] ?? altMatch?.[1] ?? void 0;
|
|
593
|
+
}
|
|
594
|
+
let pageModule;
|
|
595
|
+
if (!pageModuleUrl) {
|
|
596
|
+
const loader = window.__VINEXT_PAGE_LOADERS__?.[nextData.page];
|
|
597
|
+
if (!loader) scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: no page module URL found");
|
|
598
|
+
pageModule = await loader();
|
|
599
|
+
} else {
|
|
600
|
+
if (!isValidModulePath(pageModuleUrl)) {
|
|
601
|
+
console.error("[vinext] Blocked import of invalid page module path:", pageModuleUrl);
|
|
602
|
+
scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: invalid page module path");
|
|
603
|
+
}
|
|
604
|
+
pageModule = await import(
|
|
605
|
+
/* @vite-ignore */
|
|
606
|
+
pageModuleUrl
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
assertStillCurrent();
|
|
610
|
+
const PageComponent = pageModule.default;
|
|
611
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: page module default export is not a component");
|
|
612
|
+
const React = (await import("react")).default;
|
|
613
|
+
assertStillCurrent();
|
|
614
|
+
let AppComponent = window.__VINEXT_APP__;
|
|
615
|
+
const appModuleUrl = nextData.__vinext?.appModuleUrl;
|
|
616
|
+
if (!AppComponent && appModuleUrl) if (!isValidModulePath(appModuleUrl)) console.error("[vinext] Blocked import of invalid app module path:", appModuleUrl);
|
|
617
|
+
else try {
|
|
618
|
+
const appModule = await import(
|
|
619
|
+
/* @vite-ignore */
|
|
620
|
+
appModuleUrl
|
|
621
|
+
);
|
|
622
|
+
AppComponent = isAppComponent(appModule.default) ? appModule.default : void 0;
|
|
623
|
+
window.__VINEXT_APP__ = AppComponent;
|
|
624
|
+
} catch {}
|
|
625
|
+
assertStillCurrent();
|
|
626
|
+
let element;
|
|
627
|
+
if (AppComponent) element = React.createElement(AppComponent, {
|
|
628
|
+
Component: PageComponent,
|
|
629
|
+
pageProps
|
|
630
|
+
});
|
|
631
|
+
else element = React.createElement(PageComponent, pageProps);
|
|
632
|
+
element = wrapWithRouterContext(element);
|
|
633
|
+
if (pendingRedirectHistoryUrl) {
|
|
634
|
+
window.history.replaceState(window.history.state ?? {}, "", pendingRedirectHistoryUrl);
|
|
635
|
+
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
636
|
+
}
|
|
637
|
+
window.__NEXT_DATA__ = nextData;
|
|
638
|
+
applyVinextLocaleGlobals(window, nextData);
|
|
639
|
+
root.render(element);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Perform client-side navigation. Prefers the JSON data endpoint when the
|
|
643
|
+
* client has a registered code-split loader for the target route (the prod
|
|
644
|
+
* hot path); otherwise falls back to fetching the page's full HTML (dev and
|
|
645
|
+
* any unmapped route).
|
|
646
|
+
*
|
|
647
|
+
* Throws NavigationCancelledError if a newer navigation supersedes this one.
|
|
648
|
+
* Throws on hard-navigation failures (non-OK response, missing data) so the
|
|
649
|
+
* caller can distinguish success from failure for event emission.
|
|
650
|
+
*
|
|
651
|
+
* `fetchUrl` is the HTML-path fetch URL (already includes locale-root
|
|
652
|
+
* fixups). The JSON path derives its own URL from the browser-facing `url`
|
|
653
|
+
* because the data endpoint speaks the unprefixed path.
|
|
654
|
+
*/
|
|
655
|
+
async function navigateClient(url, fetchUrl = url, options = {}) {
|
|
656
|
+
if (typeof window === "undefined") return;
|
|
347
657
|
_activeAbortController?.abort();
|
|
348
658
|
const controller = new AbortController();
|
|
349
659
|
_activeAbortController = controller;
|
|
@@ -353,65 +663,32 @@ async function navigateClient(url, fetchUrl = url) {
|
|
|
353
663
|
if (navId !== _navigationId) throw new NavigationCancelledError(url);
|
|
354
664
|
}
|
|
355
665
|
try {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (!isValidModulePath(pageModuleUrl)) {
|
|
382
|
-
console.error("[vinext] Blocked import of invalid page module path:", pageModuleUrl);
|
|
383
|
-
scheduleHardNavigationAndThrow(url, "Navigation failed: invalid page module path");
|
|
666
|
+
if (options.allowNotFoundResponse === true) await navigateClientHtml(url, fetchUrl, controller, navId, assertStillCurrent, options);
|
|
667
|
+
else {
|
|
668
|
+
let browserUrl = url;
|
|
669
|
+
let htmlFetchUrl = fetchUrl;
|
|
670
|
+
const dataTarget = resolvePagesDataNavigationTarget(browserUrl, __basePath);
|
|
671
|
+
if (!dataTarget) {
|
|
672
|
+
let redirectLocation;
|
|
673
|
+
try {
|
|
674
|
+
redirectLocation = await resolveMiddlewareDataRedirect(browserUrl, controller.signal);
|
|
675
|
+
} catch (err) {
|
|
676
|
+
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(browserUrl);
|
|
677
|
+
throw err;
|
|
678
|
+
}
|
|
679
|
+
assertStillCurrent();
|
|
680
|
+
if (redirectLocation) {
|
|
681
|
+
const redirectedUrl = resolveLocalRedirectUrl(redirectLocation);
|
|
682
|
+
if (!redirectedUrl) scheduleHardNavigationAndThrow(redirectLocation, "Navigation redirected externally");
|
|
683
|
+
window.history.replaceState(window.history.state ?? {}, "", redirectedUrl);
|
|
684
|
+
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
685
|
+
browserUrl = redirectedUrl;
|
|
686
|
+
htmlFetchUrl = redirectedUrl;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (dataTarget) await navigateClientData(browserUrl, dataTarget, controller, navId, assertStillCurrent);
|
|
690
|
+
else await navigateClientHtml(browserUrl, htmlFetchUrl, controller, navId, assertStillCurrent, options);
|
|
384
691
|
}
|
|
385
|
-
const pageModule = await import(
|
|
386
|
-
/* @vite-ignore */
|
|
387
|
-
pageModuleUrl
|
|
388
|
-
);
|
|
389
|
-
assertStillCurrent();
|
|
390
|
-
const PageComponent = pageModule.default;
|
|
391
|
-
if (!PageComponent) scheduleHardNavigationAndThrow(url, "Navigation failed: page module has no default export");
|
|
392
|
-
const React = (await import("react")).default;
|
|
393
|
-
assertStillCurrent();
|
|
394
|
-
let AppComponent = window.__VINEXT_APP__;
|
|
395
|
-
const appModuleUrl = nextData.__vinext?.appModuleUrl;
|
|
396
|
-
if (!AppComponent && appModuleUrl) if (!isValidModulePath(appModuleUrl)) console.error("[vinext] Blocked import of invalid app module path:", appModuleUrl);
|
|
397
|
-
else try {
|
|
398
|
-
AppComponent = (await import(
|
|
399
|
-
/* @vite-ignore */
|
|
400
|
-
appModuleUrl
|
|
401
|
-
)).default;
|
|
402
|
-
window.__VINEXT_APP__ = AppComponent;
|
|
403
|
-
} catch {}
|
|
404
|
-
assertStillCurrent();
|
|
405
|
-
let element;
|
|
406
|
-
if (AppComponent) element = React.createElement(AppComponent, {
|
|
407
|
-
Component: PageComponent,
|
|
408
|
-
pageProps
|
|
409
|
-
});
|
|
410
|
-
else element = React.createElement(PageComponent, pageProps);
|
|
411
|
-
element = wrapWithRouterContext(element);
|
|
412
|
-
window.__NEXT_DATA__ = nextData;
|
|
413
|
-
applyVinextLocaleGlobals(window, nextData);
|
|
414
|
-
root.render(element);
|
|
415
692
|
} finally {
|
|
416
693
|
if (navId === _navigationId) _activeAbortController = null;
|
|
417
694
|
}
|
|
@@ -428,9 +705,9 @@ async function navigateClient(url, fetchUrl = url) {
|
|
|
428
705
|
* - "failed" — genuine error, caller should return false (hard nav is already
|
|
429
706
|
* scheduled as recovery)
|
|
430
707
|
*/
|
|
431
|
-
async function runNavigateClient(fullUrl, resolvedUrl, fetchUrl = fullUrl) {
|
|
708
|
+
async function runNavigateClient(fullUrl, resolvedUrl, fetchUrl = fullUrl, options = {}) {
|
|
432
709
|
try {
|
|
433
|
-
await navigateClient(fullUrl, fetchUrl);
|
|
710
|
+
await navigateClient(fullUrl, fetchUrl, options);
|
|
434
711
|
return "completed";
|
|
435
712
|
} catch (err) {
|
|
436
713
|
routerEvents.emit("routeChangeError", err, resolvedUrl, { shallow: false });
|
|
@@ -530,7 +807,9 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
530
807
|
}
|
|
531
808
|
resolved = normalizePathTrailingSlash(resolved, __trailingSlash);
|
|
532
809
|
const full = normalizePathTrailingSlash(toBrowserNavigationHref(resolved, window.location.href, __basePath), __trailingSlash);
|
|
533
|
-
const
|
|
810
|
+
const errorRouteHtmlFetchUrl = resolvePagesErrorHtmlFetchUrl(url, navigationLocale);
|
|
811
|
+
const htmlFetchUrl = errorRouteHtmlFetchUrl ?? getPagesHtmlFetchUrl(full, navigationLocale);
|
|
812
|
+
const navigateOptions = errorRouteHtmlFetchUrl ? { allowNotFoundResponse: true } : {};
|
|
534
813
|
const shallow = options?.shallow ?? false;
|
|
535
814
|
const doScroll = options?.scroll !== false;
|
|
536
815
|
if (isHashOnlyChange(full)) {
|
|
@@ -548,7 +827,7 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
548
827
|
routerEvents.emit("beforeHistoryChange", resolved, { shallow });
|
|
549
828
|
updateHistory(mode, full);
|
|
550
829
|
if (!shallow) {
|
|
551
|
-
const result = await runNavigateClient(full, resolved, htmlFetchUrl);
|
|
830
|
+
const result = await runNavigateClient(full, resolved, htmlFetchUrl, navigateOptions);
|
|
552
831
|
if (result === "cancelled") return true;
|
|
553
832
|
if (result === "failed") return false;
|
|
554
833
|
}
|
|
@@ -560,15 +839,38 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
560
839
|
dispatchNavigateEvent();
|
|
561
840
|
return true;
|
|
562
841
|
}
|
|
563
|
-
/**
|
|
842
|
+
/**
|
|
843
|
+
* Prefetch the resources needed for a future Pages Router navigation.
|
|
844
|
+
*
|
|
845
|
+
* When the client has a registered code-split loader for the target route
|
|
846
|
+
* (the prod hot path), we prefetch in parallel:
|
|
847
|
+
* 1. The `/_next/data/<buildId>/<page>.json` payload — same URL the actual
|
|
848
|
+
* navigation will request, so a cache hit is automatic.
|
|
849
|
+
* 2. The page's JS chunk — by invoking the loader thunk now. Vite's
|
|
850
|
+
* dynamic `import()` machinery is responsible for fetching + caching;
|
|
851
|
+
* the returned Promise is intentionally discarded.
|
|
852
|
+
*
|
|
853
|
+
* When no loader is registered (dev server, or an unmapped route), we fall
|
|
854
|
+
* back to the legacy `<link rel="prefetch" as="document">` hint, which lets
|
|
855
|
+
* the browser preload the HTML document. This matches the pre-`_next/data`
|
|
856
|
+
* behaviour so dev doesn't regress.
|
|
857
|
+
*
|
|
858
|
+
* Ported from Next.js: `packages/next/src/client/page-loader.ts` `prefetch`
|
|
859
|
+
* (the data + chunk parallel prefetch shape).
|
|
860
|
+
*/
|
|
564
861
|
async function prefetchUrl(url) {
|
|
565
|
-
if (typeof document
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
document.head.appendChild(link);
|
|
862
|
+
if (typeof document === "undefined") return;
|
|
863
|
+
const dataTarget = resolvePagesDataNavigationTarget(url, __basePath);
|
|
864
|
+
if (dataTarget) {
|
|
865
|
+
prefetchPagesData(dataTarget);
|
|
866
|
+
return;
|
|
571
867
|
}
|
|
868
|
+
markAppRouteDetectedOnPrefetch(url, __basePath);
|
|
869
|
+
const link = document.createElement("link");
|
|
870
|
+
link.rel = "prefetch";
|
|
871
|
+
link.href = url;
|
|
872
|
+
link.as = "document";
|
|
873
|
+
document.head.appendChild(link);
|
|
572
874
|
}
|
|
573
875
|
/**
|
|
574
876
|
* useRouter hook - Pages Router compatible.
|
|
@@ -681,13 +983,19 @@ function withRouter(ComposedComponent) {
|
|
|
681
983
|
if (process.env.NODE_ENV !== "production") WithRouterWrapper.displayName = `withRouter(${composed.displayName || composed.name || "Unknown"})`;
|
|
682
984
|
return WithRouterWrapper;
|
|
683
985
|
}
|
|
684
|
-
const
|
|
986
|
+
const RouterMethods = {
|
|
987
|
+
/** See `_components` comment above for the dual role this map plays. */
|
|
988
|
+
components: getPagesRouterComponentsMap(),
|
|
685
989
|
push: (url, as, options) => {
|
|
686
990
|
if (typeof window === "undefined") throwNoRouterInstance();
|
|
991
|
+
assertSafeNavigationUrl(resolveUrl(url));
|
|
992
|
+
if (as !== void 0) assertSafeNavigationUrl(String(as));
|
|
687
993
|
return performNavigation(url, as, options, "push");
|
|
688
994
|
},
|
|
689
995
|
replace: (url, as, options) => {
|
|
690
996
|
if (typeof window === "undefined") throwNoRouterInstance();
|
|
997
|
+
assertSafeNavigationUrl(resolveUrl(url));
|
|
998
|
+
if (as !== void 0) assertSafeNavigationUrl(String(as));
|
|
691
999
|
return performNavigation(url, as, options, "replace");
|
|
692
1000
|
},
|
|
693
1001
|
back: () => {
|
|
@@ -707,7 +1015,8 @@ const Router = Object.defineProperties({
|
|
|
707
1015
|
_beforePopStateCb = cb;
|
|
708
1016
|
},
|
|
709
1017
|
events: routerEvents
|
|
710
|
-
}
|
|
1018
|
+
};
|
|
1019
|
+
const Router = Object.defineProperties(RouterMethods, {
|
|
711
1020
|
pathname: {
|
|
712
1021
|
enumerable: true,
|
|
713
1022
|
get() {
|