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.
Files changed (238) hide show
  1. package/README.md +1 -1
  2. package/dist/build/clean-output.d.ts +14 -0
  3. package/dist/build/clean-output.js +36 -0
  4. package/dist/build/clean-output.js.map +1 -0
  5. package/dist/build/prerender.d.ts +6 -2
  6. package/dist/build/prerender.js +49 -11
  7. package/dist/build/prerender.js.map +1 -1
  8. package/dist/build/run-prerender.js +10 -1
  9. package/dist/build/run-prerender.js.map +1 -1
  10. package/dist/build/static-export.d.ts +5 -0
  11. package/dist/build/static-export.js +8 -3
  12. package/dist/build/static-export.js.map +1 -1
  13. package/dist/cli.js +19 -4
  14. package/dist/cli.js.map +1 -1
  15. package/dist/client/instrumentation-client-inject.d.ts +34 -0
  16. package/dist/client/instrumentation-client-inject.js +57 -0
  17. package/dist/client/instrumentation-client-inject.js.map +1 -0
  18. package/dist/client/navigation-runtime.d.ts +14 -1
  19. package/dist/client/navigation-runtime.js +16 -1
  20. package/dist/client/navigation-runtime.js.map +1 -1
  21. package/dist/client/vinext-next-data.d.ts +2 -1
  22. package/dist/client/vinext-next-data.js.map +1 -1
  23. package/dist/client/window-next.d.ts +10 -2
  24. package/dist/client/window-next.js.map +1 -1
  25. package/dist/cloudflare/tpr.js +1 -1
  26. package/dist/cloudflare/tpr.js.map +1 -1
  27. package/dist/config/config-matchers.js +2 -1
  28. package/dist/config/config-matchers.js.map +1 -1
  29. package/dist/config/next-config.d.ts +12 -3
  30. package/dist/config/next-config.js +44 -14
  31. package/dist/config/next-config.js.map +1 -1
  32. package/dist/deploy.js +29 -7
  33. package/dist/deploy.js.map +1 -1
  34. package/dist/entries/app-rsc-entry.d.ts +4 -2
  35. package/dist/entries/app-rsc-entry.js +23 -3
  36. package/dist/entries/app-rsc-entry.js.map +1 -1
  37. package/dist/entries/pages-client-entry.js +22 -1
  38. package/dist/entries/pages-client-entry.js.map +1 -1
  39. package/dist/entries/pages-server-entry.js +211 -31
  40. package/dist/entries/pages-server-entry.js.map +1 -1
  41. package/dist/index.js +29 -6
  42. package/dist/index.js.map +1 -1
  43. package/dist/plugins/fonts.js +25 -2
  44. package/dist/plugins/fonts.js.map +1 -1
  45. package/dist/routing/route-trie.js +13 -18
  46. package/dist/routing/route-trie.js.map +1 -1
  47. package/dist/routing/utils.d.ts +11 -1
  48. package/dist/routing/utils.js +15 -1
  49. package/dist/routing/utils.js.map +1 -1
  50. package/dist/server/api-handler.js +18 -9
  51. package/dist/server/api-handler.js.map +1 -1
  52. package/dist/server/app-browser-action-result.d.ts +16 -1
  53. package/dist/server/app-browser-action-result.js +15 -1
  54. package/dist/server/app-browser-action-result.js.map +1 -1
  55. package/dist/server/app-browser-entry.js +22 -12
  56. package/dist/server/app-browser-entry.js.map +1 -1
  57. package/dist/server/app-elements.js +1 -1
  58. package/dist/server/app-fallback-renderer.d.ts +12 -3
  59. package/dist/server/app-fallback-renderer.js +10 -5
  60. package/dist/server/app-fallback-renderer.js.map +1 -1
  61. package/dist/server/app-history-state.js +6 -2
  62. package/dist/server/app-history-state.js.map +1 -1
  63. package/dist/server/app-interception-context-header.d.ts +33 -0
  64. package/dist/server/app-interception-context-header.js +44 -0
  65. package/dist/server/app-interception-context-header.js.map +1 -0
  66. package/dist/server/app-mounted-slots-header.d.ts +19 -0
  67. package/dist/server/app-mounted-slots-header.js +40 -1
  68. package/dist/server/app-mounted-slots-header.js.map +1 -1
  69. package/dist/server/app-optimistic-routing.js +26 -18
  70. package/dist/server/app-optimistic-routing.js.map +1 -1
  71. package/dist/server/app-page-boundary-render.d.ts +1 -0
  72. package/dist/server/app-page-boundary-render.js +2 -0
  73. package/dist/server/app-page-boundary-render.js.map +1 -1
  74. package/dist/server/app-page-boundary.d.ts +1 -0
  75. package/dist/server/app-page-boundary.js +2 -0
  76. package/dist/server/app-page-boundary.js.map +1 -1
  77. package/dist/server/app-page-cache.d.ts +2 -0
  78. package/dist/server/app-page-cache.js +7 -1
  79. package/dist/server/app-page-cache.js.map +1 -1
  80. package/dist/server/app-page-dispatch.d.ts +3 -0
  81. package/dist/server/app-page-dispatch.js +11 -4
  82. package/dist/server/app-page-dispatch.js.map +1 -1
  83. package/dist/server/app-page-element-builder.d.ts +2 -1
  84. package/dist/server/app-page-element-builder.js +5 -2
  85. package/dist/server/app-page-element-builder.js.map +1 -1
  86. package/dist/server/app-page-execution.d.ts +1 -0
  87. package/dist/server/app-page-execution.js +2 -0
  88. package/dist/server/app-page-execution.js.map +1 -1
  89. package/dist/server/app-page-head.d.ts +1 -0
  90. package/dist/server/app-page-head.js +8 -0
  91. package/dist/server/app-page-head.js.map +1 -1
  92. package/dist/server/app-page-render-observation.js +1 -1
  93. package/dist/server/app-page-render.d.ts +1 -0
  94. package/dist/server/app-page-render.js +5 -2
  95. package/dist/server/app-page-render.js.map +1 -1
  96. package/dist/server/app-page-response.d.ts +11 -1
  97. package/dist/server/app-page-response.js +14 -2
  98. package/dist/server/app-page-response.js.map +1 -1
  99. package/dist/server/app-page-route-wiring.d.ts +1 -0
  100. package/dist/server/app-page-route-wiring.js +19 -6
  101. package/dist/server/app-page-route-wiring.js.map +1 -1
  102. package/dist/server/app-page-stream.d.ts +1 -0
  103. package/dist/server/app-page-stream.js +2 -0
  104. package/dist/server/app-page-stream.js.map +1 -1
  105. package/dist/server/app-route-handler-dispatch.d.ts +1 -0
  106. package/dist/server/app-route-handler-dispatch.js +3 -0
  107. package/dist/server/app-route-handler-dispatch.js.map +1 -1
  108. package/dist/server/app-route-handler-execution.d.ts +1 -0
  109. package/dist/server/app-route-handler-execution.js +1 -0
  110. package/dist/server/app-route-handler-execution.js.map +1 -1
  111. package/dist/server/app-route-handler-response.js +1 -1
  112. package/dist/server/app-rsc-handler.d.ts +2 -0
  113. package/dist/server/app-rsc-handler.js +18 -9
  114. package/dist/server/app-rsc-handler.js.map +1 -1
  115. package/dist/server/app-rsc-request-normalization.js +3 -2
  116. package/dist/server/app-rsc-request-normalization.js.map +1 -1
  117. package/dist/server/app-segment-config.d.ts +4 -1
  118. package/dist/server/app-segment-config.js +6 -1
  119. package/dist/server/app-segment-config.js.map +1 -1
  120. package/dist/server/app-server-action-execution.d.ts +1 -0
  121. package/dist/server/app-server-action-execution.js +4 -0
  122. package/dist/server/app-server-action-execution.js.map +1 -1
  123. package/dist/server/app-ssr-entry.js +39 -3
  124. package/dist/server/app-ssr-entry.js.map +1 -1
  125. package/dist/server/app-ssr-stream.d.ts +24 -1
  126. package/dist/server/app-ssr-stream.js +78 -5
  127. package/dist/server/app-ssr-stream.js.map +1 -1
  128. package/dist/server/app-static-generation.d.ts +1 -0
  129. package/dist/server/app-static-generation.js +2 -1
  130. package/dist/server/app-static-generation.js.map +1 -1
  131. package/dist/server/default-not-found-module.d.ts +20 -0
  132. package/dist/server/default-not-found-module.js +20 -0
  133. package/dist/server/default-not-found-module.js.map +1 -0
  134. package/dist/server/dev-server.d.ts +1 -1
  135. package/dist/server/dev-server.js +23 -7
  136. package/dist/server/dev-server.js.map +1 -1
  137. package/dist/server/headers.d.ts +5 -1
  138. package/dist/server/headers.js +5 -1
  139. package/dist/server/headers.js.map +1 -1
  140. package/dist/server/image-optimization.d.ts +13 -4
  141. package/dist/server/image-optimization.js +15 -4
  142. package/dist/server/image-optimization.js.map +1 -1
  143. package/dist/server/middleware.js +1 -1
  144. package/dist/server/middleware.js.map +1 -1
  145. package/dist/server/pages-api-route.d.ts +18 -0
  146. package/dist/server/pages-api-route.js +3 -1
  147. package/dist/server/pages-api-route.js.map +1 -1
  148. package/dist/server/pages-body-parser-config.d.ts +60 -0
  149. package/dist/server/pages-body-parser-config.js +79 -0
  150. package/dist/server/pages-body-parser-config.js.map +1 -0
  151. package/dist/server/pages-data-route.js +1 -0
  152. package/dist/server/pages-data-route.js.map +1 -1
  153. package/dist/server/pages-default-404.d.ts +31 -0
  154. package/dist/server/pages-default-404.js +40 -0
  155. package/dist/server/pages-default-404.js.map +1 -0
  156. package/dist/server/pages-node-compat.d.ts +10 -0
  157. package/dist/server/pages-node-compat.js +12 -1
  158. package/dist/server/pages-node-compat.js.map +1 -1
  159. package/dist/server/pages-page-data.d.ts +40 -0
  160. package/dist/server/pages-page-data.js +16 -14
  161. package/dist/server/pages-page-data.js.map +1 -1
  162. package/dist/server/pages-page-response.d.ts +2 -0
  163. package/dist/server/pages-page-response.js +11 -8
  164. package/dist/server/pages-page-response.js.map +1 -1
  165. package/dist/server/prerender-route-params.d.ts +14 -0
  166. package/dist/server/prerender-route-params.js +94 -0
  167. package/dist/server/prerender-route-params.js.map +1 -0
  168. package/dist/server/prod-server.d.ts +3 -23
  169. package/dist/server/prod-server.js +40 -57
  170. package/dist/server/prod-server.js.map +1 -1
  171. package/dist/server/proxy-trust.d.ts +41 -0
  172. package/dist/server/proxy-trust.js +70 -0
  173. package/dist/server/proxy-trust.js.map +1 -0
  174. package/dist/server/request-pipeline.d.ts +3 -3
  175. package/dist/server/request-pipeline.js +5 -4
  176. package/dist/server/request-pipeline.js.map +1 -1
  177. package/dist/server/seed-cache.js +12 -6
  178. package/dist/server/seed-cache.js.map +1 -1
  179. package/dist/server/static-file-cache.js +1 -1
  180. package/dist/server/static-file-cache.js.map +1 -1
  181. package/dist/server/streaming-metadata.d.ts +5 -0
  182. package/dist/server/streaming-metadata.js +10 -0
  183. package/dist/server/streaming-metadata.js.map +1 -0
  184. package/dist/shims/app-router-scroll-state.d.ts +12 -0
  185. package/dist/shims/app-router-scroll-state.js +38 -0
  186. package/dist/shims/app-router-scroll-state.js.map +1 -0
  187. package/dist/shims/app-router-scroll.d.ts +14 -0
  188. package/dist/shims/app-router-scroll.js +100 -0
  189. package/dist/shims/app-router-scroll.js.map +1 -0
  190. package/dist/shims/before-interactive-context.d.ts +30 -0
  191. package/dist/shims/before-interactive-context.js +10 -0
  192. package/dist/shims/before-interactive-context.js.map +1 -0
  193. package/dist/shims/cache-runtime.d.ts +1 -1
  194. package/dist/shims/cache-runtime.js +14 -1
  195. package/dist/shims/cache-runtime.js.map +1 -1
  196. package/dist/shims/default-not-found.d.ts +12 -0
  197. package/dist/shims/default-not-found.js +61 -0
  198. package/dist/shims/default-not-found.js.map +1 -0
  199. package/dist/shims/font-local.d.ts +5 -0
  200. package/dist/shims/font-local.js +6 -2
  201. package/dist/shims/font-local.js.map +1 -1
  202. package/dist/shims/head.js +4 -4
  203. package/dist/shims/head.js.map +1 -1
  204. package/dist/shims/headers.d.ts +6 -2
  205. package/dist/shims/headers.js +64 -21
  206. package/dist/shims/headers.js.map +1 -1
  207. package/dist/shims/image.d.ts +1 -1
  208. package/dist/shims/image.js +4 -4
  209. package/dist/shims/image.js.map +1 -1
  210. package/dist/shims/internal/pages-data-target.d.ts +58 -0
  211. package/dist/shims/internal/pages-data-target.js +91 -0
  212. package/dist/shims/internal/pages-data-target.js.map +1 -0
  213. package/dist/shims/internal/pages-data-url.d.ts +42 -0
  214. package/dist/shims/internal/pages-data-url.js +73 -0
  215. package/dist/shims/internal/pages-data-url.js.map +1 -0
  216. package/dist/shims/link.js +59 -9
  217. package/dist/shims/link.js.map +1 -1
  218. package/dist/shims/metadata.d.ts +2 -1
  219. package/dist/shims/metadata.js +61 -2
  220. package/dist/shims/metadata.js.map +1 -1
  221. package/dist/shims/navigation.js +32 -9
  222. package/dist/shims/navigation.js.map +1 -1
  223. package/dist/shims/router.js +376 -77
  224. package/dist/shims/router.js.map +1 -1
  225. package/dist/shims/script.js +86 -12
  226. package/dist/shims/script.js.map +1 -1
  227. package/dist/shims/server.js +1 -0
  228. package/dist/shims/server.js.map +1 -1
  229. package/dist/shims/url-utils.d.ts +2 -1
  230. package/dist/shims/url-utils.js +15 -4
  231. package/dist/shims/url-utils.js.map +1 -1
  232. package/dist/utils/html-limited-bots.d.ts +5 -0
  233. package/dist/utils/html-limited-bots.js +15 -0
  234. package/dist/utils/html-limited-bots.js.map +1 -0
  235. package/dist/utils/query.d.ts +6 -0
  236. package/dist/utils/query.js +10 -1
  237. package/dist/utils/query.js.map +1 -1
  238. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","names":[],"sources":["../../src/shims/router.ts"],"sourcesContent":["/**\n * next/router shim\n *\n * Provides useRouter() hook and Router singleton for Pages Router.\n * Backed by the browser History API. Supports client-side navigation\n * by fetching new page data and re-rendering the React root.\n */\nimport {\n useState,\n useEffect,\n useMemo,\n useContext,\n createElement,\n type ReactElement,\n type ReactNode,\n type ComponentType,\n} from \"react\";\nimport { RouterContext } from \"./internal/router-context.js\";\nimport {\n applyVinextLocaleGlobals,\n extractVinextNextDataJson,\n parseVinextNextDataJson,\n type VinextNextData,\n} from \"../client/vinext-next-data.js\";\nimport { isValidModulePath } from \"../client/validate-module-path.js\";\nimport { installWindowNext, type PagesRouterPublicInstance } from \"../client/window-next.js\";\nimport {\n isAbsoluteOrProtocolRelativeUrl,\n isHashOnlyBrowserUrlChange,\n normalizePathTrailingSlash,\n toBrowserNavigationHref,\n toSameOriginAppPath,\n} from \"./url-utils.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport {\n addLocalePrefix,\n getDomainLocaleUrl,\n getLocalePathPrefix,\n type DomainLocale,\n} from \"../utils/domain-locale.js\";\nimport {\n addQueryParam,\n appendSearchParamsToUrl,\n type UrlQuery,\n urlQueryToSearchParams,\n} from \"../utils/query.js\";\nimport { matchRoutePattern, routePatternParts } from \"../routing/route-pattern.js\";\nimport { scrollToHashTarget } from \"./hash-scroll.js\";\nimport { setPagesRouterPopStateHandler } from \"./pages-router-runtime.js\";\nimport { assertSafeNavigationUrl } from \"./url-safety.js\";\nimport { getCurrentBrowserLocale } from \"./client-locale.js\";\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\";\n\ntype BeforePopStateCallback = (state: {\n url: string;\n as: string;\n options: { shallow: boolean };\n}) => boolean;\n\nexport type NextRouter = {\n /** Current pathname */\n pathname: string;\n /** Current route pattern (e.g., \"/posts/[id]\") */\n route: string;\n /** Query parameters */\n query: Record<string, string | string[]>;\n /** Full URL including query string */\n asPath: string;\n /** Base path */\n basePath: string;\n /** Current locale */\n locale?: string;\n /** Available locales */\n locales?: string[];\n /** Default locale */\n defaultLocale?: string;\n /** Configured domain locales */\n domainLocales?: VinextNextData[\"domainLocales\"];\n /** Whether the router is ready */\n isReady: boolean;\n /** Whether this is a preview */\n isPreview: boolean;\n /** Whether this is a fallback page */\n isFallback: boolean;\n\n /** Navigate to a new URL */\n push(url: string | UrlObject, as?: string, options?: TransitionOptions): Promise<boolean>;\n /** Replace current URL */\n replace(url: string | UrlObject, as?: string, options?: TransitionOptions): Promise<boolean>;\n /** Go back */\n back(): void;\n /** Reload the page */\n reload(): void;\n /** Prefetch a page (injects <link rel=\"prefetch\">) */\n prefetch(url: string): Promise<void>;\n /** Register a callback to run before popstate navigation */\n beforePopState(cb: BeforePopStateCallback): void;\n /** Listen for route changes */\n events: RouterEvents;\n};\n\ntype UrlObject = {\n pathname?: string;\n query?: UrlQuery;\n};\n\ntype TransitionOptions = {\n shallow?: boolean;\n scroll?: boolean;\n locale?: string | false;\n};\n\ntype RouterEvents = {\n on(event: string, handler: (...args: unknown[]) => void): void;\n off(event: string, handler: (...args: unknown[]) => void): void;\n emit(event: string, ...args: unknown[]): void;\n};\n\nfunction createRouterEvents(): RouterEvents {\n const listeners = new Map<string, Set<(...args: unknown[]) => void>>();\n\n return {\n on(event: string, handler: (...args: unknown[]) => void) {\n if (!listeners.has(event)) listeners.set(event, new Set());\n (listeners.get(event) as Set<(...args: unknown[]) => void>).add(handler);\n },\n off(event: string, handler: (...args: unknown[]) => void) {\n listeners.get(event)?.delete(handler);\n },\n emit(event: string, ...args: unknown[]) {\n listeners.get(event)?.forEach((handler) => handler(...args));\n },\n };\n}\n\n// Singleton events instance\nconst routerEvents = createRouterEvents();\n\nfunction resolveUrl(url: string | UrlObject): string {\n if (typeof url === \"string\") return url;\n let result = url.pathname ?? \"/\";\n if (url.query) {\n const params = urlQueryToSearchParams(url.query);\n result = appendSearchParamsToUrl(result, params);\n }\n return result;\n}\n\n/**\n * When `as` is provided, use it as the navigation target. This is a\n * simplification: Next.js keeps `url` and `as` as separate values (url for\n * data fetching, as for the browser URL). We collapse them because vinext's\n * navigateClient() fetches HTML from the target URL, so `as` must be a\n * server-resolvable path. Purely decorative `as` values are not supported.\n */\nfunction resolveNavigationTarget(\n url: string | UrlObject,\n as: string | undefined,\n locale: string | undefined,\n): string {\n return applyNavigationLocale(as ?? resolveUrl(url), locale);\n}\n\nfunction getCurrentUrlLocale(): string | undefined {\n return getCurrentBrowserLocale({\n basePath: __basePath,\n domainLocales: getDomainLocales(),\n hostname: getCurrentHostname(),\n });\n}\n\nfunction resolveTransitionLocale(locale: TransitionOptions[\"locale\"]): string | undefined {\n if (typeof window === \"undefined\") return undefined;\n if (locale === false) return window.__VINEXT_DEFAULT_LOCALE__;\n return locale ?? getCurrentUrlLocale();\n}\n\nfunction getDomainLocales(): readonly DomainLocale[] | undefined {\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.domainLocales;\n}\n\nfunction getCurrentHostname(): string | undefined {\n return window.location?.hostname;\n}\n\nfunction getDomainLocalePath(url: string, locale: string): string | undefined {\n return getDomainLocaleUrl(url, locale, {\n basePath: __basePath,\n currentHostname: getCurrentHostname(),\n domainItems: getDomainLocales(),\n });\n}\n\n/**\n * Apply locale prefix to a URL for client-side navigation.\n * Same logic as Link's applyLocaleToHref but reads from window globals.\n */\nexport function applyNavigationLocale(url: string, locale?: string): string {\n if (!locale || typeof window === \"undefined\") return url;\n // Absolute and protocol-relative URLs must not be prefixed — locale\n // only applies to local paths.\n if (isAbsoluteOrProtocolRelativeUrl(url)) {\n return url;\n }\n if (getLocalePathPrefix(url, window.__VINEXT_LOCALES__)) {\n return url;\n }\n\n const domainLocalePath = getDomainLocalePath(url, locale);\n if (domainLocalePath) return domainLocalePath;\n\n return addLocalePrefix(url, locale, window.__VINEXT_DEFAULT_LOCALE__ ?? \"\");\n}\n\nfunction isDefaultLocaleRootNavigation(url: string, locale: string | undefined): boolean {\n if (typeof window === \"undefined\") return false;\n if (!locale || locale !== window.__VINEXT_DEFAULT_LOCALE__) return false;\n\n let parsed: URL;\n try {\n parsed = new URL(url, window.location.href);\n } catch {\n return false;\n }\n\n return stripBasePath(parsed.pathname, __basePath) === \"/\";\n}\n\nfunction getPagesHtmlFetchUrl(browserUrl: string, locale: string | undefined): string {\n if (!isDefaultLocaleRootNavigation(browserUrl, locale)) return browserUrl;\n\n // Browser URL stays unprefixed for the default locale, but the internal\n // HTML fetch must bypass root Accept-Language detection.\n const parsed = new URL(browserUrl, window.location.href);\n const localeRoot = normalizePathTrailingSlash(`/${locale}`, __trailingSlash);\n // Base path joining can change slash shape, then the final URL must still\n // conform to the app's trailingSlash setting.\n return normalizePathTrailingSlash(\n toBrowserNavigationHref(\n `${localeRoot}${parsed.search}${parsed.hash}`,\n window.location.href,\n __basePath,\n ),\n __trailingSlash,\n );\n}\n\n/** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */\nexport function isExternalUrl(url: string): boolean {\n return isAbsoluteOrProtocolRelativeUrl(url);\n}\n\n/** Resolve a hash URL to a basePath-stripped app URL for event payloads */\nfunction resolveHashUrl(url: string): string {\n if (typeof window === \"undefined\") return url;\n if (url.startsWith(\"#\"))\n return stripBasePath(window.location.pathname, __basePath) + window.location.search + url;\n // Full-path hash URL — strip basePath for consistency with other events\n try {\n const parsed = new URL(url, window.location.href);\n return stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;\n } catch {\n return url;\n }\n}\n\n/** Check if a href is only a hash change relative to the current URL */\nexport function isHashOnlyChange(href: string): boolean {\n if (href.startsWith(\"#\")) return true;\n if (typeof window === \"undefined\") return false;\n return isHashOnlyBrowserUrlChange(href, window.location.href, __basePath);\n}\n\n/** Save current scroll position into history state for back/forward restoration */\nfunction saveScrollPosition(): void {\n const state = window.history.state ?? {};\n window.history.replaceState(\n { ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY },\n \"\",\n );\n}\n\n/** Restore scroll position from history state */\nfunction restoreScrollPosition(state: unknown): void {\n if (state && typeof state === \"object\" && \"__vinext_scrollY\" in state) {\n const { __vinext_scrollX: x, __vinext_scrollY: y } = state as {\n __vinext_scrollX: number;\n __vinext_scrollY: number;\n };\n requestAnimationFrame(() => window.scrollTo(x, y));\n }\n}\n\n/**\n * SSR context - set by the dev server before rendering each page.\n */\ntype SSRContext = {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n domainLocales?: VinextNextData[\"domainLocales\"];\n /**\n * True when rendering a `getStaticPaths` fallback shell for a path that\n * hasn't been pre-rendered yet (`fallback: true` + unlisted path). Mirrors\n * `renderContext.isFallback` in Next.js's `render.tsx`: `getStaticProps`\n * is skipped, the page renders with empty props, and `useRouter().isFallback`\n * returns `true` so user code can show a loading state.\n */\n isFallback?: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Server-side SSR state uses a registration pattern so this module can be\n// bundled for the browser. The ALS-backed implementation lives in\n// router-state.ts (server-only) and registers itself on import.\n// ---------------------------------------------------------------------------\n\nlet _ssrContext: SSRContext | null = null;\n\nlet _getSSRContext = (): SSRContext | null => _ssrContext;\nlet _setSSRContextImpl = (ctx: SSRContext | null): void => {\n _ssrContext = ctx;\n};\n\n/**\n * Register ALS-backed state accessors. Called by router-state.ts on import.\n * @internal\n */\nexport function _registerRouterStateAccessors(accessors: {\n getSSRContext: () => SSRContext | null;\n setSSRContext: (ctx: SSRContext | null) => void;\n}): void {\n _getSSRContext = accessors.getSSRContext;\n _setSSRContextImpl = accessors.setSSRContext;\n}\n\nexport function setSSRContext(ctx: SSRContext | null): void {\n _setSSRContextImpl(ctx);\n}\n\ntype PagesNavigationContextShape = {\n pathname: string;\n searchParams: URLSearchParams;\n params: Record<string, string | string[]>;\n};\n\n// Client-only cache for snapshot stability. useSyncExternalStore compares\n// snapshots with Object.is, so returning a fresh object on every render would\n// trigger re-render loops. We use a module-level cache keyed by URL inputs;\n// this is safe in the browser because there is exactly one request at a time\n// but it must NOT be used on the server (concurrent ALS-scoped requests).\nlet _cachedClientPagesNavCtx: PagesNavigationContextShape | null = null;\nlet _cachedClientPagesNavCtxKey: string | null = null;\n\nfunction _buildClientPagesNavigationContext(\n routePattern: string,\n resolvedPath: string,\n searchString: string,\n): PagesNavigationContextShape {\n const cacheKey = `${routePattern}|${resolvedPath}|${searchString}`;\n if (_cachedClientPagesNavCtxKey === cacheKey && _cachedClientPagesNavCtx) {\n return _cachedClientPagesNavCtx;\n }\n const searchParams = new URLSearchParams(searchString);\n const params = routePattern ? (extractRouteParamsFromPath(routePattern, resolvedPath) ?? {}) : {};\n const ctx: PagesNavigationContextShape = { pathname: resolvedPath, searchParams, params };\n _cachedClientPagesNavCtx = ctx;\n _cachedClientPagesNavCtxKey = cacheKey;\n return ctx;\n}\n\n/**\n * Cross-router compat shim source for `next/navigation` hooks.\n *\n * Returns the current Pages Router state shaped as a navigation context so\n * the App Router hooks (useParams/useSearchParams/usePathname) can act as\n * compat shims when invoked inside a Pages Router render. Mirrors Next.js's\n * `adaptForPathParams` and `adaptForSearchParams` in\n * .nextjs-ref/packages/next/src/shared/lib/router/adapters.tsx, which Next.js\n * uses to populate SearchParamsContext / PathParamsContext for the Pages\n * Router (see packages/next/src/server/render.tsx and\n * packages/next/src/client/index.tsx).\n *\n * Returns `null` when there is no Pages Router state available — e.g. App\n * Router pages, RSC-only renders, or pre-router renders. Callers should\n * treat null as \"App Router context, use normal app-router state\".\n */\nexport function getPagesNavigationContext(): PagesNavigationContextShape | null {\n if (typeof window === \"undefined\") {\n const ssrCtx = _getSSRContext();\n if (!ssrCtx) return null;\n // ssrCtx.pathname is the route pattern (e.g. \"/blog/[slug]\").\n // ssrCtx.asPath is the resolved URL with query string. For useSearchParams\n // we want only the URL search string; for useParams we want only the\n // dynamic route params. Build a fresh object each call — server scope is\n // request-isolated via ALS but module state must not be cached across\n // concurrent requests.\n let searchParams: URLSearchParams;\n let resolvedPath: string;\n try {\n const url = new URL(ssrCtx.asPath, \"http://_\");\n searchParams = url.searchParams;\n resolvedPath = url.pathname;\n } catch {\n searchParams = new URLSearchParams();\n resolvedPath = ssrCtx.pathname;\n }\n const params = extractRouteParamsFromPath(ssrCtx.pathname, resolvedPath) ?? {};\n return { pathname: resolvedPath, searchParams, params };\n }\n\n // Client: derive from window.location + __NEXT_DATA__. __NEXT_DATA__.page\n // is the route pattern that was matched; navigateClient() keeps it in sync\n // with the visible URL on every client-side navigation. Cached so\n // useSyncExternalStore sees a stable snapshot between renders.\n const resolvedPath = stripBasePath(window.location.pathname, __basePath);\n const pattern = window.__NEXT_DATA__?.page ?? \"\";\n return _buildClientPagesNavigationContext(pattern, resolvedPath, window.location.search);\n}\n\n/**\n * Extract param names from a Next.js route pattern.\n * E.g., \"/posts/[id]\" → [\"id\"], \"/docs/[...slug]\" → [\"slug\"],\n * \"/shop/[[...path]]\" → [\"path\"], \"/blog/[year]/[month]\" → [\"year\", \"month\"]\n * Also handles internal format: \"/posts/:id\" → [\"id\"], \"/docs/:slug+\" → [\"slug\"]\n */\nfunction extractRouteParamNames(pattern: string): string[] {\n const names: string[] = [];\n // Match Next.js bracket format: [id], [...slug], [[...slug]]\n // Accepts any non-] characters inside brackets (Next.js PARAMETER_PATTERN parity).\n const bracketMatches = pattern.matchAll(/\\[{1,2}(?:\\.\\.\\.)?([^\\]]+)\\]{1,2}/g);\n for (const m of bracketMatches) {\n names.push(m[1]);\n }\n if (names.length > 0) return names;\n // Fallback: match internal :param format (any chars except /, +, *)\n const colonMatches = pattern.matchAll(/:([^/+*]+)[+*]?/g);\n for (const m of colonMatches) {\n names.push(m[1]);\n }\n return names;\n}\n\ntype RouteQueryNextData = {\n page?: string;\n query?: Record<string, string | string[] | undefined>;\n};\n\nfunction splitPathSegments(pathname: string): string[] {\n return pathname.split(\"/\").filter(Boolean);\n}\n\nfunction extractRouteParamsFromPath(\n pattern: string,\n pathname: string,\n): Record<string, string | string[]> | null {\n return matchRoutePattern(splitPathSegments(pathname), routePatternParts(pattern));\n}\n\nfunction getRouteQueryFromNextData(\n nextData: RouteQueryNextData | undefined,\n resolvedPath: string,\n): Record<string, string | string[]> {\n const routeQuery: Record<string, string | string[]> = {};\n if (!nextData?.query || !nextData.page) return routeQuery;\n\n const routeParamNames = extractRouteParamNames(nextData.page);\n if (routeParamNames.length === 0) return routeQuery;\n\n const currentRouteParams = extractRouteParamsFromPath(nextData.page, resolvedPath);\n if (currentRouteParams) return currentRouteParams;\n\n for (const key of routeParamNames) {\n const value = nextData.query[key];\n if (typeof value === \"string\") {\n routeQuery[key] = value;\n } else if (Array.isArray(value)) {\n routeQuery[key] = [...value];\n }\n }\n return routeQuery;\n}\n\nfunction getPathnameAndQuery(): {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n} {\n if (typeof window === \"undefined\") {\n const _ssrCtx = _getSSRContext();\n if (_ssrCtx) {\n const query: Record<string, string | string[]> = {};\n for (const [key, value] of Object.entries(_ssrCtx.query)) {\n query[key] = Array.isArray(value) ? [...value] : value;\n }\n return { pathname: _ssrCtx.pathname, query, asPath: _ssrCtx.asPath };\n }\n return { pathname: \"/\", query: {}, asPath: \"/\" };\n }\n const resolvedPath = stripBasePath(window.location.pathname, __basePath);\n // In Next.js, router.pathname is the route pattern (e.g., \"/posts/[id]\"),\n // not the resolved path (\"/posts/42\"). __NEXT_DATA__.page holds the route\n // pattern and is updated by navigateClient() on every client-side navigation.\n const pathname = window.__NEXT_DATA__?.page ?? resolvedPath;\n const nextData = window.__NEXT_DATA__;\n const routeQuery = getRouteQueryFromNextData(nextData, resolvedPath);\n // URL search params always reflect the current URL\n const searchQuery: Record<string, string | string[]> = {};\n const params = new URLSearchParams(window.location.search);\n for (const [key, value] of params) {\n addQueryParam(searchQuery, key, value);\n }\n const query = { ...searchQuery, ...routeQuery };\n // asPath uses the resolved browser path, not the route pattern\n const asPath = resolvedPath + window.location.search + window.location.hash;\n return { pathname, query, asPath };\n}\n\n/**\n * Error thrown when a navigation is superseded by a newer one.\n * Matches Next.js's convention of an Error with `.cancelled = true`.\n */\nclass NavigationCancelledError extends Error {\n cancelled = true;\n constructor(route: string) {\n super(`Abort fetching component for route: \"${route}\"`);\n this.name = \"NavigationCancelledError\";\n }\n}\n\n/**\n * Error thrown after queueing a hard navigation fallback for a known failure\n * mode. Callers can use this to avoid scheduling the same hard navigation twice.\n */\nclass HardNavigationScheduledError extends Error {\n hardNavigationScheduled = true;\n constructor(message: string) {\n super(message);\n this.name = \"HardNavigationScheduledError\";\n }\n}\n\n/**\n * Monotonically increasing ID for tracking the current navigation.\n * Each call to navigateClient() increments this and captures the value.\n * After each async boundary, the navigation checks whether it is still\n * the active one. If a newer navigation has started, the stale one\n * throws NavigationCancelledError so the caller can emit routeChangeError\n * and skip routeChangeComplete.\n *\n * Replaces the old boolean `_navInProgress` guard which silently dropped\n * the second navigation, causing URL/content mismatch.\n */\nlet _navigationId = 0;\n\n/** AbortController for the in-flight fetch, so superseded navigations abort network I/O. */\nlet _activeAbortController: AbortController | null = null;\n\nfunction scheduleHardNavigationAndThrow(url: string, message: string): never {\n if (typeof window === \"undefined\") {\n throw new HardNavigationScheduledError(message);\n }\n window.location.href = url;\n throw new HardNavigationScheduledError(message);\n}\n\n/**\n * Perform client-side navigation: fetch the target page's HTML,\n * extract __NEXT_DATA__, and re-render the React root.\n *\n * Throws NavigationCancelledError if a newer navigation supersedes this one.\n * Throws on hard-navigation failures (non-OK response, missing data) so the\n * caller can distinguish success from failure for event emission.\n */\nasync function navigateClient(url: string, fetchUrl = url): Promise<void> {\n if (typeof window === \"undefined\") return;\n\n const root = window.__VINEXT_ROOT__;\n if (!root) {\n // No React root yet — fall back to hard navigation\n window.location.href = url;\n return;\n }\n\n // Cancel any in-flight navigation (abort its fetch, mark it stale)\n _activeAbortController?.abort();\n const controller = new AbortController();\n _activeAbortController = controller;\n\n const navId = ++_navigationId;\n\n /** Check if this navigation is still the active one. If not, throw. */\n function assertStillCurrent(): void {\n if (navId !== _navigationId) {\n throw new NavigationCancelledError(url);\n }\n }\n\n try {\n // Fetch the target page's SSR HTML\n let res: Response;\n try {\n res = await fetch(fetchUrl, {\n headers: { Accept: \"text/html\" },\n signal: controller.signal,\n });\n } catch (err: unknown) {\n // AbortError means a newer navigation cancelled this fetch\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new NavigationCancelledError(url);\n }\n throw err;\n }\n assertStillCurrent();\n\n if (!res.ok) {\n // Set window.location.href first so the browser navigates to the correct\n // page even if the caller suppresses the error. The assignment schedules\n // the navigation asynchronously (as a task), so synchronous routeChangeError\n // listeners still run — and observe the error — before the page unloads.\n // Contract: routeChangeError listeners MUST be synchronous; async listeners\n // will not fire before the navigation completes. Callers (runNavigateClient)\n // must NOT schedule a second hard navigation — this assignment already queues\n // the browser fallback, and the helper-level HardNavigationScheduledError\n // makes that contract explicit to callers.\n scheduleHardNavigationAndThrow(url, `Navigation failed: ${res.status} ${res.statusText}`);\n }\n\n const html = await res.text();\n assertStillCurrent();\n\n // Extract __NEXT_DATA__ from the HTML\n const nextDataJson = extractVinextNextDataJson(html);\n if (!nextDataJson) {\n scheduleHardNavigationAndThrow(url, \"Navigation failed: missing __NEXT_DATA__ in response\");\n }\n\n const nextData = parseVinextNextDataJson(nextDataJson);\n const { pageProps } = nextData.props;\n // Defer writing window.__NEXT_DATA__ until just before root.render() —\n // writing it here would let a stale navigation briefly pollute the global\n // between this assertStillCurrent() and the next one after await import().\n\n // Get the page module URL from __NEXT_DATA__.__vinext (preferred),\n // or fall back to parsing the hydration script\n let pageModuleUrl: string | undefined = nextData.__vinext?.pageModuleUrl;\n\n if (!pageModuleUrl) {\n // Legacy fallback: try to find the module URL in the inline script\n const moduleMatch = html.match(/import\\(\"([^\"]+)\"\\);\\s*\\n\\s*const PageComponent/);\n const altMatch = html.match(/await import\\(\"([^\"]+pages\\/[^\"]+)\"\\)/);\n pageModuleUrl = moduleMatch?.[1] ?? altMatch?.[1] ?? undefined;\n }\n\n if (!pageModuleUrl) {\n scheduleHardNavigationAndThrow(url, \"Navigation failed: no page module URL found\");\n }\n\n // Validate the module URL before importing — defense-in-depth against\n // unexpected __NEXT_DATA__ or malformed HTML responses\n if (!isValidModulePath(pageModuleUrl)) {\n console.error(\"[vinext] Blocked import of invalid page module path:\", pageModuleUrl);\n scheduleHardNavigationAndThrow(url, \"Navigation failed: invalid page module path\");\n }\n\n // Dynamically import the new page module\n const pageModule = await import(/* @vite-ignore */ pageModuleUrl);\n assertStillCurrent();\n\n const PageComponent = pageModule.default;\n\n if (!PageComponent) {\n scheduleHardNavigationAndThrow(url, \"Navigation failed: page module has no default export\");\n }\n\n // Import React for createElement\n const React = (await import(\"react\")).default;\n assertStillCurrent();\n\n // Re-render with the new page, loading _app if needed\n let AppComponent = window.__VINEXT_APP__;\n const appModuleUrl: string | undefined = nextData.__vinext?.appModuleUrl;\n\n if (!AppComponent && appModuleUrl) {\n if (!isValidModulePath(appModuleUrl)) {\n console.error(\"[vinext] Blocked import of invalid app module path:\", appModuleUrl);\n } else {\n try {\n const appModule = await import(/* @vite-ignore */ appModuleUrl);\n AppComponent = appModule.default;\n window.__VINEXT_APP__ = AppComponent;\n } catch {\n // _app not available — continue without it\n }\n }\n }\n assertStillCurrent();\n\n let element;\n if (AppComponent) {\n element = React.createElement(AppComponent, {\n Component: PageComponent,\n pageProps,\n });\n } else {\n element = React.createElement(PageComponent, pageProps);\n }\n\n // Wrap with RouterContext.Provider so next/router and next/compat/router work.\n element = wrapWithRouterContext(element);\n\n // Commit __NEXT_DATA__ only after all assertStillCurrent() checks have passed,\n // so a stale navigation can never pollute the global.\n // INVARIANT: Everything after the final assertStillCurrent() above (the\n // checkpoint immediately after the optional _app import) through\n // root.render() is synchronous. If any step here ever becomes async, add\n // another assertStillCurrent() before writing __NEXT_DATA__.\n window.__NEXT_DATA__ = nextData;\n applyVinextLocaleGlobals(window, nextData);\n root.render(element);\n } finally {\n // Clean up the abort controller if this navigation is still the active one\n if (navId === _navigationId) {\n _activeAbortController = null;\n }\n }\n}\n\n/**\n * Run navigateClient and handle errors: emit routeChangeError on failure,\n * and fall back to a hard navigation for non-cancel errors so the browser\n * recovers to a consistent state.\n *\n * Returns:\n * - \"completed\" — navigation finished, caller should emit routeChangeComplete\n * - \"cancelled\" — superseded by a newer navigation, caller should return true\n * without emitting routeChangeComplete (matches Next.js behaviour)\n * - \"failed\" — genuine error, caller should return false (hard nav is already\n * scheduled as recovery)\n */\nasync function runNavigateClient(\n fullUrl: string,\n resolvedUrl: string,\n fetchUrl = fullUrl,\n): Promise<\"completed\" | \"cancelled\" | \"failed\"> {\n try {\n await navigateClient(fullUrl, fetchUrl);\n return \"completed\";\n } catch (err: unknown) {\n routerEvents.emit(\"routeChangeError\", err, resolvedUrl, { shallow: false });\n if (err instanceof NavigationCancelledError) {\n return \"cancelled\";\n }\n // Genuine error (network, parse, import failure): fall back to a hard\n // navigation so the browser lands on the correct page. Known failure modes\n // throw HardNavigationScheduledError, and this guard skips those; only\n // unexpected failures (parse, import, render) need recovery here.\n if (typeof window !== \"undefined\" && !(err instanceof HardNavigationScheduledError)) {\n window.location.href = fullUrl;\n }\n return \"failed\";\n }\n}\n\n/**\n * Build the full router value object from the current pathname, query, asPath,\n * and a set of navigation methods. Shared by the Pages Router context provider\n * and tests so the public router shape stays in sync.\n */\nfunction buildRouterValue(\n pathname: string,\n query: Record<string, string | string[]>,\n asPath: string,\n methods: {\n push: NextRouter[\"push\"];\n replace: NextRouter[\"replace\"];\n back: NextRouter[\"back\"];\n reload: NextRouter[\"reload\"];\n prefetch: NextRouter[\"prefetch\"];\n beforePopState: NextRouter[\"beforePopState\"];\n },\n): NextRouter {\n const _ssrState = _getSSRContext();\n const nextData =\n typeof window !== \"undefined\"\n ? (window.__NEXT_DATA__ as VinextNextData | undefined)\n : undefined;\n const locale = typeof window === \"undefined\" ? _ssrState?.locale : window.__VINEXT_LOCALE__;\n const locales = typeof window === \"undefined\" ? _ssrState?.locales : window.__VINEXT_LOCALES__;\n const defaultLocale =\n typeof window === \"undefined\" ? _ssrState?.defaultLocale : window.__VINEXT_DEFAULT_LOCALE__;\n const domainLocales =\n typeof window === \"undefined\" ? _ssrState?.domainLocales : nextData?.domainLocales;\n\n const route = typeof window !== \"undefined\" ? (nextData?.page ?? pathname) : pathname;\n\n return {\n pathname,\n route,\n query,\n asPath,\n basePath: __basePath,\n locale,\n locales,\n defaultLocale,\n domainLocales,\n isReady: true,\n isPreview: false,\n isFallback:\n typeof window !== \"undefined\"\n ? nextData?.isFallback === true\n : _ssrState?.isFallback === true,\n ...methods,\n events: routerEvents,\n };\n}\n\n/** Extract the hash fragment from a URL, including the leading `#`. */\nfunction extractHash(url: string): string {\n const i = url.indexOf(\"#\");\n return i === -1 ? \"\" : url.slice(i);\n}\n\n/** Notify in-page listeners (e.g. useRouter hooks) that navigation occurred. */\nfunction dispatchNavigateEvent(): void {\n window.dispatchEvent(new CustomEvent(\"vinext:navigate\"));\n}\n\n/**\n * Update history with the new URL and refresh the hash-only-detection tracker.\n * Centralises the `pushState`/`replaceState` branch so callers don't repeat it.\n */\nfunction updateHistory(mode: \"push\" | \"replace\", url: string): void {\n if (mode === \"push\") window.history.pushState({}, \"\", url);\n else window.history.replaceState({}, \"\", url);\n _lastPathnameAndSearch = window.location.pathname + window.location.search;\n}\n\n/**\n * Throw the canonical \"no router instance\" error used when a Pages Router\n * navigation method (push/replace/back/reload/prefetch/beforePopState) is\n * invoked during SSR or prerendering.\n *\n * Mirrors Next.js's `ServerRouter.push`/`replace`/etc. which all call\n * `noRouter()` in `packages/next/src/server/render.tsx`. The error message\n * matches Next.js verbatim so userland error handling and docs links work\n * unchanged.\n *\n * Ported from Next.js: packages/next/src/server/render.tsx\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/server/render.tsx\n */\nfunction throwNoRouterInstance(): never {\n throw new Error(\n 'No router instance found. you should only use \"next/router\" inside the client side of your app. https://nextjs.org/docs/messages/no-router-instance',\n );\n}\n\n/**\n * Shared client-side navigation flow used by both `useRouter()` and the\n * `Router` singleton. The only differences between push/replace are the\n * history method (`pushState` vs `replaceState`), the external-URL fallback\n * (`assign` vs `replace`), and the fact that push saves scroll position for\n * back/forward restoration while replace does not.\n *\n * `onStateUpdate` lets the hook trigger a `setState` re-render at the same\n * point that hashChangeComplete/routeChangeComplete fires; the singleton\n * passes no callback.\n */\nasync function performNavigation(\n url: string | UrlObject,\n as: string | undefined,\n options: TransitionOptions | undefined,\n mode: \"push\" | \"replace\",\n onStateUpdate?: () => void,\n): Promise<boolean> {\n // SSR / prerender guard. Calling Router.push or Router.replace from a\n // Pages Router component during server rendering would otherwise crash\n // with `ReferenceError: window is not defined` (window.location is\n // accessed unconditionally below). Match Next.js's `ServerRouter.push`\n // behaviour and throw the documented \"no router instance\" error so the\n // failure surfaces as a normal render error instead of a ReferenceError\n // that takes down the request pipeline.\n if (typeof window === \"undefined\") {\n throwNoRouterInstance();\n }\n\n // Block dangerous URI schemes (javascript:, data:, vbscript:) before any\n // navigation work happens. Mirrors Next.js's Pages Router guard at\n // packages/next/src/shared/lib/router/router.ts:1020-1028,1052-1060, which\n // throws and (via React's event-handler runtime) surfaces a console.error\n // that the `test/e2e/app-dir/javascript-urls/javascript-urls.test.ts` suite\n // asserts on. `assertSafeNavigationUrl` emits the matching console.error\n // before throwing so the same observable behaviour holds when the throw is\n // swallowed by an async event handler (e.g. Link's click delegation).\n assertSafeNavigationUrl(resolveUrl(url));\n if (as !== undefined) {\n assertSafeNavigationUrl(String(as));\n }\n\n const navigationLocale = resolveTransitionLocale(options?.locale);\n let resolved = resolveNavigationTarget(url, as, navigationLocale);\n\n // External URLs — delegate to browser (unless same-origin)\n if (isExternalUrl(resolved)) {\n const localPath = toSameOriginAppPath(resolved, __basePath);\n if (localPath == null) {\n if (mode === \"push\") window.location.assign(resolved);\n else window.location.replace(resolved);\n return true;\n }\n resolved = localPath;\n }\n\n resolved = normalizePathTrailingSlash(resolved, __trailingSlash);\n const full = normalizePathTrailingSlash(\n toBrowserNavigationHref(resolved, window.location.href, __basePath),\n __trailingSlash,\n );\n const htmlFetchUrl = getPagesHtmlFetchUrl(full, navigationLocale);\n const shallow = options?.shallow ?? false;\n const doScroll = options?.scroll !== false;\n\n // Hash-only change — no page fetch needed\n if (isHashOnlyChange(full)) {\n const eventUrl = resolveHashUrl(full);\n routerEvents.emit(\"hashChangeStart\", eventUrl, { shallow });\n updateHistory(mode, resolved.startsWith(\"#\") ? resolved : full);\n if (doScroll) scrollToHashTarget(extractHash(resolved));\n onStateUpdate?.();\n routerEvents.emit(\"hashChangeComplete\", eventUrl, { shallow });\n dispatchNavigateEvent();\n return true;\n }\n\n if (mode === \"push\") saveScrollPosition();\n routerEvents.emit(\"routeChangeStart\", resolved, { shallow });\n routerEvents.emit(\"beforeHistoryChange\", resolved, { shallow });\n updateHistory(mode, full);\n if (!shallow) {\n const result = await runNavigateClient(full, resolved, htmlFetchUrl);\n if (result === \"cancelled\") return true;\n if (result === \"failed\") return false;\n }\n onStateUpdate?.();\n routerEvents.emit(\"routeChangeComplete\", resolved, { shallow });\n\n const hash = extractHash(resolved);\n if (doScroll) {\n if (hash) scrollToHashTarget(hash);\n else window.scrollTo(0, 0);\n }\n dispatchNavigateEvent();\n return true;\n}\n\n/** Inject a `<link rel=\"prefetch\">` for the target page. */\nasync function prefetchUrl(url: string): Promise<void> {\n if (typeof document !== \"undefined\") {\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.href = url;\n link.as = \"document\";\n document.head.appendChild(link);\n }\n}\n\n/**\n * useRouter hook - Pages Router compatible.\n *\n * Ported from Next.js: packages/next/src/client/router.ts\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/router.ts\n */\nexport function useRouter(): NextRouter {\n const router = useContext(RouterContext);\n if (!router) {\n throw new Error(\n \"NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted\",\n );\n }\n\n return router;\n}\n\nfunction PagesRouterProvider({ children }: { children: ReactNode }): ReactElement {\n const [{ pathname, query, asPath }, setState] = useState(getPathnameAndQuery);\n\n // Popstate is handled by the Pages Router client entry via\n // installPagesRouterRuntime() so beforePopState() is consistently enforced\n // regardless of hook consumers. Keep URL snapshot subscriptions at the\n // provider boundary so many useRouter() calls share one router state and one\n // vinext:navigate listener.\n useEffect(() => {\n const onNavigate = ((_e: CustomEvent) => {\n setState(getPathnameAndQuery());\n }) as EventListener;\n window.addEventListener(\"vinext:navigate\", onNavigate);\n return () => window.removeEventListener(\"vinext:navigate\", onNavigate);\n }, []);\n\n const router = useMemo(\n (): NextRouter =>\n buildRouterValue(pathname, query, asPath, {\n push: Router.push,\n replace: Router.replace,\n back: Router.back,\n reload: Router.reload,\n prefetch: Router.prefetch,\n beforePopState: Router.beforePopState,\n }),\n [pathname, query, asPath],\n );\n\n return createElement(RouterContext.Provider, { value: router }, children);\n}\n\n// beforePopState callback: called before handling browser back/forward.\n// If it returns false, the navigation is cancelled.\nlet _beforePopStateCb: BeforePopStateCallback | undefined;\n\n// Track pathname+search for detecting hash-only back/forward in the popstate\n// handler. Updated after every pushState/replaceState so that popstate can\n// compare the previous value with the (already-changed) window.location.\nlet _lastPathnameAndSearch =\n typeof window !== \"undefined\" ? window.location.pathname + window.location.search : \"\";\n\nfunction handlePagesRouterPopState(e: PopStateEvent): void {\n const browserUrl = window.location.pathname + window.location.search;\n const appUrl = stripBasePath(window.location.pathname, __basePath) + window.location.search;\n\n // Detect hash-only back/forward: pathname+search unchanged, only hash differs.\n const isHashOnly = browserUrl === _lastPathnameAndSearch;\n\n // Check beforePopState callback\n if (_beforePopStateCb !== undefined) {\n const shouldContinue = _beforePopStateCb({\n url: appUrl,\n as: appUrl,\n options: { shallow: false },\n });\n if (!shouldContinue) return;\n }\n\n // Update tracker only after beforePopState confirms navigation proceeds.\n // If beforePopState cancels, the tracker must retain the previous value\n // so the next popstate compares against the correct baseline.\n _lastPathnameAndSearch = browserUrl;\n\n if (isHashOnly) {\n // Hash-only back/forward — no page fetch needed\n const hashUrl = appUrl + window.location.hash;\n routerEvents.emit(\"hashChangeStart\", hashUrl, { shallow: false });\n scrollToHashTarget(window.location.hash);\n routerEvents.emit(\"hashChangeComplete\", hashUrl, { shallow: false });\n dispatchNavigateEvent();\n return;\n }\n\n const fullAppUrl = appUrl + window.location.hash;\n routerEvents.emit(\"routeChangeStart\", fullAppUrl, { shallow: false });\n // Note: The browser has already updated window.location by the time popstate\n // fires, so this is not truly \"before\" the URL change. In Next.js the popstate\n // handler calls replaceState to store history metadata — beforeHistoryChange\n // precedes that call, not the URL change itself. We emit it here for API\n // compatibility.\n routerEvents.emit(\"beforeHistoryChange\", fullAppUrl, { shallow: false });\n void (async () => {\n const result = await runNavigateClient(\n browserUrl,\n fullAppUrl,\n getPagesHtmlFetchUrl(browserUrl, window.__VINEXT_LOCALE__),\n );\n if (result === \"completed\") {\n routerEvents.emit(\"routeChangeComplete\", fullAppUrl, { shallow: false });\n restoreScrollPosition(e.state);\n dispatchNavigateEvent();\n }\n // \"cancelled\": superseded by a newer navigation, so this popstate no longer wins.\n // \"failed\": runNavigateClient already scheduled the hard-navigation fallback.\n })();\n}\n\nsetPagesRouterPopStateHandler(handlePagesRouterPopState);\n\n/**\n * Wrap a React element in a RouterContext.Provider so that\n * next/compat/router's useRouter() returns the real Pages Router value.\n *\n * The provider owns the reactive Pages Router snapshot so next/router and\n * next/compat/router consumers share one context value instead of each hook\n * installing its own global URL-change listener.\n */\nexport function wrapWithRouterContext(element: ReactElement): ReactElement {\n return createElement(PagesRouterProvider, null, element);\n}\n\n/**\n * Props injected by `withRouter` into the wrapped component.\n *\n * Ported from Next.js: packages/next/src/client/with-router.tsx\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/with-router.tsx\n */\nexport type WithRouterProps = {\n router: NextRouter;\n};\n\n/**\n * Pick<P, Exclude<keyof P, keyof WithRouterProps>> — the props of the\n * composed component minus the `router` prop that `withRouter` injects.\n *\n * Ported from Next.js: packages/next/src/client/with-router.tsx\n */\nexport type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>;\n\n/**\n * Higher-order component that injects the Pages Router `router` instance as\n * a `router` prop into a wrapped component. Primarily used by class\n * components (which cannot call hooks) to access the router. The wrapped\n * component receives the same props as the original, minus `router`, which\n * is filled in by the HOC.\n *\n * Ported from Next.js: packages/next/src/client/with-router.tsx\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/with-router.tsx\n *\n * Differences from Next.js:\n * - We type the composed component as `ComponentType<P>` instead of\n * `NextComponentType<C, any, P>` because vinext does not expose\n * `NextComponentType` from this shim. The runtime shape (and the props\n * the wrapper forwards) is identical.\n * - We forward `getInitialProps` and `origGetInitialProps` from the\n * composed component so `_app` parity holds for class components that\n * define `getInitialProps`.\n */\nexport function withRouter<P extends WithRouterProps>(\n ComposedComponent: ComponentType<P>,\n): ComponentType<ExcludeRouterProps<P>> {\n function WithRouterWrapper(props: ExcludeRouterProps<P>): ReactElement {\n const router = useRouter();\n // Match Next.js spread order:\n // `<ComposedComponent router={useRouter()} {...props} />`\n // The injected `router` is placed first, and `{...props}` is spread\n // after, so a user-passed `router` prop overrides the HOC-injected\n // one (last-spread wins). Mirrors\n // packages/next/src/client/with-router.tsx. At the type level\n // `props: ExcludeRouterProps<P>` has no `router` key, but TS still\n // sees `P` as `WithRouterProps`-extending when checking the literal,\n // so we widen to a `Record` for the final prop bag.\n const merged: Record<string, unknown> = { router, ...(props as Record<string, unknown>) };\n return createElement(ComposedComponent, merged as unknown as P);\n }\n\n // Forward getInitialProps so class-component pages that define it keep\n // working when wrapped. Mirrors Next.js's with-router.tsx.\n const composed = ComposedComponent as ComponentType<P> & {\n getInitialProps?: unknown;\n origGetInitialProps?: unknown;\n };\n (WithRouterWrapper as unknown as { getInitialProps?: unknown }).getInitialProps =\n composed.getInitialProps;\n (WithRouterWrapper as unknown as { origGetInitialProps?: unknown }).origGetInitialProps =\n composed.origGetInitialProps;\n\n if (process.env.NODE_ENV !== \"production\") {\n const name = composed.displayName || composed.name || \"Unknown\";\n WithRouterWrapper.displayName = `withRouter(${name})`;\n }\n\n return WithRouterWrapper;\n}\n\n// Note: `withRouter` is exposed only as a named export from `next/router`.\n// The default export of that module is the Router singleton declared below.\n\n// Also export a default Router singleton for `import Router from 'next/router'`.\n//\n// State fields (`pathname`, `route`, `query`, `asPath`, etc.) are exposed as\n// live getters so `window.next.router.pathname` reflects the current URL\n// without callers needing to know about React render cycles. Mirrors\n// Next.js's `singletonRouter` shape from\n// .nextjs-ref/packages/next/src/client/router.ts (lines 32–47), which uses\n// `Object.defineProperty` to forward `urlPropertyFields` to the active\n// router instance. The Next.js deploy test suite drives navigations through\n// `browser.eval('next.router.push(...)')` and then reads\n// `browser.eval('next.router.pathname')` to assert success, so the fields\n// must be readable, not just the methods.\n//\n// Every navigation method is also guarded against SSR/prerender execution.\n// Matches Next.js's `ServerRouter` (packages/next/src/server/render.tsx) which\n// throws `noRouter()` from push/replace/back/reload/prefetch/beforePopState so\n// that invoking them during server rendering surfaces as a documented render\n// error rather than a `ReferenceError: window is not defined`. The throws are\n// synchronous (not via the returned Promise) so render-time callers see the\n// error inline — matching Next.js behaviour and avoiding unhandled rejections.\nconst RouterMethods = {\n push: (url: string | UrlObject, as?: string, options?: TransitionOptions) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n return performNavigation(url, as, options, \"push\");\n },\n replace: (url: string | UrlObject, as?: string, options?: TransitionOptions) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n return performNavigation(url, as, options, \"replace\");\n },\n back: () => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n window.history.back();\n },\n reload: () => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n window.location.reload();\n },\n prefetch: (url: string) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n return prefetchUrl(url);\n },\n beforePopState: (cb: BeforePopStateCallback) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n _beforePopStateCb = cb;\n },\n events: routerEvents,\n};\n\nconst Router: typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods> =\n Object.defineProperties(RouterMethods, {\n pathname: {\n enumerable: true,\n get(): string {\n return getPathnameAndQuery().pathname;\n },\n },\n route: {\n enumerable: true,\n get(): string {\n const { pathname } = getPathnameAndQuery();\n if (typeof window === \"undefined\") return pathname;\n const nextData = window.__NEXT_DATA__ as VinextNextData | undefined;\n return nextData?.page ?? pathname;\n },\n },\n query: {\n enumerable: true,\n get(): Record<string, string | string[]> {\n return getPathnameAndQuery().query;\n },\n },\n asPath: {\n enumerable: true,\n get(): string {\n return getPathnameAndQuery().asPath;\n },\n },\n basePath: { enumerable: true, value: __basePath, writable: false },\n locale: {\n enumerable: true,\n get(): string | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.locale;\n return window.__VINEXT_LOCALE__;\n },\n },\n locales: {\n enumerable: true,\n get(): string[] | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.locales;\n return window.__VINEXT_LOCALES__;\n },\n },\n defaultLocale: {\n enumerable: true,\n get(): string | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.defaultLocale;\n return window.__VINEXT_DEFAULT_LOCALE__;\n },\n },\n domainLocales: {\n enumerable: true,\n get(): VinextNextData[\"domainLocales\"] | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.domainLocales;\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.domainLocales;\n },\n },\n isReady: { enumerable: true, value: true, writable: false },\n isPreview: { enumerable: true, value: false, writable: false },\n isFallback: {\n enumerable: true,\n get(): boolean {\n if (typeof window === \"undefined\") return _getSSRContext()?.isFallback === true;\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.isFallback === true;\n },\n },\n }) as typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods>;\n\n// Expose `window.next.router` for Next.js parity. Pages Router test suites,\n// userland scripts, and third-party libraries reach for this global directly\n// (e.g. `window.next.router.push(...)`, `window.next.router.events.on(...)`,\n// `window.next.router.pathname`).\n// Without this assignment, those callers crash with\n// `TypeError: Cannot read properties of undefined (reading 'router')`.\n//\n// Ported from Next.js: `packages/next/src/client/next.ts` (line 13). We do\n// NOT use a live-binding getter like Next.js does because vinext's Router\n// singleton is constructed synchronously here, so by the time this module\n// finishes loading the value is final.\nif (typeof window !== \"undefined\") {\n // Cast: `NextRouter.push`/`replace` are typed with narrow parameters\n // (UrlObject | string) while `PagesRouterPublicInstance` accepts unknown\n // args. The two are structurally compatible at runtime; TypeScript flags\n // the narrowing of contravariant function params, which is benign here\n // because callers reading off `window.next.router` are tests/userland\n // and treat the surface as opaque.\n installWindowNext({ router: Router as unknown as PagesRouterPublicInstance });\n}\n\n// Register the Pages Router compat shim source for `next/navigation` hooks\n// (useParams / useSearchParams / usePathname). The accessor is exposed\n// through a well-known Symbol.for so navigation.ts can read it without\n// importing this module — that avoids triggering navigation.ts's\n// `window.history.pushState` patch in tests that only need next/router.\n//\n// Mirrors Next.js's behavior where the pages-router server (render.tsx) and\n// client (client/index.tsx) wrap pages with SearchParamsContext /\n// PathParamsContext / PathnameContext providers populated from the router.\nconst _PAGES_NAVIGATION_ACCESSOR_KEY = Symbol.for(\n \"vinext.navigation.pagesNavigationContextAccessor\",\n);\n(globalThis as Record<PropertyKey, unknown>)[_PAGES_NAVIGATION_ACCESSOR_KEY] =\n getPagesNavigationContext;\n\nexport default Router;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqDA,MAAM,aAAqB,QAAQ,IAAI,0BAA0B;;AAEjE,MAAM,kBAA2B,QAAQ,IAAI,4BAA4B;AAmEzE,SAAS,qBAAmC;CAC1C,MAAM,4BAAY,IAAI,KAAgD;CAEtE,OAAO;EACL,GAAG,OAAe,SAAuC;GACvD,IAAI,CAAC,UAAU,IAAI,MAAM,EAAE,UAAU,IAAI,uBAAO,IAAI,KAAK,C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":[],"sources":["../../src/shims/router.ts"],"sourcesContent":["/**\n * next/router shim\n *\n * Provides useRouter() hook and Router singleton for Pages Router.\n * Backed by the browser History API. Supports client-side navigation\n * by fetching new page data and re-rendering the React root.\n */\nimport {\n useState,\n useEffect,\n useMemo,\n useContext,\n createElement,\n type ReactElement,\n type ReactNode,\n type ComponentType,\n} from \"react\";\nimport { RouterContext } from \"./internal/router-context.js\";\nimport {\n applyVinextLocaleGlobals,\n extractVinextNextDataJson,\n parseVinextNextDataJson,\n type VinextNextData,\n} from \"../client/vinext-next-data.js\";\nimport { isValidModulePath } from \"../client/validate-module-path.js\";\nimport {\n prefetchPagesData,\n resolvePagesDataNavigationTarget,\n type PagesDataTarget,\n} from \"./internal/pages-data-target.js\";\nimport { buildPagesDataHref } from \"./internal/pages-data-url.js\";\nimport { installWindowNext, type PagesRouterPublicInstance } from \"../client/window-next.js\";\nimport { isUnknownRecord } from \"../utils/record.js\";\nimport {\n isAbsoluteOrProtocolRelativeUrl,\n isHashOnlyBrowserUrlChange,\n normalizePathTrailingSlash,\n toBrowserNavigationHref,\n toSameOriginAppPath,\n getWindowOrigin,\n} from \"./url-utils.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport {\n addLocalePrefix,\n getDomainLocaleUrl,\n getLocalePathPrefix,\n type DomainLocale,\n} from \"../utils/domain-locale.js\";\nimport {\n addQueryParam,\n appendSearchParamsToUrl,\n mergeRouteParamsIntoQuery,\n parseQueryString,\n type UrlQuery,\n urlQueryToSearchParams,\n} from \"../utils/query.js\";\nimport { matchRoutePattern, routePatternParts } from \"../routing/route-pattern.js\";\nimport { scrollToHashTarget } from \"./hash-scroll.js\";\nimport { setPagesRouterPopStateHandler } from \"./pages-router-runtime.js\";\nimport { assertSafeNavigationUrl } from \"./url-safety.js\";\nimport { getCurrentBrowserLocale } from \"./client-locale.js\";\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\";\n\ntype BeforePopStateCallback = (state: {\n url: string;\n as: string;\n options: { shallow: boolean };\n}) => boolean;\n\nexport type NextRouter = {\n /** Current pathname */\n pathname: string;\n /** Current route pattern (e.g., \"/posts/[id]\") */\n route: string;\n /** Query parameters */\n query: Record<string, string | string[]>;\n /** Full URL including query string */\n asPath: string;\n /** Base path */\n basePath: string;\n /** Current locale */\n locale?: string;\n /** Available locales */\n locales?: string[];\n /** Default locale */\n defaultLocale?: string;\n /** Configured domain locales */\n domainLocales?: VinextNextData[\"domainLocales\"];\n /** Whether the router is ready */\n isReady: boolean;\n /** Whether this is a preview */\n isPreview: boolean;\n /** Whether this is a fallback page */\n isFallback: boolean;\n\n /** Navigate to a new URL */\n push(url: string | UrlObject, as?: string, options?: TransitionOptions): Promise<boolean>;\n /** Replace current URL */\n replace(url: string | UrlObject, as?: string, options?: TransitionOptions): Promise<boolean>;\n /** Go back */\n back(): void;\n /** Reload the page */\n reload(): void;\n /** Prefetch a page (injects <link rel=\"prefetch\">) */\n prefetch(url: string): Promise<void>;\n /** Register a callback to run before popstate navigation */\n beforePopState(cb: BeforePopStateCallback): void;\n /** Listen for route changes */\n events: RouterEvents;\n};\n\ntype UrlObject = {\n pathname?: string;\n query?: UrlQuery;\n};\n\ntype TransitionOptions = {\n shallow?: boolean;\n scroll?: boolean;\n locale?: string | false;\n};\n\ntype RouterEvents = {\n on(event: string, handler: (...args: unknown[]) => void): void;\n off(event: string, handler: (...args: unknown[]) => void): void;\n emit(event: string, ...args: unknown[]): void;\n};\n\nfunction createRouterEvents(): RouterEvents {\n const listeners = new Map<string, Set<(...args: unknown[]) => void>>();\n\n return {\n on(event: string, handler: (...args: unknown[]) => void) {\n if (!listeners.has(event)) listeners.set(event, new Set());\n (listeners.get(event) as Set<(...args: unknown[]) => void>).add(handler);\n },\n off(event: string, handler: (...args: unknown[]) => void) {\n listeners.get(event)?.delete(handler);\n },\n emit(event: string, ...args: unknown[]) {\n listeners.get(event)?.forEach((handler) => handler(...args));\n },\n };\n}\n\n// Singleton events instance\nconst routerEvents = createRouterEvents();\n\nfunction resolveUrl(url: string | UrlObject): string {\n if (typeof url === \"string\") return url;\n let result = url.pathname ?? \"/\";\n if (url.query) {\n const params = urlQueryToSearchParams(url.query);\n result = appendSearchParamsToUrl(result, params);\n }\n return result;\n}\n\n/**\n * When `as` is provided, use it as the navigation target. This is a\n * simplification: Next.js keeps `url` and `as` as separate values (url for\n * data fetching, as for the browser URL). We collapse them because vinext's\n * navigateClient() fetches HTML from the target URL, so `as` must be a\n * server-resolvable path. Purely decorative `as` values are not supported.\n * Pages error routes are handled as a narrow exception below because Next.js\n * treats their href as the component route while preserving `as` in history.\n */\nfunction resolveNavigationTarget(\n url: string | UrlObject,\n as: string | undefined,\n locale: string | undefined,\n): string {\n return applyNavigationLocale(as ?? resolveUrl(url), locale);\n}\n\nfunction getCurrentUrlLocale(): string | undefined {\n return getCurrentBrowserLocale({\n basePath: __basePath,\n domainLocales: getDomainLocales(),\n hostname: getCurrentHostname(),\n });\n}\n\nfunction getLocalPathname(url: string): string | null {\n if (typeof window === \"undefined\") return null;\n if (isAbsoluteOrProtocolRelativeUrl(url)) {\n const localPath = toSameOriginAppPath(url, __basePath);\n if (localPath == null) return null;\n return stripBasePath(new URL(localPath, window.location.href).pathname, __basePath);\n }\n try {\n return stripBasePath(new URL(url, window.location.href).pathname, __basePath);\n } catch {\n return null;\n }\n}\n\nfunction resolvePagesErrorHtmlFetchUrl(\n url: string | UrlObject,\n locale: string | undefined,\n): string | null {\n const href = resolveUrl(url);\n const errorRoutePathname = getLocalPathname(href);\n if (errorRoutePathname !== \"/404\" && errorRoutePathname !== \"/_error\") return null;\n\n const fetchHref = errorRoutePathname === \"/_error\" ? replaceUrlPathname(href, \"/404\") : href;\n const resolvedUrl = applyNavigationLocale(fetchHref, locale);\n\n let parsed: URL;\n try {\n parsed = new URL(resolvedUrl, window.location.href);\n } catch {\n return null;\n }\n const appPathname = stripBasePath(parsed.pathname, __basePath);\n const fetchTarget = `${appPathname}${parsed.search}${parsed.hash}`;\n return normalizePathTrailingSlash(\n toBrowserNavigationHref(fetchTarget, window.location.href, __basePath),\n __trailingSlash,\n );\n}\n\nfunction replaceUrlPathname(url: string, pathname: string): string {\n try {\n const parsed = new URL(url, window.location.href);\n return `${pathname}${parsed.search}${parsed.hash}`;\n } catch {\n return pathname;\n }\n}\n\nfunction resolveTransitionLocale(locale: TransitionOptions[\"locale\"]): string | undefined {\n if (typeof window === \"undefined\") return undefined;\n if (locale === false) return window.__VINEXT_DEFAULT_LOCALE__;\n return locale ?? getCurrentUrlLocale();\n}\n\nfunction getDomainLocales(): readonly DomainLocale[] | undefined {\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.domainLocales;\n}\n\nfunction getCurrentHostname(): string | undefined {\n return window.location?.hostname;\n}\n\nfunction getDomainLocalePath(url: string, locale: string): string | undefined {\n return getDomainLocaleUrl(url, locale, {\n basePath: __basePath,\n currentHostname: getCurrentHostname(),\n domainItems: getDomainLocales(),\n });\n}\n\n/**\n * Apply locale prefix to a URL for client-side navigation.\n * Same logic as Link's applyLocaleToHref but reads from window globals.\n */\nexport function applyNavigationLocale(url: string, locale?: string): string {\n if (!locale || typeof window === \"undefined\") return url;\n // Absolute and protocol-relative URLs must not be prefixed — locale\n // only applies to local paths.\n if (isAbsoluteOrProtocolRelativeUrl(url)) {\n return url;\n }\n if (getLocalePathPrefix(url, window.__VINEXT_LOCALES__)) {\n return url;\n }\n\n const domainLocalePath = getDomainLocalePath(url, locale);\n if (domainLocalePath) return domainLocalePath;\n\n return addLocalePrefix(url, locale, window.__VINEXT_DEFAULT_LOCALE__ ?? \"\");\n}\n\nfunction isDefaultLocaleRootNavigation(url: string, locale: string | undefined): boolean {\n if (typeof window === \"undefined\") return false;\n if (!locale || locale !== window.__VINEXT_DEFAULT_LOCALE__) return false;\n\n let parsed: URL;\n try {\n parsed = new URL(url, window.location.href);\n } catch {\n return false;\n }\n\n return stripBasePath(parsed.pathname, __basePath) === \"/\";\n}\n\nfunction getPagesHtmlFetchUrl(browserUrl: string, locale: string | undefined): string {\n if (!isDefaultLocaleRootNavigation(browserUrl, locale)) return browserUrl;\n\n // Browser URL stays unprefixed for the default locale, but the internal\n // HTML fetch must bypass root Accept-Language detection.\n const parsed = new URL(browserUrl, window.location.href);\n const localeRoot = normalizePathTrailingSlash(`/${locale}`, __trailingSlash);\n // Base path joining can change slash shape, then the final URL must still\n // conform to the app's trailingSlash setting.\n return normalizePathTrailingSlash(\n toBrowserNavigationHref(\n `${localeRoot}${parsed.search}${parsed.hash}`,\n window.location.href,\n __basePath,\n ),\n __trailingSlash,\n );\n}\n\n/** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */\nexport function isExternalUrl(url: string): boolean {\n return isAbsoluteOrProtocolRelativeUrl(url);\n}\n\n/** Resolve a hash URL to a basePath-stripped app URL for event payloads */\nfunction resolveHashUrl(url: string): string {\n if (typeof window === \"undefined\") return url;\n if (url.startsWith(\"#\"))\n return stripBasePath(window.location.pathname, __basePath) + window.location.search + url;\n // Full-path hash URL — strip basePath for consistency with other events\n try {\n const parsed = new URL(url, window.location.href);\n return stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;\n } catch {\n return url;\n }\n}\n\n/** Check if a href is only a hash change relative to the current URL */\nexport function isHashOnlyChange(href: string): boolean {\n if (href.startsWith(\"#\")) return true;\n if (typeof window === \"undefined\") return false;\n return isHashOnlyBrowserUrlChange(href, window.location.href, __basePath);\n}\n\n/** Save current scroll position into history state for back/forward restoration */\nfunction saveScrollPosition(): void {\n const state = window.history.state ?? {};\n window.history.replaceState(\n { ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY },\n \"\",\n );\n}\n\n/** Restore scroll position from history state */\nfunction restoreScrollPosition(state: unknown): void {\n if (state && typeof state === \"object\" && \"__vinext_scrollY\" in state) {\n const { __vinext_scrollX: x, __vinext_scrollY: y } = state as {\n __vinext_scrollX: number;\n __vinext_scrollY: number;\n };\n requestAnimationFrame(() => window.scrollTo(x, y));\n }\n}\n\n/**\n * SSR context - set by the dev server before rendering each page.\n */\ntype SSRContext = {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n domainLocales?: VinextNextData[\"domainLocales\"];\n /**\n * True when rendering a `getStaticPaths` fallback shell for a path that\n * hasn't been pre-rendered yet (`fallback: true` + unlisted path). Mirrors\n * `renderContext.isFallback` in Next.js's `render.tsx`: `getStaticProps`\n * is skipped, the page renders with empty props, and `useRouter().isFallback`\n * returns `true` so user code can show a loading state.\n */\n isFallback?: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Server-side SSR state uses a registration pattern so this module can be\n// bundled for the browser. The ALS-backed implementation lives in\n// router-state.ts (server-only) and registers itself on import.\n// ---------------------------------------------------------------------------\n\nlet _ssrContext: SSRContext | null = null;\n\nlet _getSSRContext = (): SSRContext | null => _ssrContext;\nlet _setSSRContextImpl = (ctx: SSRContext | null): void => {\n _ssrContext = ctx;\n};\n\n/**\n * Register ALS-backed state accessors. Called by router-state.ts on import.\n * @internal\n */\nexport function _registerRouterStateAccessors(accessors: {\n getSSRContext: () => SSRContext | null;\n setSSRContext: (ctx: SSRContext | null) => void;\n}): void {\n _getSSRContext = accessors.getSSRContext;\n _setSSRContextImpl = accessors.setSSRContext;\n}\n\nexport function setSSRContext(ctx: SSRContext | null): void {\n _setSSRContextImpl(ctx);\n}\n\ntype PagesNavigationContextShape = {\n pathname: string;\n searchParams: URLSearchParams;\n params: Record<string, string | string[]>;\n};\n\n// Client-only cache for snapshot stability. useSyncExternalStore compares\n// snapshots with Object.is, so returning a fresh object on every render would\n// trigger re-render loops. We use a module-level cache keyed by URL inputs;\n// this is safe in the browser because there is exactly one request at a time\n// but it must NOT be used on the server (concurrent ALS-scoped requests).\nlet _cachedClientPagesNavCtx: PagesNavigationContextShape | null = null;\nlet _cachedClientPagesNavCtxKey: string | null = null;\n\nfunction _buildClientPagesNavigationContext(\n routePattern: string,\n resolvedPath: string,\n searchString: string,\n): PagesNavigationContextShape {\n const cacheKey = `${routePattern}|${resolvedPath}|${searchString}`;\n if (_cachedClientPagesNavCtxKey === cacheKey && _cachedClientPagesNavCtx) {\n return _cachedClientPagesNavCtx;\n }\n const searchParams = new URLSearchParams(searchString);\n const params = routePattern ? (extractRouteParamsFromPath(routePattern, resolvedPath) ?? {}) : {};\n const ctx: PagesNavigationContextShape = { pathname: resolvedPath, searchParams, params };\n _cachedClientPagesNavCtx = ctx;\n _cachedClientPagesNavCtxKey = cacheKey;\n return ctx;\n}\n\n/**\n * Cross-router compat shim source for `next/navigation` hooks.\n *\n * Returns the current Pages Router state shaped as a navigation context so\n * the App Router hooks (useParams/useSearchParams/usePathname) can act as\n * compat shims when invoked inside a Pages Router render. Mirrors Next.js's\n * `adaptForPathParams` and `adaptForSearchParams` in\n * .nextjs-ref/packages/next/src/shared/lib/router/adapters.tsx, which Next.js\n * uses to populate SearchParamsContext / PathParamsContext for the Pages\n * Router (see packages/next/src/server/render.tsx and\n * packages/next/src/client/index.tsx).\n *\n * Returns `null` when there is no Pages Router state available — e.g. App\n * Router pages, RSC-only renders, or pre-router renders. Callers should\n * treat null as \"App Router context, use normal app-router state\".\n */\nexport function getPagesNavigationContext(): PagesNavigationContextShape | null {\n if (typeof window === \"undefined\") {\n const ssrCtx = _getSSRContext();\n if (!ssrCtx) return null;\n // ssrCtx.pathname is the route pattern (e.g. \"/blog/[slug]\").\n // ssrCtx.asPath is the resolved URL with query string. For useSearchParams\n // we want only the URL search string; for useParams we want only the\n // dynamic route params. Build a fresh object each call — server scope is\n // request-isolated via ALS but module state must not be cached across\n // concurrent requests.\n let searchParams: URLSearchParams;\n let resolvedPath: string;\n try {\n const url = new URL(ssrCtx.asPath, \"http://_\");\n searchParams = url.searchParams;\n resolvedPath = url.pathname;\n } catch {\n searchParams = new URLSearchParams();\n resolvedPath = ssrCtx.pathname;\n }\n const params = extractRouteParamsFromPath(ssrCtx.pathname, resolvedPath) ?? {};\n return { pathname: resolvedPath, searchParams, params };\n }\n\n // Client: derive from window.location + __NEXT_DATA__. __NEXT_DATA__.page\n // is the route pattern that was matched; navigateClient() keeps it in sync\n // with the visible URL on every client-side navigation. Cached so\n // useSyncExternalStore sees a stable snapshot between renders.\n const resolvedPath = stripBasePath(window.location.pathname, __basePath);\n const pattern = window.__NEXT_DATA__?.page ?? \"\";\n return _buildClientPagesNavigationContext(pattern, resolvedPath, window.location.search);\n}\n\n/**\n * Extract param names from a Next.js route pattern.\n * E.g., \"/posts/[id]\" → [\"id\"], \"/docs/[...slug]\" → [\"slug\"],\n * \"/shop/[[...path]]\" → [\"path\"], \"/blog/[year]/[month]\" → [\"year\", \"month\"]\n * Also handles internal format: \"/posts/:id\" → [\"id\"], \"/docs/:slug+\" → [\"slug\"]\n */\nfunction extractRouteParamNames(pattern: string): string[] {\n const names: string[] = [];\n // Match Next.js bracket format: [id], [...slug], [[...slug]]\n // Accepts any non-] characters inside brackets (Next.js PARAMETER_PATTERN parity).\n const bracketMatches = pattern.matchAll(/\\[{1,2}(?:\\.\\.\\.)?([^\\]]+)\\]{1,2}/g);\n for (const m of bracketMatches) {\n names.push(m[1]);\n }\n if (names.length > 0) return names;\n // Fallback: match internal :param format (any chars except /, +, *)\n const colonMatches = pattern.matchAll(/:([^/+*]+)[+*]?/g);\n for (const m of colonMatches) {\n names.push(m[1]);\n }\n return names;\n}\n\ntype RouteQueryNextData = {\n page?: string;\n query?: Record<string, string | string[] | undefined>;\n};\n\nfunction splitPathSegments(pathname: string): string[] {\n return pathname.split(\"/\").filter(Boolean);\n}\n\nfunction extractRouteParamsFromPath(\n pattern: string,\n pathname: string,\n): Record<string, string | string[]> | null {\n return matchRoutePattern(splitPathSegments(pathname), routePatternParts(pattern));\n}\n\nfunction getRouteQueryFromNextData(\n nextData: RouteQueryNextData | undefined,\n resolvedPath: string,\n): Record<string, string | string[]> {\n const routeQuery: Record<string, string | string[]> = {};\n if (!nextData?.query || !nextData.page) return routeQuery;\n\n const routeParamNames = extractRouteParamNames(nextData.page);\n if (routeParamNames.length === 0) return routeQuery;\n\n const currentRouteParams = extractRouteParamsFromPath(nextData.page, resolvedPath);\n if (currentRouteParams) return currentRouteParams;\n\n for (const key of routeParamNames) {\n const value = nextData.query[key];\n if (typeof value === \"string\") {\n routeQuery[key] = value;\n } else if (Array.isArray(value)) {\n routeQuery[key] = [...value];\n }\n }\n return routeQuery;\n}\n\nfunction getPathnameAndQuery(): {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n} {\n if (typeof window === \"undefined\") {\n const _ssrCtx = _getSSRContext();\n if (_ssrCtx) {\n const query: Record<string, string | string[]> = {};\n for (const [key, value] of Object.entries(_ssrCtx.query)) {\n query[key] = Array.isArray(value) ? [...value] : value;\n }\n return { pathname: _ssrCtx.pathname, query, asPath: _ssrCtx.asPath };\n }\n return { pathname: \"/\", query: {}, asPath: \"/\" };\n }\n const resolvedPath = stripBasePath(window.location.pathname, __basePath);\n // In Next.js, router.pathname is the route pattern (e.g., \"/posts/[id]\"),\n // not the resolved path (\"/posts/42\"). __NEXT_DATA__.page holds the route\n // pattern and is updated by navigateClient() on every client-side navigation.\n const pathname = window.__NEXT_DATA__?.page ?? resolvedPath;\n const nextData = window.__NEXT_DATA__;\n const routeQuery = getRouteQueryFromNextData(nextData, resolvedPath);\n // URL search params always reflect the current URL\n const searchQuery: Record<string, string | string[]> = {};\n const params = new URLSearchParams(window.location.search);\n for (const [key, value] of params) {\n addQueryParam(searchQuery, key, value);\n }\n const query = { ...searchQuery, ...routeQuery };\n // asPath uses the resolved browser path, not the route pattern\n const asPath = resolvedPath + window.location.search + window.location.hash;\n return { pathname, query, asPath };\n}\n\n/**\n * Error thrown when a navigation is superseded by a newer one.\n * Matches Next.js's convention of an Error with `.cancelled = true`.\n */\nclass NavigationCancelledError extends Error {\n cancelled = true;\n constructor(route: string) {\n super(`Abort fetching component for route: \"${route}\"`);\n this.name = \"NavigationCancelledError\";\n }\n}\n\n/**\n * Error thrown after queueing a hard navigation fallback for a known failure\n * mode. Callers can use this to avoid scheduling the same hard navigation twice.\n */\nclass HardNavigationScheduledError extends Error {\n hardNavigationScheduled = true;\n constructor(message: string) {\n super(message);\n this.name = \"HardNavigationScheduledError\";\n }\n}\n\n/**\n * Monotonically increasing ID for tracking the current navigation.\n * Each call to navigateClient() increments this and captures the value.\n * After each async boundary, the navigation checks whether it is still\n * the active one. If a newer navigation has started, the stale one\n * throws NavigationCancelledError so the caller can emit routeChangeError\n * and skip routeChangeComplete.\n *\n * Replaces the old boolean `_navInProgress` guard which silently dropped\n * the second navigation, causing URL/content mismatch.\n */\nlet _navigationId = 0;\n\n/** AbortController for the in-flight fetch, so superseded navigations abort network I/O. */\nlet _activeAbortController: AbortController | null = null;\n\nfunction scheduleHardNavigationAndThrow(url: string, message: string): never {\n if (typeof window === \"undefined\") {\n throw new HardNavigationScheduledError(message);\n }\n window.location.href = url;\n throw new HardNavigationScheduledError(message);\n}\n\ntype NavigateClientOptions = {\n allowNotFoundResponse?: boolean;\n};\n\n/** Wire format of `/_next/data/<id>/<page>.json` response bodies. */\ntype PagesDataResponse = {\n pageProps?: Record<string, unknown>;\n // Server may also emit `notFound`, `__N_SSP`, etc. — we only consume\n // `pageProps`; everything else triggers a hard reload per the\n // user-configured fallback policy.\n [key: string]: unknown;\n};\n\nfunction isPageComponent(value: unknown): value is ComponentType<Record<string, unknown>> {\n if (typeof value === \"function\") return true;\n if (!isUnknownRecord(value)) return false;\n return (\n value.$$typeof === Symbol.for(\"react.forward_ref\") ||\n value.$$typeof === Symbol.for(\"react.memo\")\n );\n}\n\nfunction isAppComponent(value: unknown): value is NonNullable<Window[\"__VINEXT_APP__\"]> {\n return isPageComponent(value);\n}\n\nfunction resolveSameOriginRedirectedUrl(responseUrl: string): string | null {\n const appPath = toSameOriginAppPath(responseUrl, __basePath);\n if (appPath === null) return null;\n return normalizePathTrailingSlash(\n toBrowserNavigationHref(appPath, window.location.href, __basePath),\n __trailingSlash,\n );\n}\n\nfunction stripLocalePrefixForApiRedirect(appPath: string): string {\n const locales = window.__VINEXT_LOCALES__;\n if (!locales || locales.length === 0) return appPath;\n\n try {\n const parsed = new URL(appPath, \"http://vinext.local\");\n const pathname = stripBasePath(parsed.pathname, __basePath);\n const firstSegment = pathname.split(\"/\")[1];\n if (!firstSegment || !locales.includes(firstSegment)) return appPath;\n\n const withoutLocale = pathname.slice(firstSegment.length + 1) || \"/\"; // +1 for leading `/`\n if (withoutLocale !== \"/api\" && !withoutLocale.startsWith(\"/api/\")) {\n return appPath;\n }\n\n return `${withoutLocale}${parsed.search}${parsed.hash}`;\n } catch {\n return appPath;\n }\n}\n\nfunction resolveLocalRedirectUrl(location: string): string | null {\n let appPath: string | null;\n if (location.startsWith(\"/\") && !location.startsWith(\"//\")) {\n try {\n // Data redirect headers can already be browser paths with basePath.\n // Convert back to app paths before toBrowserNavigationHref re-applies it.\n const parsed = new URL(location, \"http://vinext.local\");\n appPath = stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;\n } catch {\n appPath = location;\n }\n } else {\n appPath = toSameOriginAppPath(location, __basePath);\n }\n\n if (appPath === null) return null;\n return normalizePathTrailingSlash(\n toBrowserNavigationHref(\n stripLocalePrefixForApiRedirect(appPath),\n window.location.href,\n __basePath,\n ),\n __trailingSlash,\n );\n}\n\nfunction hasVinextMiddleware(nextData: unknown): boolean {\n if (!isUnknownRecord(nextData)) return false;\n const vinext = nextData.__vinext;\n return isUnknownRecord(vinext) && vinext.hasMiddleware === true;\n}\n\nfunction getMiddlewarePagesDataFetchUrl(browserUrl: string): string | null {\n const nextData = window.__NEXT_DATA__;\n if (!nextData || !hasVinextMiddleware(nextData)) return null;\n const buildId = nextData.buildId;\n if (typeof buildId !== \"string\" || buildId.length === 0) 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 !== getWindowOrigin()) return null;\n\n const appPathname = stripBasePath(parsed.pathname, __basePath);\n return buildPagesDataHref(__basePath, buildId, appPathname, parsed.search);\n}\n\nasync function resolveMiddlewareDataRedirect(\n browserUrl: string,\n signal: AbortSignal,\n): Promise<string | null> {\n const dataUrl = getMiddlewarePagesDataFetchUrl(browserUrl);\n if (!dataUrl) return null;\n\n try {\n const res = await fetch(dataUrl, {\n headers: {\n Accept: \"application/json\",\n \"x-nextjs-data\": \"1\",\n },\n signal,\n });\n return res.headers.get(\"x-nextjs-redirect\");\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === \"AbortError\") throw err;\n return null;\n }\n}\n\n/**\n * Perform client-side navigation via the `/_next/data/<id>/<page>.json`\n * endpoint. Used when `__VINEXT_PAGE_LOADERS__` has a matching code-split\n * loader for the target pattern (the prod hot path). Falls back to the\n * HTML extraction path (`navigateClientHtml`) when this returns `null`.\n *\n * Failure modes (404, 5xx, network, parse, missing loader, soft redirect)\n * all queue a hard navigation and throw `HardNavigationScheduledError`,\n * mirroring the existing HTML-path failure protocol. The hard reload is\n * the deploy-skew safety net: when the server's buildId has rotated, the\n * data endpoint returns 404 and the client lands on the new build via a\n * full document load.\n */\nasync function navigateClientData(\n url: string,\n target: PagesDataTarget,\n controller: AbortController,\n navId: number,\n assertStillCurrent: () => void,\n): Promise<void> {\n const root = window.__VINEXT_ROOT__;\n if (!root) {\n // No React root yet — fall back to hard navigation\n window.location.href = url;\n return;\n }\n\n // Fetch the page-data JSON.\n let res: Response;\n try {\n res = await fetch(target.dataHref, {\n headers: { Accept: \"application/json\", \"x-nextjs-data\": \"1\" },\n signal: controller.signal,\n });\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new NavigationCancelledError(url);\n }\n throw err;\n }\n assertStillCurrent();\n\n // Soft-redirect protocol: the data endpoint emits 200 + x-nextjs-redirect\n // when middleware (or gSSP/gSP) chose a redirect for this URL.\n const softRedirect = res.headers.get(\"x-nextjs-redirect\");\n if (softRedirect) {\n const redirectedUrl = resolveLocalRedirectUrl(softRedirect);\n if (!redirectedUrl) {\n scheduleHardNavigationAndThrow(softRedirect, \"Navigation redirected externally\");\n }\n\n window.history.replaceState(window.history.state ?? {}, \"\", redirectedUrl);\n _lastPathnameAndSearch = window.location.pathname + window.location.search;\n await navigateClientHtml(redirectedUrl, redirectedUrl, controller, navId, assertStillCurrent);\n return;\n }\n\n if (!res.ok) {\n // 404 here is the deploy-skew signal (server buildId rotated) — hard\n // reload to land on the new build's HTML. Any other non-OK status is\n // treated the same way per the user-configured \"always hard reload\"\n // fallback policy.\n scheduleHardNavigationAndThrow(url, `Data navigation failed: ${res.status} ${res.statusText}`);\n }\n\n let body: PagesDataResponse;\n try {\n body = (await res.json()) as PagesDataResponse;\n } catch {\n scheduleHardNavigationAndThrow(url, \"Data navigation failed: invalid JSON response\");\n }\n assertStillCurrent();\n\n const pageProps: Record<string, unknown> =\n body.pageProps && typeof body.pageProps === \"object\" ? body.pageProps : {};\n\n // Load the page module via the registered code-split loader. Vite has\n // already split each page into its own chunk; the loader is just the\n // `import()` thunk the build generated.\n let pageModule: { default?: unknown; [key: string]: unknown };\n try {\n pageModule = await target.loader();\n } catch (err) {\n console.error(\"[vinext] Page loader threw during navigation:\", err);\n scheduleHardNavigationAndThrow(url, \"Data navigation failed: page loader threw\");\n }\n assertStillCurrent();\n\n const PageComponent = pageModule.default;\n if (!isPageComponent(PageComponent)) {\n scheduleHardNavigationAndThrow(\n url,\n \"Data navigation failed: page module default export is not a component\",\n );\n }\n\n // Lazy-load `_app` if we have an app loader and haven't cached it yet.\n let AppComponent = window.__VINEXT_APP__;\n if (!AppComponent && typeof window.__VINEXT_APP_LOADER__ === \"function\") {\n try {\n const appModule = await window.__VINEXT_APP_LOADER__();\n AppComponent = isAppComponent(appModule.default) ? appModule.default : undefined;\n if (AppComponent) window.__VINEXT_APP__ = AppComponent;\n } catch {\n // _app load failed — fall through and render without it. This matches\n // the HTML path which also tolerates a missing _app gracefully.\n }\n }\n assertStillCurrent();\n\n // Import React (already evaluated; this is a cached re-import).\n const React = (await import(\"react\")).default;\n assertStillCurrent();\n\n let element: ReactElement;\n if (AppComponent) {\n element = React.createElement(AppComponent, {\n Component: PageComponent,\n pageProps,\n });\n } else {\n element = React.createElement(PageComponent, pageProps);\n }\n element = wrapWithRouterContext(element);\n\n // Build the updated __NEXT_DATA__. The JSON envelope is intentionally\n // minimal (just `pageProps`), so we synthesise the surrounding fields\n // from the data we already have: the matched pattern, the params, and\n // the previous nextData's buildId/locale state. This keeps\n // `useRouter()`, `getPagesNavigationContext()`, and any code reading\n // `window.__NEXT_DATA__` in sync after a JSON navigation — mirroring\n // what the HTML path produces.\n //\n // The cast through `unknown` is unavoidable: the upstream `NEXT_DATA`\n // type defines `query` as `ParsedUrlQuery` which is structurally\n // identical to our `Record<string, string | string[]>` but nominally\n // disjoint, so TypeScript rejects the direct assignment. We spread the\n // previous nextData first to inherit locale/locales/defaultLocale/\n // domainLocales unchanged, then override the per-navigation fields.\n // Mirror Next.js' `__NEXT_DATA__.query`: search params + dynamic route params\n // merged in one object, with route params winning on key collision (so\n // `/posts/123?id=456` still exposes `id: \"123\"`). Without this, code reading\n // `window.__NEXT_DATA__.query` directly would see only the dynamic params.\n const mergedQuery = mergeRouteParamsIntoQuery(parseQueryString(target.search), target.params);\n\n const prev = window.__NEXT_DATA__ as NonNullable<Window[\"__NEXT_DATA__\"]> | undefined;\n // Locale-prefixed URLs change the active locale; the JSON envelope itself\n // has no locale metadata, so derive it from the URL we navigated to.\n // `target.locale` is `undefined` when the URL is unprefixed — that means\n // either no i18n config (keep `prev.locale`) or the default locale\n // (override `prev.locale` so locale transitions back to default land\n // correctly). The locales list / defaultLocale / domainLocales are\n // build-time config and don't change between pages, so they spread through\n // from `prev` unchanged.\n const hasI18n = (window.__VINEXT_LOCALES__?.length ?? 0) > 0;\n const nextLocale = hasI18n\n ? (target.locale ?? window.__VINEXT_DEFAULT_LOCALE__)\n : (prev as VinextNextData | undefined)?.locale;\n const nextData = {\n ...prev,\n props: { pageProps },\n page: target.pattern,\n query: mergedQuery,\n buildId: target.buildId,\n isFallback: false,\n ...(nextLocale !== undefined ? { locale: nextLocale } : {}),\n } as unknown as NonNullable<Window[\"__NEXT_DATA__\"]> & VinextNextData;\n\n // INVARIANT: Everything between the final assertStillCurrent() above and\n // root.render() must be synchronous. If a future change introduces another\n // await, add an assertStillCurrent() before mutating window.__NEXT_DATA__.\n window.__NEXT_DATA__ = nextData;\n applyVinextLocaleGlobals(window, nextData);\n root.render(element);\n}\n\n/**\n * Perform client-side navigation by fetching the page's full HTML and\n * extracting `__NEXT_DATA__` plus the page module URL. Used in dev (where\n * the per-page inline hydration script does not populate the loader map) and\n * as a generic fallback when the data path is not available.\n *\n * Throws NavigationCancelledError if a newer navigation supersedes this one.\n * Throws on hard-navigation failures (non-OK response, missing data) so the\n * caller can distinguish success from failure for event emission.\n */\nasync function navigateClientHtml(\n url: string,\n fetchUrl: string,\n controller: AbortController,\n navId: number,\n assertStillCurrent: () => void,\n options: NavigateClientOptions = {},\n): Promise<void> {\n let browserUrl = url;\n let pendingRedirectHistoryUrl: string | null = fetchUrl === url ? null : url;\n const root = window.__VINEXT_ROOT__;\n if (!root) {\n // No React root yet — fall back to hard navigation\n window.location.href = browserUrl;\n return;\n }\n\n // Fetch the target page's SSR HTML\n let res: Response;\n try {\n res = await fetch(fetchUrl, {\n headers: { Accept: \"text/html\" },\n signal: controller.signal,\n });\n } catch (err: unknown) {\n // AbortError means a newer navigation cancelled this fetch\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new NavigationCancelledError(url);\n }\n throw err;\n }\n assertStillCurrent();\n\n if (res.redirected && res.url) {\n const redirectedUrl = resolveSameOriginRedirectedUrl(res.url);\n if (redirectedUrl) {\n browserUrl = redirectedUrl;\n pendingRedirectHistoryUrl = redirectedUrl;\n }\n }\n\n if (!res.ok && !(options.allowNotFoundResponse === true && res.status === 404)) {\n // Set window.location.href first so the browser navigates to the correct\n // page even if the caller suppresses the error. The assignment schedules\n // the navigation asynchronously (as a task), so synchronous routeChangeError\n // listeners still run — and observe the error — before the page unloads.\n // Contract: routeChangeError listeners MUST be synchronous; async listeners\n // will not fire before the navigation completes. Callers (runNavigateClient)\n // must NOT schedule a second hard navigation — this assignment already queues\n // the browser fallback, and the helper-level HardNavigationScheduledError\n // makes that contract explicit to callers.\n scheduleHardNavigationAndThrow(\n browserUrl,\n `Navigation failed: ${res.status} ${res.statusText}`,\n );\n }\n\n const html = await res.text();\n assertStillCurrent();\n\n // Extract __NEXT_DATA__ from the HTML\n const nextDataJson = extractVinextNextDataJson(html);\n if (!nextDataJson) {\n scheduleHardNavigationAndThrow(url, \"Navigation failed: missing __NEXT_DATA__ in response\");\n }\n\n const nextData = parseVinextNextDataJson(nextDataJson);\n const { pageProps } = nextData.props;\n // Defer writing window.__NEXT_DATA__ until just before root.render() —\n // writing it here would let a stale navigation briefly pollute the global\n // between this assertStillCurrent() and the next one after await import().\n\n // Get the page module URL from __NEXT_DATA__.__vinext (preferred),\n // or fall back to parsing the hydration script\n let pageModuleUrl: string | undefined = nextData.__vinext?.pageModuleUrl;\n\n if (!pageModuleUrl) {\n // Legacy fallback: try to find the module URL in the inline script\n const moduleMatch = html.match(/import\\(\"([^\"]+)\"\\);\\s*\\n\\s*const PageComponent/);\n const altMatch = html.match(/await import\\(\"([^\"]+pages\\/[^\"]+)\"\\)/);\n pageModuleUrl = moduleMatch?.[1] ?? altMatch?.[1] ?? undefined;\n }\n\n let pageModule: { default?: unknown; [key: string]: unknown };\n if (!pageModuleUrl) {\n const loader = window.__VINEXT_PAGE_LOADERS__?.[nextData.page];\n if (!loader) {\n scheduleHardNavigationAndThrow(browserUrl, \"Navigation failed: no page module URL found\");\n }\n pageModule = await loader();\n } else {\n // Validate the module URL before importing — defense-in-depth against\n // unexpected __NEXT_DATA__ or malformed HTML responses\n if (!isValidModulePath(pageModuleUrl)) {\n console.error(\"[vinext] Blocked import of invalid page module path:\", pageModuleUrl);\n scheduleHardNavigationAndThrow(browserUrl, \"Navigation failed: invalid page module path\");\n }\n\n // Dynamically import the new page module\n pageModule = await import(/* @vite-ignore */ pageModuleUrl);\n }\n assertStillCurrent();\n\n const PageComponent = pageModule.default;\n if (!isPageComponent(PageComponent)) {\n scheduleHardNavigationAndThrow(\n browserUrl,\n \"Navigation failed: page module default export is not a component\",\n );\n }\n\n // Import React for createElement\n const React = (await import(\"react\")).default;\n assertStillCurrent();\n\n // Re-render with the new page, loading _app if needed\n let AppComponent = window.__VINEXT_APP__;\n const appModuleUrl: string | undefined = nextData.__vinext?.appModuleUrl;\n\n if (!AppComponent && appModuleUrl) {\n if (!isValidModulePath(appModuleUrl)) {\n console.error(\"[vinext] Blocked import of invalid app module path:\", appModuleUrl);\n } else {\n try {\n const appModule = await import(/* @vite-ignore */ appModuleUrl);\n AppComponent = isAppComponent(appModule.default) ? appModule.default : undefined;\n window.__VINEXT_APP__ = AppComponent;\n } catch {\n // _app not available — continue without it\n }\n }\n }\n assertStillCurrent();\n\n let element;\n if (AppComponent) {\n element = React.createElement(AppComponent, {\n Component: PageComponent,\n pageProps,\n });\n } else {\n element = React.createElement(PageComponent, pageProps);\n }\n\n // Wrap with RouterContext.Provider so next/router and next/compat/router work.\n element = wrapWithRouterContext(element);\n\n // Commit __NEXT_DATA__ only after all assertStillCurrent() checks have passed,\n // so a stale navigation can never pollute the global.\n // INVARIANT: Everything after the final assertStillCurrent() above (the\n // checkpoint immediately after the optional _app import) through\n // root.render() is synchronous. If any step here ever becomes async, add\n // another assertStillCurrent() before writing __NEXT_DATA__.\n if (pendingRedirectHistoryUrl) {\n window.history.replaceState(window.history.state ?? {}, \"\", pendingRedirectHistoryUrl);\n _lastPathnameAndSearch = window.location.pathname + window.location.search;\n }\n window.__NEXT_DATA__ = nextData;\n applyVinextLocaleGlobals(window, nextData);\n root.render(element);\n}\n\n/**\n * Perform client-side navigation. Prefers the JSON data endpoint when the\n * client has a registered code-split loader for the target route (the prod\n * hot path); otherwise falls back to fetching the page's full HTML (dev and\n * any unmapped route).\n *\n * Throws NavigationCancelledError if a newer navigation supersedes this one.\n * Throws on hard-navigation failures (non-OK response, missing data) so the\n * caller can distinguish success from failure for event emission.\n *\n * `fetchUrl` is the HTML-path fetch URL (already includes locale-root\n * fixups). The JSON path derives its own URL from the browser-facing `url`\n * because the data endpoint speaks the unprefixed path.\n */\nasync function navigateClient(\n url: string,\n fetchUrl = url,\n options: NavigateClientOptions = {},\n): Promise<void> {\n if (typeof window === \"undefined\") return;\n\n // Cancel any in-flight navigation (abort its fetch, mark it stale)\n _activeAbortController?.abort();\n const controller = new AbortController();\n _activeAbortController = controller;\n\n const navId = ++_navigationId;\n\n /** Check if this navigation is still the active one. If not, throw. */\n function assertStillCurrent(): void {\n if (navId !== _navigationId) {\n throw new NavigationCancelledError(url);\n }\n }\n\n try {\n // Error-route navigation (`router.push('/404'|'/_error', as)`): the masked\n // browser URL and the component route differ, and the error page has no\n // data endpoint. Skip data navigation and middleware-redirect probing\n // (both would target the fictional masked URL) and fetch the resolved\n // error HTML directly, allowing a 404 response to hydrate.\n if (options.allowNotFoundResponse === true) {\n await navigateClientHtml(url, fetchUrl, controller, navId, assertStillCurrent, options);\n } else {\n let browserUrl = url;\n let htmlFetchUrl = fetchUrl;\n const dataTarget = resolvePagesDataNavigationTarget(browserUrl, __basePath);\n if (!dataTarget) {\n let redirectLocation: string | null;\n try {\n redirectLocation = await resolveMiddlewareDataRedirect(browserUrl, controller.signal);\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new NavigationCancelledError(browserUrl);\n }\n throw err;\n }\n assertStillCurrent();\n if (redirectLocation) {\n const redirectedUrl = resolveLocalRedirectUrl(redirectLocation);\n if (!redirectedUrl) {\n scheduleHardNavigationAndThrow(redirectLocation, \"Navigation redirected externally\");\n }\n window.history.replaceState(window.history.state ?? {}, \"\", redirectedUrl);\n _lastPathnameAndSearch = window.location.pathname + window.location.search;\n browserUrl = redirectedUrl;\n htmlFetchUrl = redirectedUrl;\n }\n }\n\n if (dataTarget) {\n await navigateClientData(browserUrl, dataTarget, controller, navId, assertStillCurrent);\n } else {\n await navigateClientHtml(\n browserUrl,\n htmlFetchUrl,\n controller,\n navId,\n assertStillCurrent,\n options,\n );\n }\n }\n } finally {\n // Clean up the abort controller if this navigation is still the active one\n if (navId === _navigationId) {\n _activeAbortController = null;\n }\n }\n}\n\n/**\n * Run navigateClient and handle errors: emit routeChangeError on failure,\n * and fall back to a hard navigation for non-cancel errors so the browser\n * recovers to a consistent state.\n *\n * Returns:\n * - \"completed\" — navigation finished, caller should emit routeChangeComplete\n * - \"cancelled\" — superseded by a newer navigation, caller should return true\n * without emitting routeChangeComplete (matches Next.js behaviour)\n * - \"failed\" — genuine error, caller should return false (hard nav is already\n * scheduled as recovery)\n */\nasync function runNavigateClient(\n fullUrl: string,\n resolvedUrl: string,\n fetchUrl = fullUrl,\n options: NavigateClientOptions = {},\n): Promise<\"completed\" | \"cancelled\" | \"failed\"> {\n try {\n await navigateClient(fullUrl, fetchUrl, options);\n return \"completed\";\n } catch (err: unknown) {\n routerEvents.emit(\"routeChangeError\", err, resolvedUrl, { shallow: false });\n if (err instanceof NavigationCancelledError) {\n return \"cancelled\";\n }\n // Genuine error (network, parse, import failure): fall back to a hard\n // navigation so the browser lands on the correct page. Known failure modes\n // throw HardNavigationScheduledError, and this guard skips those; only\n // unexpected failures (parse, import, render) need recovery here.\n if (typeof window !== \"undefined\" && !(err instanceof HardNavigationScheduledError)) {\n window.location.href = fullUrl;\n }\n return \"failed\";\n }\n}\n\n/**\n * Build the full router value object from the current pathname, query, asPath,\n * and a set of navigation methods. Shared by the Pages Router context provider\n * and tests so the public router shape stays in sync.\n */\nfunction buildRouterValue(\n pathname: string,\n query: Record<string, string | string[]>,\n asPath: string,\n methods: {\n push: NextRouter[\"push\"];\n replace: NextRouter[\"replace\"];\n back: NextRouter[\"back\"];\n reload: NextRouter[\"reload\"];\n prefetch: NextRouter[\"prefetch\"];\n beforePopState: NextRouter[\"beforePopState\"];\n },\n): NextRouter {\n const _ssrState = _getSSRContext();\n const nextData =\n typeof window !== \"undefined\"\n ? (window.__NEXT_DATA__ as VinextNextData | undefined)\n : undefined;\n const locale = typeof window === \"undefined\" ? _ssrState?.locale : window.__VINEXT_LOCALE__;\n const locales = typeof window === \"undefined\" ? _ssrState?.locales : window.__VINEXT_LOCALES__;\n const defaultLocale =\n typeof window === \"undefined\" ? _ssrState?.defaultLocale : window.__VINEXT_DEFAULT_LOCALE__;\n const domainLocales =\n typeof window === \"undefined\" ? _ssrState?.domainLocales : nextData?.domainLocales;\n\n const route = typeof window !== \"undefined\" ? (nextData?.page ?? pathname) : pathname;\n\n return {\n pathname,\n route,\n query,\n asPath,\n basePath: __basePath,\n locale,\n locales,\n defaultLocale,\n domainLocales,\n isReady: true,\n isPreview: false,\n isFallback:\n typeof window !== \"undefined\"\n ? nextData?.isFallback === true\n : _ssrState?.isFallback === true,\n ...methods,\n events: routerEvents,\n };\n}\n\n/** Extract the hash fragment from a URL, including the leading `#`. */\nfunction extractHash(url: string): string {\n const i = url.indexOf(\"#\");\n return i === -1 ? \"\" : url.slice(i);\n}\n\n/** Notify in-page listeners (e.g. useRouter hooks) that navigation occurred. */\nfunction dispatchNavigateEvent(): void {\n window.dispatchEvent(new CustomEvent(\"vinext:navigate\"));\n}\n\n/**\n * Update history with the new URL and refresh the hash-only-detection tracker.\n * Centralises the `pushState`/`replaceState` branch so callers don't repeat it.\n */\nfunction updateHistory(mode: \"push\" | \"replace\", url: string): void {\n if (mode === \"push\") window.history.pushState({}, \"\", url);\n else window.history.replaceState({}, \"\", url);\n _lastPathnameAndSearch = window.location.pathname + window.location.search;\n}\n\n/**\n * Throw the canonical \"no router instance\" error used when a Pages Router\n * navigation method (push/replace/back/reload/prefetch/beforePopState) is\n * invoked during SSR or prerendering.\n *\n * Mirrors Next.js's `ServerRouter.push`/`replace`/etc. which all call\n * `noRouter()` in `packages/next/src/server/render.tsx`. The error message\n * matches Next.js verbatim so userland error handling and docs links work\n * unchanged.\n *\n * Ported from Next.js: packages/next/src/server/render.tsx\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/server/render.tsx\n */\nfunction throwNoRouterInstance(): never {\n throw new Error(\n 'No router instance found. you should only use \"next/router\" inside the client side of your app. https://nextjs.org/docs/messages/no-router-instance',\n );\n}\n\n/**\n * Shared client-side navigation flow used by both `useRouter()` and the\n * `Router` singleton. The only differences between push/replace are the\n * history method (`pushState` vs `replaceState`), the external-URL fallback\n * (`assign` vs `replace`), and the fact that push saves scroll position for\n * back/forward restoration while replace does not.\n *\n * `onStateUpdate` lets the hook trigger a `setState` re-render at the same\n * point that hashChangeComplete/routeChangeComplete fires; the singleton\n * passes no callback.\n */\nasync function performNavigation(\n url: string | UrlObject,\n as: string | undefined,\n options: TransitionOptions | undefined,\n mode: \"push\" | \"replace\",\n onStateUpdate?: () => void,\n): Promise<boolean> {\n // SSR / prerender guard. Calling Router.push or Router.replace from a\n // Pages Router component during server rendering would otherwise crash\n // with `ReferenceError: window is not defined` (window.location is\n // accessed unconditionally below). Match Next.js's `ServerRouter.push`\n // behaviour and throw the documented \"no router instance\" error so the\n // failure surfaces as a normal render error instead of a ReferenceError\n // that takes down the request pipeline.\n if (typeof window === \"undefined\") {\n throwNoRouterInstance();\n }\n\n // Defence-in-depth dangerous-scheme guard. The synchronous guard inside\n // `Router.push` / `Router.replace` (see RouterMethods below) is the primary\n // line of defence and is what surfaces the matching console.error to React's\n // event-handler runtime. This inner guard catches any future call sites\n // that bypass the public Router methods and call `performNavigation`\n // directly. Mirrors Next.js's Pages Router check at\n // packages/next/src/shared/lib/router/router.ts:1025-1033,1057-1065.\n assertSafeNavigationUrl(resolveUrl(url));\n if (as !== undefined) {\n assertSafeNavigationUrl(String(as));\n }\n\n const navigationLocale = resolveTransitionLocale(options?.locale);\n let resolved = resolveNavigationTarget(url, as, navigationLocale);\n\n // External URLs — delegate to browser (unless same-origin)\n if (isExternalUrl(resolved)) {\n const localPath = toSameOriginAppPath(resolved, __basePath);\n if (localPath == null) {\n if (mode === \"push\") window.location.assign(resolved);\n else window.location.replace(resolved);\n return true;\n }\n resolved = localPath;\n }\n\n resolved = normalizePathTrailingSlash(resolved, __trailingSlash);\n const full = normalizePathTrailingSlash(\n toBrowserNavigationHref(resolved, window.location.href, __basePath),\n __trailingSlash,\n );\n const errorRouteHtmlFetchUrl = resolvePagesErrorHtmlFetchUrl(url, navigationLocale);\n const htmlFetchUrl = errorRouteHtmlFetchUrl ?? getPagesHtmlFetchUrl(full, navigationLocale);\n const navigateOptions: NavigateClientOptions = errorRouteHtmlFetchUrl\n ? { allowNotFoundResponse: true }\n : {};\n const shallow = options?.shallow ?? false;\n const doScroll = options?.scroll !== false;\n\n // Hash-only change — no page fetch needed\n if (isHashOnlyChange(full)) {\n const eventUrl = resolveHashUrl(full);\n routerEvents.emit(\"hashChangeStart\", eventUrl, { shallow });\n updateHistory(mode, resolved.startsWith(\"#\") ? resolved : full);\n if (doScroll) scrollToHashTarget(extractHash(resolved));\n onStateUpdate?.();\n routerEvents.emit(\"hashChangeComplete\", eventUrl, { shallow });\n dispatchNavigateEvent();\n return true;\n }\n\n if (mode === \"push\") saveScrollPosition();\n routerEvents.emit(\"routeChangeStart\", resolved, { shallow });\n routerEvents.emit(\"beforeHistoryChange\", resolved, { shallow });\n updateHistory(mode, full);\n if (!shallow) {\n const result = await runNavigateClient(full, resolved, htmlFetchUrl, navigateOptions);\n if (result === \"cancelled\") return true;\n if (result === \"failed\") return false;\n }\n onStateUpdate?.();\n routerEvents.emit(\"routeChangeComplete\", resolved, { shallow });\n\n const hash = extractHash(resolved);\n if (doScroll) {\n if (hash) scrollToHashTarget(hash);\n else window.scrollTo(0, 0);\n }\n dispatchNavigateEvent();\n return true;\n}\n\n/**\n * Prefetch the resources needed for a future Pages Router navigation.\n *\n * When the client has a registered code-split loader for the target route\n * (the prod hot path), we prefetch in parallel:\n * 1. The `/_next/data/<buildId>/<page>.json` payload — same URL the actual\n * navigation will request, so a cache hit is automatic.\n * 2. The page's JS chunk — by invoking the loader thunk now. Vite's\n * dynamic `import()` machinery is responsible for fetching + caching;\n * the returned Promise is intentionally discarded.\n *\n * When no loader is registered (dev server, or an unmapped route), we fall\n * back to the legacy `<link rel=\"prefetch\" as=\"document\">` hint, which lets\n * the browser preload the HTML document. This matches the pre-`_next/data`\n * behaviour so dev doesn't regress.\n *\n * Ported from Next.js: `packages/next/src/client/page-loader.ts` `prefetch`\n * (the data + chunk parallel prefetch shape).\n */\nasync function prefetchUrl(url: string): Promise<void> {\n if (typeof document === \"undefined\") return;\n\n const dataTarget = resolvePagesDataNavigationTarget(url, __basePath);\n if (dataTarget) {\n prefetchPagesData(dataTarget);\n return;\n }\n\n // Legacy fallback for routes without a registered loader (e.g. dev).\n // Hints the browser to preload the HTML document so the next click feels\n // faster, even though we can't resolve the chunk ahead of time.\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.href = url;\n link.as = \"document\";\n document.head.appendChild(link);\n}\n\n/**\n * useRouter hook - Pages Router compatible.\n *\n * Ported from Next.js: packages/next/src/client/router.ts\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/router.ts\n */\nexport function useRouter(): NextRouter {\n const router = useContext(RouterContext);\n if (!router) {\n throw new Error(\n \"NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted\",\n );\n }\n\n return router;\n}\n\nfunction PagesRouterProvider({ children }: { children: ReactNode }): ReactElement {\n const [{ pathname, query, asPath }, setState] = useState(getPathnameAndQuery);\n\n // Popstate is handled by the Pages Router client entry via\n // installPagesRouterRuntime() so beforePopState() is consistently enforced\n // regardless of hook consumers. Keep URL snapshot subscriptions at the\n // provider boundary so many useRouter() calls share one router state and one\n // vinext:navigate listener.\n useEffect(() => {\n const onNavigate = ((_e: CustomEvent) => {\n setState(getPathnameAndQuery());\n }) as EventListener;\n window.addEventListener(\"vinext:navigate\", onNavigate);\n return () => window.removeEventListener(\"vinext:navigate\", onNavigate);\n }, []);\n\n const router = useMemo(\n (): NextRouter =>\n buildRouterValue(pathname, query, asPath, {\n push: Router.push,\n replace: Router.replace,\n back: Router.back,\n reload: Router.reload,\n prefetch: Router.prefetch,\n beforePopState: Router.beforePopState,\n }),\n [pathname, query, asPath],\n );\n\n return createElement(RouterContext.Provider, { value: router }, children);\n}\n\n// beforePopState callback: called before handling browser back/forward.\n// If it returns false, the navigation is cancelled.\nlet _beforePopStateCb: BeforePopStateCallback | undefined;\n\n// Track pathname+search for detecting hash-only back/forward in the popstate\n// handler. Updated after every pushState/replaceState so that popstate can\n// compare the previous value with the (already-changed) window.location.\nlet _lastPathnameAndSearch =\n typeof window !== \"undefined\" ? window.location.pathname + window.location.search : \"\";\n\nfunction handlePagesRouterPopState(e: PopStateEvent): void {\n const browserUrl = window.location.pathname + window.location.search;\n const appUrl = stripBasePath(window.location.pathname, __basePath) + window.location.search;\n\n // Detect hash-only back/forward: pathname+search unchanged, only hash differs.\n const isHashOnly = browserUrl === _lastPathnameAndSearch;\n\n // Check beforePopState callback\n if (_beforePopStateCb !== undefined) {\n const shouldContinue = _beforePopStateCb({\n url: appUrl,\n as: appUrl,\n options: { shallow: false },\n });\n if (!shouldContinue) return;\n }\n\n // Update tracker only after beforePopState confirms navigation proceeds.\n // If beforePopState cancels, the tracker must retain the previous value\n // so the next popstate compares against the correct baseline.\n _lastPathnameAndSearch = browserUrl;\n\n if (isHashOnly) {\n // Hash-only back/forward — no page fetch needed\n const hashUrl = appUrl + window.location.hash;\n routerEvents.emit(\"hashChangeStart\", hashUrl, { shallow: false });\n scrollToHashTarget(window.location.hash);\n routerEvents.emit(\"hashChangeComplete\", hashUrl, { shallow: false });\n dispatchNavigateEvent();\n return;\n }\n\n const fullAppUrl = appUrl + window.location.hash;\n routerEvents.emit(\"routeChangeStart\", fullAppUrl, { shallow: false });\n // Note: The browser has already updated window.location by the time popstate\n // fires, so this is not truly \"before\" the URL change. In Next.js the popstate\n // handler calls replaceState to store history metadata — beforeHistoryChange\n // precedes that call, not the URL change itself. We emit it here for API\n // compatibility.\n routerEvents.emit(\"beforeHistoryChange\", fullAppUrl, { shallow: false });\n void (async () => {\n const result = await runNavigateClient(\n browserUrl,\n fullAppUrl,\n getPagesHtmlFetchUrl(browserUrl, window.__VINEXT_LOCALE__),\n );\n if (result === \"completed\") {\n routerEvents.emit(\"routeChangeComplete\", fullAppUrl, { shallow: false });\n restoreScrollPosition(e.state);\n dispatchNavigateEvent();\n }\n // \"cancelled\": superseded by a newer navigation, so this popstate no longer wins.\n // \"failed\": runNavigateClient already scheduled the hard-navigation fallback.\n })();\n}\n\nsetPagesRouterPopStateHandler(handlePagesRouterPopState);\n\n/**\n * Wrap a React element in a RouterContext.Provider so that\n * next/compat/router's useRouter() returns the real Pages Router value.\n *\n * The provider owns the reactive Pages Router snapshot so next/router and\n * next/compat/router consumers share one context value instead of each hook\n * installing its own global URL-change listener.\n */\nexport function wrapWithRouterContext(element: ReactElement): ReactElement {\n return createElement(PagesRouterProvider, null, element);\n}\n\n/**\n * Props injected by `withRouter` into the wrapped component.\n *\n * Ported from Next.js: packages/next/src/client/with-router.tsx\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/with-router.tsx\n */\nexport type WithRouterProps = {\n router: NextRouter;\n};\n\n/**\n * Pick<P, Exclude<keyof P, keyof WithRouterProps>> — the props of the\n * composed component minus the `router` prop that `withRouter` injects.\n *\n * Ported from Next.js: packages/next/src/client/with-router.tsx\n */\nexport type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>;\n\n/**\n * Higher-order component that injects the Pages Router `router` instance as\n * a `router` prop into a wrapped component. Primarily used by class\n * components (which cannot call hooks) to access the router. The wrapped\n * component receives the same props as the original, minus `router`, which\n * is filled in by the HOC.\n *\n * Ported from Next.js: packages/next/src/client/with-router.tsx\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/with-router.tsx\n *\n * Differences from Next.js:\n * - We type the composed component as `ComponentType<P>` instead of\n * `NextComponentType<C, any, P>` because vinext does not expose\n * `NextComponentType` from this shim. The runtime shape (and the props\n * the wrapper forwards) is identical.\n * - We forward `getInitialProps` and `origGetInitialProps` from the\n * composed component so `_app` parity holds for class components that\n * define `getInitialProps`.\n */\nexport function withRouter<P extends WithRouterProps>(\n ComposedComponent: ComponentType<P>,\n): ComponentType<ExcludeRouterProps<P>> {\n function WithRouterWrapper(props: ExcludeRouterProps<P>): ReactElement {\n const router = useRouter();\n // Match Next.js spread order:\n // `<ComposedComponent router={useRouter()} {...props} />`\n // The injected `router` is placed first, and `{...props}` is spread\n // after, so a user-passed `router` prop overrides the HOC-injected\n // one (last-spread wins). Mirrors\n // packages/next/src/client/with-router.tsx. At the type level\n // `props: ExcludeRouterProps<P>` has no `router` key, but TS still\n // sees `P` as `WithRouterProps`-extending when checking the literal,\n // so we widen to a `Record` for the final prop bag.\n const merged: Record<string, unknown> = { router, ...(props as Record<string, unknown>) };\n return createElement(ComposedComponent, merged as unknown as P);\n }\n\n // Forward getInitialProps so class-component pages that define it keep\n // working when wrapped. Mirrors Next.js's with-router.tsx.\n const composed = ComposedComponent as ComponentType<P> & {\n getInitialProps?: unknown;\n origGetInitialProps?: unknown;\n };\n (WithRouterWrapper as unknown as { getInitialProps?: unknown }).getInitialProps =\n composed.getInitialProps;\n (WithRouterWrapper as unknown as { origGetInitialProps?: unknown }).origGetInitialProps =\n composed.origGetInitialProps;\n\n if (process.env.NODE_ENV !== \"production\") {\n const name = composed.displayName || composed.name || \"Unknown\";\n WithRouterWrapper.displayName = `withRouter(${name})`;\n }\n\n return WithRouterWrapper;\n}\n\n// Note: `withRouter` is exposed only as a named export from `next/router`.\n// The default export of that module is the Router singleton declared below.\n\n// Also export a default Router singleton for `import Router from 'next/router'`.\n//\n// State fields (`pathname`, `route`, `query`, `asPath`, etc.) are exposed as\n// live getters so `window.next.router.pathname` reflects the current URL\n// without callers needing to know about React render cycles. Mirrors\n// Next.js's `singletonRouter` shape from\n// .nextjs-ref/packages/next/src/client/router.ts (lines 32–47), which uses\n// `Object.defineProperty` to forward `urlPropertyFields` to the active\n// router instance. The Next.js deploy test suite drives navigations through\n// `browser.eval('next.router.push(...)')` and then reads\n// `browser.eval('next.router.pathname')` to assert success, so the fields\n// must be readable, not just the methods.\n//\n// Every navigation method is also guarded against SSR/prerender execution.\n// Matches Next.js's `ServerRouter` (packages/next/src/server/render.tsx) which\n// throws `noRouter()` from push/replace/back/reload/prefetch/beforePopState so\n// that invoking them during server rendering surfaces as a documented render\n// error rather than a `ReferenceError: window is not defined`. The throws are\n// synchronous (not via the returned Promise) so render-time callers see the\n// error inline — matching Next.js behaviour and avoiding unhandled rejections.\nconst RouterMethods = {\n push: (url: string | UrlObject, as?: string, options?: TransitionOptions) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n // Synchronously guard dangerous URI schemes (javascript:, data:, vbscript:)\n // before the async performNavigation kicks off. Mirrors Next.js's\n // Pages Router `push` at packages/next/src/shared/lib/router/router.ts:1025-1033,\n // where the check runs synchronously inside push() so the throw bubbles up\n // through React's event-handler error reporter (surfacing console.error).\n // Without this synchronous hoist, the throw inside `performNavigation`\n // (an async function) becomes a rejected Promise that React does not\n // observe from an event handler that does not await it (e.g.\n // `<button onClick={() => router.push(...)}>`).\n assertSafeNavigationUrl(resolveUrl(url));\n if (as !== undefined) {\n assertSafeNavigationUrl(String(as));\n }\n return performNavigation(url, as, options, \"push\");\n },\n replace: (url: string | UrlObject, as?: string, options?: TransitionOptions) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n // See `push` above for the rationale on the synchronous guard.\n assertSafeNavigationUrl(resolveUrl(url));\n if (as !== undefined) {\n assertSafeNavigationUrl(String(as));\n }\n return performNavigation(url, as, options, \"replace\");\n },\n back: () => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n window.history.back();\n },\n reload: () => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n window.location.reload();\n },\n prefetch: (url: string) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n return prefetchUrl(url);\n },\n beforePopState: (cb: BeforePopStateCallback) => {\n if (typeof window === \"undefined\") throwNoRouterInstance();\n _beforePopStateCb = cb;\n },\n events: routerEvents,\n};\n\nconst Router: typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods> =\n Object.defineProperties(RouterMethods, {\n pathname: {\n enumerable: true,\n get(): string {\n return getPathnameAndQuery().pathname;\n },\n },\n route: {\n enumerable: true,\n get(): string {\n const { pathname } = getPathnameAndQuery();\n if (typeof window === \"undefined\") return pathname;\n const nextData = window.__NEXT_DATA__ as VinextNextData | undefined;\n return nextData?.page ?? pathname;\n },\n },\n query: {\n enumerable: true,\n get(): Record<string, string | string[]> {\n return getPathnameAndQuery().query;\n },\n },\n asPath: {\n enumerable: true,\n get(): string {\n return getPathnameAndQuery().asPath;\n },\n },\n basePath: { enumerable: true, value: __basePath, writable: false },\n locale: {\n enumerable: true,\n get(): string | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.locale;\n return window.__VINEXT_LOCALE__;\n },\n },\n locales: {\n enumerable: true,\n get(): string[] | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.locales;\n return window.__VINEXT_LOCALES__;\n },\n },\n defaultLocale: {\n enumerable: true,\n get(): string | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.defaultLocale;\n return window.__VINEXT_DEFAULT_LOCALE__;\n },\n },\n domainLocales: {\n enumerable: true,\n get(): VinextNextData[\"domainLocales\"] | undefined {\n if (typeof window === \"undefined\") return _getSSRContext()?.domainLocales;\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.domainLocales;\n },\n },\n isReady: { enumerable: true, value: true, writable: false },\n isPreview: { enumerable: true, value: false, writable: false },\n isFallback: {\n enumerable: true,\n get(): boolean {\n if (typeof window === \"undefined\") return _getSSRContext()?.isFallback === true;\n return (window.__NEXT_DATA__ as VinextNextData | undefined)?.isFallback === true;\n },\n },\n }) as typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods>;\n\n// Expose `window.next.router` for Next.js parity. Pages Router test suites,\n// userland scripts, and third-party libraries reach for this global directly\n// (e.g. `window.next.router.push(...)`, `window.next.router.events.on(...)`,\n// `window.next.router.pathname`).\n// Without this assignment, those callers crash with\n// `TypeError: Cannot read properties of undefined (reading 'router')`.\n//\n// Ported from Next.js: `packages/next/src/client/next.ts` (line 13). We do\n// NOT use a live-binding getter like Next.js does because vinext's Router\n// singleton is constructed synchronously here, so by the time this module\n// finishes loading the value is final.\nif (typeof window !== \"undefined\") {\n // Cast: `NextRouter.push`/`replace` are typed with narrow parameters\n // (UrlObject | string) while `PagesRouterPublicInstance` accepts unknown\n // args. The two are structurally compatible at runtime; TypeScript flags\n // the narrowing of contravariant function params, which is benign here\n // because callers reading off `window.next.router` are tests/userland\n // and treat the surface as opaque.\n installWindowNext({ router: Router as unknown as PagesRouterPublicInstance });\n}\n\n// Register the Pages Router compat shim source for `next/navigation` hooks\n// (useParams / useSearchParams / usePathname). The accessor is exposed\n// through a well-known Symbol.for so navigation.ts can read it without\n// importing this module — that avoids triggering navigation.ts's\n// `window.history.pushState` patch in tests that only need next/router.\n//\n// Mirrors Next.js's behavior where the pages-router server (render.tsx) and\n// client (client/index.tsx) wrap pages with SearchParamsContext /\n// PathParamsContext / PathnameContext providers populated from the router.\nconst _PAGES_NAVIGATION_ACCESSOR_KEY = Symbol.for(\n \"vinext.navigation.pagesNavigationContextAccessor\",\n);\n(globalThis as Record<PropertyKey, unknown>)[_PAGES_NAVIGATION_ACCESSOR_KEY] =\n getPagesNavigationContext;\n\nexport default Router;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAM,aAAqB,QAAQ,IAAI,0BAA0B;;AAEjE,MAAM,kBAA2B,QAAQ,IAAI,4BAA4B;AAmEzE,SAAS,qBAAmC;CAC1C,MAAM,4BAAY,IAAI,KAAgD;CAEtE,OAAO;EACL,GAAG,OAAe,SA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EACZ,MAA0B;GACxB,IAAI,OAAO,WAAW,aAAa,OAAO,gBAAgB,EAAE;GAC5D,OAAO,OAAO;;EAEjB;CACD,SAAS;EACP,YAAY;EACZ,MAA4B;GAC1B,IAAI,OAAO,WAAW,aAAa,OAAO,gBAAgB,EAAE;GAC5D,OAAO,OAAO;;EAEjB;CACD,eAAe;EACb,YAAY;EACZ,MAA0B;GACxB,IAAI,OAAO,WAAW,aAAa,OAAO,gBAAgB,EAAE;GAC5D,OAAO,OAAO;;EAEjB;CACD,eAAe;EACb,YAAY;EACZ,MAAmD;GACjD,IAAI,OAAO,WAAW,aAAa,OAAO,gBAAgB,EAAE;GAC5D,OAAQ,OAAO,eAA8C;;EAEhE;CACD,SAAS;EAAE,YAAY;EAAM,OAAO;EAAM,UAAU;EAAO;CAC3D,WAAW;EAAE,YAAY;EAAM,OAAO;EAAO,UAAU;EAAO;CAC9D,YAAY;EACV,YAAY;EACZ,MAAe;GACb,IAAI,OAAO,WAAW,aAAa,OAAO,gBAAgB,EAAE,eAAe;GAC3E,OAAQ,OAAO,eAA8C,eAAe;;EAE/E;CACF,CAAC;AAaJ,IAAI,OAAO,WAAW,aAOpB,kBAAkB,EAAE,QAAQ,QAAgD,CAAC;AAY/E,MAAM,iCAAiC,OAAO,IAC5C,mDACD;AACD,WAA6C,kCAC3C"}
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { escapeInlineContent } from "./head.js";
3
+ import { hasAppNavigationRuntimeBootstrap } from "../client/navigation-runtime.js";
3
4
  import { useScriptNonce } from "./script-nonce-context.js";
5
+ import { useBeforeInteractiveRegister } from "./before-interactive-context.js";
4
6
  import React, { useEffect, useRef } from "react";
5
7
  import * as ReactDOM from "react-dom";
6
8
  //#region src/shims/script.tsx
@@ -21,12 +23,14 @@ const loadingScripts = /* @__PURE__ */ new Map();
21
23
  function getClientAutoNonce() {
22
24
  if (typeof document === "undefined") return void 0;
23
25
  const existingNonceElement = document.querySelector("[nonce]");
24
- if (!(existingNonceElement instanceof HTMLElement)) return;
25
- return existingNonceElement.nonce || existingNonceElement.getAttribute("nonce") || void 0;
26
+ if (!existingNonceElement) return void 0;
27
+ if (typeof HTMLElement !== "undefined" && existingNonceElement instanceof HTMLElement) return existingNonceElement.nonce || existingNonceElement.getAttribute("nonce") || void 0;
28
+ return existingNonceElement.getAttribute("nonce") || void 0;
26
29
  }
27
30
  function resolveScriptNonce(explicitNonce, contextualNonce) {
28
31
  if (typeof explicitNonce === "string" && explicitNonce.length > 0) return explicitNonce;
29
- if (typeof window === "undefined") return contextualNonce;
32
+ if (typeof contextualNonce === "string" && contextualNonce.length > 0) return contextualNonce;
33
+ if (typeof window === "undefined") return;
30
34
  return getClientAutoNonce();
31
35
  }
32
36
  function buildBeforeInteractiveScriptProps(options) {
@@ -37,6 +41,60 @@ function buildBeforeInteractiveScriptProps(options) {
37
41
  if (options.dangerouslySetInnerHTML) scriptProps.dangerouslySetInnerHTML = { __html: escapeInlineContent(options.dangerouslySetInnerHTML.__html, "script") };
38
42
  return scriptProps;
39
43
  }
44
+ /**
45
+ * Extract the inline script content for a `beforeInteractive` Script element
46
+ * with no `src`. Returns `null` when the element has neither a string-shaped
47
+ * `children` value nor a valid `dangerouslySetInnerHTML.__html` payload — in
48
+ * that case the caller should fall through to React's regular rendering path.
49
+ *
50
+ * The returned string is the raw author-supplied JavaScript content. Callers
51
+ * are responsible for passing it through `escapeInlineContent(..., "script")`
52
+ * before emitting it inside a `<script>` tag (we keep that escape adjacent
53
+ * to the emit point so the rule is obvious at the boundary).
54
+ */
55
+ function extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML) {
56
+ if (dangerouslySetInnerHTML && typeof dangerouslySetInnerHTML.__html === "string" && dangerouslySetInnerHTML.__html.length > 0) return dangerouslySetInnerHTML.__html;
57
+ if (typeof children === "string" && children.length > 0) return children;
58
+ if (Array.isArray(children) && children.every((c) => typeof c === "string")) {
59
+ const joined = children.join("");
60
+ return joined.length > 0 ? joined : null;
61
+ }
62
+ return null;
63
+ }
64
+ /**
65
+ * Convert the residual `<Script>` props into a plain string-attributes record
66
+ * for emission inside a hoisted `<script>` tag. Drops React-only props
67
+ * (event handlers, children, etc.) and reserved keys already handled by the
68
+ * pre-head-injection emitter (id, nonce). Skips `undefined`/`null` so they
69
+ * round-trip as "attribute absent" rather than `attr="undefined"`.
70
+ */
71
+ function collectBeforeInteractiveAttributes(rest) {
72
+ const RESERVED = new Set([
73
+ "id",
74
+ "nonce",
75
+ "src",
76
+ "children",
77
+ "strategy",
78
+ "dangerouslySetInnerHTML",
79
+ "onLoad",
80
+ "onReady",
81
+ "onError"
82
+ ]);
83
+ const out = {};
84
+ for (const [key, value] of Object.entries(rest)) {
85
+ if (RESERVED.has(key)) continue;
86
+ if (value === void 0 || value === null || value === false) continue;
87
+ if (typeof value === "boolean") {
88
+ out[key] = true;
89
+ continue;
90
+ }
91
+ if (typeof value === "string" || typeof value === "number") {
92
+ out[key] = String(value);
93
+ continue;
94
+ }
95
+ }
96
+ return out;
97
+ }
40
98
  function setBooleanScriptAttribute(el, attr, value) {
41
99
  const enabled = value !== false && value !== "false" && Boolean(value);
42
100
  switch (attr) {
@@ -142,6 +200,7 @@ function Script(props) {
142
200
  const key = id ?? src ?? "";
143
201
  const contextualNonce = useScriptNonce();
144
202
  const resolvedNonce = resolveScriptNonce(rest.nonce, contextualNonce);
203
+ const registerBeforeInteractive = useBeforeInteractiveRegister();
145
204
  useEffect(() => {
146
205
  if (hasMounted.current) return;
147
206
  hasMounted.current = true;
@@ -201,22 +260,37 @@ function Script(props) {
201
260
  if (integrity !== void 0) preloadOptions.integrity = integrity;
202
261
  ReactDOM.preload(src, preloadOptions);
203
262
  }
204
- if (strategy === "beforeInteractive") return React.createElement("script", buildBeforeInteractiveScriptProps({
263
+ if (strategy === "beforeInteractive") {
264
+ const inlineContent = src ? null : extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML);
265
+ if (inlineContent !== null && registerBeforeInteractive) {
266
+ registerBeforeInteractive({
267
+ id,
268
+ innerHTML: escapeInlineContent(inlineContent, "script"),
269
+ nonce: resolvedNonce,
270
+ attributes: collectBeforeInteractiveAttributes(rest)
271
+ });
272
+ return null;
273
+ }
274
+ return React.createElement("script", buildBeforeInteractiveScriptProps({
275
+ src,
276
+ id,
277
+ rest,
278
+ resolvedNonce,
279
+ dangerouslySetInnerHTML
280
+ }), children);
281
+ }
282
+ return null;
283
+ }
284
+ if (strategy === "beforeInteractive") {
285
+ if ((src ? null : extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML)) !== null && hasAppNavigationRuntimeBootstrap()) return null;
286
+ return React.createElement("script", buildBeforeInteractiveScriptProps({
205
287
  src,
206
288
  id,
207
289
  rest,
208
290
  resolvedNonce,
209
291
  dangerouslySetInnerHTML
210
292
  }), children);
211
- return null;
212
293
  }
213
- if (strategy === "beforeInteractive") return React.createElement("script", buildBeforeInteractiveScriptProps({
214
- src,
215
- id,
216
- rest,
217
- resolvedNonce,
218
- dangerouslySetInnerHTML
219
- }), children);
220
294
  return null;
221
295
  }
222
296
  //#endregion