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