vinext 0.0.29 → 0.0.31

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 (428) hide show
  1. package/README.md +12 -6
  2. package/dist/build/prerender.d.ts +188 -0
  3. package/dist/build/prerender.js +675 -0
  4. package/dist/build/prerender.js.map +1 -0
  5. package/dist/build/report.d.ts +45 -46
  6. package/dist/build/report.js +247 -276
  7. package/dist/build/report.js.map +1 -1
  8. package/dist/build/run-prerender.d.ts +62 -0
  9. package/dist/build/run-prerender.js +183 -0
  10. package/dist/build/run-prerender.js.map +1 -0
  11. package/dist/build/server-manifest.d.ts +19 -0
  12. package/dist/build/server-manifest.js +29 -0
  13. package/dist/build/server-manifest.js.map +1 -0
  14. package/dist/build/static-export.d.ts +51 -66
  15. package/dist/build/static-export.js +51 -545
  16. package/dist/build/static-export.js.map +1 -1
  17. package/dist/check.d.ts +26 -24
  18. package/dist/check.js +591 -567
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +430 -491
  22. package/dist/cli.js.map +1 -1
  23. package/dist/client/entry.d.ts +1 -2
  24. package/dist/client/entry.js +49 -62
  25. package/dist/client/entry.js.map +1 -1
  26. package/dist/client/validate-module-path.d.ts +4 -1
  27. package/dist/client/validate-module-path.js +23 -28
  28. package/dist/client/validate-module-path.js.map +1 -1
  29. package/dist/client/vinext-next-data.d.ts +15 -20
  30. package/dist/client/vinext-next-data.js +0 -1
  31. package/dist/cloudflare/index.d.ts +3 -8
  32. package/dist/cloudflare/index.js +3 -8
  33. package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
  34. package/dist/cloudflare/kv-cache-handler.js +354 -366
  35. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  36. package/dist/cloudflare/tpr.d.ts +36 -34
  37. package/dist/cloudflare/tpr.js +460 -603
  38. package/dist/cloudflare/tpr.js.map +1 -1
  39. package/dist/config/config-matchers.d.ts +31 -40
  40. package/dist/config/config-matchers.js +727 -936
  41. package/dist/config/config-matchers.js.map +1 -1
  42. package/dist/config/dotenv.d.ts +18 -11
  43. package/dist/config/dotenv.js +79 -84
  44. package/dist/config/dotenv.js.map +1 -1
  45. package/dist/config/next-config.d.ts +156 -146
  46. package/dist/config/next-config.js +374 -464
  47. package/dist/config/next-config.js.map +1 -1
  48. package/dist/deploy.d.ts +87 -96
  49. package/dist/deploy.js +490 -628
  50. package/dist/deploy.js.map +1 -1
  51. package/dist/entries/app-browser-entry.d.ts +4 -1
  52. package/dist/entries/app-browser-entry.js +12 -8
  53. package/dist/entries/app-browser-entry.js.map +1 -1
  54. package/dist/entries/app-rsc-entry.d.ts +33 -20
  55. package/dist/entries/app-rsc-entry.js +618 -343
  56. package/dist/entries/app-rsc-entry.js.map +1 -1
  57. package/dist/entries/app-ssr-entry.d.ts +9 -1
  58. package/dist/entries/app-ssr-entry.js +61 -28
  59. package/dist/entries/app-ssr-entry.js.map +1 -1
  60. package/dist/entries/pages-client-entry.d.ts +6 -2
  61. package/dist/entries/pages-client-entry.js +30 -33
  62. package/dist/entries/pages-client-entry.js.map +1 -1
  63. package/dist/entries/pages-entry-helpers.d.ts +5 -1
  64. package/dist/entries/pages-entry-helpers.js +17 -14
  65. package/dist/entries/pages-entry-helpers.js.map +1 -1
  66. package/dist/entries/pages-server-entry.d.ts +6 -2
  67. package/dist/entries/pages-server-entry.js +229 -207
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +82 -62
  70. package/dist/index.js +2172 -3125
  71. package/dist/index.js.map +1 -1
  72. package/dist/init.d.ts +40 -37
  73. package/dist/init.js +201 -258
  74. package/dist/init.js.map +1 -1
  75. package/dist/plugins/async-hooks-stub.d.ts +7 -3
  76. package/dist/plugins/async-hooks-stub.js +39 -42
  77. package/dist/plugins/async-hooks-stub.js.map +1 -1
  78. package/dist/plugins/client-reference-dedup.d.ts +7 -3
  79. package/dist/plugins/client-reference-dedup.js +63 -88
  80. package/dist/plugins/client-reference-dedup.js.map +1 -1
  81. package/dist/routing/app-router.d.ts +100 -96
  82. package/dist/routing/app-router.js +563 -659
  83. package/dist/routing/app-router.js.map +1 -1
  84. package/dist/routing/file-matcher.d.ts +18 -15
  85. package/dist/routing/file-matcher.js +65 -65
  86. package/dist/routing/file-matcher.js.map +1 -1
  87. package/dist/routing/pages-router.d.ts +23 -24
  88. package/dist/routing/pages-router.js +147 -172
  89. package/dist/routing/pages-router.js.map +1 -1
  90. package/dist/routing/route-trie.d.ts +23 -20
  91. package/dist/routing/route-trie.js +131 -151
  92. package/dist/routing/route-trie.js.map +1 -1
  93. package/dist/routing/route-validation.d.ts +5 -2
  94. package/dist/routing/route-validation.js +98 -130
  95. package/dist/routing/route-validation.js.map +1 -1
  96. package/dist/routing/utils.d.ts +10 -7
  97. package/dist/routing/utils.js +75 -111
  98. package/dist/routing/utils.js.map +1 -1
  99. package/dist/server/api-handler.d.ts +8 -13
  100. package/dist/server/api-handler.js +161 -193
  101. package/dist/server/api-handler.js.map +1 -1
  102. package/dist/server/app-router-entry.d.ts +6 -16
  103. package/dist/server/app-router-entry.js +26 -54
  104. package/dist/server/app-router-entry.js.map +1 -1
  105. package/dist/server/dev-module-runner.d.ts +11 -64
  106. package/dist/server/dev-module-runner.js +89 -101
  107. package/dist/server/dev-module-runner.js.map +1 -1
  108. package/dist/server/dev-origin-check.d.ts +12 -10
  109. package/dist/server/dev-origin-check.js +98 -108
  110. package/dist/server/dev-origin-check.js.map +1 -1
  111. package/dist/server/dev-server.d.ts +17 -13
  112. package/dist/server/dev-server.js +547 -874
  113. package/dist/server/dev-server.js.map +1 -1
  114. package/dist/server/html.d.ts +4 -1
  115. package/dist/server/html.js +25 -26
  116. package/dist/server/html.js.map +1 -1
  117. package/dist/server/image-optimization.d.ts +31 -28
  118. package/dist/server/image-optimization.js +183 -200
  119. package/dist/server/image-optimization.js.map +1 -1
  120. package/dist/server/instrumentation.d.ts +25 -22
  121. package/dist/server/instrumentation.js +110 -122
  122. package/dist/server/instrumentation.js.map +1 -1
  123. package/dist/server/isr-cache.d.ts +16 -26
  124. package/dist/server/isr-cache.js +109 -126
  125. package/dist/server/isr-cache.js.map +1 -1
  126. package/dist/server/metadata-routes.d.ts +85 -88
  127. package/dist/server/metadata-routes.js +277 -286
  128. package/dist/server/metadata-routes.js.map +1 -1
  129. package/dist/server/middleware-codegen.d.ts +7 -4
  130. package/dist/server/middleware-codegen.js +98 -65
  131. package/dist/server/middleware-codegen.js.map +1 -1
  132. package/dist/server/middleware-request-headers.d.ts +8 -6
  133. package/dist/server/middleware-request-headers.js +47 -65
  134. package/dist/server/middleware-request-headers.js.map +1 -1
  135. package/dist/server/middleware.d.ts +31 -47
  136. package/dist/server/middleware.js +276 -363
  137. package/dist/server/middleware.js.map +1 -1
  138. package/dist/server/normalize-path.d.ts +4 -1
  139. package/dist/server/normalize-path.js +33 -47
  140. package/dist/server/normalize-path.js.map +1 -1
  141. package/dist/server/pages-i18n.d.ts +58 -0
  142. package/dist/server/pages-i18n.js +125 -0
  143. package/dist/server/pages-i18n.js.map +1 -0
  144. package/dist/server/prod-server.d.ts +19 -31
  145. package/dist/server/prod-server.js +714 -945
  146. package/dist/server/prod-server.js.map +1 -1
  147. package/dist/server/request-log.d.ts +18 -12
  148. package/dist/server/request-log.js +45 -52
  149. package/dist/server/request-log.js.map +1 -1
  150. package/dist/server/request-pipeline.d.ts +9 -17
  151. package/dist/server/request-pipeline.js +133 -184
  152. package/dist/server/request-pipeline.js.map +1 -1
  153. package/dist/server/worker-utils.d.ts +4 -1
  154. package/dist/server/worker-utils.js +31 -37
  155. package/dist/server/worker-utils.js.map +1 -1
  156. package/dist/shims/amp.d.ts +5 -2
  157. package/dist/shims/amp.js +19 -15
  158. package/dist/shims/amp.js.map +1 -1
  159. package/dist/shims/app.d.ts +8 -10
  160. package/dist/shims/app.js +0 -1
  161. package/dist/shims/cache-runtime.d.ts +21 -43
  162. package/dist/shims/cache-runtime.js +271 -405
  163. package/dist/shims/cache-runtime.js.map +1 -1
  164. package/dist/shims/cache.d.ts +131 -119
  165. package/dist/shims/cache.js +339 -418
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/client-only.d.ts +1 -18
  168. package/dist/shims/client-only.js +0 -17
  169. package/dist/shims/compat-router.d.ts +4 -1
  170. package/dist/shims/compat-router.js +23 -19
  171. package/dist/shims/compat-router.js.map +1 -1
  172. package/dist/shims/config.d.ts +7 -5
  173. package/dist/shims/config.js +16 -23
  174. package/dist/shims/config.js.map +1 -1
  175. package/dist/shims/constants.d.ts +119 -118
  176. package/dist/shims/constants.js +159 -165
  177. package/dist/shims/constants.js.map +1 -1
  178. package/dist/shims/document.d.ts +20 -16
  179. package/dist/shims/document.js +41 -22
  180. package/dist/shims/document.js.map +1 -1
  181. package/dist/shims/dynamic.d.ts +13 -22
  182. package/dist/shims/dynamic.js +122 -136
  183. package/dist/shims/dynamic.js.map +1 -1
  184. package/dist/shims/error-boundary.d.ts +22 -15
  185. package/dist/shims/error-boundary.js +81 -79
  186. package/dist/shims/error-boundary.js.map +1 -1
  187. package/dist/shims/error.d.ts +11 -12
  188. package/dist/shims/error.js +35 -39
  189. package/dist/shims/error.js.map +1 -1
  190. package/dist/shims/fetch-cache.d.ts +26 -10
  191. package/dist/shims/fetch-cache.js +443 -586
  192. package/dist/shims/fetch-cache.js.map +1 -1
  193. package/dist/shims/font-google-base.d.ts +28 -26
  194. package/dist/shims/font-google-base.js +238 -325
  195. package/dist/shims/font-google-base.js.map +1 -1
  196. package/dist/shims/font-google.d.ts +3 -3
  197. package/dist/shims/font-google.generated.d.ts +1928 -1924
  198. package/dist/shims/font-google.generated.js +1928 -2133
  199. package/dist/shims/font-google.generated.js.map +1 -1
  200. package/dist/shims/font-google.js +3 -3
  201. package/dist/shims/font-local.d.ts +28 -26
  202. package/dist/shims/font-local.js +204 -260
  203. package/dist/shims/font-local.js.map +1 -1
  204. package/dist/shims/form.d.ts +13 -27
  205. package/dist/shims/form.js +128 -180
  206. package/dist/shims/form.js.map +1 -1
  207. package/dist/shims/head-state.d.ts +9 -10
  208. package/dist/shims/head-state.js +25 -39
  209. package/dist/shims/head-state.js.map +1 -1
  210. package/dist/shims/head.d.ts +16 -18
  211. package/dist/shims/head.js +185 -153
  212. package/dist/shims/head.js.map +1 -1
  213. package/dist/shims/headers.d.ts +84 -71
  214. package/dist/shims/headers.js +447 -583
  215. package/dist/shims/headers.js.map +1 -1
  216. package/dist/shims/i18n-context.d.ts +23 -0
  217. package/dist/shims/i18n-context.js +44 -0
  218. package/dist/shims/i18n-context.js.map +1 -0
  219. package/dist/shims/i18n-state.d.ts +14 -0
  220. package/dist/shims/i18n-state.js +45 -0
  221. package/dist/shims/i18n-state.js.map +1 -0
  222. package/dist/shims/image-config.d.ts +11 -8
  223. package/dist/shims/image-config.js +50 -83
  224. package/dist/shims/image-config.js.map +1 -1
  225. package/dist/shims/image.d.ts +37 -44
  226. package/dist/shims/image.js +284 -301
  227. package/dist/shims/image.js.map +1 -1
  228. package/dist/shims/internal/api-utils.d.ts +7 -4
  229. package/dist/shims/internal/api-utils.js +0 -6
  230. package/dist/shims/internal/app-router-context.d.ts +22 -17
  231. package/dist/shims/internal/app-router-context.js +17 -13
  232. package/dist/shims/internal/app-router-context.js.map +1 -1
  233. package/dist/shims/internal/cookies.d.ts +2 -9
  234. package/dist/shims/internal/cookies.js +2 -9
  235. package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
  236. package/dist/shims/internal/parse-cookie-header.js +29 -29
  237. package/dist/shims/internal/parse-cookie-header.js.map +1 -1
  238. package/dist/shims/internal/router-context.d.ts +6 -1
  239. package/dist/shims/internal/router-context.js +11 -7
  240. package/dist/shims/internal/router-context.js.map +1 -1
  241. package/dist/shims/internal/utils.d.ts +40 -36
  242. package/dist/shims/internal/utils.js +24 -30
  243. package/dist/shims/internal/utils.js.map +1 -1
  244. package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
  245. package/dist/shims/internal/work-unit-async-storage.js +14 -11
  246. package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
  247. package/dist/shims/layout-segment-context.d.ts +11 -14
  248. package/dist/shims/layout-segment-context.js +24 -23
  249. package/dist/shims/layout-segment-context.js.map +1 -1
  250. package/dist/shims/legacy-image.d.ts +39 -46
  251. package/dist/shims/legacy-image.js +47 -42
  252. package/dist/shims/legacy-image.js.map +1 -1
  253. package/dist/shims/link.d.ts +32 -36
  254. package/dist/shims/link.js +262 -382
  255. package/dist/shims/link.js.map +1 -1
  256. package/dist/shims/metadata.d.ts +210 -202
  257. package/dist/shims/metadata.js +545 -544
  258. package/dist/shims/metadata.js.map +1 -1
  259. package/dist/shims/navigation-state.d.ts +19 -13
  260. package/dist/shims/navigation-state.js +68 -58
  261. package/dist/shims/navigation-state.js.map +1 -1
  262. package/dist/shims/navigation.d.ts +59 -63
  263. package/dist/shims/navigation.js +508 -690
  264. package/dist/shims/navigation.js.map +1 -1
  265. package/dist/shims/og.d.ts +2 -20
  266. package/dist/shims/og.js +2 -19
  267. package/dist/shims/readonly-url-search-params.d.ts +8 -5
  268. package/dist/shims/readonly-url-search-params.js +26 -22
  269. package/dist/shims/readonly-url-search-params.js.map +1 -1
  270. package/dist/shims/request-context.d.ts +8 -5
  271. package/dist/shims/request-context.js +50 -51
  272. package/dist/shims/request-context.js.map +1 -1
  273. package/dist/shims/request-state-types.d.ts +11 -0
  274. package/dist/shims/request-state-types.js +1 -0
  275. package/dist/shims/router-state.d.ts +15 -1
  276. package/dist/shims/router-state.js +34 -41
  277. package/dist/shims/router-state.js.map +1 -1
  278. package/dist/shims/router.d.ts +81 -81
  279. package/dist/shims/router.js +517 -543
  280. package/dist/shims/router.js.map +1 -1
  281. package/dist/shims/script.d.ts +39 -48
  282. package/dist/shims/script.js +107 -160
  283. package/dist/shims/script.js.map +1 -1
  284. package/dist/shims/server-only.d.ts +1 -19
  285. package/dist/shims/server-only.js +0 -18
  286. package/dist/shims/server.d.ts +175 -157
  287. package/dist/shims/server.js +462 -432
  288. package/dist/shims/server.js.map +1 -1
  289. package/dist/shims/unified-request-context.d.ts +66 -0
  290. package/dist/shims/unified-request-context.js +98 -0
  291. package/dist/shims/unified-request-context.js.map +1 -0
  292. package/dist/shims/url-safety.d.ts +4 -1
  293. package/dist/shims/url-safety.js +15 -11
  294. package/dist/shims/url-safety.js.map +1 -1
  295. package/dist/shims/url-utils.d.ts +8 -5
  296. package/dist/shims/url-utils.js +62 -93
  297. package/dist/shims/url-utils.js.map +1 -1
  298. package/dist/shims/web-vitals.d.ts +10 -8
  299. package/dist/shims/web-vitals.js +9 -15
  300. package/dist/shims/web-vitals.js.map +1 -1
  301. package/dist/utils/base-path.d.ts +5 -2
  302. package/dist/utils/base-path.js +21 -19
  303. package/dist/utils/base-path.js.map +1 -1
  304. package/dist/utils/domain-locale.d.ts +26 -0
  305. package/dist/utils/domain-locale.js +44 -0
  306. package/dist/utils/domain-locale.js.map +1 -0
  307. package/dist/utils/hash.d.ts +4 -1
  308. package/dist/utils/hash.js +19 -17
  309. package/dist/utils/hash.js.map +1 -1
  310. package/dist/utils/manifest-paths.d.ts +6 -3
  311. package/dist/utils/manifest-paths.js +15 -16
  312. package/dist/utils/manifest-paths.js.map +1 -1
  313. package/dist/utils/project.d.ts +13 -11
  314. package/dist/utils/project.js +169 -216
  315. package/dist/utils/project.js.map +1 -1
  316. package/dist/utils/query.d.ts +8 -6
  317. package/dist/utils/query.js +57 -67
  318. package/dist/utils/query.js.map +1 -1
  319. package/package.json +11 -10
  320. package/dist/build/report.d.ts.map +0 -1
  321. package/dist/build/static-export.d.ts.map +0 -1
  322. package/dist/check.d.ts.map +0 -1
  323. package/dist/cli.d.ts.map +0 -1
  324. package/dist/client/entry.d.ts.map +0 -1
  325. package/dist/client/validate-module-path.d.ts.map +0 -1
  326. package/dist/client/vinext-next-data.d.ts.map +0 -1
  327. package/dist/client/vinext-next-data.js.map +0 -1
  328. package/dist/cloudflare/index.d.ts.map +0 -1
  329. package/dist/cloudflare/index.js.map +0 -1
  330. package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
  331. package/dist/cloudflare/tpr.d.ts.map +0 -1
  332. package/dist/config/config-matchers.d.ts.map +0 -1
  333. package/dist/config/dotenv.d.ts.map +0 -1
  334. package/dist/config/next-config.d.ts.map +0 -1
  335. package/dist/deploy.d.ts.map +0 -1
  336. package/dist/entries/app-browser-entry.d.ts.map +0 -1
  337. package/dist/entries/app-rsc-entry.d.ts.map +0 -1
  338. package/dist/entries/app-ssr-entry.d.ts.map +0 -1
  339. package/dist/entries/pages-client-entry.d.ts.map +0 -1
  340. package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
  341. package/dist/entries/pages-server-entry.d.ts.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/init.d.ts.map +0 -1
  344. package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
  345. package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
  346. package/dist/routing/app-router.d.ts.map +0 -1
  347. package/dist/routing/file-matcher.d.ts.map +0 -1
  348. package/dist/routing/pages-router.d.ts.map +0 -1
  349. package/dist/routing/route-trie.d.ts.map +0 -1
  350. package/dist/routing/route-validation.d.ts.map +0 -1
  351. package/dist/routing/utils.d.ts.map +0 -1
  352. package/dist/server/api-handler.d.ts.map +0 -1
  353. package/dist/server/app-router-entry.d.ts.map +0 -1
  354. package/dist/server/dev-module-runner.d.ts.map +0 -1
  355. package/dist/server/dev-origin-check.d.ts.map +0 -1
  356. package/dist/server/dev-server.d.ts.map +0 -1
  357. package/dist/server/html.d.ts.map +0 -1
  358. package/dist/server/image-optimization.d.ts.map +0 -1
  359. package/dist/server/instrumentation.d.ts.map +0 -1
  360. package/dist/server/isr-cache.d.ts.map +0 -1
  361. package/dist/server/metadata-routes.d.ts.map +0 -1
  362. package/dist/server/middleware-codegen.d.ts.map +0 -1
  363. package/dist/server/middleware-request-headers.d.ts.map +0 -1
  364. package/dist/server/middleware.d.ts.map +0 -1
  365. package/dist/server/normalize-path.d.ts.map +0 -1
  366. package/dist/server/prod-server.d.ts.map +0 -1
  367. package/dist/server/request-log.d.ts.map +0 -1
  368. package/dist/server/request-pipeline.d.ts.map +0 -1
  369. package/dist/server/worker-utils.d.ts.map +0 -1
  370. package/dist/shims/amp.d.ts.map +0 -1
  371. package/dist/shims/app.d.ts.map +0 -1
  372. package/dist/shims/app.js.map +0 -1
  373. package/dist/shims/cache-runtime.d.ts.map +0 -1
  374. package/dist/shims/cache.d.ts.map +0 -1
  375. package/dist/shims/client-only.d.ts.map +0 -1
  376. package/dist/shims/client-only.js.map +0 -1
  377. package/dist/shims/compat-router.d.ts.map +0 -1
  378. package/dist/shims/config.d.ts.map +0 -1
  379. package/dist/shims/constants.d.ts.map +0 -1
  380. package/dist/shims/document.d.ts.map +0 -1
  381. package/dist/shims/dynamic.d.ts.map +0 -1
  382. package/dist/shims/error-boundary.d.ts.map +0 -1
  383. package/dist/shims/error.d.ts.map +0 -1
  384. package/dist/shims/fetch-cache.d.ts.map +0 -1
  385. package/dist/shims/font-google-base.d.ts.map +0 -1
  386. package/dist/shims/font-google.d.ts.map +0 -1
  387. package/dist/shims/font-google.generated.d.ts.map +0 -1
  388. package/dist/shims/font-google.js.map +0 -1
  389. package/dist/shims/font-local.d.ts.map +0 -1
  390. package/dist/shims/form.d.ts.map +0 -1
  391. package/dist/shims/head-state.d.ts.map +0 -1
  392. package/dist/shims/head.d.ts.map +0 -1
  393. package/dist/shims/headers.d.ts.map +0 -1
  394. package/dist/shims/image-config.d.ts.map +0 -1
  395. package/dist/shims/image.d.ts.map +0 -1
  396. package/dist/shims/internal/api-utils.d.ts.map +0 -1
  397. package/dist/shims/internal/api-utils.js.map +0 -1
  398. package/dist/shims/internal/app-router-context.d.ts.map +0 -1
  399. package/dist/shims/internal/cookies.d.ts.map +0 -1
  400. package/dist/shims/internal/cookies.js.map +0 -1
  401. package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
  402. package/dist/shims/internal/router-context.d.ts.map +0 -1
  403. package/dist/shims/internal/utils.d.ts.map +0 -1
  404. package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
  405. package/dist/shims/layout-segment-context.d.ts.map +0 -1
  406. package/dist/shims/legacy-image.d.ts.map +0 -1
  407. package/dist/shims/link.d.ts.map +0 -1
  408. package/dist/shims/metadata.d.ts.map +0 -1
  409. package/dist/shims/navigation-state.d.ts.map +0 -1
  410. package/dist/shims/navigation.d.ts.map +0 -1
  411. package/dist/shims/og.d.ts.map +0 -1
  412. package/dist/shims/og.js.map +0 -1
  413. package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
  414. package/dist/shims/request-context.d.ts.map +0 -1
  415. package/dist/shims/router-state.d.ts.map +0 -1
  416. package/dist/shims/router.d.ts.map +0 -1
  417. package/dist/shims/script.d.ts.map +0 -1
  418. package/dist/shims/server-only.d.ts.map +0 -1
  419. package/dist/shims/server-only.js.map +0 -1
  420. package/dist/shims/server.d.ts.map +0 -1
  421. package/dist/shims/url-safety.d.ts.map +0 -1
  422. package/dist/shims/url-utils.d.ts.map +0 -1
  423. package/dist/shims/web-vitals.d.ts.map +0 -1
  424. package/dist/utils/base-path.d.ts.map +0 -1
  425. package/dist/utils/hash.d.ts.map +0 -1
  426. package/dist/utils/manifest-paths.d.ts.map +0 -1
  427. package/dist/utils/project.d.ts.map +0 -1
  428. package/dist/utils/query.d.ts.map +0 -1
@@ -1,412 +1,292 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- /**
4
- * next/link shim
5
- *
6
- * Renders an <a> tag with client-side navigation support.
7
- * On click, prevents full page reload and triggers client-side
8
- * page swap via the router's navigation system.
9
- */
10
- import React, { forwardRef, useRef, useEffect, useCallback, useContext, createContext, useState, } from "react";
11
- // Import shared RSC prefetch utilities from navigation shim (relative path
12
- // so this resolves both via the Vite plugin and in direct vitest imports)
13
- import { toRscUrl, getPrefetchedUrls, storePrefetchResponse } from "./navigation.js";
14
- import { isDangerousScheme } from "./url-safety.js";
15
- import { resolveRelativeHref, toBrowserNavigationHref, toSameOriginAppPath, withBasePath, } from "./url-utils.js";
2
+ import { resolveRelativeHref, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
3
+ import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
16
4
  import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
5
+ import { getPrefetchedUrls, storePrefetchResponse, toRscUrl } from "./navigation.js";
6
+ import { isDangerousScheme } from "./url-safety.js";
7
+ import { getI18nContext } from "./i18n-context.js";
8
+ import React, { createContext, forwardRef, useCallback, useContext, useEffect, useRef, useState } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ //#region src/shims/link.tsx
11
+ /**
12
+ * next/link shim
13
+ *
14
+ * Renders an <a> tag with client-side navigation support.
15
+ * On click, prevents full page reload and triggers client-side
16
+ * page swap via the router's navigation system.
17
+ */
17
18
  const LinkStatusContext = createContext({ pending: false });
18
19
  /**
19
- * useLinkStatus returns the pending state of the enclosing <Link>.
20
- * In Next.js, this is used to show loading indicators while a
21
- * prefetch-triggered navigation is in progress.
22
- */
23
- export function useLinkStatus() {
24
- return useContext(LinkStatusContext);
20
+ * useLinkStatus returns the pending state of the enclosing <Link>.
21
+ * In Next.js, this is used to show loading indicators while a
22
+ * prefetch-triggered navigation is in progress.
23
+ */
24
+ function useLinkStatus() {
25
+ return useContext(LinkStatusContext);
25
26
  }
26
27
  /** basePath from next.config.js, injected by the plugin at build time */
27
28
  const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
28
29
  function resolveHref(href) {
29
- if (typeof href === "string")
30
- return href;
31
- let url = href.pathname ?? "/";
32
- if (href.query) {
33
- const params = urlQueryToSearchParams(href.query);
34
- url = appendSearchParamsToUrl(url, params);
35
- }
36
- return url;
30
+ if (typeof href === "string") return href;
31
+ let url = href.pathname ?? "/";
32
+ if (href.query) {
33
+ const params = urlQueryToSearchParams(href.query);
34
+ url = appendSearchParamsToUrl(url, params);
35
+ }
36
+ return url;
37
37
  }
38
38
  /**
39
- * Check if a href is only a hash change (same pathname, different/added hash).
40
- * Handles relative hashes like "#foo" and "?query#foo".
41
- */
39
+ * Check if a href is only a hash change (same pathname, different/added hash).
40
+ * Handles relative hashes like "#foo" and "?query#foo".
41
+ */
42
42
  function isHashOnlyChange(href) {
43
- if (href.startsWith("#"))
44
- return true;
45
- try {
46
- const current = new URL(window.location.href);
47
- const next = new URL(href, window.location.href);
48
- return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
49
- }
50
- catch {
51
- return false;
52
- }
43
+ if (href.startsWith("#")) return true;
44
+ try {
45
+ const current = new URL(window.location.href);
46
+ const next = new URL(href, window.location.href);
47
+ return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
48
+ } catch {
49
+ return false;
50
+ }
53
51
  }
54
52
  /**
55
- * Scroll to a hash target element, or to the top if no hash.
56
- */
53
+ * Scroll to a hash target element, or to the top if no hash.
54
+ */
57
55
  function scrollToHash(hash) {
58
- if (!hash || hash === "#") {
59
- window.scrollTo(0, 0);
60
- return;
61
- }
62
- const id = hash.slice(1); // Remove leading #
63
- const element = document.getElementById(id);
64
- if (element) {
65
- element.scrollIntoView({ behavior: "auto" });
66
- }
56
+ if (!hash || hash === "#") {
57
+ window.scrollTo(0, 0);
58
+ return;
59
+ }
60
+ const id = hash.slice(1);
61
+ const element = document.getElementById(id);
62
+ if (element) element.scrollIntoView({ behavior: "auto" });
67
63
  }
68
- // ---------------------------------------------------------------------------
69
- // Prefetching infrastructure
70
- // ---------------------------------------------------------------------------
71
64
  /**
72
- * Prefetch a URL for faster navigation.
73
- *
74
- * For App Router (RSC): fetches the .rsc payload in the background and
75
- * stores it in an in-memory cache for instant use during navigation.
76
- * For Pages Router: injects a <link rel="prefetch"> for the page module.
77
- *
78
- * Uses `requestIdleCallback` (or `setTimeout` fallback) to avoid blocking
79
- * the main thread during initial page load.
80
- */
65
+ * Prefetch a URL for faster navigation.
66
+ *
67
+ * For App Router (RSC): fetches the .rsc payload in the background and
68
+ * stores it in an in-memory cache for instant use during navigation.
69
+ * For Pages Router: injects a <link rel="prefetch"> for the page module.
70
+ *
71
+ * Uses `requestIdleCallback` (or `setTimeout` fallback) to avoid blocking
72
+ * the main thread during initial page load.
73
+ */
81
74
  function prefetchUrl(href) {
82
- if (typeof window === "undefined")
83
- return;
84
- // Normalize same-origin absolute URLs to local paths before prefetching
85
- let prefetchHref = href;
86
- if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//")) {
87
- const localPath = toSameOriginAppPath(href, __basePath);
88
- if (localPath == null)
89
- return; // truly external don't prefetch
90
- prefetchHref = localPath;
91
- }
92
- const fullHref = toBrowserNavigationHref(prefetchHref, window.location.href, __basePath);
93
- // Don't prefetch the same URL twice (keyed by rscUrl so the browser
94
- // entry can clear the key when a cache entry is consumed)
95
- const rscUrl = toRscUrl(fullHref);
96
- const prefetched = getPrefetchedUrls();
97
- if (prefetched.has(rscUrl))
98
- return;
99
- prefetched.add(rscUrl);
100
- const schedule = window.requestIdleCallback ?? ((fn) => setTimeout(fn, 100));
101
- schedule(() => {
102
- if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") {
103
- // App Router: prefetch the RSC payload and store in cache
104
- fetch(rscUrl, {
105
- headers: { Accept: "text/x-component" },
106
- credentials: "include",
107
- priority: "low",
108
- // @ts-expect-error — purpose is a valid fetch option in some browsers
109
- purpose: "prefetch",
110
- })
111
- .then((response) => {
112
- if (response.ok) {
113
- storePrefetchResponse(rscUrl, response);
114
- }
115
- else {
116
- // Non-ok response: allow retry on next viewport intersection
117
- prefetched.delete(rscUrl);
118
- }
119
- })
120
- .catch(() => {
121
- // Network error: allow retry on next viewport intersection
122
- prefetched.delete(rscUrl);
123
- });
124
- }
125
- else if (window.__NEXT_DATA__?.__vinext?.pageModuleUrl) {
126
- // Pages Router: inject a prefetch link for the target page module
127
- // We can't easily resolve the target page's module URL from the Link,
128
- // so we create a <link rel="prefetch"> for the HTML page which helps
129
- // the browser's preload scanner.
130
- const link = document.createElement("link");
131
- link.rel = "prefetch";
132
- link.href = fullHref;
133
- link.as = "document";
134
- document.head.appendChild(link);
135
- }
136
- });
75
+ if (typeof window === "undefined") return;
76
+ let prefetchHref = href;
77
+ if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//")) {
78
+ const localPath = toSameOriginAppPath(href, __basePath);
79
+ if (localPath == null) return;
80
+ prefetchHref = localPath;
81
+ }
82
+ const fullHref = toBrowserNavigationHref(prefetchHref, window.location.href, __basePath);
83
+ const rscUrl = toRscUrl(fullHref);
84
+ const prefetched = getPrefetchedUrls();
85
+ if (prefetched.has(rscUrl)) return;
86
+ prefetched.add(rscUrl);
87
+ (window.requestIdleCallback ?? ((fn) => setTimeout(fn, 100)))(() => {
88
+ if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") fetch(rscUrl, {
89
+ headers: { Accept: "text/x-component" },
90
+ credentials: "include",
91
+ priority: "low",
92
+ purpose: "prefetch"
93
+ }).then((response) => {
94
+ if (response.ok) storePrefetchResponse(rscUrl, response);
95
+ else prefetched.delete(rscUrl);
96
+ }).catch(() => {
97
+ prefetched.delete(rscUrl);
98
+ });
99
+ else if (window.__NEXT_DATA__?.__vinext?.pageModuleUrl) {
100
+ const link = document.createElement("link");
101
+ link.rel = "prefetch";
102
+ link.href = fullHref;
103
+ link.as = "document";
104
+ document.head.appendChild(link);
105
+ }
106
+ });
137
107
  }
138
108
  /**
139
- * Shared IntersectionObserver for viewport-based prefetching.
140
- * All Link elements use the same observer to minimize resource usage.
141
- */
109
+ * Shared IntersectionObserver for viewport-based prefetching.
110
+ * All Link elements use the same observer to minimize resource usage.
111
+ */
142
112
  let sharedObserver = null;
143
- const observerCallbacks = new WeakMap();
113
+ const observerCallbacks = /* @__PURE__ */ new WeakMap();
144
114
  function getSharedObserver() {
145
- if (typeof window === "undefined" || typeof IntersectionObserver === "undefined")
146
- return null;
147
- if (sharedObserver)
148
- return sharedObserver;
149
- sharedObserver = new IntersectionObserver((entries) => {
150
- for (const entry of entries) {
151
- if (entry.isIntersecting) {
152
- const callback = observerCallbacks.get(entry.target);
153
- if (callback) {
154
- callback();
155
- // Unobserve after prefetching — only prefetch once
156
- sharedObserver?.unobserve(entry.target);
157
- observerCallbacks.delete(entry.target);
158
- }
159
- }
160
- }
161
- }, {
162
- // Start prefetching when the link is within 250px of the viewport.
163
- // This gives the browser a head start before the user scrolls to it.
164
- rootMargin: "250px",
165
- });
166
- return sharedObserver;
115
+ if (typeof window === "undefined" || typeof IntersectionObserver === "undefined") return null;
116
+ if (sharedObserver) return sharedObserver;
117
+ sharedObserver = new IntersectionObserver((entries) => {
118
+ for (const entry of entries) if (entry.isIntersecting) {
119
+ const callback = observerCallbacks.get(entry.target);
120
+ if (callback) {
121
+ callback();
122
+ sharedObserver?.unobserve(entry.target);
123
+ observerCallbacks.delete(entry.target);
124
+ }
125
+ }
126
+ }, { rootMargin: "250px" });
127
+ return sharedObserver;
167
128
  }
168
129
  function getDefaultLocale() {
169
- if (typeof window !== "undefined") {
170
- return window.__VINEXT_DEFAULT_LOCALE__;
171
- }
172
- return globalThis.__VINEXT_DEFAULT_LOCALE__;
130
+ if (typeof window !== "undefined") return window.__VINEXT_DEFAULT_LOCALE__;
131
+ return getI18nContext()?.defaultLocale;
132
+ }
133
+ function getDomainLocales() {
134
+ if (typeof window !== "undefined") return window.__NEXT_DATA__?.domainLocales;
135
+ return getI18nContext()?.domainLocales;
136
+ }
137
+ function getCurrentHostname() {
138
+ if (typeof window !== "undefined") return window.location.hostname;
139
+ return getI18nContext()?.hostname;
140
+ }
141
+ function getDomainLocaleHref(href, locale) {
142
+ return getDomainLocaleUrl(href, locale, {
143
+ basePath: __basePath,
144
+ currentHostname: getCurrentHostname(),
145
+ domainItems: getDomainLocales()
146
+ });
173
147
  }
174
148
  /**
175
- * Apply locale prefix to a URL path based on the locale prop.
176
- * - locale="fr" → prepend /fr (unless it already has a locale prefix)
177
- * - locale={false} → use the href as-is (no locale prefix, link to default)
178
- * - locale=undefined → use current locale (href as-is in most cases)
179
- */
149
+ * Apply locale prefix to a URL path based on the locale prop.
150
+ * - locale="fr" → prepend /fr (unless it already has a locale prefix)
151
+ * - locale={false} → use the href as-is (no locale prefix, link to default)
152
+ * - locale=undefined → use current locale (href as-is in most cases)
153
+ */
180
154
  function applyLocaleToHref(href, locale) {
181
- if (locale === false) {
182
- // Explicit false: no locale prefix
183
- return href;
184
- }
185
- if (locale === undefined) {
186
- // No locale prop: keep current behavior (href as-is)
187
- return href;
188
- }
189
- // Absolute and protocol-relative URLs must not be prefixed — locale
190
- // only applies to local paths.
191
- if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//")) {
192
- return href;
193
- }
194
- // locale is a string: prepend the locale prefix if not already present
195
- const defaultLocale = getDefaultLocale();
196
- // For the default locale, Next.js doesn't add a prefix
197
- if (locale === defaultLocale) {
198
- return href;
199
- }
200
- // Check if href already starts with the locale
201
- if (href.startsWith(`/${locale}/`) || href === `/${locale}`) {
202
- return href;
203
- }
204
- return `/${locale}${href.startsWith("/") ? href : `/${href}`}`;
155
+ if (locale === false) return href;
156
+ if (locale === void 0) return href;
157
+ if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//")) return href;
158
+ const domainLocaleHref = getDomainLocaleHref(href, locale);
159
+ if (domainLocaleHref) return domainLocaleHref;
160
+ return addLocalePrefix(href, locale, getDefaultLocale() ?? "");
205
161
  }
206
162
  const Link = forwardRef(function Link({ href, as, replace = false, prefetch: prefetchProp, scroll = true, children, onClick, onNavigate, ...rest }, forwardedRef) {
207
- // Extract locale from rest props
208
- const { locale, ...restWithoutLocale } = rest;
209
- // If `as` is provided, use it as the actual URL (legacy Next.js pattern
210
- // where href is a route pattern like "/user/[id]" and as is "/user/1")
211
- const resolvedHref = as ?? resolveHref(href);
212
- const isDangerous = typeof resolvedHref === "string" && isDangerousScheme(resolvedHref);
213
- // Apply locale prefix if specified (safe even for dangerous hrefs since we
214
- // won't use the result when isDangerous is true)
215
- const localizedHref = applyLocaleToHref(isDangerous ? "/" : resolvedHref, locale);
216
- // Full href with basePath for browser URLs and fetches
217
- const fullHref = withBasePath(localizedHref, __basePath);
218
- // Track pending state for useLinkStatus()
219
- const [pending, setPending] = useState(false);
220
- const mountedRef = useRef(true);
221
- useEffect(() => {
222
- mountedRef.current = true;
223
- return () => {
224
- mountedRef.current = false;
225
- };
226
- }, []);
227
- // Prefetching: observe the element when it enters the viewport.
228
- // prefetch={false} disables, prefetch={true} or undefined/null (default) enables.
229
- const internalRef = useRef(null);
230
- const shouldPrefetch = prefetchProp !== false && !isDangerous;
231
- const setRefs = useCallback((node) => {
232
- internalRef.current = node;
233
- if (typeof forwardedRef === "function")
234
- forwardedRef(node);
235
- else if (forwardedRef)
236
- forwardedRef.current = node;
237
- }, [forwardedRef]);
238
- useEffect(() => {
239
- if (!shouldPrefetch || typeof window === "undefined")
240
- return;
241
- const node = internalRef.current;
242
- if (!node)
243
- return;
244
- // Normalize same-origin absolute URLs; skip truly external ones
245
- let hrefToPrefetch = localizedHref;
246
- if (localizedHref.startsWith("http://") ||
247
- localizedHref.startsWith("https://") ||
248
- localizedHref.startsWith("//")) {
249
- const localPath = toSameOriginAppPath(localizedHref, __basePath);
250
- if (localPath == null)
251
- return; // truly external
252
- hrefToPrefetch = localPath;
253
- }
254
- const observer = getSharedObserver();
255
- if (!observer)
256
- return;
257
- observerCallbacks.set(node, () => prefetchUrl(hrefToPrefetch));
258
- observer.observe(node);
259
- return () => {
260
- observer.unobserve(node);
261
- observerCallbacks.delete(node);
262
- };
263
- }, [shouldPrefetch, localizedHref]);
264
- const handleClick = async (e) => {
265
- if (onClick)
266
- onClick(e);
267
- if (e.defaultPrevented)
268
- return;
269
- // Only intercept left clicks without modifiers (standard link behavior)
270
- if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
271
- return;
272
- }
273
- // Don't intercept links with target (e.g. target="_blank")
274
- if (e.currentTarget.target && e.currentTarget.target !== "_self") {
275
- return;
276
- }
277
- // External links: let the browser handle it.
278
- // Same-origin absolute URLs (e.g. http://localhost:3000/about) are
279
- // normalized to local paths so they get client-side navigation.
280
- let navigateHref = localizedHref;
281
- if (resolvedHref.startsWith("http://") ||
282
- resolvedHref.startsWith("https://") ||
283
- resolvedHref.startsWith("//")) {
284
- const localPath = toSameOriginAppPath(resolvedHref, __basePath);
285
- if (localPath == null)
286
- return; // truly external
287
- navigateHref = localPath;
288
- }
289
- e.preventDefault();
290
- // Resolve relative hrefs (#hash, ?query) against the current URL once so
291
- // onNavigate and the actual navigation target stay in sync.
292
- const absoluteHref = resolveRelativeHref(navigateHref, window.location.href, __basePath);
293
- const absoluteFullHref = toBrowserNavigationHref(navigateHref, window.location.href, __basePath);
294
- // Call onNavigate callback if provided (Next.js 16 View Transitions support)
295
- if (onNavigate) {
296
- try {
297
- const navUrl = new URL(absoluteFullHref, window.location.origin);
298
- let prevented = false;
299
- const navEvent = {
300
- url: navUrl,
301
- preventDefault() {
302
- prevented = true;
303
- },
304
- get defaultPrevented() {
305
- return prevented;
306
- },
307
- };
308
- onNavigate(navEvent);
309
- // If the callback called preventDefault(), skip Link's default navigation.
310
- // The callback is responsible for its own navigation (e.g. via View Transitions API).
311
- if (navEvent.defaultPrevented) {
312
- return;
313
- }
314
- }
315
- catch {
316
- // Ignore URL parsing errors for relative/hash hrefs
317
- }
318
- }
319
- // Save scroll position for back/forward restoration
320
- if (!replace) {
321
- const state = window.history.state ?? {};
322
- window.history.replaceState({ ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY }, "");
323
- }
324
- // Hash-only change: update URL and scroll to target, skip RSC fetch
325
- if (typeof window !== "undefined" && isHashOnlyChange(absoluteFullHref)) {
326
- const hash = absoluteFullHref.includes("#")
327
- ? absoluteFullHref.slice(absoluteFullHref.indexOf("#"))
328
- : "";
329
- if (replace) {
330
- window.history.replaceState(null, "", absoluteFullHref);
331
- }
332
- else {
333
- window.history.pushState(null, "", absoluteFullHref);
334
- }
335
- if (scroll) {
336
- scrollToHash(hash);
337
- }
338
- return;
339
- }
340
- // Extract hash for scroll-after-navigation
341
- const hashIdx = absoluteFullHref.indexOf("#");
342
- const hash = hashIdx !== -1 ? absoluteFullHref.slice(hashIdx) : "";
343
- // Try RSC navigation first (App Router), then Pages Router
344
- if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") {
345
- // App Router: push/replace history state, then fetch RSC stream.
346
- // Await the RSC navigate so scroll-to-top happens after the new
347
- // content is committed to the DOM (prevents flash of old page at top).
348
- if (replace) {
349
- window.history.replaceState(null, "", absoluteFullHref);
350
- }
351
- else {
352
- window.history.pushState(null, "", absoluteFullHref);
353
- }
354
- setPending(true);
355
- try {
356
- await window.__VINEXT_RSC_NAVIGATE__(absoluteFullHref);
357
- }
358
- finally {
359
- if (mountedRef.current)
360
- setPending(false);
361
- }
362
- }
363
- else {
364
- // Pages Router: use the Router singleton
365
- try {
366
- const routerModule = await import("next/router");
367
- // eslint-disable-next-line -- vinext's Router shim accepts (url, as, options)
368
- const Router = routerModule.default;
369
- if (replace) {
370
- await Router.replace(absoluteHref, undefined, { scroll });
371
- }
372
- else {
373
- await Router.push(absoluteHref, undefined, { scroll });
374
- }
375
- }
376
- catch {
377
- // Fallback to hard navigation if router fails
378
- if (replace) {
379
- window.history.replaceState({}, "", absoluteFullHref);
380
- }
381
- else {
382
- window.history.pushState({}, "", absoluteFullHref);
383
- }
384
- window.dispatchEvent(new PopStateEvent("popstate"));
385
- }
386
- }
387
- if (scroll) {
388
- if (hash) {
389
- scrollToHash(hash);
390
- }
391
- else {
392
- window.scrollTo(0, 0);
393
- }
394
- }
395
- };
396
- // Remove props that shouldn't be on <a>
397
- const { passHref: _p, ...anchorProps } = restWithoutLocale;
398
- const linkStatusValue = React.useMemo(() => ({ pending }), [pending]);
399
- // Block dangerous URI schemes (javascript:, data:, vbscript:).
400
- // Render an inert <a> without href to prevent XSS while preserving
401
- // styling and attributes like className, id, aria-*.
402
- // This check is placed after all hooks to satisfy the Rules of Hooks.
403
- if (isDangerous) {
404
- if (process.env.NODE_ENV !== "production") {
405
- console.warn(`<Link> blocked dangerous href: ${resolvedHref}`);
406
- }
407
- return _jsx("a", { ...anchorProps, children: children });
408
- }
409
- return (_jsx(LinkStatusContext.Provider, { value: linkStatusValue, children: _jsx("a", { ref: setRefs, href: fullHref, onClick: handleClick, ...anchorProps, children: children }) }));
163
+ const { locale, ...restWithoutLocale } = rest;
164
+ const resolvedHref = as ?? resolveHref(href);
165
+ const isDangerous = typeof resolvedHref === "string" && isDangerousScheme(resolvedHref);
166
+ const localizedHref = applyLocaleToHref(isDangerous ? "/" : resolvedHref, locale);
167
+ const fullHref = withBasePath(localizedHref, __basePath);
168
+ const [pending, setPending] = useState(false);
169
+ const mountedRef = useRef(true);
170
+ useEffect(() => {
171
+ mountedRef.current = true;
172
+ return () => {
173
+ mountedRef.current = false;
174
+ };
175
+ }, []);
176
+ const internalRef = useRef(null);
177
+ const shouldPrefetch = prefetchProp !== false && !isDangerous;
178
+ const setRefs = useCallback((node) => {
179
+ internalRef.current = node;
180
+ if (typeof forwardedRef === "function") forwardedRef(node);
181
+ else if (forwardedRef) forwardedRef.current = node;
182
+ }, [forwardedRef]);
183
+ useEffect(() => {
184
+ if (!shouldPrefetch || typeof window === "undefined") return;
185
+ const node = internalRef.current;
186
+ if (!node) return;
187
+ let hrefToPrefetch = localizedHref;
188
+ if (localizedHref.startsWith("http://") || localizedHref.startsWith("https://") || localizedHref.startsWith("//")) {
189
+ const localPath = toSameOriginAppPath(localizedHref, __basePath);
190
+ if (localPath == null) return;
191
+ hrefToPrefetch = localPath;
192
+ }
193
+ const observer = getSharedObserver();
194
+ if (!observer) return;
195
+ observerCallbacks.set(node, () => prefetchUrl(hrefToPrefetch));
196
+ observer.observe(node);
197
+ return () => {
198
+ observer.unobserve(node);
199
+ observerCallbacks.delete(node);
200
+ };
201
+ }, [shouldPrefetch, localizedHref]);
202
+ const handleClick = async (e) => {
203
+ if (onClick) onClick(e);
204
+ if (e.defaultPrevented) return;
205
+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
206
+ if (e.currentTarget.target && e.currentTarget.target !== "_self") return;
207
+ let navigateHref = localizedHref;
208
+ if (resolvedHref.startsWith("http://") || resolvedHref.startsWith("https://") || resolvedHref.startsWith("//")) {
209
+ const localPath = toSameOriginAppPath(resolvedHref, __basePath);
210
+ if (localPath == null) return;
211
+ navigateHref = localPath;
212
+ }
213
+ e.preventDefault();
214
+ const absoluteHref = resolveRelativeHref(navigateHref, window.location.href, __basePath);
215
+ const absoluteFullHref = toBrowserNavigationHref(navigateHref, window.location.href, __basePath);
216
+ if (onNavigate) try {
217
+ const navUrl = new URL(absoluteFullHref, window.location.origin);
218
+ let prevented = false;
219
+ const navEvent = {
220
+ url: navUrl,
221
+ preventDefault() {
222
+ prevented = true;
223
+ },
224
+ get defaultPrevented() {
225
+ return prevented;
226
+ }
227
+ };
228
+ onNavigate(navEvent);
229
+ if (navEvent.defaultPrevented) return;
230
+ } catch {}
231
+ if (!replace) {
232
+ const state = window.history.state ?? {};
233
+ window.history.replaceState({
234
+ ...state,
235
+ __vinext_scrollX: window.scrollX,
236
+ __vinext_scrollY: window.scrollY
237
+ }, "");
238
+ }
239
+ if (typeof window !== "undefined" && isHashOnlyChange(absoluteFullHref)) {
240
+ const hash = absoluteFullHref.includes("#") ? absoluteFullHref.slice(absoluteFullHref.indexOf("#")) : "";
241
+ if (replace) window.history.replaceState(null, "", absoluteFullHref);
242
+ else window.history.pushState(null, "", absoluteFullHref);
243
+ if (scroll) scrollToHash(hash);
244
+ return;
245
+ }
246
+ const hashIdx = absoluteFullHref.indexOf("#");
247
+ const hash = hashIdx !== -1 ? absoluteFullHref.slice(hashIdx) : "";
248
+ if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") {
249
+ if (replace) window.history.replaceState(null, "", absoluteFullHref);
250
+ else window.history.pushState(null, "", absoluteFullHref);
251
+ setPending(true);
252
+ try {
253
+ await window.__VINEXT_RSC_NAVIGATE__(absoluteFullHref);
254
+ } finally {
255
+ if (mountedRef.current) setPending(false);
256
+ }
257
+ } else try {
258
+ const Router = (await import("next/router")).default;
259
+ if (replace) await Router.replace(absoluteHref, void 0, { scroll });
260
+ else await Router.push(absoluteHref, void 0, { scroll });
261
+ } catch {
262
+ if (replace) window.history.replaceState({}, "", absoluteFullHref);
263
+ else window.history.pushState({}, "", absoluteFullHref);
264
+ window.dispatchEvent(new PopStateEvent("popstate"));
265
+ }
266
+ if (scroll) if (hash) scrollToHash(hash);
267
+ else window.scrollTo(0, 0);
268
+ };
269
+ const { passHref: _p, ...anchorProps } = restWithoutLocale;
270
+ const linkStatusValue = React.useMemo(() => ({ pending }), [pending]);
271
+ if (isDangerous) {
272
+ if (process.env.NODE_ENV !== "production") console.warn(`<Link> blocked dangerous href: ${resolvedHref}`);
273
+ return /* @__PURE__ */ jsx("a", {
274
+ ...anchorProps,
275
+ children
276
+ });
277
+ }
278
+ return /* @__PURE__ */ jsx(LinkStatusContext.Provider, {
279
+ value: linkStatusValue,
280
+ children: /* @__PURE__ */ jsx("a", {
281
+ ref: setRefs,
282
+ href: fullHref,
283
+ onClick: handleClick,
284
+ ...anchorProps,
285
+ children
286
+ })
287
+ });
410
288
  });
411
- export default Link;
289
+ //#endregion
290
+ export { Link as default, useLinkStatus };
291
+
412
292
  //# sourceMappingURL=link.js.map