vinext 1.0.0-beta.0 → 1.0.0-beta.2

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 (305) hide show
  1. package/README.md +21 -2
  2. package/dist/build/assets-ignore.js +1 -1
  3. package/dist/build/clean-output.js +1 -1
  4. package/dist/build/client-build-config.js +7 -4
  5. package/dist/build/css-url-assets.js +3 -3
  6. package/dist/build/google-fonts/fallback-metrics.js +1 -1
  7. package/dist/build/google-fonts/font-metadata.js +1 -1
  8. package/dist/build/inject-pregenerated-paths.js +1 -1
  9. package/dist/build/inline-css.js +2 -5
  10. package/dist/build/module-dependency-cache.d.ts +4 -0
  11. package/dist/build/module-dependency-cache.js +13 -0
  12. package/dist/build/next-client-runtime-manifests.js +1 -1
  13. package/dist/build/pages-client-assets-module.js +1 -1
  14. package/dist/build/precompress.js +7 -7
  15. package/dist/build/prerender-paths.d.ts +2 -2
  16. package/dist/build/prerender-paths.js +10 -15
  17. package/dist/build/prerender-server-pool.js +2 -2
  18. package/dist/build/prerender.js +1 -1
  19. package/dist/build/preview-credentials.d.ts +11 -0
  20. package/dist/build/preview-credentials.js +19 -0
  21. package/dist/build/report.d.ts +8 -4
  22. package/dist/build/report.js +14 -6
  23. package/dist/build/run-prerender.d.ts +2 -11
  24. package/dist/build/run-prerender.js +2 -10
  25. package/dist/build/server-manifest.js +1 -1
  26. package/dist/build/ssr-manifest.d.ts +4 -0
  27. package/dist/build/ssr-manifest.js +10 -6
  28. package/dist/build/standalone.js +37 -37
  29. package/dist/cache/cache-adapters-virtual.d.ts +1 -17
  30. package/dist/cache/cache-adapters-virtual.js +20 -11
  31. package/dist/check.d.ts +0 -16
  32. package/dist/check.js +27 -36
  33. package/dist/cli.js +61 -55
  34. package/dist/client/instrumentation-client-inject.js +1 -1
  35. package/dist/client/pages-router-link-navigation.js +1 -1
  36. package/dist/config/config-matchers.d.ts +13 -37
  37. package/dist/config/config-matchers.js +33 -123
  38. package/dist/config/dotenv.js +1 -1
  39. package/dist/config/next-config.d.ts +7 -3
  40. package/dist/config/next-config.js +84 -15
  41. package/dist/config/prerender.d.ts +2 -2
  42. package/dist/config/prerender.js +7 -15
  43. package/dist/config/request-context.d.ts +14 -0
  44. package/dist/config/request-context.js +26 -0
  45. package/dist/config/server-external-packages.js +1 -1
  46. package/dist/config/tsconfig-paths.js +2 -2
  47. package/dist/{node_modules/.pnpm/am-i-vibing@0.5.0/node_modules → deps/.pnpm/am-i-vibing@0.5.0/deps}/am-i-vibing/dist/detector-1yx2Hoe0.js +2 -2
  48. package/dist/deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js +50 -0
  49. package/dist/entries/app-rsc-entry.js +39 -14
  50. package/dist/entries/app-rsc-manifest.js +21 -4
  51. package/dist/entries/pages-client-entry.js +6 -5
  52. package/dist/entries/pages-server-entry.js +18 -28
  53. package/dist/entries/runtime-entry-module.js +2 -2
  54. package/dist/index.js +314 -230
  55. package/dist/init-cloudflare.js +1 -1
  56. package/dist/init-platform.js +1 -1
  57. package/dist/init.d.ts +6 -4
  58. package/dist/init.js +25 -27
  59. package/dist/plugins/ast-utils.js +1 -1
  60. package/dist/plugins/dynamic-preload-metadata.js +7 -7
  61. package/dist/plugins/extensionless-dynamic-import.js +1 -1
  62. package/dist/plugins/fonts.js +3 -3
  63. package/dist/plugins/ignore-dynamic-requests.js +13 -8
  64. package/dist/plugins/import-meta-url.js +16 -17
  65. package/dist/plugins/middleware-export-validation.js +1 -1
  66. package/dist/plugins/middleware-server-only.js +2 -2
  67. package/dist/plugins/og-asset-ownership.js +7 -6
  68. package/dist/plugins/og-assets.js +5 -6
  69. package/dist/plugins/optimize-imports.js +12 -13
  70. package/dist/plugins/postcss.js +1 -1
  71. package/dist/plugins/remove-console.js +1 -1
  72. package/dist/plugins/require-context.js +1 -1
  73. package/dist/plugins/sass.js +2 -2
  74. package/dist/plugins/server-externals-manifest.js +1 -1
  75. package/dist/plugins/strip-server-exports.js +1 -1
  76. package/dist/plugins/styled-jsx.js +3 -2
  77. package/dist/plugins/typeof-window.js +1 -1
  78. package/dist/routing/app-route-graph.d.ts +16 -15
  79. package/dist/routing/app-route-graph.js +86 -88
  80. package/dist/routing/app-router.d.ts +0 -5
  81. package/dist/routing/app-router.js +12 -11
  82. package/dist/routing/file-matcher.d.ts +13 -28
  83. package/dist/routing/file-matcher.js +31 -44
  84. package/dist/routing/pages-router.js +26 -32
  85. package/dist/routing/route-matching.d.ts +14 -1
  86. package/dist/routing/route-matching.js +13 -1
  87. package/dist/routing/route-pattern.d.ts +2 -1
  88. package/dist/routing/route-pattern.js +7 -4
  89. package/dist/routing/route-trie.d.ts +5 -1
  90. package/dist/routing/route-trie.js +5 -2
  91. package/dist/server/api-handler.js +41 -33
  92. package/dist/server/app-browser-entry.js +18 -11
  93. package/dist/server/app-browser-history-controller.d.ts +1 -1
  94. package/dist/server/app-browser-history-controller.js +3 -3
  95. package/dist/server/app-browser-navigation-controller.js +4 -2
  96. package/dist/server/app-browser-server-action-client.js +1 -1
  97. package/dist/server/app-elements-wire.d.ts +2 -1
  98. package/dist/server/app-fallback-renderer.d.ts +11 -0
  99. package/dist/server/app-fallback-renderer.js +16 -2
  100. package/dist/server/app-middleware.js +2 -1
  101. package/dist/server/app-page-boundary-render.d.ts +26 -2
  102. package/dist/server/app-page-boundary-render.js +190 -55
  103. package/dist/server/app-page-cache-finalizer.d.ts +1 -1
  104. package/dist/server/app-page-cache.d.ts +1 -1
  105. package/dist/server/app-page-dispatch.d.ts +12 -2
  106. package/dist/server/app-page-dispatch.js +37 -51
  107. package/dist/server/app-page-element-builder.d.ts +8 -2
  108. package/dist/server/app-page-element-builder.js +112 -27
  109. package/dist/server/app-page-execution.d.ts +3 -1
  110. package/dist/server/app-page-execution.js +31 -39
  111. package/dist/server/app-page-head.d.ts +54 -2
  112. package/dist/server/app-page-head.js +164 -78
  113. package/dist/server/app-page-http-access-fallback-metadata.d.ts +29 -0
  114. package/dist/server/app-page-http-access-fallback-metadata.js +106 -0
  115. package/dist/server/app-page-render.d.ts +2 -2
  116. package/dist/server/app-page-render.js +1 -1
  117. package/dist/server/app-page-request.d.ts +12 -0
  118. package/dist/server/app-page-request.js +134 -14
  119. package/dist/server/app-page-route-wiring.d.ts +9 -0
  120. package/dist/server/app-page-route-wiring.js +44 -4
  121. package/dist/server/app-post-middleware-context.d.ts +1 -1
  122. package/dist/server/app-post-middleware-context.js +1 -1
  123. package/dist/server/app-route-handler-dispatch.js +31 -17
  124. package/dist/server/app-route-handler-execution.d.ts +6 -1
  125. package/dist/server/app-route-handler-execution.js +41 -15
  126. package/dist/server/app-route-handler-policy.d.ts +2 -0
  127. package/dist/server/app-route-handler-policy.js +3 -3
  128. package/dist/server/app-route-module-loader.d.ts +3 -1
  129. package/dist/server/app-route-module-loader.js +1 -0
  130. package/dist/server/app-route-tree-prefetch.js +1 -1
  131. package/dist/server/app-rsc-cache-busting.d.ts +1 -1
  132. package/dist/server/app-rsc-cache-busting.js +1 -1
  133. package/dist/server/app-rsc-errors.d.ts +1 -1
  134. package/dist/server/app-rsc-errors.js +12 -2
  135. package/dist/server/app-rsc-handler.d.ts +10 -5
  136. package/dist/server/app-rsc-handler.js +51 -23
  137. package/dist/server/app-rsc-redirect-flight.d.ts +66 -0
  138. package/dist/server/app-rsc-redirect-flight.js +71 -0
  139. package/dist/server/app-rsc-request-normalization.d.ts +3 -2
  140. package/dist/server/app-rsc-request-normalization.js +8 -2
  141. package/dist/server/app-rsc-response-finalizer.d.ts +2 -2
  142. package/dist/server/app-rsc-response-finalizer.js +5 -11
  143. package/dist/server/app-rsc-route-matching.d.ts +20 -0
  144. package/dist/server/app-rsc-route-matching.js +87 -11
  145. package/dist/server/app-segment-config.js +15 -5
  146. package/dist/server/app-server-action-execution.d.ts +3 -1
  147. package/dist/server/app-server-action-execution.js +8 -6
  148. package/dist/server/app-ssr-entry.js +4 -1
  149. package/dist/server/app-ssr-stream.d.ts +2 -7
  150. package/dist/server/app-ssr-stream.js +5 -10
  151. package/dist/server/cache-proof.js +1 -1
  152. package/dist/server/config-headers.d.ts +24 -0
  153. package/dist/server/config-headers.js +52 -0
  154. package/dist/server/default-global-error-module.d.ts +3 -1
  155. package/dist/server/default-not-found-module.d.ts +3 -1
  156. package/dist/server/dev-initial-server-error.d.ts +1 -1
  157. package/dist/server/dev-lockfile.js +2 -3
  158. package/dist/server/dev-route-files.js +1 -1
  159. package/dist/server/dev-server.js +281 -173
  160. package/dist/server/dev-stack-sourcemap.js +4 -3
  161. package/dist/server/headers.d.ts +3 -1
  162. package/dist/server/headers.js +3 -1
  163. package/dist/server/image-optimization.js +2 -2
  164. package/dist/server/implicit-tags.js +2 -1
  165. package/dist/server/instrumentation.js +2 -2
  166. package/dist/server/isr-cache.d.ts +1 -1
  167. package/dist/server/isr-cache.js +1 -1
  168. package/dist/server/metadata-routes.js +4 -4
  169. package/dist/server/middleware-matcher-pattern.d.ts +22 -0
  170. package/dist/server/middleware-matcher-pattern.js +219 -0
  171. package/dist/server/middleware-matcher.d.ts +2 -7
  172. package/dist/server/middleware-matcher.js +13 -60
  173. package/dist/server/middleware-path-to-regexp.d.ts +14 -0
  174. package/dist/server/middleware-path-to-regexp.js +228 -0
  175. package/dist/server/middleware-response-headers.js +1 -1
  176. package/dist/server/middleware-runtime.js +5 -4
  177. package/dist/server/middleware.d.ts +2 -1
  178. package/dist/server/middleware.js +3 -2
  179. package/dist/server/navigation-planner.d.ts +2 -0
  180. package/dist/server/navigation-planner.js +8 -2
  181. package/dist/server/next-error-digest.d.ts +9 -24
  182. package/dist/server/next-error-digest.js +23 -15
  183. package/dist/server/operation-token.js +1 -1
  184. package/dist/server/pages-body-parser-config.js +2 -1
  185. package/dist/server/pages-data-route.d.ts +11 -1
  186. package/dist/server/pages-data-route.js +16 -1
  187. package/dist/server/pages-dev-hydration.d.ts +14 -0
  188. package/dist/server/pages-dev-hydration.js +83 -0
  189. package/dist/server/pages-dev-module-url.js +2 -2
  190. package/dist/server/pages-get-initial-props.d.ts +15 -2
  191. package/dist/server/pages-get-initial-props.js +16 -6
  192. package/dist/server/pages-node-compat.d.ts +13 -6
  193. package/dist/server/pages-node-compat.js +44 -45
  194. package/dist/server/pages-page-data.d.ts +4 -2
  195. package/dist/server/pages-page-data.js +20 -10
  196. package/dist/server/pages-page-handler.d.ts +4 -2
  197. package/dist/server/pages-page-handler.js +74 -43
  198. package/dist/server/pages-page-response.d.ts +2 -2
  199. package/dist/server/pages-page-response.js +1 -1
  200. package/dist/server/pages-preview.d.ts +26 -0
  201. package/dist/server/pages-preview.js +165 -0
  202. package/dist/server/pages-readiness.d.ts +5 -4
  203. package/dist/server/pages-readiness.js +4 -2
  204. package/dist/server/pages-request-pipeline.d.ts +1 -0
  205. package/dist/server/pages-request-pipeline.js +25 -11
  206. package/dist/server/pages-router-entry.js +6 -0
  207. package/dist/server/prerender-route-params.js +2 -2
  208. package/dist/server/prod-server.d.ts +1 -4
  209. package/dist/server/prod-server.js +44 -30
  210. package/dist/server/request-pipeline.d.ts +15 -29
  211. package/dist/server/request-pipeline.js +25 -60
  212. package/dist/server/rsc-stream-hints.js +122 -18
  213. package/dist/server/seed-cache.js +1 -1
  214. package/dist/server/socket-error-backstop.js +1 -1
  215. package/dist/server/static-file-cache.js +7 -8
  216. package/dist/server/worker-utils.js +1 -1
  217. package/dist/shims/app.d.ts +1 -1
  218. package/dist/shims/cache-request-state.d.ts +27 -1
  219. package/dist/shims/cache-request-state.js +60 -1
  220. package/dist/shims/cache-runtime.d.ts +12 -1
  221. package/dist/shims/cache-runtime.js +22 -7
  222. package/dist/shims/cache.d.ts +5 -5
  223. package/dist/shims/cache.js +28 -11
  224. package/dist/shims/constants.js +1 -1
  225. package/dist/shims/document.d.ts +42 -83
  226. package/dist/shims/document.js +62 -53
  227. package/dist/shims/dynamic.d.ts +5 -25
  228. package/dist/shims/dynamic.js +29 -8
  229. package/dist/shims/error-boundary.d.ts +4 -4
  230. package/dist/shims/error.d.ts +22 -6
  231. package/dist/shims/error.js +53 -15
  232. package/dist/shims/fetch-cache.js +13 -4
  233. package/dist/shims/font-google-base.d.ts +11 -4
  234. package/dist/shims/font-local.d.ts +10 -3
  235. package/dist/shims/font-utils.js +1 -1
  236. package/dist/shims/form.d.ts +1 -1
  237. package/dist/shims/head.d.ts +13 -2
  238. package/dist/shims/head.js +6 -6
  239. package/dist/shims/headers.d.ts +28 -31
  240. package/dist/shims/headers.js +115 -53
  241. package/dist/shims/image.d.ts +27 -37
  242. package/dist/shims/image.js +21 -14
  243. package/dist/shims/internal/cookie-serialize.d.ts +3 -1
  244. package/dist/shims/internal/cookie-serialize.js +3 -1
  245. package/dist/shims/internal/hybrid-client-route-owner.js +3 -1
  246. package/dist/shims/internal/pages-data-fetch-dedup.js +5 -3
  247. package/dist/shims/internal/utils.d.ts +3 -3
  248. package/dist/shims/layout-segment-context.d.ts +1 -1
  249. package/dist/shims/legacy-image.d.ts +3 -37
  250. package/dist/shims/legacy-image.js +6 -16
  251. package/dist/shims/link.d.ts +16 -21
  252. package/dist/shims/link.js +25 -13
  253. package/dist/shims/navigation-context-state.d.ts +1 -1
  254. package/dist/shims/navigation-errors.d.ts +2 -1
  255. package/dist/shims/navigation-errors.js +9 -13
  256. package/dist/shims/navigation.d.ts +8 -4
  257. package/dist/shims/navigation.js +29 -18
  258. package/dist/shims/next-shims-augmentations.d.ts +1 -0
  259. package/dist/shims/next-shims-public.d.ts +1 -0
  260. package/dist/shims/public-shim-map.json.js +103 -0
  261. package/dist/shims/readonly-url-search-params.d.ts +3 -3
  262. package/dist/shims/readonly-url-search-params.js +3 -3
  263. package/dist/shims/request-state-types.d.ts +1 -1
  264. package/dist/shims/router-state.d.ts +1 -0
  265. package/dist/shims/router.d.ts +57 -22
  266. package/dist/shims/router.js +178 -46
  267. package/dist/shims/script.d.ts +6 -10
  268. package/dist/shims/script.js +7 -4
  269. package/dist/shims/server.d.ts +45 -22
  270. package/dist/shims/server.js +46 -7
  271. package/dist/shims/slot.d.ts +1 -1
  272. package/dist/shims/thenable-params.js +1 -1
  273. package/dist/shims/unified-request-context.d.ts +1 -1
  274. package/dist/shims/unified-request-context.js +2 -0
  275. package/dist/shims/url-safety.d.ts +1 -1
  276. package/dist/shims/url-safety.js +2 -2
  277. package/dist/typegen.d.ts +8 -2
  278. package/dist/typegen.js +84 -25
  279. package/dist/utils/client-build-manifest.js +2 -2
  280. package/dist/utils/client-entry-manifest.js +1 -1
  281. package/dist/utils/client-runtime-metadata.js +1 -1
  282. package/dist/utils/commonjs-loader.js +3 -3
  283. package/dist/utils/domain-locale.d.ts +2 -2
  284. package/dist/utils/external-url.d.ts +5 -0
  285. package/dist/utils/external-url.js +7 -0
  286. package/dist/utils/mdx-scan.js +1 -1
  287. package/dist/utils/path.d.ts +1 -13
  288. package/dist/utils/path.js +1 -15
  289. package/dist/utils/plugin-options.d.ts +4 -0
  290. package/dist/utils/plugin-options.js +8 -0
  291. package/dist/utils/project.d.ts +0 -6
  292. package/dist/utils/project.js +2 -8
  293. package/dist/utils/public-routes.js +2 -2
  294. package/dist/utils/react-version.js +1 -1
  295. package/dist/utils/redirect-digest.d.ts +9 -0
  296. package/dist/utils/redirect-digest.js +25 -0
  297. package/dist/utils/regex-safety.d.ts +8 -0
  298. package/dist/utils/regex-safety.js +737 -0
  299. package/dist/utils/vinext-root.js +1 -1
  300. package/dist/utils/vite-version.d.ts +5 -2
  301. package/dist/utils/vite-version.js +43 -17
  302. package/package.json +16 -4
  303. /package/dist/build/google-fonts/{fallback-metrics-data.js → fallback-metrics-data.json.js} +0 -0
  304. /package/dist/build/google-fonts/{font-data.js → font-data.json.js} +0 -0
  305. /package/dist/{node_modules/.pnpm/process-ancestry@0.1.0/node_modules → deps/.pnpm/process-ancestry@0.1.0/deps}/process-ancestry/dist/index.js +0 -0
@@ -1,7 +1,10 @@
1
1
  import { VinextNextData } from "../client/vinext-next-data.js";
2
+ import { isExternalUrl } from "../utils/external-url.js";
2
3
  import { PagesRouterComponentsMap } from "./internal/pages-router-components.js";
3
- import { UrlQuery } from "../utils/query.js";
4
+ import { UrlObject } from "node:url";
4
5
  import { ComponentType, ReactElement } from "react";
6
+ import { ParsedUrlQuery } from "node:querystring";
7
+ import { BaseContext, NextComponentType, NextPageContext } from "@vinext/types/next/upstream/dist/shared/lib/utils";
5
8
 
6
9
  //#region src/shims/router.d.ts
7
10
  type BeforePopStateCallback = (state: {
@@ -12,30 +15,27 @@ type BeforePopStateCallback = (state: {
12
15
  type NextRouter = {
13
16
  /** Current pathname */pathname: string; /** Current route pattern (e.g., "/posts/[id]") */
14
17
  route: string; /** Query parameters */
15
- query: Record<string, string | string[]>; /** Full URL including query string */
18
+ query: ParsedUrlQuery; /** Full URL including query string */
16
19
  asPath: string; /** Base path */
17
20
  basePath: string; /** Current locale */
18
21
  locale?: string; /** Available locales */
19
- locales?: string[]; /** Default locale */
22
+ locales?: readonly string[]; /** Default locale */
20
23
  defaultLocale?: string; /** Configured domain locales */
21
- domainLocales?: VinextNextData["domainLocales"]; /** Whether the router is ready */
24
+ domainLocales?: VinextNextData["domainLocales"]; /** Whether the active hostname matches a configured locale domain */
25
+ isLocaleDomain: boolean; /** Whether the router is ready */
22
26
  isReady: boolean; /** Whether this is a preview */
23
27
  isPreview: boolean; /** Whether this is a fallback page */
24
28
  isFallback: boolean; /** Navigate to a new URL */
25
- push(url: string | UrlObject, as?: string, options?: TransitionOptions): Promise<boolean>; /** Replace current URL */
26
- replace(url: string | UrlObject, as?: string, options?: TransitionOptions): Promise<boolean>; /** Go back */
27
- back(): void; /** Reload the page */
29
+ push(url: string | UrlObject$1, as?: string, options?: TransitionOptions): Promise<boolean>; /** Replace current URL */
30
+ replace(url: string | UrlObject$1, as?: string, options?: TransitionOptions): Promise<boolean>; /** Go back */
31
+ back(): void; /** Go forward */
32
+ forward(): void; /** Reload the page */
28
33
  reload(): void; /** Prefetch a page (injects <link rel="prefetch">) */
29
34
  prefetch(url: string, as?: string): Promise<void>; /** Register a callback to run before popstate navigation */
30
35
  beforePopState(cb: BeforePopStateCallback): void; /** Listen for route changes */
31
36
  events: RouterEvents;
32
37
  };
33
- type UrlObject = {
34
- pathname?: string;
35
- query?: UrlQuery;
36
- search?: string;
37
- hash?: string;
38
- };
38
+ type UrlObject$1 = UrlObject;
39
39
  type TransitionOptions = {
40
40
  _h?: 1;
41
41
  shallow?: boolean;
@@ -53,8 +53,6 @@ type RouterEvents = {
53
53
  * Same logic as Link's applyLocaleToHref but reads from window globals.
54
54
  */
55
55
  declare function applyNavigationLocale(url: string, locale?: string, replaceExistingLocale?: boolean): string;
56
- /** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */
57
- declare function isExternalUrl(url: string): boolean;
58
56
  /** Check if a href is only a hash change relative to the current URL */
59
57
  declare function isHashOnlyChange(href: string): boolean;
60
58
  /**
@@ -70,6 +68,7 @@ type SSRContext = {
70
68
  locales?: string[];
71
69
  defaultLocale?: string;
72
70
  domainLocales?: VinextNextData["domainLocales"];
71
+ isPreview?: boolean;
73
72
  /**
74
73
  * True when rendering a `getStaticPaths` fallback shell for a path that
75
74
  * hasn't been pre-rendered yet (`fallback: true` + unlisted path). Mirrors
@@ -112,7 +111,7 @@ type PagesNavigationContextShape = {
112
111
  declare function getPagesNavigationContext(): PagesNavigationContextShape | null;
113
112
  declare function getPagesNavigationIsReadyFromSerializedState(routePattern: string | undefined, searchString: string, nextData?: VinextNextData): boolean;
114
113
  declare function markPagesRouterReady(): boolean;
115
- declare function initializePagesRouterReadyFromNextData(nextData: VinextNextData): void;
114
+ declare function initializePagesRouterReadyFromNextData(nextData: VinextNextData, forceReady?: boolean): void;
116
115
  /**
117
116
  * useRouter hook - Pages Router compatible.
118
117
  *
@@ -173,18 +172,54 @@ type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>;
173
172
  * composed component so `_app` parity holds for class components that
174
173
  * define `getInitialProps`.
175
174
  */
176
- declare function withRouter<P extends WithRouterProps>(ComposedComponent: ComponentType<P>): ComponentType<ExcludeRouterProps<P>>;
175
+ declare function withRouter<P extends WithRouterProps, C extends BaseContext = NextPageContext>(ComposedComponent: NextComponentType<C, any, P>): ComponentType<ExcludeRouterProps<P>>;
177
176
  declare const RouterMethods: {
178
- /** See `_components` comment above for the dual role this map plays. */components: PagesRouterComponentsMap;
177
+ router: null;
178
+ readyCallbacks: Array<() => unknown>;
179
+ ready(callback: () => unknown): void; /** See `_components` comment above for the dual role this map plays. */
180
+ components: PagesRouterComponentsMap;
179
181
  sdc: Record<string, Promise<Response>>;
180
- push: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
181
- replace: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
182
+ push: (url: string | UrlObject$1, as?: string, options?: TransitionOptions) => Promise<boolean>;
183
+ replace: (url: string | UrlObject$1, as?: string, options?: TransitionOptions) => Promise<boolean>;
182
184
  back: () => void;
185
+ forward: () => void;
183
186
  reload: () => void;
184
187
  prefetch: (url: string, as?: string) => Promise<void>;
185
188
  beforePopState: (cb: BeforePopStateCallback) => void;
186
189
  events: RouterEvents;
187
190
  };
188
- declare const Router: typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods>;
191
+ declare const singletonRouter: typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods>;
192
+ /**
193
+ * Constructible named export matching `next/router`'s Router class surface.
194
+ * Vinext owns one browser history runtime, so instances delegate to that
195
+ * shared runtime while preserving the class/static-events API used by apps.
196
+ */
197
+ declare class Router {
198
+ static events: RouterEvents;
199
+ constructor(..._args: unknown[]);
200
+ get route(): string;
201
+ get pathname(): string;
202
+ get query(): ParsedUrlQuery;
203
+ get asPath(): string;
204
+ get basePath(): string;
205
+ get locale(): string | undefined;
206
+ get locales(): readonly string[] | undefined;
207
+ get defaultLocale(): string | undefined;
208
+ get domainLocales(): VinextNextData["domainLocales"];
209
+ get isLocaleDomain(): boolean;
210
+ get isReady(): boolean;
211
+ get isPreview(): boolean;
212
+ get isFallback(): boolean;
213
+ get events(): RouterEvents;
214
+ get components(): PagesRouterComponentsMap;
215
+ get sdc(): Record<string, Promise<Response>>;
216
+ push(url: string | UrlObject$1, as?: string, options?: TransitionOptions): Promise<boolean>;
217
+ replace(url: string | UrlObject$1, as?: string, options?: TransitionOptions): Promise<boolean>;
218
+ reload(): void;
219
+ back(): void;
220
+ forward(): void;
221
+ prefetch(url: string, as?: string): Promise<void>;
222
+ beforePopState(cb: BeforePopStateCallback): void;
223
+ }
189
224
  //#endregion
190
- export { ExcludeRouterProps, NextRouter, WithRouterProps, initializePagesRouterReadyFromNextData as _initializePagesRouterReadyFromNextData, markPagesRouterReady as _markPagesRouterReady, _registerRouterStateAccessors, applyNavigationLocale, Router as default, getPagesNavigationContext, getPagesNavigationIsReadyFromSerializedState, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
225
+ export { ExcludeRouterProps, NextRouter, Router, WithRouterProps, initializePagesRouterReadyFromNextData as _initializePagesRouterReadyFromNextData, markPagesRouterReady as _markPagesRouterReady, _registerRouterStateAccessors, applyNavigationLocale, singletonRouter as default, getPagesNavigationContext, getPagesNavigationIsReadyFromSerializedState, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
@@ -2,6 +2,7 @@ import { splitPathSegments } from "../routing/utils.js";
2
2
  import { hasBasePath, removeTrailingSlash, stripBasePath } from "../utils/base-path.js";
3
3
  import { parseCookieHeader } from "../utils/parse-cookie.js";
4
4
  import { assertSafeNavigationUrl } from "./url-safety.js";
5
+ import { isExternalUrl } from "../utils/external-url.js";
5
6
  import { isUnknownRecord } from "../utils/record.js";
6
7
  import { AppRouterContext } from "./internal/app-router-context.js";
7
8
  import { RouterContext } from "./internal/router-context.js";
@@ -217,7 +218,8 @@ function getPagesRouterRuntimeComponents() {
217
218
  }
218
219
  function resolveUrl(url) {
219
220
  if (typeof url === "string") return url;
220
- const hasQuery = url.query !== void 0 && Object.keys(url.query).length > 0;
221
+ const query = url.query && typeof url.query === "object" ? url.query : void 0;
222
+ const hasQuery = query !== void 0 && Object.keys(query).length > 0;
221
223
  const hasSearch = typeof url.search === "string" && url.search.length > 0;
222
224
  const hasHash = typeof url.hash === "string" && url.hash.length > 0;
223
225
  const inheritsVisiblePath = url.pathname === void 0 && (hasQuery || hasSearch || hasHash);
@@ -227,7 +229,7 @@ function resolveUrl(url) {
227
229
  const hashIndex = search.indexOf("#");
228
230
  result += hashIndex === -1 ? search : `${search.slice(0, hashIndex)}%23${search.slice(hashIndex + 1)}`;
229
231
  } else if (hasQuery) {
230
- const params = urlQueryToSearchParams(url.query);
232
+ const params = urlQueryToSearchParams(query);
231
233
  result = appendSearchParamsToUrl(result, params);
232
234
  } else if (hasHash && typeof window !== "undefined") result += window.location.search;
233
235
  if (hasHash) result += url.hash.startsWith("#") ? url.hash : `#${url.hash}`;
@@ -245,6 +247,23 @@ function resolveUrl(url) {
245
247
  function resolveNavigationTarget(url, as, locale, replaceExistingLocale = false) {
246
248
  return applyNavigationLocale(as ?? resolveUrl(url), locale, replaceExistingLocale);
247
249
  }
250
+ /**
251
+ * Next.js's internal `_h` replacement receives browser-visible URLs, which may
252
+ * already contain basePath and a locale prefix. Convert those back to app
253
+ * paths before the normal history/data URL builders run; otherwise basePath is
254
+ * added twice and locale-domain routing can turn a same-document hydration
255
+ * update into an external navigation.
256
+ */
257
+ function normalizeHydrationNavigationUrl(url) {
258
+ try {
259
+ const parsed = new URL(url, window.location.href);
260
+ const origin = getWindowOrigin();
261
+ if (!origin || parsed.origin !== origin) return url;
262
+ return stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;
263
+ } catch {
264
+ return url;
265
+ }
266
+ }
248
267
  var HrefInterpolationError = class extends Error {};
249
268
  function interpolateCurrentDynamicRoute(resolved) {
250
269
  if (typeof window === "undefined") return resolved;
@@ -376,10 +395,6 @@ function getPagesHtmlFetchUrl(browserUrl, locale) {
376
395
  const parsed = new URL(browserUrl, window.location.href);
377
396
  return normalizePathTrailingSlash(toBrowserNavigationHref(`${normalizePathTrailingSlash(`/${locale}`, __trailingSlash)}${parsed.search}${parsed.hash}`, window.location.href, __basePath), __trailingSlash);
378
397
  }
379
- /** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */
380
- function isExternalUrl(url) {
381
- return isAbsoluteOrProtocolRelativeUrl(url);
382
- }
383
398
  /** Resolve a hash URL to a basePath-stripped app URL for event payloads */
384
399
  function resolveHashUrl(url) {
385
400
  if (typeof window === "undefined") return url;
@@ -579,7 +594,7 @@ function getPagesNavigationContext() {
579
594
  return ctx;
580
595
  }
581
596
  if (!isPagesRouterDocumentActive()) return null;
582
- const resolvedPath = stripBasePath(window.location.pathname, __basePath);
597
+ const resolvedPath = removeNavigationLocalePrefix(stripBasePath(window.location.pathname, __basePath));
583
598
  const nextData = window.__NEXT_DATA__;
584
599
  const pattern = resolvePagesRoutePatternForPath(nextData?.page, resolvedPath);
585
600
  if (!pattern) return null;
@@ -626,6 +641,12 @@ function resolvePagesRoutePatternForPath(nextDataPage, resolvedPath) {
626
641
  _cachedPagesRoutePattern = resolved;
627
642
  return resolved;
628
643
  }
644
+ function getSerializedRouteQuery(nextData) {
645
+ const query = {};
646
+ for (const [key, value] of Object.entries(nextData?.query ?? {})) if (typeof value === "string") query[key] = value;
647
+ else if (Array.isArray(value)) query[key] = [...value];
648
+ return query;
649
+ }
629
650
  function extractRouteParamsFromPath(pattern, pathname) {
630
651
  return matchRoutePattern(splitPathSegments(pathname), routePatternParts(pattern));
631
652
  }
@@ -684,8 +705,14 @@ function getPathnameAndQuery() {
684
705
  };
685
706
  }
686
707
  const resolvedPath = stripBasePath(window.location.pathname, __basePath);
687
- const pathname = window.__NEXT_DATA__?.page ?? resolvedPath;
708
+ const canonicalResolvedPath = removeNavigationLocalePrefix(resolvedPath);
709
+ const pathname = window.__NEXT_DATA__?.page ?? canonicalResolvedPath;
688
710
  const nextData = window.__NEXT_DATA__;
711
+ if (!isPagesRouterReady() && !routerRuntimeState.routerDidNavigate && nextData) return {
712
+ pathname,
713
+ query: getSerializedRouteQuery(nextData),
714
+ asPath: getCurrentHistoryAsPath() ?? canonicalResolvedPath + window.location.search + window.location.hash
715
+ };
689
716
  const routeQuery = getRouteQueryFromNextData(nextData, resolvedPath);
690
717
  const searchQuery = {};
691
718
  const params = new URLSearchParams(window.location.search);
@@ -696,7 +723,7 @@ function getPathnameAndQuery() {
696
723
  ...searchQuery,
697
724
  ...routeQuery
698
725
  },
699
- asPath: getCurrentHistoryAsPath() ?? resolvedPath + window.location.search + window.location.hash
726
+ asPath: getCurrentHistoryAsPath() ?? canonicalResolvedPath + window.location.search + window.location.hash
700
727
  };
701
728
  }
702
729
  function getCurrentHistoryAsPath() {
@@ -704,10 +731,12 @@ function getCurrentHistoryAsPath() {
704
731
  if (!isNextRouterState(state) || typeof state.as !== "string") return null;
705
732
  try {
706
733
  const browserUrl = new URL(window.location.href);
707
- const stateUrl = new URL(toBrowserNavigationHref(state.as, window.location.href, __basePath), window.location.href);
734
+ const stateLocale = state.options.locale === false ? void 0 : state.options.locale;
735
+ const localizedStateAs = applyNavigationLocale(state.as, stateLocale);
736
+ const stateUrl = new URL(toBrowserNavigationHref(localizedStateAs, window.location.href, __basePath), window.location.href);
708
737
  if (stateUrl.pathname !== browserUrl.pathname || stateUrl.search !== browserUrl.search) return null;
709
- const stateAs = stripHash(state.as);
710
- const visibleAs = `${stripBasePath(window.location.pathname, __basePath)}${window.location.search}`;
738
+ const stateAs = removeNavigationLocalePrefix(stripHash(state.as));
739
+ const visibleAs = `${removeNavigationLocalePrefix(stripBasePath(window.location.pathname, __basePath))}${window.location.search}`;
711
740
  return `${stateAs || visibleAs}${window.location.hash}`;
712
741
  } catch {
713
742
  return null;
@@ -742,9 +771,9 @@ function markPagesRouterReady() {
742
771
  routerRuntimeState.pagesRouterReady = true;
743
772
  return true;
744
773
  }
745
- function initializePagesRouterReadyFromNextData(nextData) {
774
+ function initializePagesRouterReadyFromNextData(nextData, forceReady = false) {
746
775
  if (typeof window === "undefined") return;
747
- routerRuntimeState.pagesRouterReady = getPagesNavigationIsReadyFromSerializedState(nextData.page, window.location.search, nextData);
776
+ routerRuntimeState.pagesRouterReady = forceReady || getPagesNavigationIsReadyFromSerializedState(nextData.page, window.location.search, nextData);
748
777
  }
749
778
  function markPagesRouterHydrated() {
750
779
  if (typeof window === "undefined" || window.__NEXT_HYDRATED === true) return;
@@ -798,6 +827,7 @@ function cancelPreviousRenderCommit() {
798
827
  routerRuntimeState.cancelPendingRenderCommit = null;
799
828
  }
800
829
  function scheduleHardNavigationAndThrow(url, message) {
830
+ assertSafeNavigationUrl(url, HardNavigationScheduledError);
801
831
  if (typeof window === "undefined") throw new HardNavigationScheduledError(message);
802
832
  window.location.href = url;
803
833
  throw new HardNavigationScheduledError(message);
@@ -885,7 +915,7 @@ async function resolveClientConfigRedirect(href) {
885
915
  if (!redirects || redirects.length === 0) return null;
886
916
  const routeContext = getClientConfigRouteContext(href);
887
917
  if (!routeContext) return null;
888
- const { isExternalUrl, matchRedirect, preserveRedirectDestinationQuery } = await import("../config/config-matchers.js");
918
+ const { matchRedirect, preserveRedirectDestinationQuery } = await import("../config/config-matchers.js");
889
919
  const redirect = matchRedirect(routeContext.pathname, redirects, routeContext.context, routeContext.basePathState);
890
920
  if (!redirect) return null;
891
921
  return preserveRedirectDestinationQuery(__basePath && routeContext.basePathState.hadBasePath && !isExternalUrl(redirect.destination) && !hasBasePath(redirect.destination, __basePath) ? __basePath + redirect.destination : redirect.destination, routeContext.search);
@@ -893,7 +923,7 @@ async function resolveClientConfigRedirect(href) {
893
923
  async function applyClientConfigRewrite(href, rewrite) {
894
924
  const routeContext = getClientConfigRouteContext(href);
895
925
  if (!routeContext) return null;
896
- const { isExternalUrl, matchRewrite } = await import("../config/config-matchers.js");
926
+ const { matchRewrite } = await import("../config/config-matchers.js");
897
927
  const rewritten = matchRewrite(routeContext.pathname, [rewrite], routeContext.context, routeContext.basePathState);
898
928
  if (rewritten === null) return null;
899
929
  if (isExternalUrl(rewritten)) return { kind: "document" };
@@ -1087,6 +1117,7 @@ function buildPagesNavigationNextData(target, props) {
1087
1117
  query: mergedQuery,
1088
1118
  buildId: target.buildId,
1089
1119
  isFallback: false,
1120
+ isPreview: props.__N_PREVIEW === true,
1090
1121
  ...nextLocale !== void 0 ? { locale: nextLocale } : {}
1091
1122
  };
1092
1123
  }
@@ -1107,13 +1138,13 @@ async function loadComponentOnlyProps(PageComponent, AppComponent, target, asPat
1107
1138
  const AppTree = (appProps) => createElement(AppComponent, {
1108
1139
  ...appProps,
1109
1140
  Component: PageComponent,
1110
- router: Router
1141
+ router: singletonRouter
1111
1142
  });
1112
1143
  return propsObject(await AppComponent.getInitialProps({
1113
1144
  Component: PageComponent,
1114
1145
  AppTree,
1115
1146
  ctx,
1116
- router: Router
1147
+ router: singletonRouter
1117
1148
  }));
1118
1149
  }
1119
1150
  if (typeof PageComponent.getInitialProps === "function") return { pageProps: propsObject(await PageComponent.getInitialProps(ctx)) };
@@ -1135,7 +1166,7 @@ async function renderPagesNavigationTarget(url, target, props, options, assertSt
1135
1166
  ...props,
1136
1167
  Component: PageComponent,
1137
1168
  pageProps: rawPageProps,
1138
- router: Router
1169
+ router: singletonRouter
1139
1170
  });
1140
1171
  else element = React.createElement(PageComponent, pageProps);
1141
1172
  const nextData = buildPagesNavigationNextData(target, props);
@@ -1190,7 +1221,7 @@ async function navigateClientData(url, initialTarget, controller, navId, assertS
1190
1221
  };
1191
1222
  const deploymentId = getDeploymentId();
1192
1223
  if (deploymentId) headers[NEXT_DEPLOYMENT_ID_HEADER] = deploymentId;
1193
- res = await (initialTarget.dataKind === "static" ? fetchStaticPagesData : dedupedPagesDataFetch)(initialTarget.dataHref, {
1224
+ res = await (initialTarget.dataKind === "static" && singletonRouter.isPreview !== true ? fetchStaticPagesData : dedupedPagesDataFetch)(initialTarget.dataHref, {
1194
1225
  headers,
1195
1226
  signal: controller.signal
1196
1227
  });
@@ -1231,6 +1262,7 @@ async function navigateClientData(url, initialTarget, controller, navId, assertS
1231
1262
  const rawPageProps = props.pageProps;
1232
1263
  const pageProps = isUnknownRecord(rawPageProps) ? rawPageProps : {};
1233
1264
  if (initialTarget.dataKind === "server") evictPagesDataCache(initialTarget.dataHref);
1265
+ if (props.__N_PREVIEW === true || singletonRouter.isPreview === true) evictPagesDataCache(initialTarget.dataHref);
1234
1266
  const redirectDestination = pageProps.__N_REDIRECT;
1235
1267
  if (typeof redirectDestination === "string") {
1236
1268
  handleDataRedirect(redirectDestination, pageProps.__N_REDIRECT_BASE_PATH, options.mode);
@@ -1324,7 +1356,7 @@ async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillC
1324
1356
  ...props,
1325
1357
  Component: PageComponent,
1326
1358
  pageProps: rawPageProps,
1327
- router: Router
1359
+ router: singletonRouter
1328
1360
  });
1329
1361
  else element = React.createElement(PageComponent, pageProps);
1330
1362
  if (pendingRedirectHistoryUrl) {
@@ -1483,8 +1515,9 @@ function buildRouterValue(pathname, query, asPath, isReady, methods) {
1483
1515
  locales,
1484
1516
  defaultLocale,
1485
1517
  domainLocales,
1518
+ isLocaleDomain: typeof window !== "undefined" && domainLocales?.some((domain) => domain.domain === window.location.hostname) === true,
1486
1519
  isReady,
1487
- isPreview: false,
1520
+ isPreview: typeof window !== "undefined" ? nextData?.isPreview === true : _ssrState?.isPreview === true,
1488
1521
  isFallback: typeof window !== "undefined" ? nextData?.isFallback === true : _ssrState?.isFallback === true,
1489
1522
  ...methods,
1490
1523
  events: routerEvents
@@ -1572,11 +1605,12 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
1572
1605
  if (typeof window === "undefined") throwNoRouterInstance();
1573
1606
  assertSafeNavigationUrl(resolveUrl(url));
1574
1607
  if (as !== void 0) assertSafeNavigationUrl(String(as));
1608
+ const isHydrationQueryUpdate = options?._h === 1;
1575
1609
  const navigationLocale = resolveTransitionLocale(options?.locale);
1576
- const replaceInheritedLocale = as === void 0 && options?.locale !== void 0 && typeof url !== "string" && url.pathname === void 0 && (url.query !== void 0 && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0 || typeof url.hash === "string" && url.hash.length > 0);
1577
- let resolved = resolveNavigationTarget(url, as, navigationLocale, replaceInheritedLocale);
1578
- let resolvedRoute = applyNavigationLocale(resolveUrl(url), navigationLocale, replaceInheritedLocale);
1579
- if (as === void 0 && (typeof url === "string" && options?._vinextInterpolateDynamicRoute === true || typeof url !== "string" && url.pathname === void 0 && (url.query !== void 0 && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0))) {
1610
+ const replaceInheritedLocale = as === void 0 && options?.locale !== void 0 && typeof url !== "string" && url.pathname === void 0 && (url.query !== null && typeof url.query === "object" && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0 || typeof url.hash === "string" && url.hash.length > 0);
1611
+ let resolved = isHydrationQueryUpdate ? normalizeHydrationNavigationUrl(as ?? resolveUrl(url)) : resolveNavigationTarget(url, as, navigationLocale, replaceInheritedLocale);
1612
+ let resolvedRoute = isHydrationQueryUpdate ? normalizeHydrationNavigationUrl(resolveUrl(url)) : applyNavigationLocale(resolveUrl(url), navigationLocale, replaceInheritedLocale);
1613
+ if (as === void 0 && (typeof url === "string" && options?._vinextInterpolateDynamicRoute === true || typeof url !== "string" && url.pathname === void 0 && (url.query !== null && typeof url.query === "object" && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0))) {
1580
1614
  resolved = interpolateCurrentDynamicRoute(resolved);
1581
1615
  resolvedRoute = interpolateCurrentDynamicRoute(resolvedRoute);
1582
1616
  }
@@ -1597,7 +1631,7 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
1597
1631
  resolvedRoute = normalizePathTrailingSlash(resolvedRoute, __trailingSlash);
1598
1632
  let interpolatedRoute = resolvedRoute;
1599
1633
  if (resolvedRoute.includes("[")) {
1600
- const projection = interpolateDynamicRouteHref(resolvedRoute, resolved, typeof url === "string" ? void 0 : url.query);
1634
+ const projection = interpolateDynamicRouteHref(resolvedRoute, resolved, typeof url === "string" || !url.query || typeof url.query === "string" ? void 0 : url.query);
1601
1635
  if (projection?.href) {
1602
1636
  interpolatedRoute = projection.href;
1603
1637
  if (as === void 0 && stripHash(resolved).split("?", 1)[0] === projection.routePathname) {
@@ -1737,7 +1771,7 @@ async function prefetchUrl(url, as) {
1737
1771
  function useRouter() {
1738
1772
  const router = useContext(RouterContext);
1739
1773
  if (router) return router;
1740
- if (typeof window !== "undefined" && window.__VINEXT_PAGE_LOADERS__ !== void 0) return Router;
1774
+ if (typeof window !== "undefined" && window.__VINEXT_PAGE_LOADERS__ !== void 0) return singletonRouter;
1741
1775
  throw new Error("NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted");
1742
1776
  }
1743
1777
  function PagesRouterProvider({ children }) {
@@ -1762,12 +1796,13 @@ function PagesRouterProvider({ children }) {
1762
1796
  };
1763
1797
  }, []);
1764
1798
  const router = useMemo(() => buildRouterValue(pathname, query, asPath, isReady, {
1765
- push: Router.push,
1766
- replace: Router.replace,
1767
- back: Router.back,
1768
- reload: Router.reload,
1769
- prefetch: Router.prefetch,
1770
- beforePopState: Router.beforePopState
1799
+ push: singletonRouter.push,
1800
+ replace: singletonRouter.replace,
1801
+ back: singletonRouter.back,
1802
+ forward: singletonRouter.forward,
1803
+ reload: singletonRouter.reload,
1804
+ prefetch: singletonRouter.prefetch,
1805
+ beforePopState: singletonRouter.beforePopState
1771
1806
  }), [
1772
1807
  pathname,
1773
1808
  query,
@@ -1777,23 +1812,23 @@ function PagesRouterProvider({ children }) {
1777
1812
  const appRouter = useMemo(() => ({
1778
1813
  bfcacheId: "0",
1779
1814
  back() {
1780
- Router.back();
1815
+ singletonRouter.back();
1781
1816
  },
1782
1817
  forward() {
1783
1818
  if (typeof window === "undefined") throwNoRouterInstance();
1784
1819
  window.history.forward();
1785
1820
  },
1786
1821
  refresh() {
1787
- Router.reload();
1822
+ singletonRouter.reload();
1788
1823
  },
1789
1824
  push(href, options) {
1790
- Router.push(href, void 0, { scroll: options?.scroll });
1825
+ singletonRouter.push(href, void 0, { scroll: options?.scroll });
1791
1826
  },
1792
1827
  replace(href, options) {
1793
- Router.replace(href, void 0, { scroll: options?.scroll });
1828
+ singletonRouter.replace(href, void 0, { scroll: options?.scroll });
1794
1829
  },
1795
1830
  prefetch(href) {
1796
- Router.prefetch(href);
1831
+ singletonRouter.prefetch(href);
1797
1832
  }
1798
1833
  }), []);
1799
1834
  const content = createElement(RouterContext.Provider, { value: router }, createElement(Fragment, null, children, createElement(PagesRouterHydrationMarker)));
@@ -1936,6 +1971,11 @@ function withRouter(ComposedComponent) {
1936
1971
  return WithRouterWrapper;
1937
1972
  }
1938
1973
  const RouterMethods = {
1974
+ router: null,
1975
+ readyCallbacks: [],
1976
+ ready(callback) {
1977
+ callback();
1978
+ },
1939
1979
  /** See `_components` comment above for the dual role this map plays. */
1940
1980
  components: getPagesRouterComponentsMap(),
1941
1981
  sdc: getPagesStaticDataCache(),
@@ -1955,6 +1995,10 @@ const RouterMethods = {
1955
1995
  if (typeof window === "undefined") throwNoRouterInstance();
1956
1996
  window.history.back();
1957
1997
  },
1998
+ forward: () => {
1999
+ if (typeof window === "undefined") throwNoRouterInstance();
2000
+ window.history.forward();
2001
+ },
1958
2002
  reload: () => {
1959
2003
  if (typeof window === "undefined") throwNoRouterInstance();
1960
2004
  window.location.reload();
@@ -1969,7 +2013,7 @@ const RouterMethods = {
1969
2013
  },
1970
2014
  events: routerEvents
1971
2015
  };
1972
- const Router = Object.defineProperties(RouterMethods, {
2016
+ const singletonRouter = Object.defineProperties(RouterMethods, {
1973
2017
  pathname: {
1974
2018
  enumerable: true,
1975
2019
  get() {
@@ -2029,6 +2073,14 @@ const Router = Object.defineProperties(RouterMethods, {
2029
2073
  return window.__NEXT_DATA__?.domainLocales;
2030
2074
  }
2031
2075
  },
2076
+ isLocaleDomain: {
2077
+ enumerable: true,
2078
+ get() {
2079
+ const domainLocales = typeof window === "undefined" ? _getSSRContext()?.domainLocales : window.__NEXT_DATA__?.domainLocales;
2080
+ if (!domainLocales || typeof window === "undefined") return false;
2081
+ return domainLocales.some((domain) => domain.domain === window.location.hostname);
2082
+ }
2083
+ },
2032
2084
  isReady: {
2033
2085
  enumerable: true,
2034
2086
  get() {
@@ -2037,8 +2089,10 @@ const Router = Object.defineProperties(RouterMethods, {
2037
2089
  },
2038
2090
  isPreview: {
2039
2091
  enumerable: true,
2040
- value: false,
2041
- writable: false
2092
+ get() {
2093
+ if (typeof window === "undefined") return _getSSRContext()?.isPreview === true;
2094
+ return window.__NEXT_DATA__?.isPreview === true;
2095
+ }
2042
2096
  },
2043
2097
  isFallback: {
2044
2098
  enumerable: true,
@@ -2048,7 +2102,7 @@ const Router = Object.defineProperties(RouterMethods, {
2048
2102
  }
2049
2103
  }
2050
2104
  });
2051
- routerRuntimeState.publicRouter = Router;
2105
+ routerRuntimeState.publicRouter = singletonRouter;
2052
2106
  const deprecatedRouterEvents = [
2053
2107
  "routeChangeStart",
2054
2108
  "beforeHistoryChange",
@@ -2062,7 +2116,7 @@ if (!routerRuntimeState.deprecatedEventBridgeInstalled) {
2062
2116
  for (const event of deprecatedRouterEvents) {
2063
2117
  const eventField = `on${event.charAt(0).toUpperCase()}${event.substring(1)}`;
2064
2118
  routerEvents.on(event, (...args) => {
2065
- const handler = (routerRuntimeState.publicRouter ?? Router)[eventField];
2119
+ const handler = (routerRuntimeState.publicRouter ?? singletonRouter)[eventField];
2066
2120
  if (typeof handler === "function") try {
2067
2121
  handler(...args);
2068
2122
  } catch (err) {
@@ -2074,9 +2128,87 @@ if (!routerRuntimeState.deprecatedEventBridgeInstalled) {
2074
2128
  }
2075
2129
  if (typeof window !== "undefined") {
2076
2130
  installPagesRouterRuntime();
2077
- installWindowNext({ router: Router });
2131
+ installWindowNext({ router: singletonRouter });
2078
2132
  }
2079
2133
  const _PAGES_NAVIGATION_ACCESSOR_KEY = Symbol.for("vinext.navigation.pagesNavigationContextAccessor");
2080
2134
  globalThis[_PAGES_NAVIGATION_ACCESSOR_KEY] = getPagesNavigationContext;
2135
+ /**
2136
+ * Constructible named export matching `next/router`'s Router class surface.
2137
+ * Vinext owns one browser history runtime, so instances delegate to that
2138
+ * shared runtime while preserving the class/static-events API used by apps.
2139
+ */
2140
+ var Router = class {
2141
+ static events = routerEvents;
2142
+ constructor(..._args) {}
2143
+ get route() {
2144
+ return singletonRouter.route;
2145
+ }
2146
+ get pathname() {
2147
+ return singletonRouter.pathname;
2148
+ }
2149
+ get query() {
2150
+ return singletonRouter.query;
2151
+ }
2152
+ get asPath() {
2153
+ return singletonRouter.asPath;
2154
+ }
2155
+ get basePath() {
2156
+ return singletonRouter.basePath;
2157
+ }
2158
+ get locale() {
2159
+ return singletonRouter.locale;
2160
+ }
2161
+ get locales() {
2162
+ return singletonRouter.locales;
2163
+ }
2164
+ get defaultLocale() {
2165
+ return singletonRouter.defaultLocale;
2166
+ }
2167
+ get domainLocales() {
2168
+ return singletonRouter.domainLocales;
2169
+ }
2170
+ get isLocaleDomain() {
2171
+ return singletonRouter.isLocaleDomain;
2172
+ }
2173
+ get isReady() {
2174
+ return singletonRouter.isReady;
2175
+ }
2176
+ get isPreview() {
2177
+ return singletonRouter.isPreview;
2178
+ }
2179
+ get isFallback() {
2180
+ return singletonRouter.isFallback;
2181
+ }
2182
+ get events() {
2183
+ return singletonRouter.events;
2184
+ }
2185
+ get components() {
2186
+ return singletonRouter.components;
2187
+ }
2188
+ get sdc() {
2189
+ return singletonRouter.sdc;
2190
+ }
2191
+ push(url, as, options) {
2192
+ return singletonRouter.push(url, as, options);
2193
+ }
2194
+ replace(url, as, options) {
2195
+ return singletonRouter.replace(url, as, options);
2196
+ }
2197
+ reload() {
2198
+ singletonRouter.reload();
2199
+ }
2200
+ back() {
2201
+ singletonRouter.back();
2202
+ }
2203
+ forward() {
2204
+ singletonRouter.forward();
2205
+ }
2206
+ prefetch(url, as) {
2207
+ return singletonRouter.prefetch(url, as);
2208
+ }
2209
+ beforePopState(cb) {
2210
+ singletonRouter.beforePopState(cb);
2211
+ }
2212
+ };
2081
2213
  //#endregion
2082
- export { initializePagesRouterReadyFromNextData as _initializePagesRouterReadyFromNextData, markPagesRouterReady as _markPagesRouterReady, _registerRouterStateAccessors, applyNavigationLocale, Router as default, getPagesNavigationContext, getPagesNavigationIsReadyFromSerializedState, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
2214
+ export { Router, initializePagesRouterReadyFromNextData as _initializePagesRouterReadyFromNextData, markPagesRouterReady as _markPagesRouterReady, _registerRouterStateAccessors, applyNavigationLocale, singletonRouter as default, getPagesNavigationContext, getPagesNavigationIsReadyFromSerializedState, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
@@ -1,21 +1,18 @@
1
1
  import React from "react";
2
2
 
3
3
  //#region src/shims/script.d.ts
4
- type ScriptProps = {
4
+ type ScriptProps = React.ScriptHTMLAttributes<HTMLScriptElement> & {
5
5
  /** Script source URL */src?: string; /** Loading strategy. Default: "afterInteractive" */
6
6
  strategy?: "beforeInteractive" | "afterInteractive" | "lazyOnload" | "worker"; /** Unique identifier for the script */
7
7
  id?: string; /** Called when the script has loaded */
8
- onLoad?: (e: Event) => void; /** Called when the script is ready (after load, and on every re-render if already loaded) */
8
+ onLoad?: (e: unknown) => void; /** Called when the script is ready (after load, and on every re-render if already loaded) */
9
9
  onReady?: () => void; /** Called on script load error */
10
- onError?: (e: Event) => void; /** Inline script content */
11
- children?: React.ReactNode; /** Dangerous inner HTML */
12
- dangerouslySetInnerHTML?: {
13
- __html: string;
14
- }; /** Script type attribute */
10
+ onError?: (e: unknown) => void; /** Inline script content */
11
+ children?: React.ReactNode; /** Script type attribute */
15
12
  type?: string; /** Async attribute */
16
13
  async?: boolean; /** Defer attribute */
17
14
  defer?: boolean; /** Crossorigin attribute */
18
- crossOrigin?: string; /** Nonce for CSP */
15
+ crossOrigin?: React.ScriptHTMLAttributes<HTMLScriptElement>["crossOrigin"]; /** Nonce for CSP */
19
16
  nonce?: string; /** Integrity hash */
20
17
  integrity?: string;
21
18
  /**
@@ -27,8 +24,7 @@ type ScriptProps = {
27
24
  * `.nextjs-ref/packages/next/src/client/script.tsx` (`insertStylesheets`
28
25
  * and the `appDir` block).
29
26
  */
30
- stylesheets?: string[]; /** Additional attributes */
31
- [key: string]: unknown;
27
+ stylesheets?: string[];
32
28
  };
33
29
  /**
34
30
  * Load a script imperatively (outside of React).