vinext 0.0.51 → 0.0.53
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/precompress.d.ts +7 -7
- package/dist/build/precompress.js +18 -17
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +9 -16
- package/dist/build/prerender.js +88 -50
- 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-args.d.ts +1 -0
- package/dist/cli-args.js +5 -0
- package/dist/cli-args.js.map +1 -1
- package/dist/cli.js +58 -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 +60 -0
- package/dist/client/navigation-runtime.js +171 -0
- package/dist/client/navigation-runtime.js.map +1 -0
- package/dist/client/pages-router-link-navigation.d.ts +26 -0
- package/dist/client/pages-router-link-navigation.js +14 -0
- package/dist/client/pages-router-link-navigation.js.map +1 -0
- package/dist/client/vinext-next-data.d.ts +14 -3
- package/dist/client/vinext-next-data.js +50 -1
- package/dist/client/vinext-next-data.js.map +1 -0
- package/dist/client/window-next.d.ts +10 -2
- package/dist/client/window-next.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js +2 -1
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +63 -16
- package/dist/config/config-matchers.js +145 -9
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +32 -5
- package/dist/config/next-config.js +55 -15
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +130 -46
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.js +9 -3
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -2
- package/dist/entries/app-rsc-entry.js +76 -16
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +1 -0
- package/dist/entries/app-rsc-manifest.js +53 -6
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +3 -3
- package/dist/entries/app-ssr-entry.js +4 -4
- package/dist/entries/app-ssr-entry.js.map +1 -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 +261 -31
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +2 -1
- package/dist/entries/runtime-entry-module.js +9 -3
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +161 -46
- package/dist/index.js.map +1 -1
- package/dist/plugins/css-data-url.d.ts +7 -0
- package/dist/plugins/css-data-url.js +81 -0
- package/dist/plugins/css-data-url.js.map +1 -0
- package/dist/plugins/fonts.js +30 -5
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/middleware-server-only.d.ts +54 -0
- package/dist/plugins/middleware-server-only.js +91 -0
- package/dist/plugins/middleware-server-only.js.map +1 -0
- package/dist/plugins/optimize-imports.js +4 -4
- package/dist/plugins/optimize-imports.js.map +1 -1
- package/dist/plugins/strip-server-exports.js +5 -8
- package/dist/plugins/strip-server-exports.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +20 -1
- package/dist/routing/app-route-graph.js +58 -6
- 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/route-trie.js +13 -18
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/utils.d.ts +12 -1
- package/dist/routing/utils.js +18 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +153 -42
- 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 +309 -155
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-interception-context.d.ts +24 -0
- package/dist/server/app-browser-interception-context.js +32 -0
- package/dist/server/app-browser-interception-context.js.map +1 -0
- package/dist/server/app-browser-navigation-controller.d.ts +3 -1
- package/dist/server/app-browser-navigation-controller.js +5 -1
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
- package/dist/server/app-browser-rsc-redirect.js +2 -2
- package/dist/server/app-browser-rsc-redirect.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +18 -1
- package/dist/server/app-browser-state.js +19 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +5 -14
- package/dist/server/app-browser-stream.js +13 -7
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +2 -1
- package/dist/server/app-browser-visible-commit.js +1 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -1
- package/dist/server/app-elements-wire.d.ts +10 -5
- package/dist/server/app-elements-wire.js +84 -2
- package/dist/server/app-elements-wire.js.map +1 -1
- package/dist/server/app-elements.d.ts +3 -2
- package/dist/server/app-elements.js +3 -2
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +12 -3
- package/dist/server/app-fallback-renderer.js +15 -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-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-middleware.d.ts +13 -0
- package/dist/server/app-middleware.js +3 -1
- package/dist/server/app-middleware.js.map +1 -1
- 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.d.ts +54 -0
- package/dist/server/app-optimistic-routing.js +208 -0
- package/dist/server/app-optimistic-routing.js.map +1 -0
- 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 +1 -0
- package/dist/server/app-page-boundary.js +2 -0
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +15 -1
- package/dist/server/app-page-cache.js +68 -7
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +5 -0
- package/dist/server/app-page-dispatch.js +39 -5
- 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 +7 -3
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +29 -1
- package/dist/server/app-page-execution.js +91 -4
- 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 +29 -2
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-probe.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +3 -0
- package/dist/server/app-page-render.js +7 -3
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-response.d.ts +11 -1
- package/dist/server/app-page-response.js +18 -5
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +35 -15
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +4 -0
- package/dist/server/app-page-stream.js +3 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-prerender-static-params.d.ts +2 -1
- package/dist/server/app-prerender-static-params.js +44 -8
- package/dist/server/app-prerender-static-params.js.map +1 -1
- package/dist/server/app-route-handler-cache.d.ts +2 -2
- package/dist/server/app-route-handler-cache.js +3 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +7 -1
- package/dist/server/app-route-handler-dispatch.js +4 -1
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +18 -2
- 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 +6 -5
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-router-entry.js +6 -2
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-handler.d.ts +11 -1
- package/dist/server/app-rsc-handler.js +48 -21
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-render-mode.d.ts +4 -3
- package/dist/server/app-rsc-render-mode.js +7 -1
- package/dist/server/app-rsc-render-mode.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.d.ts +4 -1
- package/dist/server/app-rsc-request-normalization.js +6 -2
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-rsc-response-finalizer.d.ts +8 -1
- package/dist/server/app-rsc-response-finalizer.js +10 -3
- package/dist/server/app-rsc-response-finalizer.js.map +1 -1
- package/dist/server/app-rsc-route-matching.js +2 -2
- package/dist/server/app-rsc-route-matching.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 +1 -0
- package/dist/server/app-server-action-execution.js +5 -1
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.d.ts +2 -0
- package/dist/server/app-ssr-entry.js +92 -55
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +30 -2
- package/dist/server/app-ssr-stream.js +95 -8
- 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/artifact-compatibility.d.ts +1 -1
- package/dist/server/artifact-compatibility.js.map +1 -1
- package/dist/server/cache-headers.d.ts +7 -0
- package/dist/server/cache-headers.js +19 -0
- package/dist/server/cache-headers.js.map +1 -0
- package/dist/server/cache-proof.d.ts +49 -3
- package/dist/server/cache-proof.js +78 -22
- package/dist/server/cache-proof.js.map +1 -1
- package/dist/server/client-reuse-manifest.d.ts +99 -0
- package/dist/server/client-reuse-manifest.js +212 -0
- package/dist/server/client-reuse-manifest.js.map +1 -0
- package/dist/server/default-global-error-module.d.ts +20 -0
- package/dist/server/default-global-error-module.js +20 -0
- package/dist/server/default-global-error-module.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 +10 -2
- package/dist/server/dev-server.js +99 -36
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/edge-api-runtime.d.ts +5 -0
- package/dist/server/edge-api-runtime.js +8 -0
- package/dist/server/edge-api-runtime.js.map +1 -0
- package/dist/server/headers.d.ts +22 -1
- package/dist/server/headers.js +22 -1
- package/dist/server/headers.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +16 -1
- package/dist/server/http-error-responses.js +21 -1
- package/dist/server/http-error-responses.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 +6 -2
- package/dist/server/isr-cache.js +20 -4
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/middleware-runtime.d.ts +15 -0
- package/dist/server/middleware-runtime.js +59 -7
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +5 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/navigation-planner.d.ts +9 -3
- package/dist/server/navigation-planner.js +98 -25
- package/dist/server/navigation-planner.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +2 -1
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/navigation-trace.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +45 -1
- package/dist/server/pages-api-route.js +27 -4
- 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.d.ts +77 -0
- package/dist/server/pages-data-route.js +98 -0
- package/dist/server/pages-data-route.js.map +1 -0
- 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-i18n.d.ts +51 -1
- package/dist/server/pages-i18n.js +61 -1
- package/dist/server/pages-i18n.js.map +1 -1
- 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 +69 -2
- package/dist/server/pages-page-data.js +47 -31
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +13 -1
- package/dist/server/pages-page-response.js +16 -11
- package/dist/server/pages-page-response.js.map +1 -1
- 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 +15 -37
- package/dist/server/prod-server.js +143 -107
- 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 +13 -4
- package/dist/server/request-pipeline.js +32 -14
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/seed-cache.d.ts +12 -31
- package/dist/server/seed-cache.js +30 -37
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/server-action-not-found.js +8 -3
- package/dist/server/server-action-not-found.js.map +1 -1
- package/dist/server/skip-cache-proof.d.ts +41 -0
- package/dist/server/skip-cache-proof.js +101 -0
- package/dist/server/skip-cache-proof.js.map +1 -0
- package/dist/server/static-file-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js +8 -7
- 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 +12 -0
- package/dist/shims/app-router-scroll-state.js +38 -0
- package/dist/shims/app-router-scroll-state.js.map +1 -0
- package/dist/shims/app-router-scroll.d.ts +14 -0
- package/dist/shims/app-router-scroll.js +100 -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/client-locale.d.ts +15 -0
- package/dist/shims/client-locale.js +13 -0
- package/dist/shims/client-locale.js.map +1 -0
- package/dist/shims/default-global-error.d.ts +32 -0
- package/dist/shims/default-global-error.js +181 -0
- package/dist/shims/default-global-error.js.map +1 -0
- 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/document.d.ts +59 -3
- package/dist/shims/document.js +36 -5
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +2 -2
- 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/form.js +13 -6
- package/dist/shims/form.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 +6 -2
- package/dist/shims/headers.js +64 -21
- 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/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 +21 -3
- package/dist/shims/link.js +189 -30
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +2 -1
- package/dist/shims/metadata.js +65 -6
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +8 -2
- package/dist/shims/navigation.js +67 -23
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +18 -2
- package/dist/shims/og.js +49 -1
- package/dist/shims/og.js.map +1 -0
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/root-params.d.ts +3 -1
- package/dist/shims/root-params.js +11 -3
- package/dist/shims/root-params.js.map +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +12 -5
- package/dist/shims/router.js +535 -86
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.js +86 -12
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.d.ts +21 -4
- package/dist/shims/server.js +30 -9
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.js +5 -1
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-safety.d.ts +23 -1
- package/dist/shims/url-safety.js +29 -2
- package/dist/shims/url-safety.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/typegen.d.ts +10 -0
- package/dist/typegen.js +242 -0
- package/dist/typegen.js.map +1 -0
- package/dist/utils/asset-prefix.d.ts +33 -5
- package/dist/utils/asset-prefix.js +39 -6
- package/dist/utils/asset-prefix.js.map +1 -1
- package/dist/utils/cache-control-metadata.d.ts +2 -1
- package/dist/utils/cache-control-metadata.js +1 -3
- package/dist/utils/cache-control-metadata.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +2 -1
- package/dist/utils/domain-locale.js +9 -1
- package/dist/utils/domain-locale.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/lazy-chunks.d.ts +1 -1
- package/dist/utils/lazy-chunks.js +1 -1
- package/dist/utils/lazy-chunks.js.map +1 -1
- package/dist/utils/prerender-output-paths.d.ts +15 -0
- package/dist/utils/prerender-output-paths.js +24 -0
- package/dist/utils/prerender-output-paths.js.map +1 -0
- package/dist/utils/query.d.ts +23 -1
- package/dist/utils/query.js +46 -2
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/record.d.ts +5 -0
- package/dist/utils/record.js +8 -0
- package/dist/utils/record.js.map +1 -0
- package/package.json +11 -3
package/dist/shims/router.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
|
+
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
3
|
+
import { addQueryParam, appendSearchParamsToUrl, mergeRouteParamsIntoQuery, parseQueryString, urlQueryToSearchParams } from "../utils/query.js";
|
|
2
4
|
import { matchRoutePattern, routePatternParts } from "../routing/route-pattern.js";
|
|
5
|
+
import { isUnknownRecord } from "../utils/record.js";
|
|
3
6
|
import { RouterContext } from "./internal/router-context.js";
|
|
7
|
+
import { applyVinextLocaleGlobals, extractVinextNextDataJson, parseVinextNextDataJson } from "../client/vinext-next-data.js";
|
|
4
8
|
import { isValidModulePath } from "../client/validate-module-path.js";
|
|
9
|
+
import { addLocalePrefix, getDomainLocaleUrl, getLocalePathPrefix } from "../utils/domain-locale.js";
|
|
10
|
+
import { buildPagesDataHref } from "./internal/pages-data-url.js";
|
|
11
|
+
import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
5
12
|
import { installWindowNext } from "../client/window-next.js";
|
|
6
|
-
import { isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
7
|
-
import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
|
|
8
|
-
import { addQueryParam, appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
13
|
+
import { getWindowOrigin, isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
9
14
|
import { scrollToHashTarget } from "./hash-scroll.js";
|
|
10
15
|
import { setPagesRouterPopStateHandler } from "./pages-router-runtime.js";
|
|
16
|
+
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
11
17
|
import { createElement, useContext, useEffect, useMemo, useState } from "react";
|
|
12
18
|
//#region src/shims/router.ts
|
|
13
19
|
/**
|
|
@@ -19,6 +25,8 @@ import { createElement, useContext, useEffect, useMemo, useState } from "react";
|
|
|
19
25
|
*/
|
|
20
26
|
/** basePath from next.config.js, injected by the plugin at build time */
|
|
21
27
|
const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
|
|
28
|
+
/** trailingSlash from next.config.js, injected by the plugin at build time */
|
|
29
|
+
const __trailingSlash = process.env.__VINEXT_TRAILING_SLASH === "true";
|
|
22
30
|
function createRouterEvents() {
|
|
23
31
|
const listeners = /* @__PURE__ */ new Map();
|
|
24
32
|
return {
|
|
@@ -50,10 +58,58 @@ function resolveUrl(url) {
|
|
|
50
58
|
* data fetching, as for the browser URL). We collapse them because vinext's
|
|
51
59
|
* navigateClient() fetches HTML from the target URL, so `as` must be a
|
|
52
60
|
* server-resolvable path. Purely decorative `as` values are not supported.
|
|
61
|
+
* Pages error routes are handled as a narrow exception below because Next.js
|
|
62
|
+
* treats their href as the component route while preserving `as` in history.
|
|
53
63
|
*/
|
|
54
64
|
function resolveNavigationTarget(url, as, locale) {
|
|
55
65
|
return applyNavigationLocale(as ?? resolveUrl(url), locale);
|
|
56
66
|
}
|
|
67
|
+
function getCurrentUrlLocale() {
|
|
68
|
+
return getCurrentBrowserLocale({
|
|
69
|
+
basePath: __basePath,
|
|
70
|
+
domainLocales: getDomainLocales(),
|
|
71
|
+
hostname: getCurrentHostname()
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function getLocalPathname(url) {
|
|
75
|
+
if (typeof window === "undefined") return null;
|
|
76
|
+
if (isAbsoluteOrProtocolRelativeUrl(url)) {
|
|
77
|
+
const localPath = toSameOriginAppPath(url, __basePath);
|
|
78
|
+
if (localPath == null) return null;
|
|
79
|
+
return stripBasePath(new URL(localPath, window.location.href).pathname, __basePath);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return stripBasePath(new URL(url, window.location.href).pathname, __basePath);
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function resolvePagesErrorHtmlFetchUrl(url, locale) {
|
|
88
|
+
const href = resolveUrl(url);
|
|
89
|
+
const errorRoutePathname = getLocalPathname(href);
|
|
90
|
+
if (errorRoutePathname !== "/404" && errorRoutePathname !== "/_error") return null;
|
|
91
|
+
const resolvedUrl = applyNavigationLocale(errorRoutePathname === "/_error" ? replaceUrlPathname(href, "/404") : href, locale);
|
|
92
|
+
let parsed;
|
|
93
|
+
try {
|
|
94
|
+
parsed = new URL(resolvedUrl, window.location.href);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(`${stripBasePath(parsed.pathname, __basePath)}${parsed.search}${parsed.hash}`, window.location.href, __basePath), __trailingSlash);
|
|
99
|
+
}
|
|
100
|
+
function replaceUrlPathname(url, pathname) {
|
|
101
|
+
try {
|
|
102
|
+
const parsed = new URL(url, window.location.href);
|
|
103
|
+
return `${pathname}${parsed.search}${parsed.hash}`;
|
|
104
|
+
} catch {
|
|
105
|
+
return pathname;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function resolveTransitionLocale(locale) {
|
|
109
|
+
if (typeof window === "undefined") return void 0;
|
|
110
|
+
if (locale === false) return window.__VINEXT_DEFAULT_LOCALE__;
|
|
111
|
+
return locale ?? getCurrentUrlLocale();
|
|
112
|
+
}
|
|
57
113
|
function getDomainLocales() {
|
|
58
114
|
return window.__NEXT_DATA__?.domainLocales;
|
|
59
115
|
}
|
|
@@ -74,10 +130,27 @@ function getDomainLocalePath(url, locale) {
|
|
|
74
130
|
function applyNavigationLocale(url, locale) {
|
|
75
131
|
if (!locale || typeof window === "undefined") return url;
|
|
76
132
|
if (isAbsoluteOrProtocolRelativeUrl(url)) return url;
|
|
133
|
+
if (getLocalePathPrefix(url, window.__VINEXT_LOCALES__)) return url;
|
|
77
134
|
const domainLocalePath = getDomainLocalePath(url, locale);
|
|
78
135
|
if (domainLocalePath) return domainLocalePath;
|
|
79
136
|
return addLocalePrefix(url, locale, window.__VINEXT_DEFAULT_LOCALE__ ?? "");
|
|
80
137
|
}
|
|
138
|
+
function isDefaultLocaleRootNavigation(url, locale) {
|
|
139
|
+
if (typeof window === "undefined") return false;
|
|
140
|
+
if (!locale || locale !== window.__VINEXT_DEFAULT_LOCALE__) return false;
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
parsed = new URL(url, window.location.href);
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return stripBasePath(parsed.pathname, __basePath) === "/";
|
|
148
|
+
}
|
|
149
|
+
function getPagesHtmlFetchUrl(browserUrl, locale) {
|
|
150
|
+
if (!isDefaultLocaleRootNavigation(browserUrl, locale)) return browserUrl;
|
|
151
|
+
const parsed = new URL(browserUrl, window.location.href);
|
|
152
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(`${normalizePathTrailingSlash(`/${locale}`, __trailingSlash)}${parsed.search}${parsed.hash}`, window.location.href, __basePath), __trailingSlash);
|
|
153
|
+
}
|
|
81
154
|
/** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */
|
|
82
155
|
function isExternalUrl(url) {
|
|
83
156
|
return isAbsoluteOrProtocolRelativeUrl(url);
|
|
@@ -295,21 +368,286 @@ function scheduleHardNavigationAndThrow(url, message) {
|
|
|
295
368
|
window.location.href = url;
|
|
296
369
|
throw new HardNavigationScheduledError(message);
|
|
297
370
|
}
|
|
371
|
+
function isPageComponent(value) {
|
|
372
|
+
if (typeof value === "function") return true;
|
|
373
|
+
if (!isUnknownRecord(value)) return false;
|
|
374
|
+
return value.$$typeof === Symbol.for("react.forward_ref") || value.$$typeof === Symbol.for("react.memo");
|
|
375
|
+
}
|
|
376
|
+
function isAppComponent(value) {
|
|
377
|
+
return isPageComponent(value);
|
|
378
|
+
}
|
|
379
|
+
function resolveSameOriginRedirectedUrl(responseUrl) {
|
|
380
|
+
const appPath = toSameOriginAppPath(responseUrl, __basePath);
|
|
381
|
+
if (appPath === null) return null;
|
|
382
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(appPath, window.location.href, __basePath), __trailingSlash);
|
|
383
|
+
}
|
|
384
|
+
function stripLocalePrefixForApiRedirect(appPath) {
|
|
385
|
+
const locales = window.__VINEXT_LOCALES__;
|
|
386
|
+
if (!locales || locales.length === 0) return appPath;
|
|
387
|
+
try {
|
|
388
|
+
const parsed = new URL(appPath, "http://vinext.local");
|
|
389
|
+
const pathname = stripBasePath(parsed.pathname, __basePath);
|
|
390
|
+
const firstSegment = pathname.split("/")[1];
|
|
391
|
+
if (!firstSegment || !locales.includes(firstSegment)) return appPath;
|
|
392
|
+
const withoutLocale = pathname.slice(firstSegment.length + 1) || "/";
|
|
393
|
+
if (withoutLocale !== "/api" && !withoutLocale.startsWith("/api/")) return appPath;
|
|
394
|
+
return `${withoutLocale}${parsed.search}${parsed.hash}`;
|
|
395
|
+
} catch {
|
|
396
|
+
return appPath;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function resolveLocalRedirectUrl(location) {
|
|
400
|
+
let appPath;
|
|
401
|
+
if (location.startsWith("/") && !location.startsWith("//")) try {
|
|
402
|
+
const parsed = new URL(location, "http://vinext.local");
|
|
403
|
+
appPath = stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;
|
|
404
|
+
} catch {
|
|
405
|
+
appPath = location;
|
|
406
|
+
}
|
|
407
|
+
else appPath = toSameOriginAppPath(location, __basePath);
|
|
408
|
+
if (appPath === null) return null;
|
|
409
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(stripLocalePrefixForApiRedirect(appPath), window.location.href, __basePath), __trailingSlash);
|
|
410
|
+
}
|
|
411
|
+
function hasVinextMiddleware(nextData) {
|
|
412
|
+
if (!isUnknownRecord(nextData)) return false;
|
|
413
|
+
const vinext = nextData.__vinext;
|
|
414
|
+
return isUnknownRecord(vinext) && vinext.hasMiddleware === true;
|
|
415
|
+
}
|
|
416
|
+
function getMiddlewarePagesDataFetchUrl(browserUrl) {
|
|
417
|
+
const nextData = window.__NEXT_DATA__;
|
|
418
|
+
if (!nextData || !hasVinextMiddleware(nextData)) return null;
|
|
419
|
+
const buildId = nextData.buildId;
|
|
420
|
+
if (typeof buildId !== "string" || buildId.length === 0) return null;
|
|
421
|
+
let parsed;
|
|
422
|
+
try {
|
|
423
|
+
parsed = new URL(browserUrl, window.location.href);
|
|
424
|
+
} catch {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
if (parsed.origin !== getWindowOrigin()) return null;
|
|
428
|
+
return buildPagesDataHref(__basePath, buildId, stripBasePath(parsed.pathname, __basePath), parsed.search);
|
|
429
|
+
}
|
|
430
|
+
async function resolveMiddlewareDataRedirect(browserUrl, signal) {
|
|
431
|
+
const dataUrl = getMiddlewarePagesDataFetchUrl(browserUrl);
|
|
432
|
+
if (!dataUrl) return null;
|
|
433
|
+
try {
|
|
434
|
+
return (await fetch(dataUrl, {
|
|
435
|
+
headers: {
|
|
436
|
+
Accept: "application/json",
|
|
437
|
+
"x-nextjs-data": "1"
|
|
438
|
+
},
|
|
439
|
+
signal
|
|
440
|
+
})).headers.get("x-nextjs-redirect");
|
|
441
|
+
} catch (err) {
|
|
442
|
+
if (err instanceof DOMException && err.name === "AbortError") throw err;
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Perform client-side navigation via the `/_next/data/<id>/<page>.json`
|
|
448
|
+
* endpoint. Used when `__VINEXT_PAGE_LOADERS__` has a matching code-split
|
|
449
|
+
* loader for the target pattern (the prod hot path). Falls back to the
|
|
450
|
+
* HTML extraction path (`navigateClientHtml`) when this returns `null`.
|
|
451
|
+
*
|
|
452
|
+
* Failure modes (404, 5xx, network, parse, missing loader, soft redirect)
|
|
453
|
+
* all queue a hard navigation and throw `HardNavigationScheduledError`,
|
|
454
|
+
* mirroring the existing HTML-path failure protocol. The hard reload is
|
|
455
|
+
* the deploy-skew safety net: when the server's buildId has rotated, the
|
|
456
|
+
* data endpoint returns 404 and the client lands on the new build via a
|
|
457
|
+
* full document load.
|
|
458
|
+
*/
|
|
459
|
+
async function navigateClientData(url, target, controller, navId, assertStillCurrent) {
|
|
460
|
+
const root = window.__VINEXT_ROOT__;
|
|
461
|
+
if (!root) {
|
|
462
|
+
window.location.href = url;
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
let res;
|
|
466
|
+
try {
|
|
467
|
+
res = await fetch(target.dataHref, {
|
|
468
|
+
headers: {
|
|
469
|
+
Accept: "application/json",
|
|
470
|
+
"x-nextjs-data": "1"
|
|
471
|
+
},
|
|
472
|
+
signal: controller.signal
|
|
473
|
+
});
|
|
474
|
+
} catch (err) {
|
|
475
|
+
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(url);
|
|
476
|
+
throw err;
|
|
477
|
+
}
|
|
478
|
+
assertStillCurrent();
|
|
479
|
+
const softRedirect = res.headers.get("x-nextjs-redirect");
|
|
480
|
+
if (softRedirect) {
|
|
481
|
+
const redirectedUrl = resolveLocalRedirectUrl(softRedirect);
|
|
482
|
+
if (!redirectedUrl) scheduleHardNavigationAndThrow(softRedirect, "Navigation redirected externally");
|
|
483
|
+
window.history.replaceState(window.history.state ?? {}, "", redirectedUrl);
|
|
484
|
+
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
485
|
+
await navigateClientHtml(redirectedUrl, redirectedUrl, controller, navId, assertStillCurrent);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (!res.ok) scheduleHardNavigationAndThrow(url, `Data navigation failed: ${res.status} ${res.statusText}`);
|
|
489
|
+
let body;
|
|
490
|
+
try {
|
|
491
|
+
body = await res.json();
|
|
492
|
+
} catch {
|
|
493
|
+
scheduleHardNavigationAndThrow(url, "Data navigation failed: invalid JSON response");
|
|
494
|
+
}
|
|
495
|
+
assertStillCurrent();
|
|
496
|
+
const pageProps = body.pageProps && typeof body.pageProps === "object" ? body.pageProps : {};
|
|
497
|
+
let pageModule;
|
|
498
|
+
try {
|
|
499
|
+
pageModule = await target.loader();
|
|
500
|
+
} catch (err) {
|
|
501
|
+
console.error("[vinext] Page loader threw during navigation:", err);
|
|
502
|
+
scheduleHardNavigationAndThrow(url, "Data navigation failed: page loader threw");
|
|
503
|
+
}
|
|
504
|
+
assertStillCurrent();
|
|
505
|
+
const PageComponent = pageModule.default;
|
|
506
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(url, "Data navigation failed: page module default export is not a component");
|
|
507
|
+
let AppComponent = window.__VINEXT_APP__;
|
|
508
|
+
if (!AppComponent && typeof window.__VINEXT_APP_LOADER__ === "function") try {
|
|
509
|
+
const appModule = await window.__VINEXT_APP_LOADER__();
|
|
510
|
+
AppComponent = isAppComponent(appModule.default) ? appModule.default : void 0;
|
|
511
|
+
if (AppComponent) window.__VINEXT_APP__ = AppComponent;
|
|
512
|
+
} catch {}
|
|
513
|
+
assertStillCurrent();
|
|
514
|
+
const React = (await import("react")).default;
|
|
515
|
+
assertStillCurrent();
|
|
516
|
+
let element;
|
|
517
|
+
if (AppComponent) element = React.createElement(AppComponent, {
|
|
518
|
+
Component: PageComponent,
|
|
519
|
+
pageProps
|
|
520
|
+
});
|
|
521
|
+
else element = React.createElement(PageComponent, pageProps);
|
|
522
|
+
element = wrapWithRouterContext(element);
|
|
523
|
+
const mergedQuery = mergeRouteParamsIntoQuery(parseQueryString(target.search), target.params);
|
|
524
|
+
const prev = window.__NEXT_DATA__;
|
|
525
|
+
const nextLocale = (window.__VINEXT_LOCALES__?.length ?? 0) > 0 ? target.locale ?? window.__VINEXT_DEFAULT_LOCALE__ : prev?.locale;
|
|
526
|
+
const nextData = {
|
|
527
|
+
...prev,
|
|
528
|
+
props: { pageProps },
|
|
529
|
+
page: target.pattern,
|
|
530
|
+
query: mergedQuery,
|
|
531
|
+
buildId: target.buildId,
|
|
532
|
+
isFallback: false,
|
|
533
|
+
...nextLocale !== void 0 ? { locale: nextLocale } : {}
|
|
534
|
+
};
|
|
535
|
+
window.__NEXT_DATA__ = nextData;
|
|
536
|
+
applyVinextLocaleGlobals(window, nextData);
|
|
537
|
+
root.render(element);
|
|
538
|
+
}
|
|
298
539
|
/**
|
|
299
|
-
* Perform client-side navigation
|
|
300
|
-
*
|
|
540
|
+
* Perform client-side navigation by fetching the page's full HTML and
|
|
541
|
+
* extracting `__NEXT_DATA__` plus the page module URL. Used in dev (where
|
|
542
|
+
* the per-page inline hydration script does not populate the loader map) and
|
|
543
|
+
* as a generic fallback when the data path is not available.
|
|
301
544
|
*
|
|
302
545
|
* Throws NavigationCancelledError if a newer navigation supersedes this one.
|
|
303
546
|
* Throws on hard-navigation failures (non-OK response, missing data) so the
|
|
304
547
|
* caller can distinguish success from failure for event emission.
|
|
305
548
|
*/
|
|
306
|
-
async function
|
|
307
|
-
|
|
549
|
+
async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillCurrent, options = {}) {
|
|
550
|
+
let browserUrl = url;
|
|
551
|
+
let pendingRedirectHistoryUrl = fetchUrl === url ? null : url;
|
|
308
552
|
const root = window.__VINEXT_ROOT__;
|
|
309
553
|
if (!root) {
|
|
310
|
-
window.location.href =
|
|
554
|
+
window.location.href = browserUrl;
|
|
311
555
|
return;
|
|
312
556
|
}
|
|
557
|
+
let res;
|
|
558
|
+
try {
|
|
559
|
+
res = await fetch(fetchUrl, {
|
|
560
|
+
headers: { Accept: "text/html" },
|
|
561
|
+
signal: controller.signal
|
|
562
|
+
});
|
|
563
|
+
} catch (err) {
|
|
564
|
+
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(url);
|
|
565
|
+
throw err;
|
|
566
|
+
}
|
|
567
|
+
assertStillCurrent();
|
|
568
|
+
if (res.redirected && res.url) {
|
|
569
|
+
const redirectedUrl = resolveSameOriginRedirectedUrl(res.url);
|
|
570
|
+
if (redirectedUrl) {
|
|
571
|
+
browserUrl = redirectedUrl;
|
|
572
|
+
pendingRedirectHistoryUrl = redirectedUrl;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (!res.ok && !(options.allowNotFoundResponse === true && res.status === 404)) scheduleHardNavigationAndThrow(browserUrl, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
576
|
+
const html = await res.text();
|
|
577
|
+
assertStillCurrent();
|
|
578
|
+
const nextDataJson = extractVinextNextDataJson(html);
|
|
579
|
+
if (!nextDataJson) scheduleHardNavigationAndThrow(url, "Navigation failed: missing __NEXT_DATA__ in response");
|
|
580
|
+
const nextData = parseVinextNextDataJson(nextDataJson);
|
|
581
|
+
const { pageProps } = nextData.props;
|
|
582
|
+
let pageModuleUrl = nextData.__vinext?.pageModuleUrl;
|
|
583
|
+
if (!pageModuleUrl) {
|
|
584
|
+
const moduleMatch = html.match(/import\("([^"]+)"\);\s*\n\s*const PageComponent/);
|
|
585
|
+
const altMatch = html.match(/await import\("([^"]+pages\/[^"]+)"\)/);
|
|
586
|
+
pageModuleUrl = moduleMatch?.[1] ?? altMatch?.[1] ?? void 0;
|
|
587
|
+
}
|
|
588
|
+
let pageModule;
|
|
589
|
+
if (!pageModuleUrl) {
|
|
590
|
+
const loader = window.__VINEXT_PAGE_LOADERS__?.[nextData.page];
|
|
591
|
+
if (!loader) scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: no page module URL found");
|
|
592
|
+
pageModule = await loader();
|
|
593
|
+
} else {
|
|
594
|
+
if (!isValidModulePath(pageModuleUrl)) {
|
|
595
|
+
console.error("[vinext] Blocked import of invalid page module path:", pageModuleUrl);
|
|
596
|
+
scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: invalid page module path");
|
|
597
|
+
}
|
|
598
|
+
pageModule = await import(
|
|
599
|
+
/* @vite-ignore */
|
|
600
|
+
pageModuleUrl
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
assertStillCurrent();
|
|
604
|
+
const PageComponent = pageModule.default;
|
|
605
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: page module default export is not a component");
|
|
606
|
+
const React = (await import("react")).default;
|
|
607
|
+
assertStillCurrent();
|
|
608
|
+
let AppComponent = window.__VINEXT_APP__;
|
|
609
|
+
const appModuleUrl = nextData.__vinext?.appModuleUrl;
|
|
610
|
+
if (!AppComponent && appModuleUrl) if (!isValidModulePath(appModuleUrl)) console.error("[vinext] Blocked import of invalid app module path:", appModuleUrl);
|
|
611
|
+
else try {
|
|
612
|
+
const appModule = await import(
|
|
613
|
+
/* @vite-ignore */
|
|
614
|
+
appModuleUrl
|
|
615
|
+
);
|
|
616
|
+
AppComponent = isAppComponent(appModule.default) ? appModule.default : void 0;
|
|
617
|
+
window.__VINEXT_APP__ = AppComponent;
|
|
618
|
+
} catch {}
|
|
619
|
+
assertStillCurrent();
|
|
620
|
+
let element;
|
|
621
|
+
if (AppComponent) element = React.createElement(AppComponent, {
|
|
622
|
+
Component: PageComponent,
|
|
623
|
+
pageProps
|
|
624
|
+
});
|
|
625
|
+
else element = React.createElement(PageComponent, pageProps);
|
|
626
|
+
element = wrapWithRouterContext(element);
|
|
627
|
+
if (pendingRedirectHistoryUrl) {
|
|
628
|
+
window.history.replaceState(window.history.state ?? {}, "", pendingRedirectHistoryUrl);
|
|
629
|
+
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
630
|
+
}
|
|
631
|
+
window.__NEXT_DATA__ = nextData;
|
|
632
|
+
applyVinextLocaleGlobals(window, nextData);
|
|
633
|
+
root.render(element);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Perform client-side navigation. Prefers the JSON data endpoint when the
|
|
637
|
+
* client has a registered code-split loader for the target route (the prod
|
|
638
|
+
* hot path); otherwise falls back to fetching the page's full HTML (dev and
|
|
639
|
+
* any unmapped route).
|
|
640
|
+
*
|
|
641
|
+
* Throws NavigationCancelledError if a newer navigation supersedes this one.
|
|
642
|
+
* Throws on hard-navigation failures (non-OK response, missing data) so the
|
|
643
|
+
* caller can distinguish success from failure for event emission.
|
|
644
|
+
*
|
|
645
|
+
* `fetchUrl` is the HTML-path fetch URL (already includes locale-root
|
|
646
|
+
* fixups). The JSON path derives its own URL from the browser-facing `url`
|
|
647
|
+
* because the data endpoint speaks the unprefixed path.
|
|
648
|
+
*/
|
|
649
|
+
async function navigateClient(url, fetchUrl = url, options = {}) {
|
|
650
|
+
if (typeof window === "undefined") return;
|
|
313
651
|
_activeAbortController?.abort();
|
|
314
652
|
const controller = new AbortController();
|
|
315
653
|
_activeAbortController = controller;
|
|
@@ -319,64 +657,32 @@ async function navigateClient(url) {
|
|
|
319
657
|
if (navId !== _navigationId) throw new NavigationCancelledError(url);
|
|
320
658
|
}
|
|
321
659
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (!isValidModulePath(pageModuleUrl)) {
|
|
348
|
-
console.error("[vinext] Blocked import of invalid page module path:", pageModuleUrl);
|
|
349
|
-
scheduleHardNavigationAndThrow(url, "Navigation failed: invalid page module path");
|
|
660
|
+
if (options.allowNotFoundResponse === true) await navigateClientHtml(url, fetchUrl, controller, navId, assertStillCurrent, options);
|
|
661
|
+
else {
|
|
662
|
+
let browserUrl = url;
|
|
663
|
+
let htmlFetchUrl = fetchUrl;
|
|
664
|
+
const dataTarget = resolvePagesDataNavigationTarget(browserUrl, __basePath);
|
|
665
|
+
if (!dataTarget) {
|
|
666
|
+
let redirectLocation;
|
|
667
|
+
try {
|
|
668
|
+
redirectLocation = await resolveMiddlewareDataRedirect(browserUrl, controller.signal);
|
|
669
|
+
} catch (err) {
|
|
670
|
+
if (err instanceof DOMException && err.name === "AbortError") throw new NavigationCancelledError(browserUrl);
|
|
671
|
+
throw err;
|
|
672
|
+
}
|
|
673
|
+
assertStillCurrent();
|
|
674
|
+
if (redirectLocation) {
|
|
675
|
+
const redirectedUrl = resolveLocalRedirectUrl(redirectLocation);
|
|
676
|
+
if (!redirectedUrl) scheduleHardNavigationAndThrow(redirectLocation, "Navigation redirected externally");
|
|
677
|
+
window.history.replaceState(window.history.state ?? {}, "", redirectedUrl);
|
|
678
|
+
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
679
|
+
browserUrl = redirectedUrl;
|
|
680
|
+
htmlFetchUrl = redirectedUrl;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (dataTarget) await navigateClientData(browserUrl, dataTarget, controller, navId, assertStillCurrent);
|
|
684
|
+
else await navigateClientHtml(browserUrl, htmlFetchUrl, controller, navId, assertStillCurrent, options);
|
|
350
685
|
}
|
|
351
|
-
const pageModule = await import(
|
|
352
|
-
/* @vite-ignore */
|
|
353
|
-
pageModuleUrl
|
|
354
|
-
);
|
|
355
|
-
assertStillCurrent();
|
|
356
|
-
const PageComponent = pageModule.default;
|
|
357
|
-
if (!PageComponent) scheduleHardNavigationAndThrow(url, "Navigation failed: page module has no default export");
|
|
358
|
-
const React = (await import("react")).default;
|
|
359
|
-
assertStillCurrent();
|
|
360
|
-
let AppComponent = window.__VINEXT_APP__;
|
|
361
|
-
const appModuleUrl = nextData.__vinext?.appModuleUrl;
|
|
362
|
-
if (!AppComponent && appModuleUrl) if (!isValidModulePath(appModuleUrl)) console.error("[vinext] Blocked import of invalid app module path:", appModuleUrl);
|
|
363
|
-
else try {
|
|
364
|
-
AppComponent = (await import(
|
|
365
|
-
/* @vite-ignore */
|
|
366
|
-
appModuleUrl
|
|
367
|
-
)).default;
|
|
368
|
-
window.__VINEXT_APP__ = AppComponent;
|
|
369
|
-
} catch {}
|
|
370
|
-
assertStillCurrent();
|
|
371
|
-
let element;
|
|
372
|
-
if (AppComponent) element = React.createElement(AppComponent, {
|
|
373
|
-
Component: PageComponent,
|
|
374
|
-
pageProps
|
|
375
|
-
});
|
|
376
|
-
else element = React.createElement(PageComponent, pageProps);
|
|
377
|
-
element = wrapWithRouterContext(element);
|
|
378
|
-
window.__NEXT_DATA__ = nextData;
|
|
379
|
-
root.render(element);
|
|
380
686
|
} finally {
|
|
381
687
|
if (navId === _navigationId) _activeAbortController = null;
|
|
382
688
|
}
|
|
@@ -393,9 +699,9 @@ async function navigateClient(url) {
|
|
|
393
699
|
* - "failed" — genuine error, caller should return false (hard nav is already
|
|
394
700
|
* scheduled as recovery)
|
|
395
701
|
*/
|
|
396
|
-
async function runNavigateClient(fullUrl, resolvedUrl) {
|
|
702
|
+
async function runNavigateClient(fullUrl, resolvedUrl, fetchUrl = fullUrl, options = {}) {
|
|
397
703
|
try {
|
|
398
|
-
await navigateClient(fullUrl);
|
|
704
|
+
await navigateClient(fullUrl, fetchUrl, options);
|
|
399
705
|
return "completed";
|
|
400
706
|
} catch (err) {
|
|
401
707
|
routerEvents.emit("routeChangeError", err, resolvedUrl, { shallow: false });
|
|
@@ -428,7 +734,7 @@ function buildRouterValue(pathname, query, asPath, methods) {
|
|
|
428
734
|
domainLocales,
|
|
429
735
|
isReady: true,
|
|
430
736
|
isPreview: false,
|
|
431
|
-
isFallback: typeof window !== "undefined"
|
|
737
|
+
isFallback: typeof window !== "undefined" ? nextData?.isFallback === true : _ssrState?.isFallback === true,
|
|
432
738
|
...methods,
|
|
433
739
|
events: routerEvents
|
|
434
740
|
};
|
|
@@ -452,6 +758,22 @@ function updateHistory(mode, url) {
|
|
|
452
758
|
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
453
759
|
}
|
|
454
760
|
/**
|
|
761
|
+
* Throw the canonical "no router instance" error used when a Pages Router
|
|
762
|
+
* navigation method (push/replace/back/reload/prefetch/beforePopState) is
|
|
763
|
+
* invoked during SSR or prerendering.
|
|
764
|
+
*
|
|
765
|
+
* Mirrors Next.js's `ServerRouter.push`/`replace`/etc. which all call
|
|
766
|
+
* `noRouter()` in `packages/next/src/server/render.tsx`. The error message
|
|
767
|
+
* matches Next.js verbatim so userland error handling and docs links work
|
|
768
|
+
* unchanged.
|
|
769
|
+
*
|
|
770
|
+
* Ported from Next.js: packages/next/src/server/render.tsx
|
|
771
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/server/render.tsx
|
|
772
|
+
*/
|
|
773
|
+
function throwNoRouterInstance() {
|
|
774
|
+
throw new Error("No router instance found. you should only use \"next/router\" inside the client side of your app. https://nextjs.org/docs/messages/no-router-instance");
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
455
777
|
* Shared client-side navigation flow used by both `useRouter()` and the
|
|
456
778
|
* `Router` singleton. The only differences between push/replace are the
|
|
457
779
|
* history method (`pushState` vs `replaceState`), the external-URL fallback
|
|
@@ -463,7 +785,11 @@ function updateHistory(mode, url) {
|
|
|
463
785
|
* passes no callback.
|
|
464
786
|
*/
|
|
465
787
|
async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
466
|
-
|
|
788
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
789
|
+
assertSafeNavigationUrl(resolveUrl(url));
|
|
790
|
+
if (as !== void 0) assertSafeNavigationUrl(String(as));
|
|
791
|
+
const navigationLocale = resolveTransitionLocale(options?.locale);
|
|
792
|
+
let resolved = resolveNavigationTarget(url, as, navigationLocale);
|
|
467
793
|
if (isExternalUrl(resolved)) {
|
|
468
794
|
const localPath = toSameOriginAppPath(resolved, __basePath);
|
|
469
795
|
if (localPath == null) {
|
|
@@ -473,7 +799,11 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
473
799
|
}
|
|
474
800
|
resolved = localPath;
|
|
475
801
|
}
|
|
476
|
-
|
|
802
|
+
resolved = normalizePathTrailingSlash(resolved, __trailingSlash);
|
|
803
|
+
const full = normalizePathTrailingSlash(toBrowserNavigationHref(resolved, window.location.href, __basePath), __trailingSlash);
|
|
804
|
+
const errorRouteHtmlFetchUrl = resolvePagesErrorHtmlFetchUrl(url, navigationLocale);
|
|
805
|
+
const htmlFetchUrl = errorRouteHtmlFetchUrl ?? getPagesHtmlFetchUrl(full, navigationLocale);
|
|
806
|
+
const navigateOptions = errorRouteHtmlFetchUrl ? { allowNotFoundResponse: true } : {};
|
|
477
807
|
const shallow = options?.shallow ?? false;
|
|
478
808
|
const doScroll = options?.scroll !== false;
|
|
479
809
|
if (isHashOnlyChange(full)) {
|
|
@@ -491,7 +821,7 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
491
821
|
routerEvents.emit("beforeHistoryChange", resolved, { shallow });
|
|
492
822
|
updateHistory(mode, full);
|
|
493
823
|
if (!shallow) {
|
|
494
|
-
const result = await runNavigateClient(full, resolved);
|
|
824
|
+
const result = await runNavigateClient(full, resolved, htmlFetchUrl, navigateOptions);
|
|
495
825
|
if (result === "cancelled") return true;
|
|
496
826
|
if (result === "failed") return false;
|
|
497
827
|
}
|
|
@@ -503,15 +833,37 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
503
833
|
dispatchNavigateEvent();
|
|
504
834
|
return true;
|
|
505
835
|
}
|
|
506
|
-
/**
|
|
836
|
+
/**
|
|
837
|
+
* Prefetch the resources needed for a future Pages Router navigation.
|
|
838
|
+
*
|
|
839
|
+
* When the client has a registered code-split loader for the target route
|
|
840
|
+
* (the prod hot path), we prefetch in parallel:
|
|
841
|
+
* 1. The `/_next/data/<buildId>/<page>.json` payload — same URL the actual
|
|
842
|
+
* navigation will request, so a cache hit is automatic.
|
|
843
|
+
* 2. The page's JS chunk — by invoking the loader thunk now. Vite's
|
|
844
|
+
* dynamic `import()` machinery is responsible for fetching + caching;
|
|
845
|
+
* the returned Promise is intentionally discarded.
|
|
846
|
+
*
|
|
847
|
+
* When no loader is registered (dev server, or an unmapped route), we fall
|
|
848
|
+
* back to the legacy `<link rel="prefetch" as="document">` hint, which lets
|
|
849
|
+
* the browser preload the HTML document. This matches the pre-`_next/data`
|
|
850
|
+
* behaviour so dev doesn't regress.
|
|
851
|
+
*
|
|
852
|
+
* Ported from Next.js: `packages/next/src/client/page-loader.ts` `prefetch`
|
|
853
|
+
* (the data + chunk parallel prefetch shape).
|
|
854
|
+
*/
|
|
507
855
|
async function prefetchUrl(url) {
|
|
508
|
-
if (typeof document
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
document.head.appendChild(link);
|
|
856
|
+
if (typeof document === "undefined") return;
|
|
857
|
+
const dataTarget = resolvePagesDataNavigationTarget(url, __basePath);
|
|
858
|
+
if (dataTarget) {
|
|
859
|
+
prefetchPagesData(dataTarget);
|
|
860
|
+
return;
|
|
514
861
|
}
|
|
862
|
+
const link = document.createElement("link");
|
|
863
|
+
link.rel = "prefetch";
|
|
864
|
+
link.href = url;
|
|
865
|
+
link.as = "document";
|
|
866
|
+
document.head.appendChild(link);
|
|
515
867
|
}
|
|
516
868
|
/**
|
|
517
869
|
* useRouter hook - Pages Router compatible.
|
|
@@ -573,7 +925,7 @@ function handlePagesRouterPopState(e) {
|
|
|
573
925
|
routerEvents.emit("routeChangeStart", fullAppUrl, { shallow: false });
|
|
574
926
|
routerEvents.emit("beforeHistoryChange", fullAppUrl, { shallow: false });
|
|
575
927
|
(async () => {
|
|
576
|
-
if (await runNavigateClient(browserUrl, fullAppUrl) === "completed") {
|
|
928
|
+
if (await runNavigateClient(browserUrl, fullAppUrl, getPagesHtmlFetchUrl(browserUrl, window.__VINEXT_LOCALE__)) === "completed") {
|
|
577
929
|
routerEvents.emit("routeChangeComplete", fullAppUrl, { shallow: false });
|
|
578
930
|
restoreScrollPosition(e.state);
|
|
579
931
|
dispatchNavigateEvent();
|
|
@@ -624,17 +976,114 @@ function withRouter(ComposedComponent) {
|
|
|
624
976
|
if (process.env.NODE_ENV !== "production") WithRouterWrapper.displayName = `withRouter(${composed.displayName || composed.name || "Unknown"})`;
|
|
625
977
|
return WithRouterWrapper;
|
|
626
978
|
}
|
|
627
|
-
const Router = {
|
|
628
|
-
push: (url, as, options) =>
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
979
|
+
const Router = Object.defineProperties({
|
|
980
|
+
push: (url, as, options) => {
|
|
981
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
982
|
+
assertSafeNavigationUrl(resolveUrl(url));
|
|
983
|
+
if (as !== void 0) assertSafeNavigationUrl(String(as));
|
|
984
|
+
return performNavigation(url, as, options, "push");
|
|
985
|
+
},
|
|
986
|
+
replace: (url, as, options) => {
|
|
987
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
988
|
+
assertSafeNavigationUrl(resolveUrl(url));
|
|
989
|
+
if (as !== void 0) assertSafeNavigationUrl(String(as));
|
|
990
|
+
return performNavigation(url, as, options, "replace");
|
|
991
|
+
},
|
|
992
|
+
back: () => {
|
|
993
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
994
|
+
window.history.back();
|
|
995
|
+
},
|
|
996
|
+
reload: () => {
|
|
997
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
998
|
+
window.location.reload();
|
|
999
|
+
},
|
|
1000
|
+
prefetch: (url) => {
|
|
1001
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
1002
|
+
return prefetchUrl(url);
|
|
1003
|
+
},
|
|
633
1004
|
beforePopState: (cb) => {
|
|
1005
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
634
1006
|
_beforePopStateCb = cb;
|
|
635
1007
|
},
|
|
636
1008
|
events: routerEvents
|
|
637
|
-
}
|
|
1009
|
+
}, {
|
|
1010
|
+
pathname: {
|
|
1011
|
+
enumerable: true,
|
|
1012
|
+
get() {
|
|
1013
|
+
return getPathnameAndQuery().pathname;
|
|
1014
|
+
}
|
|
1015
|
+
},
|
|
1016
|
+
route: {
|
|
1017
|
+
enumerable: true,
|
|
1018
|
+
get() {
|
|
1019
|
+
const { pathname } = getPathnameAndQuery();
|
|
1020
|
+
if (typeof window === "undefined") return pathname;
|
|
1021
|
+
return window.__NEXT_DATA__?.page ?? pathname;
|
|
1022
|
+
}
|
|
1023
|
+
},
|
|
1024
|
+
query: {
|
|
1025
|
+
enumerable: true,
|
|
1026
|
+
get() {
|
|
1027
|
+
return getPathnameAndQuery().query;
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
asPath: {
|
|
1031
|
+
enumerable: true,
|
|
1032
|
+
get() {
|
|
1033
|
+
return getPathnameAndQuery().asPath;
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
basePath: {
|
|
1037
|
+
enumerable: true,
|
|
1038
|
+
value: __basePath,
|
|
1039
|
+
writable: false
|
|
1040
|
+
},
|
|
1041
|
+
locale: {
|
|
1042
|
+
enumerable: true,
|
|
1043
|
+
get() {
|
|
1044
|
+
if (typeof window === "undefined") return _getSSRContext()?.locale;
|
|
1045
|
+
return window.__VINEXT_LOCALE__;
|
|
1046
|
+
}
|
|
1047
|
+
},
|
|
1048
|
+
locales: {
|
|
1049
|
+
enumerable: true,
|
|
1050
|
+
get() {
|
|
1051
|
+
if (typeof window === "undefined") return _getSSRContext()?.locales;
|
|
1052
|
+
return window.__VINEXT_LOCALES__;
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
defaultLocale: {
|
|
1056
|
+
enumerable: true,
|
|
1057
|
+
get() {
|
|
1058
|
+
if (typeof window === "undefined") return _getSSRContext()?.defaultLocale;
|
|
1059
|
+
return window.__VINEXT_DEFAULT_LOCALE__;
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
domainLocales: {
|
|
1063
|
+
enumerable: true,
|
|
1064
|
+
get() {
|
|
1065
|
+
if (typeof window === "undefined") return _getSSRContext()?.domainLocales;
|
|
1066
|
+
return window.__NEXT_DATA__?.domainLocales;
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
isReady: {
|
|
1070
|
+
enumerable: true,
|
|
1071
|
+
value: true,
|
|
1072
|
+
writable: false
|
|
1073
|
+
},
|
|
1074
|
+
isPreview: {
|
|
1075
|
+
enumerable: true,
|
|
1076
|
+
value: false,
|
|
1077
|
+
writable: false
|
|
1078
|
+
},
|
|
1079
|
+
isFallback: {
|
|
1080
|
+
enumerable: true,
|
|
1081
|
+
get() {
|
|
1082
|
+
if (typeof window === "undefined") return _getSSRContext()?.isFallback === true;
|
|
1083
|
+
return window.__NEXT_DATA__?.isFallback === true;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
638
1087
|
if (typeof window !== "undefined") installWindowNext({ router: Router });
|
|
639
1088
|
const _PAGES_NAVIGATION_ACCESSOR_KEY = Symbol.for("vinext.navigation.pagesNavigationContextAccessor");
|
|
640
1089
|
globalThis[_PAGES_NAVIGATION_ACCESSOR_KEY] = getPagesNavigationContext;
|