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/link.d.ts
CHANGED
|
@@ -21,7 +21,15 @@ type LinkProps = {
|
|
|
21
21
|
* is upgraded to a full prefetch when the user shows navigation intent.
|
|
22
22
|
*/
|
|
23
23
|
unstable_dynamicOnHover?: boolean; /** Whether to pass the href to the child element */
|
|
24
|
-
passHref?: boolean;
|
|
24
|
+
passHref?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Pre-Next.js-13 link behaviour. When true, <Link> expects its child to be
|
|
27
|
+
* an `<a>` (or a component that renders one) and forwards `href`, click,
|
|
28
|
+
* and prefetch handlers to the child via `React.cloneElement` instead of
|
|
29
|
+
* rendering its own wrapping `<a>`. Required when the user wants to
|
|
30
|
+
* style/instrument the anchor themselves.
|
|
31
|
+
*/
|
|
32
|
+
legacyBehavior?: boolean; /** Scroll to top on navigation (default: true) */
|
|
25
33
|
scroll?: boolean;
|
|
26
34
|
/**
|
|
27
35
|
* Pages Router: update the URL without re-running data fetching methods
|
|
@@ -68,7 +76,15 @@ declare const Link: React.ForwardRefExoticComponent<{
|
|
|
68
76
|
* is upgraded to a full prefetch when the user shows navigation intent.
|
|
69
77
|
*/
|
|
70
78
|
unstable_dynamicOnHover?: boolean; /** Whether to pass the href to the child element */
|
|
71
|
-
passHref?: boolean;
|
|
79
|
+
passHref?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Pre-Next.js-13 link behaviour. When true, <Link> expects its child to be
|
|
82
|
+
* an `<a>` (or a component that renders one) and forwards `href`, click,
|
|
83
|
+
* and prefetch handlers to the child via `React.cloneElement` instead of
|
|
84
|
+
* rendering its own wrapping `<a>`. Required when the user wants to
|
|
85
|
+
* style/instrument the anchor themselves.
|
|
86
|
+
*/
|
|
87
|
+
legacyBehavior?: boolean; /** Scroll to top on navigation (default: true) */
|
|
72
88
|
scroll?: boolean;
|
|
73
89
|
/**
|
|
74
90
|
* Pages Router: update the URL without re-running data fetching methods
|
package/dist/shims/link.js
CHANGED
|
@@ -3,14 +3,16 @@ import { stripBasePath } from "../utils/base-path.js";
|
|
|
3
3
|
import { createRouteTrieCache, matchRouteWithTrie } from "../routing/route-matching.js";
|
|
4
4
|
import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/headers.js";
|
|
5
5
|
import { isDangerousScheme, reportBlockedDangerousNavigation } from "./url-safety.js";
|
|
6
|
-
import {
|
|
6
|
+
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
7
7
|
import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
8
|
-
import
|
|
8
|
+
import "../server/app-elements.js";
|
|
9
9
|
import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
|
|
10
|
+
import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
11
|
+
import { markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.js";
|
|
12
|
+
import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, resolveRelativeHref, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
13
|
+
import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
10
14
|
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
11
15
|
import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
|
|
12
|
-
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
13
|
-
import "../server/app-elements.js";
|
|
14
16
|
import { createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam, stripRscSuffix } from "../server/app-rsc-cache-busting.js";
|
|
15
17
|
import { getMountedSlotsHeader, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, navigateClientSide, prefetchRscResponse } from "./navigation.js";
|
|
16
18
|
import { navigatePagesRouterLink } from "../client/pages-router-link-navigation.js";
|
|
@@ -49,6 +51,50 @@ function resolveHref(href) {
|
|
|
49
51
|
}
|
|
50
52
|
return url;
|
|
51
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Collapse repeated forward-slashes (and convert backslashes to forward-slashes)
|
|
56
|
+
* in the path portion of a URL, preserving any query string.
|
|
57
|
+
*
|
|
58
|
+
* Ported from Next.js: packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts
|
|
59
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts
|
|
60
|
+
*/
|
|
61
|
+
function normalizeRepeatedSlashes(url) {
|
|
62
|
+
const urlParts = url.split("?");
|
|
63
|
+
const urlNoQueryString = urlParts.shift() ?? "";
|
|
64
|
+
const queryString = urlParts.join("?");
|
|
65
|
+
return urlNoQueryString.replace(/\\/g, "/").replace(/\/\/+/g, "/") + (queryString ? `?${queryString}` : "");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Emit Next.js's "Invalid href" `console.error` when `href` contains repeated
|
|
69
|
+
* forward slashes or backslashes in its path portion, and return the
|
|
70
|
+
* normalized URL (with `\\` converted to `/` and runs of `/` collapsed). If
|
|
71
|
+
* the href is already well-formed, the original string is returned unchanged.
|
|
72
|
+
*
|
|
73
|
+
* Ported from Next.js: packages/next/src/client/resolve-href.ts
|
|
74
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/resolve-href.ts
|
|
75
|
+
*
|
|
76
|
+
* Matches the message asserted by:
|
|
77
|
+
* test/e2e/repeated-forward-slashes-error/repeated-forward-slashes-error.test.ts
|
|
78
|
+
*
|
|
79
|
+
* Note: Next.js fires this warning unconditionally on every call to
|
|
80
|
+
* `resolveHref`. We mirror that behaviour (no dedup) for exact parity.
|
|
81
|
+
*
|
|
82
|
+
* Note: Next.js uses `router.pathname` (the route pattern, e.g.
|
|
83
|
+
* `/posts/[id]`) for the "in page" segment of the message. We do not have
|
|
84
|
+
* cheap access to the route pattern from inside the Link shim, so we
|
|
85
|
+
* fall back to `window.location.pathname` (or `"/"` during SSR). The text
|
|
86
|
+
* is cosmetic and is not asserted by the Next.js compat test.
|
|
87
|
+
*/
|
|
88
|
+
function warnAndNormalizeRepeatedSlashesInHref(urlAsString) {
|
|
89
|
+
if (urlAsString.startsWith("//")) return urlAsString;
|
|
90
|
+
const urlProtoMatch = urlAsString.match(/^[a-z][a-z0-9+.-]*:\/\//i);
|
|
91
|
+
const urlAsStringNoProto = urlProtoMatch ? urlAsString.slice(urlProtoMatch[0].length) : urlAsString;
|
|
92
|
+
if (!(urlAsStringNoProto.split("?", 1)[0] || "").match(/(\/\/|\\)/)) return urlAsString;
|
|
93
|
+
const pathname = typeof window !== "undefined" && window.location ? window.location.pathname : "/";
|
|
94
|
+
console.error(`Invalid href '${urlAsString}' passed to next/router in page: '${pathname}'. Repeated forward-slashes (//) or backslashes \\ are not valid in the href.`);
|
|
95
|
+
const normalizedNoProto = normalizeRepeatedSlashes(urlAsStringNoProto);
|
|
96
|
+
return (urlProtoMatch ? urlProtoMatch[0] : "") + normalizedNoProto;
|
|
97
|
+
}
|
|
52
98
|
function resolveLinkPrefetchMode(prefetchProp, isDangerous) {
|
|
53
99
|
if (isDangerous || prefetchProp === false) return "disabled";
|
|
54
100
|
if (prefetchProp === true) return "full";
|
|
@@ -159,12 +205,17 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
159
205
|
cacheForNavigation: autoPrefetch.cacheForNavigation,
|
|
160
206
|
optimisticRouteShell: isOptimisticRouteShellPrefetch
|
|
161
207
|
});
|
|
162
|
-
} else if (window.__NEXT_DATA__
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
208
|
+
} else if (window.__NEXT_DATA__) {
|
|
209
|
+
const dataTarget = resolvePagesDataNavigationTarget(fullHref, __basePath);
|
|
210
|
+
if (dataTarget) prefetchPagesData(dataTarget);
|
|
211
|
+
else {
|
|
212
|
+
markAppRouteDetectedOnPrefetch(fullHref, __basePath);
|
|
213
|
+
const link = document.createElement("link");
|
|
214
|
+
link.rel = "prefetch";
|
|
215
|
+
link.href = fullHref;
|
|
216
|
+
link.as = "document";
|
|
217
|
+
document.head.appendChild(link);
|
|
218
|
+
}
|
|
168
219
|
}
|
|
169
220
|
})().catch((error) => {
|
|
170
221
|
console.error("[vinext] RSC prefetch setup error:", error);
|
|
@@ -285,9 +336,12 @@ function applyLocaleToHref(href, locale) {
|
|
|
285
336
|
}
|
|
286
337
|
return addLocalePrefix(href, resolvedLocale, defaultLocale);
|
|
287
338
|
}
|
|
288
|
-
const Link = forwardRef(function Link({ href, as, replace = false, prefetch: prefetchProp, scroll = true, shallow = false, children, onClick, onMouseEnter, onTouchStart, onNavigate, unstable_dynamicOnHover = false, ...rest }, forwardedRef) {
|
|
339
|
+
const Link = forwardRef(function Link({ href, as, replace = false, prefetch: prefetchProp, scroll = true, shallow = false, children: childrenProp, onClick, onMouseEnter, onTouchStart, onNavigate, unstable_dynamicOnHover = false, legacyBehavior = false, passHref = false, ...rest }, forwardedRef) {
|
|
289
340
|
const { locale, ...restWithoutLocale } = rest;
|
|
290
|
-
|
|
341
|
+
let children = childrenProp;
|
|
342
|
+
if (legacyBehavior && (typeof childrenProp === "string" || typeof childrenProp === "number")) children = React.createElement("a", null, childrenProp);
|
|
343
|
+
const rawResolvedHref = as ?? resolveHref(href);
|
|
344
|
+
const resolvedHref = typeof rawResolvedHref === "string" ? warnAndNormalizeRepeatedSlashesInHref(rawResolvedHref) : rawResolvedHref;
|
|
291
345
|
const isDangerous = typeof resolvedHref === "string" && isDangerousScheme(resolvedHref);
|
|
292
346
|
const normalizedHref = normalizePathTrailingSlash(applyLocaleToHref(isDangerous ? "/" : resolvedHref, locale), __trailingSlash);
|
|
293
347
|
const fullHref = normalizePathTrailingSlash(withBasePath(normalizedHref, __basePath), __trailingSlash);
|
|
@@ -372,8 +426,8 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
372
426
|
onTouchStart?.(e);
|
|
373
427
|
prefetchOnIntent();
|
|
374
428
|
}, [onTouchStart, prefetchOnIntent]);
|
|
375
|
-
const handleClick = async (e) => {
|
|
376
|
-
if (onClick) onClick(e);
|
|
429
|
+
const handleClick = async (e, options = {}) => {
|
|
430
|
+
if (!options.skipLinkOnClick && onClick) onClick(e);
|
|
377
431
|
if (e.defaultPrevented) return;
|
|
378
432
|
if (e.currentTarget.hasAttribute("download")) return;
|
|
379
433
|
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
@@ -431,7 +485,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
431
485
|
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
432
486
|
}
|
|
433
487
|
};
|
|
434
|
-
const
|
|
488
|
+
const anchorProps = restWithoutLocale;
|
|
435
489
|
const linkStatusValue = React.useMemo(() => ({ pending }), [pending]);
|
|
436
490
|
if (isDangerous) {
|
|
437
491
|
if (process.env.NODE_ENV !== "production") console.warn(`<Link> blocked dangerous href: ${resolvedHref}`);
|
|
@@ -439,6 +493,26 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
439
493
|
if (onClick) onClick(event);
|
|
440
494
|
reportBlockedDangerousNavigation();
|
|
441
495
|
};
|
|
496
|
+
if (legacyBehavior) {
|
|
497
|
+
const child = React.Children.only(children);
|
|
498
|
+
const childOnClick = child.props.onClick;
|
|
499
|
+
const childRef = child.props.ref;
|
|
500
|
+
const setDangerousRefs = (node) => {
|
|
501
|
+
internalRef.current = node;
|
|
502
|
+
if (typeof childRef === "function") childRef(node);
|
|
503
|
+
else if (childRef) childRef.current = node;
|
|
504
|
+
};
|
|
505
|
+
return /* @__PURE__ */ jsx(LinkStatusContext.Provider, {
|
|
506
|
+
value: linkStatusValue,
|
|
507
|
+
children: React.cloneElement(child, {
|
|
508
|
+
ref: setDangerousRefs,
|
|
509
|
+
onClick: (event) => {
|
|
510
|
+
if (childOnClick) childOnClick(event);
|
|
511
|
+
reportBlockedDangerousNavigation();
|
|
512
|
+
}
|
|
513
|
+
})
|
|
514
|
+
});
|
|
515
|
+
}
|
|
442
516
|
return /* @__PURE__ */ jsx(LinkStatusContext.Provider, {
|
|
443
517
|
value: linkStatusValue,
|
|
444
518
|
children: /* @__PURE__ */ jsx("a", {
|
|
@@ -451,6 +525,46 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
451
525
|
})
|
|
452
526
|
});
|
|
453
527
|
}
|
|
528
|
+
if (legacyBehavior) {
|
|
529
|
+
const child = React.Children.only(children);
|
|
530
|
+
if (process.env.NODE_ENV !== "production") {
|
|
531
|
+
if (onClick) console.warn(`"onClick" was passed to <Link> with \`href\` of \`${resolveHref(href)}\` but "legacyBehavior" was set. The legacy behavior requires onClick be set on the child of next/link`);
|
|
532
|
+
if (onMouseEnter) console.warn(`"onMouseEnter" was passed to <Link> with \`href\` of \`${resolveHref(href)}\` but "legacyBehavior" was set. The legacy behavior requires onMouseEnter be set on the child of next/link`);
|
|
533
|
+
}
|
|
534
|
+
const childPropsExisting = child.props;
|
|
535
|
+
const childHasOwnHref = child.type === "a" ? "href" in childPropsExisting : false;
|
|
536
|
+
const shouldForwardHref = passHref || child.type === "a" && !childHasOwnHref;
|
|
537
|
+
const childOnClick = childPropsExisting.onClick;
|
|
538
|
+
const childOnMouseEnter = childPropsExisting.onMouseEnter;
|
|
539
|
+
const childOnTouchStart = childPropsExisting.onTouchStart;
|
|
540
|
+
const childRef = childPropsExisting.ref;
|
|
541
|
+
const setLegacyRefs = (node) => {
|
|
542
|
+
internalRef.current = node;
|
|
543
|
+
if (typeof childRef === "function") childRef(node);
|
|
544
|
+
else if (childRef) childRef.current = node;
|
|
545
|
+
};
|
|
546
|
+
const clonedProps = {
|
|
547
|
+
ref: setLegacyRefs,
|
|
548
|
+
onClick: (event) => {
|
|
549
|
+
if (childOnClick) childOnClick(event);
|
|
550
|
+
if (event.defaultPrevented) return;
|
|
551
|
+
handleClick(event, { skipLinkOnClick: true });
|
|
552
|
+
},
|
|
553
|
+
onMouseEnter: (event) => {
|
|
554
|
+
if (childOnMouseEnter) childOnMouseEnter(event);
|
|
555
|
+
prefetchOnIntent();
|
|
556
|
+
},
|
|
557
|
+
onTouchStart: (event) => {
|
|
558
|
+
if (childOnTouchStart) childOnTouchStart(event);
|
|
559
|
+
prefetchOnIntent();
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
if (shouldForwardHref) clonedProps.href = fullHref;
|
|
563
|
+
return /* @__PURE__ */ jsx(LinkStatusContext.Provider, {
|
|
564
|
+
value: linkStatusValue,
|
|
565
|
+
children: React.cloneElement(child, clonedProps)
|
|
566
|
+
});
|
|
567
|
+
}
|
|
454
568
|
return /* @__PURE__ */ jsx(LinkStatusContext.Provider, {
|
|
455
569
|
value: linkStatusValue,
|
|
456
570
|
children: /* @__PURE__ */ jsx("a", {
|
package/dist/shims/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","names":[],"sources":["../../src/shims/link.tsx"],"sourcesContent":["\"use client\";\n\n/**\n * next/link shim\n *\n * Renders an <a> tag with client-side navigation support.\n * On click, prevents full page reload and triggers client-side\n * page swap via the router's navigation system.\n */\nimport React, {\n forwardRef,\n useRef,\n useEffect,\n useCallback,\n useContext,\n createContext,\n useState,\n type AnchorHTMLAttributes,\n type MouseEvent,\n type TouchEvent,\n} from \"react\";\nimport {\n getNavigationRuntime,\n hasAppNavigationRuntime,\n registerNavigationRuntimeFunctions,\n} from \"../client/navigation-runtime.js\";\n// Import shared RSC prefetch utilities from navigation shim (relative path\n// so this resolves both via the Vite plugin and in direct vitest imports)\nimport {\n getPrefetchInterceptionContext,\n getPrefetchCache,\n getPrefetchedUrls,\n getMountedSlotsHeader,\n navigateClientSide,\n prefetchRscResponse,\n} from \"./navigation.js\";\nimport { AppElementsWire } from \"../server/app-elements.js\";\nimport {\n createRscRequestHeaders,\n createRscRequestUrl,\n stripRscCacheBustingSearchParam,\n stripRscSuffix,\n} from \"../server/app-rsc-cache-busting.js\";\nimport { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from \"../server/app-rsc-render-mode.js\";\nimport { VINEXT_MOUNTED_SLOTS_HEADER } from \"../server/headers.js\";\nimport { isDangerousScheme, reportBlockedDangerousNavigation } from \"./url-safety.js\";\nimport {\n canLinkIntentPrefetch,\n canLinkPrefetch,\n getLinkPrefetchHref,\n type LinkPrefetchRouterMode,\n} from \"./link-prefetch.js\";\nimport {\n isAbsoluteOrProtocolRelativeUrl,\n normalizePathTrailingSlash,\n resolveRelativeHref,\n toBrowserNavigationHref,\n toSameOriginAppPath,\n withBasePath,\n} from \"./url-utils.js\";\nimport { appendSearchParamsToUrl, type UrlQuery, urlQueryToSearchParams } from \"../utils/query.js\";\nimport { addLocalePrefix, getDomainLocaleUrl, type DomainLocale } from \"../utils/domain-locale.js\";\nimport { getI18nContext } from \"./i18n-context.js\";\nimport type { VinextLinkPrefetchRoute, VinextNextData } from \"../client/vinext-next-data.js\";\nimport { navigatePagesRouterLink } from \"../client/pages-router-link-navigation.js\";\nimport { createRouteTrieCache, matchRouteWithTrie } from \"../routing/route-matching.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport { getCurrentBrowserLocale } from \"./client-locale.js\";\n\ntype NavigateEvent = {\n url: URL;\n /** Call to prevent the Link's default navigation (e.g. for View Transitions). */\n preventDefault(): void;\n /** Whether preventDefault() has been called. */\n defaultPrevented: boolean;\n};\n\ntype LinkProps = {\n href: string | { pathname?: string; query?: UrlQuery };\n /** URL displayed in the browser (when href is a route pattern like /user/[id]) */\n as?: string;\n /** Replace the current history entry instead of pushing */\n replace?: boolean;\n /** Prefetch the page in the background (App Router default: auto, Pages Router default: true) */\n prefetch?: boolean | \"auto\" | null;\n /**\n * Unstable App Router option matching Next.js canary: an automatic prefetch\n * is upgraded to a full prefetch when the user shows navigation intent.\n */\n unstable_dynamicOnHover?: boolean;\n /** Whether to pass the href to the child element */\n passHref?: boolean;\n /** Scroll to top on navigation (default: true) */\n scroll?: boolean;\n /**\n * Pages Router: update the URL without re-running data fetching methods\n * (getServerSideProps / getStaticProps / getInitialProps). The shallow change\n * still triggers the route change events and updates `router.query`. Only\n * applies to navigations within the same page. No-op on the App Router.\n */\n shallow?: boolean;\n /** Locale for i18n (used for locale-prefixed URLs) */\n locale?: string | false;\n /** Called before navigation happens (Next.js 16). Return value is ignored. */\n onNavigate?: (event: NavigateEvent) => void;\n children?: React.ReactNode;\n} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, \"href\">;\n\ntype LinkPrefetchMode = \"disabled\" | \"auto\" | \"full\";\n\ndeclare global {\n // Window is an ambient interface from lib.dom; interface merging is required\n // for this global browser hook.\n // oxlint-disable-next-line typescript-eslint/consistent-type-definitions\n interface Window {\n __VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];\n }\n}\n\n// ---------------------------------------------------------------------------\n// useLinkStatus — reports the pending state of a parent <Link> navigation\n// ---------------------------------------------------------------------------\n\ntype LinkStatusContextValue = {\n pending: boolean;\n};\n\nconst LinkStatusContext = createContext<LinkStatusContextValue>({ pending: false });\n\n/**\n * useLinkStatus returns the pending state of the enclosing <Link>.\n * In Next.js, this is used to show loading indicators while a\n * prefetch-triggered navigation is in progress.\n */\nexport function useLinkStatus(): LinkStatusContextValue {\n return useContext(LinkStatusContext);\n}\n\n/** basePath from next.config.js, injected by the plugin at build time */\nconst __basePath: string = process.env.__NEXT_ROUTER_BASEPATH ?? \"\";\n/** trailingSlash from next.config.js, injected by the plugin at build time */\nconst __trailingSlash: boolean = process.env.__VINEXT_TRAILING_SLASH === \"true\";\nconst linkPrefetchRouteTrieCache = createRouteTrieCache<VinextLinkPrefetchRoute>();\n\nfunction resolveHref(href: LinkProps[\"href\"]): string {\n if (typeof href === \"string\") return href;\n let url = href.pathname ?? \"/\";\n if (href.query) {\n const params = urlQueryToSearchParams(href.query);\n url = appendSearchParamsToUrl(url, params);\n }\n return url;\n}\n\nexport function resolveLinkPrefetchMode(\n prefetchProp: LinkProps[\"prefetch\"],\n isDangerous: boolean,\n): LinkPrefetchMode {\n if (isDangerous || prefetchProp === false) return \"disabled\";\n if (prefetchProp === true) return \"full\";\n return \"auto\";\n}\n\nfunction toSameOriginRouteHref(href: string): string | null {\n if (typeof window === \"undefined\") return null;\n\n let url: URL;\n try {\n url = new URL(href, window.location.href);\n } catch {\n return null;\n }\n\n if (url.origin !== window.location.origin) return null;\n\n return `${stripBasePath(url.pathname, __basePath)}${url.search}`;\n}\n\nfunction getLinkPrefetchRouterMode(): LinkPrefetchRouterMode {\n return hasAppNavigationRuntime() ? \"app\" : \"pages\";\n}\n\nexport function canAutoPrefetchFullAppRoute(href: string): boolean {\n if (typeof window === \"undefined\") return false;\n\n const routes = window.__VINEXT_LINK_PREFETCH_ROUTES__;\n if (!routes) return false;\n\n const routeHref = toSameOriginRouteHref(href);\n if (routeHref === null) return false;\n\n const match = matchRouteWithTrie(routeHref, routes, linkPrefetchRouteTrieCache);\n if (!match) return false;\n\n return !match.route.isDynamic;\n}\n\nexport function resolveAutoAppRoutePrefetch(href: string): {\n cacheForNavigation: boolean;\n shouldPrefetch: boolean;\n} {\n if (typeof window === \"undefined\") {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n const routes = window.__VINEXT_LINK_PREFETCH_ROUTES__;\n if (!routes) {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n const routeHref = toSameOriginRouteHref(href);\n if (routeHref === null) {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n const match = matchRouteWithTrie(routeHref, routes, linkPrefetchRouteTrieCache);\n if (!match) {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n return {\n cacheForNavigation: !match.route.isDynamic,\n shouldPrefetch: !match.route.isDynamic || match.route.canPrefetchLoadingShell,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Prefetching infrastructure\n// ---------------------------------------------------------------------------\n\n/**\n * Prefetch a URL for faster navigation.\n *\n * For App Router (RSC): fetches the .rsc payload in the background and\n * stores it in an in-memory cache for instant use during navigation.\n * For Pages Router: injects a <link rel=\"prefetch\"> for the page module.\n *\n * Uses `requestIdleCallback` (or `setTimeout` fallback) to avoid blocking\n * the main thread during initial page load.\n */\nfunction prefetchUrl(href: string, mode: LinkPrefetchMode, priority: \"low\" | \"high\" = \"low\"): void {\n if (typeof window === \"undefined\") return;\n\n const prefetchHref = getLinkPrefetchHref({\n href,\n basePath: __basePath,\n currentOrigin: window.location.origin,\n });\n if (prefetchHref == null) return;\n\n const fullHref = toBrowserNavigationHref(prefetchHref, window.location.href, __basePath);\n\n const schedule = window.requestIdleCallback ?? ((fn: () => void) => setTimeout(fn, 100));\n\n schedule(() => {\n void (async () => {\n if (hasAppNavigationRuntime()) {\n const autoPrefetch =\n mode === \"auto\"\n ? resolveAutoAppRoutePrefetch(prefetchHref)\n : { cacheForNavigation: true, shouldPrefetch: true };\n if (!autoPrefetch.shouldPrefetch) return;\n\n const interceptionContext = getPrefetchInterceptionContext(fullHref);\n const mountedSlotsHeader = getMountedSlotsHeader();\n const isOptimisticRouteShellPrefetch = !autoPrefetch.cacheForNavigation;\n if (isOptimisticRouteShellPrefetch && interceptionContext !== null) return;\n const headers = createRscRequestHeaders({\n interceptionContext,\n renderMode: isOptimisticRouteShellPrefetch\n ? APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL\n : undefined,\n });\n if (mountedSlotsHeader) {\n headers.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);\n }\n // Distinguish the same visible URL when it is prefetched from different\n // request contexts such as /feed vs /gallery or different mounted slots.\n const rscUrl = await createRscRequestUrl(fullHref, headers);\n const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);\n const prefetched = getPrefetchedUrls();\n if (prefetched.has(cacheKey)) {\n if (autoPrefetch.cacheForNavigation) {\n const existing = getPrefetchCache().get(cacheKey);\n if (existing?.cacheForNavigation === false) {\n existing.cacheForNavigation = true;\n }\n }\n return;\n }\n prefetched.add(cacheKey);\n prefetchRscResponse(\n rscUrl,\n fetch(rscUrl, {\n headers,\n credentials: \"include\",\n priority,\n // @ts-expect-error — purpose is a valid fetch option in some browsers\n purpose: \"prefetch\",\n }),\n interceptionContext,\n mountedSlotsHeader,\n undefined,\n {\n cacheForNavigation: autoPrefetch.cacheForNavigation,\n optimisticRouteShell: isOptimisticRouteShellPrefetch,\n },\n );\n } else if ((window.__NEXT_DATA__ as VinextNextData | undefined)?.__vinext?.pageModuleUrl) {\n // Pages Router: inject a prefetch link for the target page module\n // We can't easily resolve the target page's module URL from the Link,\n // so we create a <link rel=\"prefetch\"> for the HTML page which helps\n // the browser's preload scanner.\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.href = fullHref;\n link.as = \"document\";\n document.head.appendChild(link);\n }\n })().catch((error) => {\n console.error(\"[vinext] RSC prefetch setup error:\", error);\n });\n });\n}\n\nfunction promotePrefetchEntriesForNavigation(href: string): void {\n if (typeof window === \"undefined\") return;\n\n let target: URL;\n try {\n target = new URL(\n toBrowserNavigationHref(href, window.location.href, __basePath),\n window.location.href,\n );\n } catch {\n return;\n }\n\n for (const [cacheKey, entry] of getPrefetchCache()) {\n if (entry.optimisticRouteShell === true) continue;\n\n const [rscUrl] = cacheKey.split(\"\\0\", 1);\n let cached: URL;\n try {\n cached = new URL(rscUrl, window.location.href);\n } catch {\n continue;\n }\n stripRscCacheBustingSearchParam(cached);\n if (stripRscSuffix(cached.pathname) === target.pathname && cached.search === target.search) {\n entry.cacheForNavigation = true;\n }\n }\n}\n\n/**\n * Shared IntersectionObserver for viewport-based prefetching.\n * All Link elements use the same observer to minimize resource usage.\n */\nlet sharedObserver: IntersectionObserver | null = null;\ntype LinkPrefetchInstance = {\n href: string;\n isVisible: boolean;\n mode: LinkPrefetchMode;\n routerMode: LinkPrefetchRouterMode;\n viewportPrefetched: boolean;\n};\n\nconst observedLinkPrefetches = new WeakMap<Element, LinkPrefetchInstance>();\nconst visibleLinkPrefetches = new Set<LinkPrefetchInstance>();\n\nfunction setVisibleLinkPrefetch(instance: LinkPrefetchInstance, isVisible: boolean): void {\n instance.isVisible = isVisible;\n if (isVisible) {\n visibleLinkPrefetches.add(instance);\n if (instance.routerMode === \"pages\" && instance.viewportPrefetched) return;\n prefetchUrl(instance.href, instance.mode, \"low\");\n instance.viewportPrefetched = true;\n } else {\n visibleLinkPrefetches.delete(instance);\n }\n}\n\nfunction registerVisibleLinkPing(): void {\n if (typeof window === \"undefined\") return;\n registerNavigationRuntimeFunctions({ pingVisibleLinks: pingVisibleLinkPrefetches });\n}\n\nfunction pingVisibleLinkPrefetches(): void {\n for (const instance of visibleLinkPrefetches) {\n if (instance.isVisible && instance.routerMode === \"app\") {\n prefetchUrl(instance.href, instance.mode, \"low\");\n }\n }\n}\n\nfunction getSharedObserver(): IntersectionObserver | null {\n if (typeof window === \"undefined\" || typeof IntersectionObserver === \"undefined\") return null;\n if (sharedObserver) return sharedObserver;\n\n sharedObserver = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n const instance = observedLinkPrefetches.get(entry.target);\n if (!instance) continue;\n setVisibleLinkPrefetch(instance, entry.isIntersecting || entry.intersectionRatio > 0);\n }\n },\n {\n // Start prefetching when the link is within 250px of the viewport.\n // This gives the browser a head start before the user scrolls to it.\n rootMargin: \"250px\",\n },\n );\n\n return sharedObserver;\n}\n\nfunction getDefaultLocale(): string | undefined {\n if (typeof window !== \"undefined\") {\n return window.__VINEXT_DEFAULT_LOCALE__;\n }\n return getI18nContext()?.defaultLocale;\n}\n\nfunction getCurrentLocale(): string | undefined {\n if (typeof window !== \"undefined\") {\n return getCurrentBrowserLocale({\n basePath: __basePath,\n domainLocales: getDomainLocales(),\n hostname: getCurrentHostname(),\n });\n }\n return getI18nContext()?.locale;\n}\n\nfunction getDomainLocales(): readonly DomainLocale[] | undefined {\n if (typeof window !== \"undefined\") {\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.domainLocales;\n }\n return getI18nContext()?.domainLocales;\n}\n\nfunction getCurrentHostname(): string | undefined {\n if (typeof window !== \"undefined\") return window.location.hostname;\n return getI18nContext()?.hostname;\n}\n\nfunction getDomainLocaleHref(href: string, locale: string): string | undefined {\n // Only cross-domain locale switches need a special absolute URL here.\n // Same-domain cases fall back to the standard locale-prefix logic below.\n return getDomainLocaleUrl(href, locale, {\n basePath: __basePath,\n currentHostname: getCurrentHostname(),\n domainItems: getDomainLocales(),\n });\n}\n\nfunction addLocalePrefixForRoot(href: string, locale: string): string | undefined {\n if (href !== \"/\" && !href.startsWith(\"/?\") && !href.startsWith(\"/#\")) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(href, \"http://vinext.local\");\n } catch {\n return undefined;\n }\n\n if (parsed.origin !== \"http://vinext.local\" || parsed.pathname !== \"/\") {\n return undefined;\n }\n\n return `/${locale}${parsed.search}${parsed.hash}`;\n}\n\n/**\n * Apply locale prefix to a URL path based on the locale prop.\n * - locale=\"fr\" → prepend /fr (unless it already has a locale prefix)\n * - locale={false} → use the href as-is (no locale prefix, link to default)\n * - locale=undefined → use current locale (href as-is in most cases)\n */\nfunction applyLocaleToHref(href: string, locale: string | false | undefined): string {\n if (locale === false) {\n // Explicit false: no locale prefix\n return href;\n }\n\n const resolvedLocale = locale ?? getCurrentLocale();\n if (resolvedLocale === undefined) {\n return href;\n }\n\n // Absolute and protocol-relative URLs must not be prefixed — locale\n // only applies to local paths.\n if (isAbsoluteOrProtocolRelativeUrl(href)) {\n return href;\n }\n\n const domainLocaleHref = getDomainLocaleHref(href, resolvedLocale);\n if (domainLocaleHref) {\n return domainLocaleHref;\n }\n\n const defaultLocale = getDefaultLocale() ?? \"\";\n if (resolvedLocale.toLowerCase() === defaultLocale.toLowerCase()) {\n const localeRootHref = addLocalePrefixForRoot(href, resolvedLocale);\n if (localeRootHref) return localeRootHref;\n }\n\n return addLocalePrefix(href, resolvedLocale, defaultLocale);\n}\n\nconst Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(\n {\n href,\n as,\n replace = false,\n prefetch: prefetchProp,\n scroll = true,\n shallow = false,\n children,\n onClick,\n onMouseEnter,\n onTouchStart,\n onNavigate,\n unstable_dynamicOnHover = false,\n ...rest\n },\n forwardedRef,\n) {\n // Extract locale from rest props\n const { locale, ...restWithoutLocale } = rest;\n\n // If `as` is provided, use it as the actual URL (legacy Next.js pattern\n // where href is a route pattern like \"/user/[id]\" and as is \"/user/1\")\n const resolvedHref = as ?? resolveHref(href);\n\n const isDangerous = typeof resolvedHref === \"string\" && isDangerousScheme(resolvedHref);\n\n // Apply locale prefix if specified (safe even for dangerous hrefs since we\n // won't use the result when isDangerous is true)\n const localizedHref = applyLocaleToHref(isDangerous ? \"/\" : resolvedHref, locale);\n // Normalise trailing slash to match `trailingSlash` config so that rendered\n // hrefs avoid the redirect bounce. Mirrors Next.js's `addLocale`/`addBasePath`,\n // both of which run `normalizePathTrailingSlash` after prefixing — we apply\n // it once after locale prefixing (for prefetch/navigation paths that bypass\n // basePath) and again after `withBasePath` for the rendered `href` attribute.\n const normalizedHref = normalizePathTrailingSlash(localizedHref, __trailingSlash);\n // Full href with basePath for browser URLs and fetches, normalised again so\n // that combining a non-empty basePath with the bare root (`/`) still\n // produces a canonical href under `trailingSlash: false` (e.g. `/foo`\n // rather than `/foo/`).\n const fullHref = normalizePathTrailingSlash(\n withBasePath(normalizedHref, __basePath),\n __trailingSlash,\n );\n\n // Track pending state for useLinkStatus()\n const [pending, setPending] = useState(false);\n const mountedRef = useRef(true);\n useEffect(() => {\n mountedRef.current = true;\n return () => {\n mountedRef.current = false;\n };\n }, []);\n\n // Prefetching: observe the element when it enters the viewport.\n // In App Router, null/undefined/\"auto\" is automatic prefetch and true opts\n // into a full RSC prefetch, matching Next.js's public prefetch contract.\n const internalRef = useRef<HTMLAnchorElement | null>(null);\n const prefetchMode = resolveLinkPrefetchMode(prefetchProp, isDangerous);\n const shouldViewportPrefetch = canLinkPrefetch({\n nodeEnv: process.env.NODE_ENV,\n prefetch: prefetchProp,\n isDangerous,\n });\n\n const setRefs = useCallback(\n (node: HTMLAnchorElement | null) => {\n internalRef.current = node;\n if (typeof forwardedRef === \"function\") forwardedRef(node);\n else if (forwardedRef)\n (forwardedRef as React.MutableRefObject<HTMLAnchorElement | null>).current = node;\n },\n [forwardedRef],\n );\n\n useEffect(() => {\n if (!shouldViewportPrefetch || typeof window === \"undefined\") return;\n const node = internalRef.current;\n if (!node) return;\n\n const hrefToPrefetch = getLinkPrefetchHref({\n href: normalizedHref,\n basePath: __basePath,\n currentOrigin: window.location.origin,\n });\n if (hrefToPrefetch == null) return;\n\n const observer = getSharedObserver();\n if (!observer) return;\n\n registerVisibleLinkPing();\n const instance: LinkPrefetchInstance = {\n href: hrefToPrefetch,\n isVisible: false,\n mode: prefetchMode,\n routerMode: getLinkPrefetchRouterMode(),\n viewportPrefetched: false,\n };\n observedLinkPrefetches.set(node, instance);\n observer.observe(node);\n\n return () => {\n observer.unobserve(node);\n observedLinkPrefetches.delete(node);\n visibleLinkPrefetches.delete(instance);\n };\n }, [shouldViewportPrefetch, prefetchMode, normalizedHref]);\n\n const prefetchOnIntent = useCallback(() => {\n if (\n !canLinkIntentPrefetch({\n nodeEnv: process.env.NODE_ENV,\n prefetch: prefetchProp,\n isDangerous,\n routerMode: getLinkPrefetchRouterMode(),\n })\n ) {\n return;\n }\n const intentMode = unstable_dynamicOnHover ? \"full\" : prefetchMode;\n if (unstable_dynamicOnHover && internalRef.current) {\n const instance = observedLinkPrefetches.get(internalRef.current);\n if (instance) {\n instance.mode = \"full\";\n }\n promotePrefetchEntriesForNavigation(normalizedHref);\n }\n prefetchUrl(normalizedHref, intentMode, \"high\");\n }, [prefetchProp, isDangerous, prefetchMode, normalizedHref, unstable_dynamicOnHover]);\n\n const handleMouseEnter = useCallback(\n (e: MouseEvent<HTMLAnchorElement>) => {\n onMouseEnter?.(e);\n prefetchOnIntent();\n },\n [onMouseEnter, prefetchOnIntent],\n );\n\n const handleTouchStart = useCallback(\n (e: TouchEvent<HTMLAnchorElement>) => {\n onTouchStart?.(e);\n prefetchOnIntent();\n },\n [onTouchStart, prefetchOnIntent],\n );\n\n const handleClick = async (e: MouseEvent<HTMLAnchorElement>) => {\n if (onClick) onClick(e);\n if (e.defaultPrevented) return;\n\n // Native download links must keep the browser's default behavior.\n if (e.currentTarget.hasAttribute(\"download\")) {\n return;\n }\n\n // Only intercept left clicks without modifiers (standard link behavior)\n if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {\n return;\n }\n\n // Don't intercept links with target (e.g. target=\"_blank\")\n if (e.currentTarget.target && e.currentTarget.target !== \"_self\") {\n return;\n }\n\n // External links: let the browser handle it.\n // Same-origin absolute URLs (e.g. http://localhost:3000/about) are\n // normalized to local paths so they get client-side navigation.\n let navigateHref = normalizedHref;\n if (isAbsoluteOrProtocolRelativeUrl(resolvedHref)) {\n const localPath = toSameOriginAppPath(resolvedHref, __basePath);\n if (localPath == null) {\n // Truly external. Mirror Next.js `linkClicked`: when `replace` is set\n // we have to take over because the browser's default click navigation\n // pushes to history rather than replacing the current entry.\n // See `.nextjs-ref/packages/next/src/client/link.tsx` `linkClicked`.\n if (replace) {\n e.preventDefault();\n window.location.replace(resolvedHref);\n }\n return;\n }\n navigateHref = localPath;\n }\n\n e.preventDefault();\n\n // Resolve relative hrefs (#hash, ?query) against the current URL once so\n // onNavigate and the actual navigation target stay in sync.\n const absoluteHref = resolveRelativeHref(navigateHref, window.location.href, __basePath);\n const absoluteFullHref = toBrowserNavigationHref(\n navigateHref,\n window.location.href,\n __basePath,\n );\n\n // Call onNavigate callback if provided (Next.js 16 View Transitions support)\n if (onNavigate) {\n try {\n const navUrl = new URL(absoluteFullHref, window.location.origin);\n let prevented = false;\n const navEvent: NavigateEvent = {\n url: navUrl,\n preventDefault() {\n prevented = true;\n },\n get defaultPrevented() {\n return prevented;\n },\n };\n onNavigate(navEvent);\n // If the callback called preventDefault(), skip Link's default navigation.\n // The callback is responsible for its own navigation (e.g. via View Transitions API).\n if (navEvent.defaultPrevented) {\n return;\n }\n } catch {\n // Ignore URL parsing errors for relative/hash hrefs\n }\n }\n\n // App Router: delegate to navigateClientSide which handles scroll save,\n // hash-only changes, RSC fetch, and two-phase URL commit.\n if (getNavigationRuntime()?.functions.navigate) {\n setPending(true);\n React.startTransition(() => {\n void navigateClientSide(navigateHref, replace ? \"replace\" : \"push\", scroll, true).finally(\n () => {\n if (mountedRef.current) setPending(false);\n },\n );\n });\n return;\n } else {\n // Next.js only consumes onRouterTransitionStart in the App Router.\n // Pages Router still executes instrumentation-client side effects\n // during startup, but it does not invoke the named export on navigation.\n // Pages Router: use the Router singleton\n try {\n const routerModule = await import(\"next/router\");\n const Router = routerModule.default;\n await navigatePagesRouterLink(Router, {\n href: absoluteHref,\n replace,\n scroll,\n shallow,\n locale,\n });\n } catch {\n // Fallback to hard navigation if router fails\n if (replace) {\n window.history.replaceState({}, \"\", absoluteFullHref);\n } else {\n window.history.pushState({}, \"\", absoluteFullHref);\n }\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n }\n }\n };\n\n // Remove props that shouldn't be on <a>\n const { passHref: _p, ...anchorProps } = restWithoutLocale;\n\n const linkStatusValue = React.useMemo(() => ({ pending }), [pending]);\n\n // Block dangerous URI schemes (javascript:, data:, vbscript:).\n // Render an inert <a> without href to prevent XSS while preserving\n // styling, refs, and developer event handlers like onClick.\n // This check is placed after all hooks to satisfy the Rules of Hooks.\n if (isDangerous) {\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(`<Link> blocked dangerous href: ${resolvedHref}`);\n }\n // Match Next.js parity: when a user clicks a Link whose href has a\n // dangerous scheme, emit the same `console.error` that Next.js surfaces\n // via React's event-handler runtime when `router.push` throws.\n // Ported from Next.js: test/e2e/app-dir/javascript-urls/javascript-urls.test.ts\n // https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/javascript-urls/javascript-urls.test.ts\n const handleDangerousClick = (event: MouseEvent<HTMLAnchorElement>) => {\n if (onClick) onClick(event);\n reportBlockedDangerousNavigation();\n };\n return (\n <LinkStatusContext.Provider value={linkStatusValue}>\n <a\n ref={setRefs}\n onClick={handleDangerousClick}\n onMouseEnter={handleMouseEnter}\n onTouchStart={handleTouchStart}\n {...anchorProps}\n >\n {children}\n </a>\n </LinkStatusContext.Provider>\n );\n }\n\n return (\n <LinkStatusContext.Provider value={linkStatusValue}>\n <a\n ref={setRefs}\n href={fullHref}\n onClick={(event) => {\n void handleClick(event);\n }}\n onMouseEnter={handleMouseEnter}\n onTouchStart={handleTouchStart}\n {...anchorProps}\n >\n {children}\n </a>\n </LinkStatusContext.Provider>\n );\n});\n\nexport default Link;\n"],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/shims/link.tsx"],"sourcesContent":["\"use client\";\n\n/**\n * next/link shim\n *\n * Renders an <a> tag with client-side navigation support.\n * On click, prevents full page reload and triggers client-side\n * page swap via the router's navigation system.\n */\nimport React, {\n forwardRef,\n useRef,\n useEffect,\n useCallback,\n useContext,\n createContext,\n useState,\n type AnchorHTMLAttributes,\n type MouseEvent,\n type TouchEvent,\n} from \"react\";\nimport {\n getNavigationRuntime,\n hasAppNavigationRuntime,\n registerNavigationRuntimeFunctions,\n} from \"../client/navigation-runtime.js\";\n// Import shared RSC prefetch utilities from navigation shim (relative path\n// so this resolves both via the Vite plugin and in direct vitest imports)\nimport {\n getPrefetchInterceptionContext,\n getPrefetchCache,\n getPrefetchedUrls,\n getMountedSlotsHeader,\n navigateClientSide,\n prefetchRscResponse,\n} from \"./navigation.js\";\nimport { AppElementsWire } from \"../server/app-elements.js\";\nimport {\n createRscRequestHeaders,\n createRscRequestUrl,\n stripRscCacheBustingSearchParam,\n stripRscSuffix,\n} from \"../server/app-rsc-cache-busting.js\";\nimport { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from \"../server/app-rsc-render-mode.js\";\nimport { VINEXT_MOUNTED_SLOTS_HEADER } from \"../server/headers.js\";\nimport { isDangerousScheme, reportBlockedDangerousNavigation } from \"./url-safety.js\";\nimport {\n canLinkIntentPrefetch,\n canLinkPrefetch,\n getLinkPrefetchHref,\n type LinkPrefetchRouterMode,\n} from \"./link-prefetch.js\";\nimport {\n isAbsoluteOrProtocolRelativeUrl,\n normalizePathTrailingSlash,\n resolveRelativeHref,\n toBrowserNavigationHref,\n toSameOriginAppPath,\n withBasePath,\n} from \"./url-utils.js\";\nimport { appendSearchParamsToUrl, type UrlQuery, urlQueryToSearchParams } from \"../utils/query.js\";\nimport { addLocalePrefix, getDomainLocaleUrl, type DomainLocale } from \"../utils/domain-locale.js\";\nimport { getI18nContext } from \"./i18n-context.js\";\nimport type { VinextLinkPrefetchRoute, VinextNextData } from \"../client/vinext-next-data.js\";\nimport { navigatePagesRouterLink } from \"../client/pages-router-link-navigation.js\";\nimport { createRouteTrieCache, matchRouteWithTrie } from \"../routing/route-matching.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport {\n prefetchPagesData,\n resolvePagesDataNavigationTarget,\n} from \"./internal/pages-data-target.js\";\nimport { markAppRouteDetectedOnPrefetch } from \"./internal/app-route-detection.js\";\nimport { getCurrentBrowserLocale } from \"./client-locale.js\";\n\ntype NavigateEvent = {\n url: URL;\n /** Call to prevent the Link's default navigation (e.g. for View Transitions). */\n preventDefault(): void;\n /** Whether preventDefault() has been called. */\n defaultPrevented: boolean;\n};\n\ntype LinkProps = {\n href: string | { pathname?: string; query?: UrlQuery };\n /** URL displayed in the browser (when href is a route pattern like /user/[id]) */\n as?: string;\n /** Replace the current history entry instead of pushing */\n replace?: boolean;\n /** Prefetch the page in the background (App Router default: auto, Pages Router default: true) */\n prefetch?: boolean | \"auto\" | null;\n /**\n * Unstable App Router option matching Next.js canary: an automatic prefetch\n * is upgraded to a full prefetch when the user shows navigation intent.\n */\n unstable_dynamicOnHover?: boolean;\n /** Whether to pass the href to the child element */\n passHref?: boolean;\n /**\n * Pre-Next.js-13 link behaviour. When true, <Link> expects its child to be\n * an `<a>` (or a component that renders one) and forwards `href`, click,\n * and prefetch handlers to the child via `React.cloneElement` instead of\n * rendering its own wrapping `<a>`. Required when the user wants to\n * style/instrument the anchor themselves.\n */\n legacyBehavior?: boolean;\n /** Scroll to top on navigation (default: true) */\n scroll?: boolean;\n /**\n * Pages Router: update the URL without re-running data fetching methods\n * (getServerSideProps / getStaticProps / getInitialProps). The shallow change\n * still triggers the route change events and updates `router.query`. Only\n * applies to navigations within the same page. No-op on the App Router.\n */\n shallow?: boolean;\n /** Locale for i18n (used for locale-prefixed URLs) */\n locale?: string | false;\n /** Called before navigation happens (Next.js 16). Return value is ignored. */\n onNavigate?: (event: NavigateEvent) => void;\n children?: React.ReactNode;\n} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, \"href\">;\n\ntype LinkPrefetchMode = \"disabled\" | \"auto\" | \"full\";\n\ndeclare global {\n // Window is an ambient interface from lib.dom; interface merging is required\n // for this global browser hook.\n // oxlint-disable-next-line typescript-eslint/consistent-type-definitions\n interface Window {\n __VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];\n }\n}\n\n// ---------------------------------------------------------------------------\n// useLinkStatus — reports the pending state of a parent <Link> navigation\n// ---------------------------------------------------------------------------\n\ntype LinkStatusContextValue = {\n pending: boolean;\n};\n\nconst LinkStatusContext = createContext<LinkStatusContextValue>({ pending: false });\n\n/**\n * useLinkStatus returns the pending state of the enclosing <Link>.\n * In Next.js, this is used to show loading indicators while a\n * prefetch-triggered navigation is in progress.\n */\nexport function useLinkStatus(): LinkStatusContextValue {\n return useContext(LinkStatusContext);\n}\n\n/** basePath from next.config.js, injected by the plugin at build time */\nconst __basePath: string = process.env.__NEXT_ROUTER_BASEPATH ?? \"\";\n/** trailingSlash from next.config.js, injected by the plugin at build time */\nconst __trailingSlash: boolean = process.env.__VINEXT_TRAILING_SLASH === \"true\";\nconst linkPrefetchRouteTrieCache = createRouteTrieCache<VinextLinkPrefetchRoute>();\n\nfunction resolveHref(href: LinkProps[\"href\"]): string {\n if (typeof href === \"string\") return href;\n let url = href.pathname ?? \"/\";\n if (href.query) {\n const params = urlQueryToSearchParams(href.query);\n url = appendSearchParamsToUrl(url, params);\n }\n return url;\n}\n\n/**\n * Collapse repeated forward-slashes (and convert backslashes to forward-slashes)\n * in the path portion of a URL, preserving any query string.\n *\n * Ported from Next.js: packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts\n */\nfunction normalizeRepeatedSlashes(url: string): string {\n const urlParts = url.split(\"?\");\n const urlNoQueryString = urlParts.shift() ?? \"\";\n const queryString = urlParts.join(\"?\");\n return (\n urlNoQueryString.replace(/\\\\/g, \"/\").replace(/\\/\\/+/g, \"/\") +\n (queryString ? `?${queryString}` : \"\")\n );\n}\n\n/**\n * Emit Next.js's \"Invalid href\" `console.error` when `href` contains repeated\n * forward slashes or backslashes in its path portion, and return the\n * normalized URL (with `\\\\` converted to `/` and runs of `/` collapsed). If\n * the href is already well-formed, the original string is returned unchanged.\n *\n * Ported from Next.js: packages/next/src/client/resolve-href.ts\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/resolve-href.ts\n *\n * Matches the message asserted by:\n * test/e2e/repeated-forward-slashes-error/repeated-forward-slashes-error.test.ts\n *\n * Note: Next.js fires this warning unconditionally on every call to\n * `resolveHref`. We mirror that behaviour (no dedup) for exact parity.\n *\n * Note: Next.js uses `router.pathname` (the route pattern, e.g.\n * `/posts/[id]`) for the \"in page\" segment of the message. We do not have\n * cheap access to the route pattern from inside the Link shim, so we\n * fall back to `window.location.pathname` (or `\"/\"` during SSR). The text\n * is cosmetic and is not asserted by the Next.js compat test.\n */\nfunction warnAndNormalizeRepeatedSlashesInHref(urlAsString: string): string {\n // Protocol-relative URLs (e.g. \"//example.com/path\") are treated by vinext\n // as external — see `isAbsoluteOrProtocolRelativeUrl` in url-utils. We\n // intentionally skip the repeated-slash warning and normalization for them\n // so that locale prefixing and same-origin detection elsewhere in this\n // shim continue to receive the original href. (Next.js itself does flag\n // these, but our external-URL handling supersedes that behaviour.)\n if (urlAsString.startsWith(\"//\")) return urlAsString;\n\n // Strip any protocol prefix (e.g. \"https://\") so we do not flag the\n // legitimate `//` that separates the scheme from the authority.\n const urlProtoMatch = urlAsString.match(/^[a-z][a-z0-9+.-]*:\\/\\//i);\n const urlAsStringNoProto = urlProtoMatch\n ? urlAsString.slice(urlProtoMatch[0].length)\n : urlAsString;\n const urlParts = urlAsStringNoProto.split(\"?\", 1);\n if (!(urlParts[0] || \"\").match(/(\\/\\/|\\\\)/)) return urlAsString;\n\n const pathname =\n typeof window !== \"undefined\" && window.location ? window.location.pathname : \"/\";\n console.error(\n `Invalid href '${urlAsString}' passed to next/router in page: '${pathname}'. Repeated forward-slashes (//) or backslashes \\\\ are not valid in the href.`,\n );\n\n const normalizedNoProto = normalizeRepeatedSlashes(urlAsStringNoProto);\n return (urlProtoMatch ? urlProtoMatch[0] : \"\") + normalizedNoProto;\n}\n\nexport function resolveLinkPrefetchMode(\n prefetchProp: LinkProps[\"prefetch\"],\n isDangerous: boolean,\n): LinkPrefetchMode {\n if (isDangerous || prefetchProp === false) return \"disabled\";\n if (prefetchProp === true) return \"full\";\n return \"auto\";\n}\n\nfunction toSameOriginRouteHref(href: string): string | null {\n if (typeof window === \"undefined\") return null;\n\n let url: URL;\n try {\n url = new URL(href, window.location.href);\n } catch {\n return null;\n }\n\n if (url.origin !== window.location.origin) return null;\n\n return `${stripBasePath(url.pathname, __basePath)}${url.search}`;\n}\n\nfunction getLinkPrefetchRouterMode(): LinkPrefetchRouterMode {\n return hasAppNavigationRuntime() ? \"app\" : \"pages\";\n}\n\nexport function canAutoPrefetchFullAppRoute(href: string): boolean {\n if (typeof window === \"undefined\") return false;\n\n const routes = window.__VINEXT_LINK_PREFETCH_ROUTES__;\n if (!routes) return false;\n\n const routeHref = toSameOriginRouteHref(href);\n if (routeHref === null) return false;\n\n const match = matchRouteWithTrie(routeHref, routes, linkPrefetchRouteTrieCache);\n if (!match) return false;\n\n return !match.route.isDynamic;\n}\n\nexport function resolveAutoAppRoutePrefetch(href: string): {\n cacheForNavigation: boolean;\n shouldPrefetch: boolean;\n} {\n if (typeof window === \"undefined\") {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n const routes = window.__VINEXT_LINK_PREFETCH_ROUTES__;\n if (!routes) {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n const routeHref = toSameOriginRouteHref(href);\n if (routeHref === null) {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n const match = matchRouteWithTrie(routeHref, routes, linkPrefetchRouteTrieCache);\n if (!match) {\n return { cacheForNavigation: false, shouldPrefetch: false };\n }\n\n return {\n cacheForNavigation: !match.route.isDynamic,\n shouldPrefetch: !match.route.isDynamic || match.route.canPrefetchLoadingShell,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Prefetching infrastructure\n// ---------------------------------------------------------------------------\n\n/**\n * Prefetch a URL for faster navigation.\n *\n * For App Router (RSC): fetches the .rsc payload in the background and\n * stores it in an in-memory cache for instant use during navigation.\n * For Pages Router: injects a <link rel=\"prefetch\"> for the page module.\n *\n * Uses `requestIdleCallback` (or `setTimeout` fallback) to avoid blocking\n * the main thread during initial page load.\n */\nfunction prefetchUrl(href: string, mode: LinkPrefetchMode, priority: \"low\" | \"high\" = \"low\"): void {\n if (typeof window === \"undefined\") return;\n\n const prefetchHref = getLinkPrefetchHref({\n href,\n basePath: __basePath,\n currentOrigin: window.location.origin,\n });\n if (prefetchHref == null) return;\n\n const fullHref = toBrowserNavigationHref(prefetchHref, window.location.href, __basePath);\n\n const schedule = window.requestIdleCallback ?? ((fn: () => void) => setTimeout(fn, 100));\n\n schedule(() => {\n void (async () => {\n if (hasAppNavigationRuntime()) {\n const autoPrefetch =\n mode === \"auto\"\n ? resolveAutoAppRoutePrefetch(prefetchHref)\n : { cacheForNavigation: true, shouldPrefetch: true };\n if (!autoPrefetch.shouldPrefetch) return;\n\n const interceptionContext = getPrefetchInterceptionContext(fullHref);\n const mountedSlotsHeader = getMountedSlotsHeader();\n const isOptimisticRouteShellPrefetch = !autoPrefetch.cacheForNavigation;\n if (isOptimisticRouteShellPrefetch && interceptionContext !== null) return;\n const headers = createRscRequestHeaders({\n interceptionContext,\n renderMode: isOptimisticRouteShellPrefetch\n ? APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL\n : undefined,\n });\n if (mountedSlotsHeader) {\n headers.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);\n }\n // Distinguish the same visible URL when it is prefetched from different\n // request contexts such as /feed vs /gallery or different mounted slots.\n const rscUrl = await createRscRequestUrl(fullHref, headers);\n const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);\n const prefetched = getPrefetchedUrls();\n if (prefetched.has(cacheKey)) {\n if (autoPrefetch.cacheForNavigation) {\n const existing = getPrefetchCache().get(cacheKey);\n if (existing?.cacheForNavigation === false) {\n existing.cacheForNavigation = true;\n }\n }\n return;\n }\n prefetched.add(cacheKey);\n prefetchRscResponse(\n rscUrl,\n fetch(rscUrl, {\n headers,\n credentials: \"include\",\n priority,\n // @ts-expect-error — purpose is a valid fetch option in some browsers\n purpose: \"prefetch\",\n }),\n interceptionContext,\n mountedSlotsHeader,\n undefined,\n {\n cacheForNavigation: autoPrefetch.cacheForNavigation,\n optimisticRouteShell: isOptimisticRouteShellPrefetch,\n },\n );\n } else if (window.__NEXT_DATA__) {\n // Pages Router prefetch. When a code-split loader is registered for\n // the target route (prod builds expose them on window via the\n // generated client entry), prefetch the data JSON + warm the page\n // chunk in parallel — matching the actual navigation, so the click\n // is a double cache hit. Otherwise (dev, or unmapped route) fall\n // back to the legacy `<link rel=\"prefetch\" as=\"document\">` so the\n // browser still preloads the HTML.\n //\n // The decision helper + prefetch action live in shims/internal/ so\n // this file does not pull in the router shim at module init time,\n // which would create a circular import and grow the SSR module graph.\n const dataTarget = resolvePagesDataNavigationTarget(fullHref, __basePath);\n if (dataTarget) {\n prefetchPagesData(dataTarget);\n } else {\n // The target is not a Pages Router route — mark it on the Pages\n // Router `components` map if it matches an App Router route in the\n // shared prefetch manifest. Mirrors Next.js's `_bfl` marker write at\n // `packages/next/src/shared/lib/router/router.ts:2525`; the Next.js\n // deploy test reads `window.next.router.components[<path>]` to\n // assert prefetch detection. See issue #1526.\n markAppRouteDetectedOnPrefetch(fullHref, __basePath);\n\n // Legacy fallback: hint the browser to preload the HTML document.\n // Used in dev (no loader map populated) and for routes not in the\n // client loader map.\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.href = fullHref;\n link.as = \"document\";\n document.head.appendChild(link);\n }\n }\n })().catch((error) => {\n console.error(\"[vinext] RSC prefetch setup error:\", error);\n });\n });\n}\n\nfunction promotePrefetchEntriesForNavigation(href: string): void {\n if (typeof window === \"undefined\") return;\n\n let target: URL;\n try {\n target = new URL(\n toBrowserNavigationHref(href, window.location.href, __basePath),\n window.location.href,\n );\n } catch {\n return;\n }\n\n for (const [cacheKey, entry] of getPrefetchCache()) {\n if (entry.optimisticRouteShell === true) continue;\n\n const [rscUrl] = cacheKey.split(\"\\0\", 1);\n let cached: URL;\n try {\n cached = new URL(rscUrl, window.location.href);\n } catch {\n continue;\n }\n stripRscCacheBustingSearchParam(cached);\n if (stripRscSuffix(cached.pathname) === target.pathname && cached.search === target.search) {\n entry.cacheForNavigation = true;\n }\n }\n}\n\n/**\n * Shared IntersectionObserver for viewport-based prefetching.\n * All Link elements use the same observer to minimize resource usage.\n */\nlet sharedObserver: IntersectionObserver | null = null;\ntype LinkPrefetchInstance = {\n href: string;\n isVisible: boolean;\n mode: LinkPrefetchMode;\n routerMode: LinkPrefetchRouterMode;\n viewportPrefetched: boolean;\n};\n\nconst observedLinkPrefetches = new WeakMap<Element, LinkPrefetchInstance>();\nconst visibleLinkPrefetches = new Set<LinkPrefetchInstance>();\n\nfunction setVisibleLinkPrefetch(instance: LinkPrefetchInstance, isVisible: boolean): void {\n instance.isVisible = isVisible;\n if (isVisible) {\n visibleLinkPrefetches.add(instance);\n if (instance.routerMode === \"pages\" && instance.viewportPrefetched) return;\n prefetchUrl(instance.href, instance.mode, \"low\");\n instance.viewportPrefetched = true;\n } else {\n visibleLinkPrefetches.delete(instance);\n }\n}\n\nfunction registerVisibleLinkPing(): void {\n if (typeof window === \"undefined\") return;\n registerNavigationRuntimeFunctions({ pingVisibleLinks: pingVisibleLinkPrefetches });\n}\n\nfunction pingVisibleLinkPrefetches(): void {\n for (const instance of visibleLinkPrefetches) {\n if (instance.isVisible && instance.routerMode === \"app\") {\n prefetchUrl(instance.href, instance.mode, \"low\");\n }\n }\n}\n\nfunction getSharedObserver(): IntersectionObserver | null {\n if (typeof window === \"undefined\" || typeof IntersectionObserver === \"undefined\") return null;\n if (sharedObserver) return sharedObserver;\n\n sharedObserver = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n const instance = observedLinkPrefetches.get(entry.target);\n if (!instance) continue;\n setVisibleLinkPrefetch(instance, entry.isIntersecting || entry.intersectionRatio > 0);\n }\n },\n {\n // Start prefetching when the link is within 250px of the viewport.\n // This gives the browser a head start before the user scrolls to it.\n rootMargin: \"250px\",\n },\n );\n\n return sharedObserver;\n}\n\nfunction getDefaultLocale(): string | undefined {\n if (typeof window !== \"undefined\") {\n return window.__VINEXT_DEFAULT_LOCALE__;\n }\n return getI18nContext()?.defaultLocale;\n}\n\nfunction getCurrentLocale(): string | undefined {\n if (typeof window !== \"undefined\") {\n return getCurrentBrowserLocale({\n basePath: __basePath,\n domainLocales: getDomainLocales(),\n hostname: getCurrentHostname(),\n });\n }\n return getI18nContext()?.locale;\n}\n\nfunction getDomainLocales(): readonly DomainLocale[] | undefined {\n if (typeof window !== \"undefined\") {\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.domainLocales;\n }\n return getI18nContext()?.domainLocales;\n}\n\nfunction getCurrentHostname(): string | undefined {\n if (typeof window !== \"undefined\") return window.location.hostname;\n return getI18nContext()?.hostname;\n}\n\nfunction getDomainLocaleHref(href: string, locale: string): string | undefined {\n // Only cross-domain locale switches need a special absolute URL here.\n // Same-domain cases fall back to the standard locale-prefix logic below.\n return getDomainLocaleUrl(href, locale, {\n basePath: __basePath,\n currentHostname: getCurrentHostname(),\n domainItems: getDomainLocales(),\n });\n}\n\nfunction addLocalePrefixForRoot(href: string, locale: string): string | undefined {\n if (href !== \"/\" && !href.startsWith(\"/?\") && !href.startsWith(\"/#\")) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(href, \"http://vinext.local\");\n } catch {\n return undefined;\n }\n\n if (parsed.origin !== \"http://vinext.local\" || parsed.pathname !== \"/\") {\n return undefined;\n }\n\n return `/${locale}${parsed.search}${parsed.hash}`;\n}\n\n/**\n * Apply locale prefix to a URL path based on the locale prop.\n * - locale=\"fr\" → prepend /fr (unless it already has a locale prefix)\n * - locale={false} → use the href as-is (no locale prefix, link to default)\n * - locale=undefined → use current locale (href as-is in most cases)\n */\nfunction applyLocaleToHref(href: string, locale: string | false | undefined): string {\n if (locale === false) {\n // Explicit false: no locale prefix\n return href;\n }\n\n const resolvedLocale = locale ?? getCurrentLocale();\n if (resolvedLocale === undefined) {\n return href;\n }\n\n // Absolute and protocol-relative URLs must not be prefixed — locale\n // only applies to local paths.\n if (isAbsoluteOrProtocolRelativeUrl(href)) {\n return href;\n }\n\n const domainLocaleHref = getDomainLocaleHref(href, resolvedLocale);\n if (domainLocaleHref) {\n return domainLocaleHref;\n }\n\n const defaultLocale = getDefaultLocale() ?? \"\";\n if (resolvedLocale.toLowerCase() === defaultLocale.toLowerCase()) {\n const localeRootHref = addLocalePrefixForRoot(href, resolvedLocale);\n if (localeRootHref) return localeRootHref;\n }\n\n return addLocalePrefix(href, resolvedLocale, defaultLocale);\n}\n\nconst Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(\n {\n href,\n as,\n replace = false,\n prefetch: prefetchProp,\n scroll = true,\n shallow = false,\n children: childrenProp,\n onClick,\n onMouseEnter,\n onTouchStart,\n onNavigate,\n unstable_dynamicOnHover = false,\n legacyBehavior = false,\n passHref = false,\n ...rest\n },\n forwardedRef,\n) {\n // Extract locale from rest props\n const { locale, ...restWithoutLocale } = rest;\n\n // Next.js parity: in legacyBehavior, a string or number child is wrapped in\n // a plain <a> so the cloneElement path below has an element to clone. The\n // wrapper anchor receives the forwarded href + handlers from Link.\n // Ported from Next.js: packages/next/src/client/link.tsx (around line 334)\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/client/link.tsx\n let children: React.ReactNode = childrenProp;\n if (legacyBehavior && (typeof childrenProp === \"string\" || typeof childrenProp === \"number\")) {\n children = React.createElement(\"a\", null, childrenProp);\n }\n\n // If `as` is provided, use it as the actual URL (legacy Next.js pattern\n // where href is a route pattern like \"/user/[id]\" and as is \"/user/1\")\n const rawResolvedHref = as ?? resolveHref(href);\n\n // Mirror Next.js: emit a console.error when the href contains repeated\n // forward-slashes (e.g. \"/foo//bar\") or backslashes, and then normalize the\n // href so navigation targets the collapsed path rather than the raw one.\n // See packages/next/src/client/resolve-href.ts.\n const resolvedHref =\n typeof rawResolvedHref === \"string\"\n ? warnAndNormalizeRepeatedSlashesInHref(rawResolvedHref)\n : rawResolvedHref;\n\n const isDangerous = typeof resolvedHref === \"string\" && isDangerousScheme(resolvedHref);\n\n // Apply locale prefix if specified (safe even for dangerous hrefs since we\n // won't use the result when isDangerous is true)\n const localizedHref = applyLocaleToHref(isDangerous ? \"/\" : resolvedHref, locale);\n // Normalise trailing slash to match `trailingSlash` config so that rendered\n // hrefs avoid the redirect bounce. Mirrors Next.js's `addLocale`/`addBasePath`,\n // both of which run `normalizePathTrailingSlash` after prefixing — we apply\n // it once after locale prefixing (for prefetch/navigation paths that bypass\n // basePath) and again after `withBasePath` for the rendered `href` attribute.\n const normalizedHref = normalizePathTrailingSlash(localizedHref, __trailingSlash);\n // Full href with basePath for browser URLs and fetches, normalised again so\n // that combining a non-empty basePath with the bare root (`/`) still\n // produces a canonical href under `trailingSlash: false` (e.g. `/foo`\n // rather than `/foo/`).\n const fullHref = normalizePathTrailingSlash(\n withBasePath(normalizedHref, __basePath),\n __trailingSlash,\n );\n\n // Track pending state for useLinkStatus()\n const [pending, setPending] = useState(false);\n const mountedRef = useRef(true);\n useEffect(() => {\n mountedRef.current = true;\n return () => {\n mountedRef.current = false;\n };\n }, []);\n\n // Prefetching: observe the element when it enters the viewport.\n // In App Router, null/undefined/\"auto\" is automatic prefetch and true opts\n // into a full RSC prefetch, matching Next.js's public prefetch contract.\n const internalRef = useRef<HTMLAnchorElement | null>(null);\n const prefetchMode = resolveLinkPrefetchMode(prefetchProp, isDangerous);\n const shouldViewportPrefetch = canLinkPrefetch({\n nodeEnv: process.env.NODE_ENV,\n prefetch: prefetchProp,\n isDangerous,\n });\n\n const setRefs = useCallback(\n (node: HTMLAnchorElement | null) => {\n internalRef.current = node;\n if (typeof forwardedRef === \"function\") forwardedRef(node);\n else if (forwardedRef)\n (forwardedRef as React.MutableRefObject<HTMLAnchorElement | null>).current = node;\n },\n [forwardedRef],\n );\n\n useEffect(() => {\n if (!shouldViewportPrefetch || typeof window === \"undefined\") return;\n const node = internalRef.current;\n if (!node) return;\n\n const hrefToPrefetch = getLinkPrefetchHref({\n href: normalizedHref,\n basePath: __basePath,\n currentOrigin: window.location.origin,\n });\n if (hrefToPrefetch == null) return;\n\n const observer = getSharedObserver();\n if (!observer) return;\n\n registerVisibleLinkPing();\n const instance: LinkPrefetchInstance = {\n href: hrefToPrefetch,\n isVisible: false,\n mode: prefetchMode,\n routerMode: getLinkPrefetchRouterMode(),\n viewportPrefetched: false,\n };\n observedLinkPrefetches.set(node, instance);\n observer.observe(node);\n\n return () => {\n observer.unobserve(node);\n observedLinkPrefetches.delete(node);\n visibleLinkPrefetches.delete(instance);\n };\n }, [shouldViewportPrefetch, prefetchMode, normalizedHref]);\n\n const prefetchOnIntent = useCallback(() => {\n if (\n !canLinkIntentPrefetch({\n nodeEnv: process.env.NODE_ENV,\n prefetch: prefetchProp,\n isDangerous,\n routerMode: getLinkPrefetchRouterMode(),\n })\n ) {\n return;\n }\n const intentMode = unstable_dynamicOnHover ? \"full\" : prefetchMode;\n if (unstable_dynamicOnHover && internalRef.current) {\n const instance = observedLinkPrefetches.get(internalRef.current);\n if (instance) {\n instance.mode = \"full\";\n }\n promotePrefetchEntriesForNavigation(normalizedHref);\n }\n prefetchUrl(normalizedHref, intentMode, \"high\");\n }, [prefetchProp, isDangerous, prefetchMode, normalizedHref, unstable_dynamicOnHover]);\n\n const handleMouseEnter = useCallback(\n (e: MouseEvent<HTMLAnchorElement>) => {\n onMouseEnter?.(e);\n prefetchOnIntent();\n },\n [onMouseEnter, prefetchOnIntent],\n );\n\n const handleTouchStart = useCallback(\n (e: TouchEvent<HTMLAnchorElement>) => {\n onTouchStart?.(e);\n prefetchOnIntent();\n },\n [onTouchStart, prefetchOnIntent],\n );\n\n const handleClick = async (\n e: MouseEvent<HTMLAnchorElement>,\n options: { skipLinkOnClick?: boolean } = {},\n ) => {\n // In legacyBehavior, the onClick prop on <Link> itself is ignored — the\n // child's onClick is the one that runs (and Next.js even warns when\n // `onClick` is passed to <Link> alongside `legacyBehavior`). Skip the\n // preamble that calls Link's own onClick when invoked from that path.\n // See: .nextjs-ref/packages/next/src/client/link.tsx (legacyBehavior branch).\n if (!options.skipLinkOnClick && onClick) onClick(e);\n if (e.defaultPrevented) return;\n\n // Native download links must keep the browser's default behavior.\n if (e.currentTarget.hasAttribute(\"download\")) {\n return;\n }\n\n // Only intercept left clicks without modifiers (standard link behavior)\n if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {\n return;\n }\n\n // Don't intercept links with target (e.g. target=\"_blank\")\n if (e.currentTarget.target && e.currentTarget.target !== \"_self\") {\n return;\n }\n\n // External links: let the browser handle it.\n // Same-origin absolute URLs (e.g. http://localhost:3000/about) are\n // normalized to local paths so they get client-side navigation.\n let navigateHref = normalizedHref;\n if (isAbsoluteOrProtocolRelativeUrl(resolvedHref)) {\n const localPath = toSameOriginAppPath(resolvedHref, __basePath);\n if (localPath == null) {\n // Truly external. Mirror Next.js `linkClicked`: when `replace` is set\n // we have to take over because the browser's default click navigation\n // pushes to history rather than replacing the current entry.\n // See `.nextjs-ref/packages/next/src/client/link.tsx` `linkClicked`.\n if (replace) {\n e.preventDefault();\n window.location.replace(resolvedHref);\n }\n return;\n }\n navigateHref = localPath;\n }\n\n e.preventDefault();\n\n // Resolve relative hrefs (#hash, ?query) against the current URL once so\n // onNavigate and the actual navigation target stay in sync.\n const absoluteHref = resolveRelativeHref(navigateHref, window.location.href, __basePath);\n const absoluteFullHref = toBrowserNavigationHref(\n navigateHref,\n window.location.href,\n __basePath,\n );\n\n // Call onNavigate callback if provided (Next.js 16 View Transitions support)\n if (onNavigate) {\n try {\n const navUrl = new URL(absoluteFullHref, window.location.origin);\n let prevented = false;\n const navEvent: NavigateEvent = {\n url: navUrl,\n preventDefault() {\n prevented = true;\n },\n get defaultPrevented() {\n return prevented;\n },\n };\n onNavigate(navEvent);\n // If the callback called preventDefault(), skip Link's default navigation.\n // The callback is responsible for its own navigation (e.g. via View Transitions API).\n if (navEvent.defaultPrevented) {\n return;\n }\n } catch {\n // Ignore URL parsing errors for relative/hash hrefs\n }\n }\n\n // App Router: delegate to navigateClientSide which handles scroll save,\n // hash-only changes, RSC fetch, and two-phase URL commit.\n if (getNavigationRuntime()?.functions.navigate) {\n setPending(true);\n React.startTransition(() => {\n void navigateClientSide(navigateHref, replace ? \"replace\" : \"push\", scroll, true).finally(\n () => {\n if (mountedRef.current) setPending(false);\n },\n );\n });\n return;\n } else {\n // Next.js only consumes onRouterTransitionStart in the App Router.\n // Pages Router still executes instrumentation-client side effects\n // during startup, but it does not invoke the named export on navigation.\n // Pages Router: use the Router singleton\n try {\n const routerModule = await import(\"next/router\");\n const Router = routerModule.default;\n await navigatePagesRouterLink(Router, {\n href: absoluteHref,\n replace,\n scroll,\n shallow,\n locale,\n });\n } catch {\n // Fallback to hard navigation if router fails\n if (replace) {\n window.history.replaceState({}, \"\", absoluteFullHref);\n } else {\n window.history.pushState({}, \"\", absoluteFullHref);\n }\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n }\n }\n };\n\n const anchorProps = restWithoutLocale;\n\n const linkStatusValue = React.useMemo(() => ({ pending }), [pending]);\n\n // Block dangerous URI schemes (javascript:, data:, vbscript:).\n // Render an inert <a> without href to prevent XSS while preserving\n // styling, refs, and developer event handlers like onClick.\n // This check is placed after all hooks to satisfy the Rules of Hooks.\n if (isDangerous) {\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(`<Link> blocked dangerous href: ${resolvedHref}`);\n }\n // Match Next.js parity: when a user clicks a Link whose href has a\n // dangerous scheme, emit the same `console.error` that Next.js surfaces\n // via React's event-handler runtime when `router.push` throws.\n // Ported from Next.js: test/e2e/app-dir/javascript-urls/javascript-urls.test.ts\n // https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/javascript-urls/javascript-urls.test.ts\n const handleDangerousClick = (event: MouseEvent<HTMLAnchorElement>): void => {\n if (onClick) onClick(event);\n reportBlockedDangerousNavigation();\n };\n // In legacyBehavior, clone the child instead of wrapping it in our own\n // <a>. Otherwise the dangerous-href branch would still produce nested\n // anchors. We do not forward the dangerous href to the child — Next.js's\n // safety guarantee is that the navigation never happens; the child can\n // keep its own (sanitized) href if it wants.\n if (legacyBehavior) {\n const child = React.Children.only(children) as React.ReactElement<{\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;\n ref?: React.Ref<HTMLAnchorElement>;\n }>;\n const childOnClick = child.props.onClick;\n const childRef = child.props.ref;\n const setDangerousRefs = (node: HTMLAnchorElement | null): void => {\n internalRef.current = node;\n if (typeof childRef === \"function\") {\n childRef(node);\n } else if (childRef) {\n (childRef as React.MutableRefObject<HTMLAnchorElement | null>).current = node;\n }\n };\n return (\n <LinkStatusContext.Provider value={linkStatusValue}>\n {React.cloneElement(child, {\n ref: setDangerousRefs,\n onClick: (event: MouseEvent<HTMLAnchorElement>) => {\n if (childOnClick) childOnClick(event);\n reportBlockedDangerousNavigation();\n },\n })}\n </LinkStatusContext.Provider>\n );\n }\n return (\n <LinkStatusContext.Provider value={linkStatusValue}>\n <a\n ref={setRefs}\n onClick={handleDangerousClick}\n onMouseEnter={handleMouseEnter}\n onTouchStart={handleTouchStart}\n {...anchorProps}\n >\n {children}\n </a>\n </LinkStatusContext.Provider>\n );\n }\n\n // Next.js parity: in legacyBehavior, forward href/handlers to the single\n // child via React.cloneElement instead of wrapping in our own <a>. This\n // avoids the nested-anchor markup that broke onClick propagation and\n // produced duplicated/hidden child content (issue #1469).\n //\n // Ported from Next.js: packages/next/src/client/link.tsx (around line 499)\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/client/link.tsx\n if (legacyBehavior) {\n const child = React.Children.only(children) as React.ReactElement<{\n href?: string;\n ref?: React.Ref<HTMLAnchorElement>;\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;\n onMouseEnter?: (event: MouseEvent<HTMLAnchorElement>) => void;\n onTouchStart?: (event: TouchEvent<HTMLAnchorElement>) => void;\n }>;\n if (process.env.NODE_ENV !== \"production\") {\n if (onClick) {\n console.warn(\n `\"onClick\" was passed to <Link> with \\`href\\` of \\`${resolveHref(href)}\\` but \"legacyBehavior\" was set. The legacy behavior requires onClick be set on the child of next/link`,\n );\n }\n if (onMouseEnter) {\n console.warn(\n `\"onMouseEnter\" was passed to <Link> with \\`href\\` of \\`${resolveHref(href)}\\` but \"legacyBehavior\" was set. The legacy behavior requires onMouseEnter be set on the child of next/link`,\n );\n }\n }\n const childPropsExisting = child.props;\n // Use `'href' in props` (matches Next.js) so `href={undefined}` on the\n // child is treated as \"the child owns its href\" — we won't overwrite it.\n const childHasOwnHref = child.type === \"a\" ? \"href\" in childPropsExisting : false;\n // Match Next.js: forward href when `passHref` is set OR the child is a\n // plain <a> that does not already have an href. Otherwise, leave the\n // child's href alone.\n const shouldForwardHref = passHref || (child.type === \"a\" && !childHasOwnHref);\n const childOnClick = childPropsExisting.onClick;\n const childOnMouseEnter = childPropsExisting.onMouseEnter;\n const childOnTouchStart = childPropsExisting.onTouchStart;\n // Mirror Next.js: in legacy mode, the ref source is the child's own\n // ref (e.g. `<a ref={myRef}>`), not Link's `forwardedRef`. In React 19\n // `ref` is a regular prop on the element. Merge with our intersection\n // observer ref via `setRefs` so prefetching still works.\n const childRef = childPropsExisting.ref;\n const setLegacyRefs = (node: HTMLAnchorElement | null): void => {\n internalRef.current = node;\n if (typeof childRef === \"function\") {\n childRef(node);\n } else if (childRef) {\n (childRef as React.MutableRefObject<HTMLAnchorElement | null>).current = node;\n }\n };\n const clonedProps: Record<string, unknown> = {\n ref: setLegacyRefs,\n onClick: (event: MouseEvent<HTMLAnchorElement>) => {\n // Next.js parity: only the child's onClick runs in legacy mode. The\n // onClick prop on <Link> is intentionally ignored (and a dev warning\n // surfaces it above).\n if (childOnClick) childOnClick(event);\n if (event.defaultPrevented) return;\n void handleClick(event, { skipLinkOnClick: true });\n },\n onMouseEnter: (event: MouseEvent<HTMLAnchorElement>) => {\n if (childOnMouseEnter) childOnMouseEnter(event);\n prefetchOnIntent();\n },\n onTouchStart: (event: TouchEvent<HTMLAnchorElement>) => {\n if (childOnTouchStart) childOnTouchStart(event);\n prefetchOnIntent();\n },\n };\n if (shouldForwardHref) {\n clonedProps.href = fullHref;\n }\n return (\n <LinkStatusContext.Provider value={linkStatusValue}>\n {React.cloneElement(child, clonedProps)}\n </LinkStatusContext.Provider>\n );\n }\n\n return (\n <LinkStatusContext.Provider value={linkStatusValue}>\n <a\n ref={setRefs}\n href={fullHref}\n onClick={(event) => {\n void handleClick(event);\n }}\n onMouseEnter={handleMouseEnter}\n onTouchStart={handleTouchStart}\n {...anchorProps}\n >\n {children}\n </a>\n </LinkStatusContext.Provider>\n );\n});\n\nexport default Link;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4IA,MAAM,oBAAoB,cAAsC,EAAE,SAAS,OAAO,CAAC;;;;;;AAOnF,SAAgB,gBAAwC;CACtD,OAAO,WAAW,kBAAkB;;;AAItC,MAAM,aAAqB,QAAQ,IAAI,0BAA0B;;AAEjE,MAAM,kBAA2B,QAAQ,IAAI,4BAA4B;AACzE,MAAM,6BAA6B,sBAA+C;AAElF,SAAS,YAAY,MAAiC;CACpD,IAAI,OAAO,SAAS,UAAU,OAAO;CACrC,IAAI,MAAM,KAAK,YAAY;CAC3B,IAAI,KAAK,OAAO;EACd,MAAM,SAAS,uBAAuB,KAAK,MAAM;EACjD,MAAM,wBAAwB,KAAK,OAAO;;CAE5C,OAAO;;;;;;;;;AAUT,SAAS,yBAAyB,KAAqB;CACrD,MAAM,WAAW,IAAI,MAAM,IAAI;CAC/B,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tB,SAAS,KAAK;QACT,IAAI,UACT,SAA+D,UAAU;;EAG7E,MAAM,cAAuC;GAC3C,KAAK;GACL,UAAU,UAAyC;IAIjD,IAAI,cAAc,aAAa,MAAM;IACrC,IAAI,MAAM,kBAAkB;IAC5B,YAAiB,OAAO,EAAE,iBAAiB,MAAM,CAAC;;GAEpD,eAAe,UAAyC;IACtD,IAAI,mBAAmB,kBAAkB,MAAM;IAC/C,kBAAkB;;GAEpB,eAAe,UAAyC;IACtD,IAAI,mBAAmB,kBAAkB,MAAM;IAC/C,kBAAkB;;GAErB;EACD,IAAI,mBACF,YAAY,OAAO;EAErB,OACE,oBAAC,kBAAkB,UAAnB;GAA4B,OAAO;aAChC,MAAM,aAAa,OAAO,YAAY;GACZ,CAAA;;CAIjC,OACE,oBAAC,kBAAkB,UAAnB;EAA4B,OAAO;YACjC,oBAAC,KAAD;GACE,KAAK;GACL,MAAM;GACN,UAAU,UAAU;IAClB,YAAiB,MAAM;;GAEzB,cAAc;GACd,cAAc;GACd,GAAI;GAEH;GACC,CAAA;EACuB,CAAA;EAE/B"}
|
package/dist/shims/metadata.d.ts
CHANGED
|
@@ -201,16 +201,17 @@ type AppleIconDescriptor = {
|
|
|
201
201
|
};
|
|
202
202
|
type IconInput = string | URL | IconDescriptor;
|
|
203
203
|
type AppleIconInput = string | URL | AppleIconDescriptor;
|
|
204
|
+
type OtherIconDescriptor = {
|
|
205
|
+
rel: string;
|
|
206
|
+
url: string | URL;
|
|
207
|
+
sizes?: string;
|
|
208
|
+
type?: string;
|
|
209
|
+
};
|
|
204
210
|
type IconsMap = {
|
|
205
211
|
icon?: IconInput | IconInput[];
|
|
206
212
|
shortcut?: string | URL | Array<string | URL>;
|
|
207
213
|
apple?: AppleIconInput | AppleIconInput[];
|
|
208
|
-
other?:
|
|
209
|
-
rel: string;
|
|
210
|
-
url: string | URL;
|
|
211
|
-
sizes?: string;
|
|
212
|
-
type?: string;
|
|
213
|
-
}>;
|
|
214
|
+
other?: OtherIconDescriptor | OtherIconDescriptor[];
|
|
214
215
|
};
|
|
215
216
|
type IconsMetadata = IconInput | IconInput[] | IconsMap;
|
|
216
217
|
type MetadataMergeEntry = {
|
|
@@ -271,10 +272,11 @@ type MetadataHeadProps = {
|
|
|
271
272
|
metadata: Metadata;
|
|
272
273
|
pathname?: string;
|
|
273
274
|
};
|
|
275
|
+
declare function renderMetadataToHtml(metadata: Metadata, pathname?: string): string;
|
|
274
276
|
declare function MetadataHead({
|
|
275
277
|
metadata,
|
|
276
278
|
pathname
|
|
277
279
|
}: MetadataHeadProps): _$react_jsx_runtime0.JSX.Element;
|
|
278
280
|
//#endregion
|
|
279
|
-
export { DEFAULT_VIEWPORT, Metadata, MetadataHead, MetadataMergeEntry, Viewport, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, resolveModuleMetadata, resolveModuleViewport };
|
|
281
|
+
export { DEFAULT_VIEWPORT, Metadata, MetadataHead, MetadataMergeEntry, Viewport, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, renderMetadataToHtml, resolveModuleMetadata, resolveModuleViewport };
|
|
280
282
|
//# sourceMappingURL=metadata.d.ts.map
|
package/dist/shims/metadata.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { isAbsoluteOrProtocolRelativeUrl } from "./url-utils.js";
|
|
2
2
|
import { makeThenableParams } from "./thenable-params.js";
|
|
3
|
-
import "react";
|
|
3
|
+
import React from "react";
|
|
4
4
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/shims/metadata.tsx
|
|
6
6
|
/**
|
|
7
|
+
* Metadata support for App Router.
|
|
8
|
+
*
|
|
9
|
+
* Handles `export const metadata` and `export async function generateMetadata()`.
|
|
10
|
+
* Resolves metadata from layouts and pages (pages override layouts).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
7
13
|
* Resolve viewport config from a module. Handles both static `viewport` export
|
|
8
14
|
* and async `generateViewport()` function.
|
|
9
15
|
*/
|
|
@@ -306,6 +312,59 @@ function resolveSocialImageUrl(image, metadataBase) {
|
|
|
306
312
|
if (typeof imageUrl === "string" && !isAbsoluteOrProtocolRelativeUrl(imageUrl) && (!metadataBase || metadataRoute)) return resolveMetadataUrl(imageUrl, getSocialImageMetadataBaseFallback(metadataBase));
|
|
307
313
|
return resolveMetadataUrl(imageUrl, metadataBase);
|
|
308
314
|
}
|
|
315
|
+
function escapeHtmlText(value) {
|
|
316
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
317
|
+
}
|
|
318
|
+
function escapeHtmlAttribute(value) {
|
|
319
|
+
return escapeHtmlText(value).replaceAll("\"", """);
|
|
320
|
+
}
|
|
321
|
+
function renderMetadataText(node) {
|
|
322
|
+
if (node === null || node === void 0 || typeof node === "boolean") return "";
|
|
323
|
+
if (Array.isArray(node)) return node.map(renderMetadataText).join("");
|
|
324
|
+
if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") return escapeHtmlText(String(node));
|
|
325
|
+
return "";
|
|
326
|
+
}
|
|
327
|
+
function renderMetadataAttributes(props, names) {
|
|
328
|
+
const attributes = [];
|
|
329
|
+
for (const name of names) {
|
|
330
|
+
const value = Reflect.get(props, name);
|
|
331
|
+
if (value === null || value === void 0 || typeof value === "boolean") continue;
|
|
332
|
+
const htmlName = name === "hrefLang" ? "hreflang" : name;
|
|
333
|
+
attributes.push(`${htmlName}="${escapeHtmlAttribute(String(value))}"`);
|
|
334
|
+
}
|
|
335
|
+
return attributes.length > 0 ? ` ${attributes.join(" ")}` : "";
|
|
336
|
+
}
|
|
337
|
+
function renderMetadataElementToHtml(node) {
|
|
338
|
+
if (node === null || node === void 0 || typeof node === "boolean") return "";
|
|
339
|
+
if (Array.isArray(node)) return node.map(renderMetadataElementToHtml).join("");
|
|
340
|
+
if (!React.isValidElement(node)) return renderMetadataText(node);
|
|
341
|
+
const props = typeof node.props === "object" && node.props !== null ? node.props : {};
|
|
342
|
+
if (node.type === React.Fragment) return renderMetadataElementToHtml(Reflect.get(props, "children"));
|
|
343
|
+
if (typeof node.type !== "string") return "";
|
|
344
|
+
switch (node.type) {
|
|
345
|
+
case "title": return `<title>${renderMetadataText(Reflect.get(props, "children"))}</title>`;
|
|
346
|
+
case "meta": return `<meta${renderMetadataAttributes(props, [
|
|
347
|
+
"name",
|
|
348
|
+
"property",
|
|
349
|
+
"content"
|
|
350
|
+
])}>`;
|
|
351
|
+
case "link": return `<link${renderMetadataAttributes(props, [
|
|
352
|
+
"rel",
|
|
353
|
+
"href",
|
|
354
|
+
"hrefLang",
|
|
355
|
+
"media",
|
|
356
|
+
"type",
|
|
357
|
+
"sizes"
|
|
358
|
+
])}>`;
|
|
359
|
+
default: return "";
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function renderMetadataToHtml(metadata, pathname = "/") {
|
|
363
|
+
return renderMetadataElementToHtml(MetadataHead({
|
|
364
|
+
metadata,
|
|
365
|
+
pathname
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
309
368
|
function MetadataHead({ metadata, pathname = "/" }) {
|
|
310
369
|
const elements = [];
|
|
311
370
|
let key = 0;
|
|
@@ -614,11 +673,15 @@ function MetadataHead({ metadata, pathname = "/" }) {
|
|
|
614
673
|
...a.sizes ? { sizes: a.sizes } : {},
|
|
615
674
|
...a.type ? { type: a.type } : {}
|
|
616
675
|
}, key++));
|
|
617
|
-
if (isIconsMap(metadata.icons) && metadata.icons.other)
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
676
|
+
if (isIconsMap(metadata.icons) && metadata.icons.other) {
|
|
677
|
+
const others = Array.isArray(metadata.icons.other) ? metadata.icons.other : [metadata.icons.other];
|
|
678
|
+
for (const o of others) elements.push(/* @__PURE__ */ jsx("link", {
|
|
679
|
+
rel: o.rel,
|
|
680
|
+
href: stringifyUrl(o.url),
|
|
681
|
+
...o.sizes ? { sizes: o.sizes } : {},
|
|
682
|
+
...o.type ? { type: o.type } : {}
|
|
683
|
+
}, key++));
|
|
684
|
+
}
|
|
622
685
|
}
|
|
623
686
|
if (metadata.manifest) elements.push(/* @__PURE__ */ jsx("link", {
|
|
624
687
|
rel: "manifest",
|
|
@@ -736,6 +799,6 @@ function MetadataHead({ metadata, pathname = "/" }) {
|
|
|
736
799
|
return /* @__PURE__ */ jsx(Fragment$1, { children: elements });
|
|
737
800
|
}
|
|
738
801
|
//#endregion
|
|
739
|
-
export { DEFAULT_VIEWPORT, MetadataHead, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, resolveModuleMetadata, resolveModuleViewport };
|
|
802
|
+
export { DEFAULT_VIEWPORT, MetadataHead, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, renderMetadataToHtml, resolveModuleMetadata, resolveModuleViewport };
|
|
740
803
|
|
|
741
804
|
//# sourceMappingURL=metadata.js.map
|