vinext 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build/clean-output.d.ts +14 -0
- package/dist/build/clean-output.js +36 -0
- package/dist/build/clean-output.js.map +1 -0
- package/dist/build/prerender.d.ts +6 -2
- package/dist/build/prerender.js +49 -11
- 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/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 +14 -1
- 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 +10 -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 +12 -3
- package/dist/config/next-config.js +44 -14
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +29 -7
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -2
- package/dist/entries/app-rsc-entry.js +23 -3
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.js +22 -1
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +211 -31
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/dist/plugins/fonts.js +25 -2
- package/dist/plugins/fonts.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 +18 -9
- 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 +22 -12
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-elements.js +1 -1
- package/dist/server/app-fallback-renderer.d.ts +12 -3
- package/dist/server/app-fallback-renderer.js +10 -5
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-history-state.js +6 -2
- package/dist/server/app-history-state.js.map +1 -1
- package/dist/server/app-interception-context-header.d.ts +33 -0
- package/dist/server/app-interception-context-header.js +44 -0
- package/dist/server/app-interception-context-header.js.map +1 -0
- package/dist/server/app-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 +1 -0
- package/dist/server/app-page-boundary.js +2 -0
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +2 -0
- package/dist/server/app-page-cache.js +7 -1
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +3 -0
- package/dist/server/app-page-dispatch.js +11 -4
- 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 +5 -2
- 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-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +1 -0
- package/dist/server/app-page-render.js +5 -2
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-response.d.ts +11 -1
- package/dist/server/app-page-response.js +14 -2
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +19 -6
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +1 -0
- package/dist/server/app-page-stream.js +2 -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 +1 -1
- package/dist/server/app-rsc-handler.d.ts +2 -0
- package/dist/server/app-rsc-handler.js +18 -9
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.js +3 -2
- 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 +1 -0
- package/dist/server/app-server-action-execution.js +4 -0
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.js +39 -3
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +24 -1
- package/dist/server/app-ssr-stream.js +78 -5
- 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/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 +1 -1
- package/dist/server/dev-server.js +23 -7
- 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/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/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-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 +16 -14
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +2 -0
- package/dist/server/pages-page-response.js +11 -8
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prerender-route-params.d.ts +14 -0
- package/dist/server/prerender-route-params.js +94 -0
- package/dist/server/prerender-route-params.js.map +1 -0
- package/dist/server/prod-server.d.ts +3 -23
- package/dist/server/prod-server.js +40 -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/static-file-cache.js +1 -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 +12 -0
- package/dist/shims/app-router-scroll-state.js +38 -0
- package/dist/shims/app-router-scroll-state.js.map +1 -0
- package/dist/shims/app-router-scroll.d.ts +14 -0
- package/dist/shims/app-router-scroll.js +100 -0
- package/dist/shims/app-router-scroll.js.map +1 -0
- package/dist/shims/before-interactive-context.d.ts +30 -0
- package/dist/shims/before-interactive-context.js +10 -0
- package/dist/shims/before-interactive-context.js.map +1 -0
- package/dist/shims/cache-runtime.d.ts +1 -1
- package/dist/shims/cache-runtime.js +14 -1
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/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/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 +6 -2
- package/dist/shims/headers.js +64 -21
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.d.ts +1 -1
- package/dist/shims/image.js +4 -4
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/pages-data-target.d.ts +58 -0
- package/dist/shims/internal/pages-data-target.js +91 -0
- package/dist/shims/internal/pages-data-target.js.map +1 -0
- package/dist/shims/internal/pages-data-url.d.ts +42 -0
- package/dist/shims/internal/pages-data-url.js +73 -0
- package/dist/shims/internal/pages-data-url.js.map +1 -0
- package/dist/shims/link.js +59 -9
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +2 -1
- package/dist/shims/metadata.js +61 -2
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.js +32 -9
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/router.js +376 -77
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.js +86 -12
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.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/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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages-data-target.js","names":[],"sources":["../../../src/shims/internal/pages-data-target.ts"],"sourcesContent":["/**\n * Shared decision helper for the Pages Router `/_next/data/<id>/<page>.json`\n * navigation fast path. Used by both the router shim (for `navigateClient` and\n * `Router.prefetch`) and the Link shim (for hover/viewport prefetch).\n *\n * Lives in `shims/internal/` so neither caller pulls in the router shim at\n * module init time — link.tsx and router.ts must remain free of circular\n * imports and SSR-side router-init side effects.\n */\nimport { stripBasePath } from \"../../utils/base-path.js\";\nimport { getLocalePathPrefix } from \"../../utils/domain-locale.js\";\nimport type { VinextNextData } from \"../../client/vinext-next-data.js\";\nimport { buildPagesDataHref, matchPagesPattern } from \"./pages-data-url.js\";\n\nexport type PagesDataTarget = {\n /** Final fetch URL for the data endpoint, including basePath and search. */\n dataHref: string;\n /** Matched route pattern (e.g. `/blog/[slug]`). */\n pattern: string;\n /** Dynamic params extracted from the URL by the pattern matcher. */\n params: Record<string, string | string[]>;\n /** Code-split loader thunk for the matched route's page module. */\n loader: () => Promise<{ default?: unknown; [key: string]: unknown }>;\n /** Current buildId snapshot, used by the data URL and consistency checks. */\n buildId: string;\n /** Locale-prefixed (server-routable) page path. */\n pagePath: string;\n /** URL search string including the leading `?`. */\n search: string;\n /**\n * Locale prefix detected on the URL, or `undefined` when the URL is\n * unprefixed (default locale, or no i18n configured). Lets the caller refresh\n * locale state on locale transitions, which the data JSON envelope itself\n * does not carry.\n */\n locale: string | undefined;\n};\n\n/**\n * Decide whether the JSON data-endpoint navigation path is usable for this\n * browser URL. We require:\n * - A registered code-split loader for the matched route pattern. Without\n * this, the client has no chunk URL to import for the new page.\n * - A buildId on the current `__NEXT_DATA__`, since the data URL embeds it.\n * - Same-origin (cross-origin URLs do not hit our data endpoint).\n *\n * Locale handling: route patterns in `__VINEXT_PAGE_PATTERNS__` are\n * locale-unaware (`/about`, not `/fr/about`), but the browser URL for a\n * locale-prefixed page is `/fr/about`. We strip the locale prefix before\n * pattern matching so locale transitions hit the JSON fast path. The data URL\n * itself keeps the locale prefix because the server uses it to pick\n * locale-specific gSSP data.\n *\n * Returns the resolved target, or `null` to signal the caller should fall\n * back to the HTML extraction path (dev server, or a route that exists on the\n * server but is not in the client loader map).\n *\n * Ported from Next.js: `packages/next/src/client/page-loader.ts`\n * (`getDataHref`). vinext's equivalent uses an in-memory loader map instead\n * of Next.js' `_buildManifest.js`.\n */\nexport function resolvePagesDataNavigationTarget(\n browserUrl: string,\n basePath: string,\n): PagesDataTarget | null {\n if (typeof window === \"undefined\") return null;\n\n const loaders = window.__VINEXT_PAGE_LOADERS__;\n const patterns = window.__VINEXT_PAGE_PATTERNS__;\n if (!loaders || !patterns || patterns.length === 0) return null;\n\n const buildId = (window.__NEXT_DATA__ as VinextNextData | undefined)?.buildId ?? undefined;\n if (!buildId) return null;\n\n let parsed: URL;\n try {\n parsed = new URL(browserUrl, window.location.href);\n } catch {\n return null;\n }\n if (parsed.origin !== window.location.origin) return null;\n\n const pagePath = stripBasePath(parsed.pathname, basePath);\n const locale = getLocalePathPrefix(pagePath, window.__VINEXT_LOCALES__);\n // `locale.length + 1` skips the `/<locale>` segment. If only the locale was\n // present (`/fr`) the remainder is empty, which normalises to `/` (root).\n const pathForMatch = locale ? pagePath.slice(locale.length + 1) || \"/\" : pagePath;\n\n const match = matchPagesPattern(pathForMatch, patterns);\n if (!match) return null;\n\n const loader = loaders[match.pattern];\n if (!loader) return null;\n\n return {\n dataHref: buildPagesDataHref(basePath, buildId, pagePath, parsed.search),\n pattern: match.pattern,\n params: match.params,\n loader,\n buildId,\n pagePath,\n search: parsed.search,\n locale,\n };\n}\n\n/**\n * Inject a `<link rel=\"prefetch\">` for the data JSON and kick off the\n * code-split loader so the chunk is warm by the time the user clicks.\n *\n * Used by both `Router.prefetch()` and `<Link>` hover/viewport prefetch. The\n * loader's returned Promise is intentionally discarded — `import()` caches the\n * result, so a subsequent navigation re-invocation hits the cache without\n * paying for a second round trip. Errors are swallowed: prefetch is\n * best-effort and must never break the page.\n */\nexport function prefetchPagesData(target: PagesDataTarget): void {\n if (typeof document === \"undefined\") return;\n\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.as = \"fetch\";\n link.crossOrigin = \"anonymous\";\n link.href = target.dataHref;\n document.head.appendChild(link);\n\n void target.loader().catch(() => {});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,iCACd,YACA,UACwB;CACxB,IAAI,OAAO,WAAW,aAAa,OAAO;CAE1C,MAAM,UAAU,OAAO;CACvB,MAAM,WAAW,OAAO;CACxB,IAAI,CAAC,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,OAAO;CAE3D,MAAM,UAAW,OAAO,eAA8C,WAAW,KAAA;CACjF,IAAI,CAAC,SAAS,OAAO;CAErB,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,YAAY,OAAO,SAAS,KAAK;SAC5C;EACN,OAAO;;CAET,IAAI,OAAO,WAAW,OAAO,SAAS,QAAQ,OAAO;CAErD,MAAM,WAAW,cAAc,OAAO,UAAU,SAAS;CACzD,MAAM,SAAS,oBAAoB,UAAU,OAAO,mBAAmB;CAKvE,MAAM,QAAQ,kBAFO,SAAS,SAAS,MAAM,OAAO,SAAS,EAAE,IAAI,MAAM,UAE3B,SAAS;CACvD,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,SAAS,QAAQ,MAAM;CAC7B,IAAI,CAAC,QAAQ,OAAO;CAEpB,OAAO;EACL,UAAU,mBAAmB,UAAU,SAAS,UAAU,OAAO,OAAO;EACxE,SAAS,MAAM;EACf,QAAQ,MAAM;EACd;EACA;EACA;EACA,QAAQ,OAAO;EACf;EACD;;;;;;;;;;;;AAaH,SAAgB,kBAAkB,QAA+B;CAC/D,IAAI,OAAO,aAAa,aAAa;CAErC,MAAM,OAAO,SAAS,cAAc,OAAO;CAC3C,KAAK,MAAM;CACX,KAAK,KAAK;CACV,KAAK,cAAc;CACnB,KAAK,OAAO,OAAO;CACnB,SAAS,KAAK,YAAY,KAAK;CAE/B,OAAY,QAAQ,CAAC,YAAY,GAAG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/shims/internal/pages-data-url.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Append `.json` and the `/_next/data/<buildId>` prefix to a page pathname.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors Next.js' `getAssetPathFromRoute` + `getDataHref` behaviour:
|
|
6
|
+
* `/` → `/_next/data/<id>/index.json`
|
|
7
|
+
* `/about` → `/_next/data/<id>/about.json`
|
|
8
|
+
* `/index` → `/_next/data/<id>/index/index.json` (explicit `/index` page)
|
|
9
|
+
* `/blog/foo` → `/_next/data/<id>/blog/foo.json`
|
|
10
|
+
*
|
|
11
|
+
* `pagePath` is the resolved page pathname (already including any locale
|
|
12
|
+
* prefix and dynamic-param substitution), with a leading slash and NO
|
|
13
|
+
* trailing slash. The function does not URL-encode — the caller is expected
|
|
14
|
+
* to have produced a server-routable path.
|
|
15
|
+
*/
|
|
16
|
+
declare function buildPagesDataPath(buildId: string, pagePath: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build the full data URL including the basePath, the search string, and the
|
|
19
|
+
* `/_next/data/<buildId>/<page>.json` segment.
|
|
20
|
+
*
|
|
21
|
+
* `pagePath` must already be the resolved pathname (param-substituted,
|
|
22
|
+
* locale-prefixed where applicable). `search` includes the leading `?`.
|
|
23
|
+
*/
|
|
24
|
+
declare function buildPagesDataHref(basePath: string, buildId: string, pagePath: string, search: string): string;
|
|
25
|
+
/** Result of matching a URL pathname against the registered route patterns. */
|
|
26
|
+
type PagesPatternMatch = {
|
|
27
|
+
/** The matched route pattern in Next.js bracket format (e.g. `/blog/[slug]`). */pattern: string; /** Dynamic route params extracted from the URL. */
|
|
28
|
+
params: Record<string, string | string[]>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Find the route pattern (Next.js bracket format) that matches `pathname`.
|
|
32
|
+
*
|
|
33
|
+
* Patterns are tried in `patterns` order — callers should pre-sort so more
|
|
34
|
+
* specific patterns come before catch-alls. Returns `null` when no pattern
|
|
35
|
+
* matches, so the caller can fall back to a hard navigation (this is how
|
|
36
|
+
* vinext handles routes that exist on the server but are not in the
|
|
37
|
+
* client-side loader map, e.g. dev-only pages).
|
|
38
|
+
*/
|
|
39
|
+
declare function matchPagesPattern(pathname: string, patterns: readonly string[]): PagesPatternMatch | null;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { buildPagesDataHref, buildPagesDataPath, matchPagesPattern };
|
|
42
|
+
//# sourceMappingURL=pages-data-url.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { matchRoutePattern, routePatternParts } from "../../routing/route-pattern.js";
|
|
2
|
+
//#region src/shims/internal/pages-data-url.ts
|
|
3
|
+
/**
|
|
4
|
+
* Client-side helpers for the Pages Router `/_next/data/<buildId>/<page>.json`
|
|
5
|
+
* endpoint.
|
|
6
|
+
*
|
|
7
|
+
* Ported from Next.js:
|
|
8
|
+
* - `packages/next/src/client/page-loader.ts` (`getDataHref`)
|
|
9
|
+
* - `packages/next/src/shared/lib/router/utils/get-asset-path-from-route.ts`
|
|
10
|
+
*
|
|
11
|
+
* The server-side counterpart lives in `server/pages-data-route.ts` and parses
|
|
12
|
+
* the URL shape this module generates. Keep the two in sync — they are the
|
|
13
|
+
* wire-format contract between vinext's client navigation and its data
|
|
14
|
+
* endpoint.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Append `.json` and the `/_next/data/<buildId>` prefix to a page pathname.
|
|
18
|
+
*
|
|
19
|
+
* Mirrors Next.js' `getAssetPathFromRoute` + `getDataHref` behaviour:
|
|
20
|
+
* `/` → `/_next/data/<id>/index.json`
|
|
21
|
+
* `/about` → `/_next/data/<id>/about.json`
|
|
22
|
+
* `/index` → `/_next/data/<id>/index/index.json` (explicit `/index` page)
|
|
23
|
+
* `/blog/foo` → `/_next/data/<id>/blog/foo.json`
|
|
24
|
+
*
|
|
25
|
+
* `pagePath` is the resolved page pathname (already including any locale
|
|
26
|
+
* prefix and dynamic-param substitution), with a leading slash and NO
|
|
27
|
+
* trailing slash. The function does not URL-encode — the caller is expected
|
|
28
|
+
* to have produced a server-routable path.
|
|
29
|
+
*/
|
|
30
|
+
function buildPagesDataPath(buildId, pagePath) {
|
|
31
|
+
let path = pagePath;
|
|
32
|
+
if (path.length > 1 && path.endsWith("/")) path = path.slice(0, -1);
|
|
33
|
+
let asset;
|
|
34
|
+
if (path === "/") asset = "/index";
|
|
35
|
+
else if (path === "/index" || path.startsWith("/index/")) asset = "/index" + path;
|
|
36
|
+
else asset = path;
|
|
37
|
+
return `/_next/data/${buildId}${asset}.json`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build the full data URL including the basePath, the search string, and the
|
|
41
|
+
* `/_next/data/<buildId>/<page>.json` segment.
|
|
42
|
+
*
|
|
43
|
+
* `pagePath` must already be the resolved pathname (param-substituted,
|
|
44
|
+
* locale-prefixed where applicable). `search` includes the leading `?`.
|
|
45
|
+
*/
|
|
46
|
+
function buildPagesDataHref(basePath, buildId, pagePath, search) {
|
|
47
|
+
const dataPath = buildPagesDataPath(buildId, pagePath);
|
|
48
|
+
return `${basePath ? basePath : ""}${dataPath}${search}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Find the route pattern (Next.js bracket format) that matches `pathname`.
|
|
52
|
+
*
|
|
53
|
+
* Patterns are tried in `patterns` order — callers should pre-sort so more
|
|
54
|
+
* specific patterns come before catch-alls. Returns `null` when no pattern
|
|
55
|
+
* matches, so the caller can fall back to a hard navigation (this is how
|
|
56
|
+
* vinext handles routes that exist on the server but are not in the
|
|
57
|
+
* client-side loader map, e.g. dev-only pages).
|
|
58
|
+
*/
|
|
59
|
+
function matchPagesPattern(pathname, patterns) {
|
|
60
|
+
const urlParts = pathname.split("/").filter(Boolean);
|
|
61
|
+
for (const pattern of patterns) {
|
|
62
|
+
const params = matchRoutePattern(urlParts, routePatternParts(pattern));
|
|
63
|
+
if (params !== null) return {
|
|
64
|
+
pattern,
|
|
65
|
+
params
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { buildPagesDataHref, buildPagesDataPath, matchPagesPattern };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=pages-data-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages-data-url.js","names":[],"sources":["../../../src/shims/internal/pages-data-url.ts"],"sourcesContent":["/**\n * Client-side helpers for the Pages Router `/_next/data/<buildId>/<page>.json`\n * endpoint.\n *\n * Ported from Next.js:\n * - `packages/next/src/client/page-loader.ts` (`getDataHref`)\n * - `packages/next/src/shared/lib/router/utils/get-asset-path-from-route.ts`\n *\n * The server-side counterpart lives in `server/pages-data-route.ts` and parses\n * the URL shape this module generates. Keep the two in sync — they are the\n * wire-format contract between vinext's client navigation and its data\n * endpoint.\n */\nimport { matchRoutePattern, routePatternParts } from \"../../routing/route-pattern.js\";\n\n/**\n * Append `.json` and the `/_next/data/<buildId>` prefix to a page pathname.\n *\n * Mirrors Next.js' `getAssetPathFromRoute` + `getDataHref` behaviour:\n * `/` → `/_next/data/<id>/index.json`\n * `/about` → `/_next/data/<id>/about.json`\n * `/index` → `/_next/data/<id>/index/index.json` (explicit `/index` page)\n * `/blog/foo` → `/_next/data/<id>/blog/foo.json`\n *\n * `pagePath` is the resolved page pathname (already including any locale\n * prefix and dynamic-param substitution), with a leading slash and NO\n * trailing slash. The function does not URL-encode — the caller is expected\n * to have produced a server-routable path.\n */\nexport function buildPagesDataPath(buildId: string, pagePath: string): string {\n // Strip trailing slash except for the root path.\n let path = pagePath;\n if (path.length > 1 && path.endsWith(\"/\")) {\n path = path.slice(0, -1);\n }\n\n // Next.js' `getAssetPathFromRoute` denormalisation:\n // \"/\" → \"/index\"\n // \"/index\" → \"/index/index\"\n // \"/index/foo\" → \"/index/index/foo\"\n // This mirrors `pages/index.tsx → /` and disambiguates an explicit\n // `pages/index.tsx` nested under a folder.\n let asset: string;\n if (path === \"/\") {\n asset = \"/index\";\n } else if (path === \"/index\" || path.startsWith(\"/index/\")) {\n asset = \"/index\" + path;\n } else {\n asset = path;\n }\n\n return `/_next/data/${buildId}${asset}.json`;\n}\n\n/**\n * Build the full data URL including the basePath, the search string, and the\n * `/_next/data/<buildId>/<page>.json` segment.\n *\n * `pagePath` must already be the resolved pathname (param-substituted,\n * locale-prefixed where applicable). `search` includes the leading `?`.\n */\nexport function buildPagesDataHref(\n basePath: string,\n buildId: string,\n pagePath: string,\n search: string,\n): string {\n const dataPath = buildPagesDataPath(buildId, pagePath);\n const prefix = basePath ? basePath : \"\";\n return `${prefix}${dataPath}${search}`;\n}\n\n/** Result of matching a URL pathname against the registered route patterns. */\ntype PagesPatternMatch = {\n /** The matched route pattern in Next.js bracket format (e.g. `/blog/[slug]`). */\n pattern: string;\n /** Dynamic route params extracted from the URL. */\n params: Record<string, string | string[]>;\n};\n\n/**\n * Find the route pattern (Next.js bracket format) that matches `pathname`.\n *\n * Patterns are tried in `patterns` order — callers should pre-sort so more\n * specific patterns come before catch-alls. Returns `null` when no pattern\n * matches, so the caller can fall back to a hard navigation (this is how\n * vinext handles routes that exist on the server but are not in the\n * client-side loader map, e.g. dev-only pages).\n */\nexport function matchPagesPattern(\n pathname: string,\n patterns: readonly string[],\n): PagesPatternMatch | null {\n const urlParts = pathname.split(\"/\").filter(Boolean);\n for (const pattern of patterns) {\n const patternParts = routePatternParts(pattern);\n const params = matchRoutePattern(urlParts, patternParts);\n if (params !== null) {\n return { pattern, params };\n }\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,mBAAmB,SAAiB,UAA0B;CAE5E,IAAI,OAAO;CACX,IAAI,KAAK,SAAS,KAAK,KAAK,SAAS,IAAI,EACvC,OAAO,KAAK,MAAM,GAAG,GAAG;CAS1B,IAAI;CACJ,IAAI,SAAS,KACX,QAAQ;MACH,IAAI,SAAS,YAAY,KAAK,WAAW,UAAU,EACxD,QAAQ,WAAW;MAEnB,QAAQ;CAGV,OAAO,eAAe,UAAU,MAAM;;;;;;;;;AAUxC,SAAgB,mBACd,UACA,SACA,UACA,QACQ;CACR,MAAM,WAAW,mBAAmB,SAAS,SAAS;CAEtD,OAAO,GADQ,WAAW,WAAW,KAClB,WAAW;;;;;;;;;;;AAoBhC,SAAgB,kBACd,UACA,UAC0B;CAC1B,MAAM,WAAW,SAAS,MAAM,IAAI,CAAC,OAAO,QAAQ;CACpD,KAAK,MAAM,WAAW,UAAU;EAE9B,MAAM,SAAS,kBAAkB,UADZ,kBAAkB,QACgB,CAAC;EACxD,IAAI,WAAW,MACb,OAAO;GAAE;GAAS;GAAQ;;CAG9B,OAAO"}
|
package/dist/shims/link.js
CHANGED
|
@@ -4,12 +4,13 @@ import { createRouteTrieCache, matchRouteWithTrie } from "../routing/route-match
|
|
|
4
4
|
import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/headers.js";
|
|
5
5
|
import { isDangerousScheme, reportBlockedDangerousNavigation } from "./url-safety.js";
|
|
6
6
|
import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
7
|
+
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
7
8
|
import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
8
|
-
import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, resolveRelativeHref, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
9
9
|
import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
|
|
10
|
+
import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
11
|
+
import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, resolveRelativeHref, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
10
12
|
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
11
13
|
import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
|
|
12
|
-
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
13
14
|
import "../server/app-elements.js";
|
|
14
15
|
import { createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam, stripRscSuffix } from "../server/app-rsc-cache-busting.js";
|
|
15
16
|
import { getMountedSlotsHeader, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, navigateClientSide, prefetchRscResponse } from "./navigation.js";
|
|
@@ -49,6 +50,50 @@ function resolveHref(href) {
|
|
|
49
50
|
}
|
|
50
51
|
return url;
|
|
51
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Collapse repeated forward-slashes (and convert backslashes to forward-slashes)
|
|
55
|
+
* in the path portion of a URL, preserving any query string.
|
|
56
|
+
*
|
|
57
|
+
* Ported from Next.js: packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts
|
|
58
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts
|
|
59
|
+
*/
|
|
60
|
+
function normalizeRepeatedSlashes(url) {
|
|
61
|
+
const urlParts = url.split("?");
|
|
62
|
+
const urlNoQueryString = urlParts.shift() ?? "";
|
|
63
|
+
const queryString = urlParts.join("?");
|
|
64
|
+
return urlNoQueryString.replace(/\\/g, "/").replace(/\/\/+/g, "/") + (queryString ? `?${queryString}` : "");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Emit Next.js's "Invalid href" `console.error` when `href` contains repeated
|
|
68
|
+
* forward slashes or backslashes in its path portion, and return the
|
|
69
|
+
* normalized URL (with `\\` converted to `/` and runs of `/` collapsed). If
|
|
70
|
+
* the href is already well-formed, the original string is returned unchanged.
|
|
71
|
+
*
|
|
72
|
+
* Ported from Next.js: packages/next/src/client/resolve-href.ts
|
|
73
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/resolve-href.ts
|
|
74
|
+
*
|
|
75
|
+
* Matches the message asserted by:
|
|
76
|
+
* test/e2e/repeated-forward-slashes-error/repeated-forward-slashes-error.test.ts
|
|
77
|
+
*
|
|
78
|
+
* Note: Next.js fires this warning unconditionally on every call to
|
|
79
|
+
* `resolveHref`. We mirror that behaviour (no dedup) for exact parity.
|
|
80
|
+
*
|
|
81
|
+
* Note: Next.js uses `router.pathname` (the route pattern, e.g.
|
|
82
|
+
* `/posts/[id]`) for the "in page" segment of the message. We do not have
|
|
83
|
+
* cheap access to the route pattern from inside the Link shim, so we
|
|
84
|
+
* fall back to `window.location.pathname` (or `"/"` during SSR). The text
|
|
85
|
+
* is cosmetic and is not asserted by the Next.js compat test.
|
|
86
|
+
*/
|
|
87
|
+
function warnAndNormalizeRepeatedSlashesInHref(urlAsString) {
|
|
88
|
+
if (urlAsString.startsWith("//")) return urlAsString;
|
|
89
|
+
const urlProtoMatch = urlAsString.match(/^[a-z][a-z0-9+.-]*:\/\//i);
|
|
90
|
+
const urlAsStringNoProto = urlProtoMatch ? urlAsString.slice(urlProtoMatch[0].length) : urlAsString;
|
|
91
|
+
if (!(urlAsStringNoProto.split("?", 1)[0] || "").match(/(\/\/|\\)/)) return urlAsString;
|
|
92
|
+
const pathname = typeof window !== "undefined" && window.location ? window.location.pathname : "/";
|
|
93
|
+
console.error(`Invalid href '${urlAsString}' passed to next/router in page: '${pathname}'. Repeated forward-slashes (//) or backslashes \\ are not valid in the href.`);
|
|
94
|
+
const normalizedNoProto = normalizeRepeatedSlashes(urlAsStringNoProto);
|
|
95
|
+
return (urlProtoMatch ? urlProtoMatch[0] : "") + normalizedNoProto;
|
|
96
|
+
}
|
|
52
97
|
function resolveLinkPrefetchMode(prefetchProp, isDangerous) {
|
|
53
98
|
if (isDangerous || prefetchProp === false) return "disabled";
|
|
54
99
|
if (prefetchProp === true) return "full";
|
|
@@ -159,12 +204,16 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
159
204
|
cacheForNavigation: autoPrefetch.cacheForNavigation,
|
|
160
205
|
optimisticRouteShell: isOptimisticRouteShellPrefetch
|
|
161
206
|
});
|
|
162
|
-
} else if (window.__NEXT_DATA__
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
207
|
+
} else if (window.__NEXT_DATA__) {
|
|
208
|
+
const dataTarget = resolvePagesDataNavigationTarget(fullHref, __basePath);
|
|
209
|
+
if (dataTarget) prefetchPagesData(dataTarget);
|
|
210
|
+
else {
|
|
211
|
+
const link = document.createElement("link");
|
|
212
|
+
link.rel = "prefetch";
|
|
213
|
+
link.href = fullHref;
|
|
214
|
+
link.as = "document";
|
|
215
|
+
document.head.appendChild(link);
|
|
216
|
+
}
|
|
168
217
|
}
|
|
169
218
|
})().catch((error) => {
|
|
170
219
|
console.error("[vinext] RSC prefetch setup error:", error);
|
|
@@ -287,7 +336,8 @@ function applyLocaleToHref(href, locale) {
|
|
|
287
336
|
}
|
|
288
337
|
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) {
|
|
289
338
|
const { locale, ...restWithoutLocale } = rest;
|
|
290
|
-
const
|
|
339
|
+
const rawResolvedHref = as ?? resolveHref(href);
|
|
340
|
+
const resolvedHref = typeof rawResolvedHref === "string" ? warnAndNormalizeRepeatedSlashesInHref(rawResolvedHref) : rawResolvedHref;
|
|
291
341
|
const isDangerous = typeof resolvedHref === "string" && isDangerousScheme(resolvedHref);
|
|
292
342
|
const normalizedHref = normalizePathTrailingSlash(applyLocaleToHref(isDangerous ? "/" : resolvedHref, locale), __trailingSlash);
|
|
293
343
|
const fullHref = normalizePathTrailingSlash(withBasePath(normalizedHref, __basePath), __trailingSlash);
|
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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HA,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;;AAGT,SAAgB,wBACd,cACA,aACkB;CAClB,IAAI,eAAe,iBAAiB,OAAO,OAAO;CAClD,IAAI,iBAAiB,MAAM,OAAO;CAClC,OAAO;;AAGT,SAAS,sBAAsB,MAA6B;CAC1D,IAAI,OAAO,WAAW,aAAa,OAAO;CAE1C,IAAI;CACJ,IAAI;EACF,MAA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rE,IAAI,aAAa;EACf,IAAI,QAAQ,IAAI,aAAa,cAC3B,QAAQ,KAAK,kCAAkC,eAAe;EAOhE,MAAM,wBAAwB,UAAyC;GACrE,IAAI,SAAS,QAAQ,MAAM;GAC3B,kCAAkC;;EAEpC,OACE,oBAAC,kBAAkB,UAAnB;GAA4B,OAAO;aACjC,oBAAC,KAAD;IACE,KAAK;IACL,SAAS;IACT,cAAc;IACd,cAAc;IACd,GAAI;IAEH;IACC,CAAA;GACuB,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"}
|
|
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 {\n prefetchPagesData,\n resolvePagesDataNavigationTarget,\n} from \"./internal/pages-data-target.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\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 // 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,\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 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 (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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmIA,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,MAAM,mBAAmB,SAAS,OAAO,IAAI;CAC7C,MAAM,cAAc,SAAS,KAAK,IAAI;CACtC,OACE,iBAAiB,QAAQ,OAAO,IAAI,CAAC,QAAQ,UAAU,IAAI,IAC1D,cAAc,IAAI,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;AAyBvC,SAAS,sCAAsC,aAA6B;CAO1E,IAAI,YAAY,WAAW,KAAK,EAAE,OAAO;CAIzC,MAAM,gBAAgB,YAAY,MAAM,2BAA2B;CACnE,MAAM,qBAAqB,gBACvB,YAAY,MAAM,cAAc,GAAG,OAAO,GAC1C;CAEJ,IAAI,EADa,mBAAmB,MAAM,KAAK,EACjC,CAAC,MAAM,IAAI,MAAM,YAAY,EAAE,OAAO;CAEpD,MAAM,WACJ,OAAO,WAAW,e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,cAAc,UAAU,YAAY,QAAQ,QAAQ,KAAK,CAAC,cAC1E;KACJ,IAAI,WAAW,SAAS,WAAW,MAAM;MAE5C;KACD;GACF;SAMA,IAAI;GAEF,MAAM,UAAS,MADY,OAAO,mBACN;GAC5B,MAAM,wBAAwB,QAAQ;IACpC,MAAM;IACN;IACA;IACA;IACA;IACD,CAAC;UACI;GAEN,IAAI,SACF,OAAO,QAAQ,aAAa,EAAE,EAAE,IAAI,iBAAiB;QAErD,OAAO,QAAQ,UAAU,EAAE,EAAE,IAAI,iBAAiB;GAEpD,OAAO,cAAc,IAAI,cAAc,WAAW,CAAC;;;CAMzD,MAAM,EAAE,UAAU,IAAI,GAAG,gBAAgB;CAEzC,MAAM,kBAAkB,MAAM,eAAe,EAAE,SAAS,GAAG,CAAC,QAAQ,CAAC;CAMrE,IAAI,aAAa;EACf,IAAI,QAAQ,IAAI,aAAa,cAC3B,QAAQ,KAAK,kCAAkC,eAAe;EAOhE,MAAM,wBAAwB,UAAyC;GACrE,IAAI,SAAS,QAAQ,MAAM;GAC3B,kCAAkC;;EAEpC,OACE,oBAAC,kBAAkB,UAAnB;GAA4B,OAAO;aACjC,oBAAC,KAAD;IACE,KAAK;IACL,SAAS;IACT,cAAc;IACd,cAAc;IACd,GAAI;IAEH;IACC,CAAA;GACuB,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
|
@@ -271,10 +271,11 @@ type MetadataHeadProps = {
|
|
|
271
271
|
metadata: Metadata;
|
|
272
272
|
pathname?: string;
|
|
273
273
|
};
|
|
274
|
+
declare function renderMetadataToHtml(metadata: Metadata, pathname?: string): string;
|
|
274
275
|
declare function MetadataHead({
|
|
275
276
|
metadata,
|
|
276
277
|
pathname
|
|
277
278
|
}: MetadataHeadProps): _$react_jsx_runtime0.JSX.Element;
|
|
278
279
|
//#endregion
|
|
279
|
-
export { DEFAULT_VIEWPORT, Metadata, MetadataHead, MetadataMergeEntry, Viewport, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, resolveModuleMetadata, resolveModuleViewport };
|
|
280
|
+
export { DEFAULT_VIEWPORT, Metadata, MetadataHead, MetadataMergeEntry, Viewport, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, renderMetadataToHtml, resolveModuleMetadata, resolveModuleViewport };
|
|
280
281
|
//# 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;
|
|
@@ -736,6 +795,6 @@ function MetadataHead({ metadata, pathname = "/" }) {
|
|
|
736
795
|
return /* @__PURE__ */ jsx(Fragment$1, { children: elements });
|
|
737
796
|
}
|
|
738
797
|
//#endregion
|
|
739
|
-
export { DEFAULT_VIEWPORT, MetadataHead, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, resolveModuleMetadata, resolveModuleViewport };
|
|
798
|
+
export { DEFAULT_VIEWPORT, MetadataHead, ViewportHead, mergeMetadata, mergeMetadataEntries, mergeViewport, postProcessMetadata, renderMetadataToHtml, resolveModuleMetadata, resolveModuleViewport };
|
|
740
799
|
|
|
741
800
|
//# sourceMappingURL=metadata.js.map
|