vinext 0.0.30 → 0.0.32

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 +15 -7
  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 +581 -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 +681 -571
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +432 -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 +376 -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 +444 -212
  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 +86 -114
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +92 -60
  70. package/dist/index.js +2151 -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 +160 -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 +19 -15
  112. package/dist/server/dev-server.js +543 -871
  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 +34 -59
  121. package/dist/server/instrumentation.js +112 -125
  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 +32 -47
  136. package/dist/server/middleware.js +261 -409
  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 +715 -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 +6 -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 +439 -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 +17 -20
  211. package/dist/shims/head.js +194 -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 +7 -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 +213 -164
  287. package/dist/shims/server.js +545 -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,764 +1,565 @@
1
- /**
2
- * next/navigation shim
3
- *
4
- * App Router navigation hooks. These work on both server (RSC) and client.
5
- * Server-side: reads from a request context set by the RSC handler.
6
- * Client-side: reads from browser Location API and provides navigation.
7
- */
8
- // Use namespace import for RSC safety: the react-server condition doesn't export
9
- // createContext/useContext/useSyncExternalStore as named exports, and strict ESM
10
- // would throw at link time for missing bindings. With `import * as React`, the
11
- // bindings are just `undefined` on the namespace object and we can guard at runtime.
12
- import * as React from "react";
13
- import { toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
14
1
  import { stripBasePath } from "../utils/base-path.js";
2
+ import { toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
15
3
  import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
16
- // ─── Layout segment context ───────────────────────────────────────────────────
17
- // Stores the child segments below the current layout. Each layout wraps its
18
- // children with a provider whose value is the remaining route tree segments
19
- // (including route groups, with dynamic params resolved to actual values).
20
- // Created lazily because `React.createContext` is NOT available in the
21
- // react-server condition of React. In the RSC environment, this remains null.
22
- // The shared context lives behind a global singleton so provider/hook pairs
23
- // still line up if Vite loads this shim through multiple resolved module IDs.
4
+ import * as React$1 from "react";
5
+ //#region src/shims/navigation.ts
6
+ /**
7
+ * next/navigation shim
8
+ *
9
+ * App Router navigation hooks. These work on both server (RSC) and client.
10
+ * Server-side: reads from a request context set by the RSC handler.
11
+ * Client-side: reads from browser Location API and provides navigation.
12
+ */
24
13
  const _LAYOUT_SEGMENT_CTX_KEY = Symbol.for("vinext.layoutSegmentContext");
25
14
  const _SERVER_INSERTED_HTML_CTX_KEY = Symbol.for("vinext.serverInsertedHTMLContext");
26
- // ─── ServerInsertedHTML context ────────────────────────────────────────────────
27
- // Used by CSS-in-JS libraries (Apollo Client, styled-components, emotion) to
28
- // register HTML injection callbacks during SSR via useContext().
29
- // The SSR entry wraps the rendered tree with a Provider whose value is a
30
- // callback registration function (useServerInsertedHTML).
31
- //
32
- // In Next.js, ServerInsertedHTMLContext holds a function:
33
- // (callback: () => React.ReactNode) => void
34
- // Libraries call useContext(ServerInsertedHTMLContext) to get this function,
35
- // then call it to register callbacks that inject HTML during SSR.
36
- //
37
- // Created eagerly at module load time. In the RSC environment (react-server
38
- // condition), createContext isn't available so this will be null.
39
15
  function getServerInsertedHTMLContext() {
40
- if (typeof React.createContext !== "function")
41
- return null;
42
- const globalState = globalThis;
43
- if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) {
44
- globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React.createContext(null);
45
- }
46
- return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;
47
- }
48
- export const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
49
- /**
50
- * Get or create the layout segment context.
51
- * Returns null in the RSC environment (createContext unavailable).
52
- */
53
- export function getLayoutSegmentContext() {
54
- if (typeof React.createContext !== "function")
55
- return null;
56
- const globalState = globalThis;
57
- if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) {
58
- globalState[_LAYOUT_SEGMENT_CTX_KEY] = React.createContext([]);
59
- }
60
- return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;
61
- }
62
- /**
63
- * Read the child segments below the current layout from context.
64
- * Returns [] if no context is available (RSC environment, outside React tree).
65
- */
16
+ if (typeof React$1.createContext !== "function") return null;
17
+ const globalState = globalThis;
18
+ if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React$1.createContext(null);
19
+ return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;
20
+ }
21
+ const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
22
+ /**
23
+ * Get or create the layout segment context.
24
+ * Returns null in the RSC environment (createContext unavailable).
25
+ */
26
+ function getLayoutSegmentContext() {
27
+ if (typeof React$1.createContext !== "function") return null;
28
+ const globalState = globalThis;
29
+ if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) globalState[_LAYOUT_SEGMENT_CTX_KEY] = React$1.createContext([]);
30
+ return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;
31
+ }
32
+ /**
33
+ * Read the child segments below the current layout from context.
34
+ * Returns [] if no context is available (RSC environment, outside React tree).
35
+ */
66
36
  function useChildSegments() {
67
- const ctx = getLayoutSegmentContext();
68
- if (!ctx)
69
- return [];
70
- // useContext is safe here because if createContext exists, useContext does too.
71
- // This branch is only taken in SSR/Browser, never in RSC.
72
- // Try/catch for unit tests that call this hook outside a React render tree.
73
- try {
74
- return React.useContext(ctx);
75
- }
76
- catch {
77
- return [];
78
- }
37
+ const ctx = getLayoutSegmentContext();
38
+ if (!ctx) return [];
39
+ try {
40
+ return React$1.useContext(ctx);
41
+ } catch {
42
+ return [];
43
+ }
79
44
  }
80
45
  const _READONLY_SEARCH_PARAMS = Symbol("vinext.navigation.readonlySearchParams");
81
46
  const _READONLY_SEARCH_PARAMS_SOURCE = Symbol("vinext.navigation.readonlySearchParamsSource");
82
- // ---------------------------------------------------------------------------
83
- // Server-side navigation state lives in a separate server-only module
84
- // (navigation-state.ts) that uses AsyncLocalStorage for request isolation.
85
- // This module is bundled for the browser, so it can't import node:async_hooks.
86
- //
87
- // On the server: state functions are set by navigation-state.ts at import time.
88
- // On the client: _serverContext falls back to null (hooks use window instead).
89
- // ---------------------------------------------------------------------------
90
47
  let _serverContext = null;
91
48
  let _serverInsertedHTMLCallbacks = [];
92
- // These are overridden by navigation-state.ts on the server to use ALS.
93
49
  let _getServerContext = () => _serverContext;
94
50
  let _setServerContext = (ctx) => {
95
- _serverContext = ctx;
51
+ _serverContext = ctx;
96
52
  };
97
53
  let _getInsertedHTMLCallbacks = () => _serverInsertedHTMLCallbacks;
98
54
  let _clearInsertedHTMLCallbacks = () => {
99
- _serverInsertedHTMLCallbacks = [];
55
+ _serverInsertedHTMLCallbacks = [];
100
56
  };
101
57
  /**
102
- * Register ALS-backed state accessors. Called by navigation-state.ts on import.
103
- * @internal
104
- */
105
- export function _registerStateAccessors(accessors) {
106
- _getServerContext = accessors.getServerContext;
107
- _setServerContext = accessors.setServerContext;
108
- _getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
109
- _clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
110
- }
111
- /**
112
- * Get the navigation context for the current SSR/RSC render.
113
- * Reads from AsyncLocalStorage when available (concurrent-safe),
114
- * otherwise falls back to module-level state.
115
- */
116
- export function getNavigationContext() {
117
- return _getServerContext();
118
- }
119
- /**
120
- * Set the navigation context for the current SSR/RSC render.
121
- * Called by the framework entry before rendering each request.
122
- */
123
- export function setNavigationContext(ctx) {
124
- _setServerContext(ctx);
125
- }
126
- // ---------------------------------------------------------------------------
127
- // Client-side state
128
- // ---------------------------------------------------------------------------
58
+ * Register ALS-backed state accessors. Called by navigation-state.ts on import.
59
+ * @internal
60
+ */
61
+ function _registerStateAccessors(accessors) {
62
+ _getServerContext = accessors.getServerContext;
63
+ _setServerContext = accessors.setServerContext;
64
+ _getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
65
+ _clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
66
+ }
67
+ /**
68
+ * Get the navigation context for the current SSR/RSC render.
69
+ * Reads from AsyncLocalStorage when available (concurrent-safe),
70
+ * otherwise falls back to module-level state.
71
+ */
72
+ function getNavigationContext() {
73
+ return _getServerContext();
74
+ }
75
+ /**
76
+ * Set the navigation context for the current SSR/RSC render.
77
+ * Called by the framework entry before rendering each request.
78
+ */
79
+ function setNavigationContext(ctx) {
80
+ _setServerContext(ctx);
81
+ }
129
82
  const isServer = typeof window === "undefined";
130
83
  /** basePath from next.config.js, injected by the plugin at build time */
131
84
  const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
132
- // ---------------------------------------------------------------------------
133
- // RSC prefetch cache utilities (shared between link.tsx and browser entry)
134
- // ---------------------------------------------------------------------------
135
85
  /** Maximum number of entries in the RSC prefetch cache. */
136
- export const MAX_PREFETCH_CACHE_SIZE = 50;
86
+ const MAX_PREFETCH_CACHE_SIZE = 50;
137
87
  /** TTL for prefetch cache entries in ms (matches Next.js static prefetch TTL). */
138
- export const PREFETCH_CACHE_TTL = 30_000;
139
- /**
140
- * Convert a pathname (with optional query/hash) to its .rsc URL.
141
- * Strips trailing slashes before appending `.rsc` so that cache keys
142
- * are consistent regardless of the `trailingSlash` config setting.
143
- */
144
- export function toRscUrl(href) {
145
- const [beforeHash] = href.split("#");
146
- const qIdx = beforeHash.indexOf("?");
147
- const pathname = qIdx === -1 ? beforeHash : beforeHash.slice(0, qIdx);
148
- const query = qIdx === -1 ? "" : beforeHash.slice(qIdx);
149
- // Strip trailing slash (but preserve "/" root) for consistent cache keys
150
- const normalizedPath = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
151
- return normalizedPath + ".rsc" + query;
88
+ const PREFETCH_CACHE_TTL = 3e4;
89
+ /**
90
+ * Convert a pathname (with optional query/hash) to its .rsc URL.
91
+ * Strips trailing slashes before appending `.rsc` so that cache keys
92
+ * are consistent regardless of the `trailingSlash` config setting.
93
+ */
94
+ function toRscUrl(href) {
95
+ const [beforeHash] = href.split("#");
96
+ const qIdx = beforeHash.indexOf("?");
97
+ const pathname = qIdx === -1 ? beforeHash : beforeHash.slice(0, qIdx);
98
+ const query = qIdx === -1 ? "" : beforeHash.slice(qIdx);
99
+ return (pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname) + ".rsc" + query;
152
100
  }
153
101
  /** Get or create the shared in-memory RSC prefetch cache on window. */
154
- export function getPrefetchCache() {
155
- if (isServer)
156
- return new Map();
157
- if (!window.__VINEXT_RSC_PREFETCH_CACHE__) {
158
- window.__VINEXT_RSC_PREFETCH_CACHE__ = new Map();
159
- }
160
- return window.__VINEXT_RSC_PREFETCH_CACHE__;
161
- }
162
- /**
163
- * Get or create the shared set of already-prefetched RSC URLs on window.
164
- * Keyed by rscUrl so that the browser entry can clear entries when consumed.
165
- */
166
- export function getPrefetchedUrls() {
167
- if (isServer)
168
- return new Set();
169
- if (!window.__VINEXT_RSC_PREFETCHED_URLS__) {
170
- window.__VINEXT_RSC_PREFETCHED_URLS__ = new Set();
171
- }
172
- return window.__VINEXT_RSC_PREFETCHED_URLS__;
173
- }
174
- /**
175
- * Store a prefetched RSC response in the cache.
176
- * Enforces a maximum cache size to prevent unbounded memory growth on
177
- * link-heavy pages.
178
- */
179
- export function storePrefetchResponse(rscUrl, response) {
180
- const cache = getPrefetchCache();
181
- const now = Date.now();
182
- // Sweep expired entries before resorting to FIFO eviction
183
- if (cache.size >= MAX_PREFETCH_CACHE_SIZE) {
184
- const prefetched = getPrefetchedUrls();
185
- for (const [key, entry] of cache) {
186
- if (now - entry.timestamp >= PREFETCH_CACHE_TTL) {
187
- cache.delete(key);
188
- prefetched.delete(key);
189
- }
190
- }
191
- }
192
- // FIFO fallback if still at capacity after sweep
193
- if (cache.size >= MAX_PREFETCH_CACHE_SIZE) {
194
- const oldest = cache.keys().next().value;
195
- if (oldest !== undefined) {
196
- cache.delete(oldest);
197
- getPrefetchedUrls().delete(oldest);
198
- }
199
- }
200
- cache.set(rscUrl, { response, timestamp: now });
201
- }
202
- const _listeners = new Set();
102
+ function getPrefetchCache() {
103
+ if (isServer) return /* @__PURE__ */ new Map();
104
+ if (!window.__VINEXT_RSC_PREFETCH_CACHE__) window.__VINEXT_RSC_PREFETCH_CACHE__ = /* @__PURE__ */ new Map();
105
+ return window.__VINEXT_RSC_PREFETCH_CACHE__;
106
+ }
107
+ /**
108
+ * Get or create the shared set of already-prefetched RSC URLs on window.
109
+ * Keyed by rscUrl so that the browser entry can clear entries when consumed.
110
+ */
111
+ function getPrefetchedUrls() {
112
+ if (isServer) return /* @__PURE__ */ new Set();
113
+ if (!window.__VINEXT_RSC_PREFETCHED_URLS__) window.__VINEXT_RSC_PREFETCHED_URLS__ = /* @__PURE__ */ new Set();
114
+ return window.__VINEXT_RSC_PREFETCHED_URLS__;
115
+ }
116
+ /**
117
+ * Store a prefetched RSC response in the cache.
118
+ * Enforces a maximum cache size to prevent unbounded memory growth on
119
+ * link-heavy pages.
120
+ */
121
+ function storePrefetchResponse(rscUrl, response) {
122
+ const cache = getPrefetchCache();
123
+ const now = Date.now();
124
+ if (cache.size >= 50) {
125
+ const prefetched = getPrefetchedUrls();
126
+ for (const [key, entry] of cache) if (now - entry.timestamp >= 3e4) {
127
+ cache.delete(key);
128
+ prefetched.delete(key);
129
+ }
130
+ }
131
+ if (cache.size >= 50) {
132
+ const oldest = cache.keys().next().value;
133
+ if (oldest !== void 0) {
134
+ cache.delete(oldest);
135
+ getPrefetchedUrls().delete(oldest);
136
+ }
137
+ }
138
+ cache.set(rscUrl, {
139
+ response,
140
+ timestamp: now
141
+ });
142
+ }
143
+ const _listeners = /* @__PURE__ */ new Set();
203
144
  function notifyListeners() {
204
- for (const fn of _listeners)
205
- fn();
145
+ for (const fn of _listeners) fn();
206
146
  }
207
- // Cached URLSearchParams, pathname, etc. for referential stability
208
- // useSyncExternalStore compares snapshots with Object.is — avoid creating
209
- // new instances on every render (infinite re-renders).
210
147
  let _cachedSearch = !isServer ? window.location.search : "";
211
148
  let _cachedReadonlySearchParams = new ReadonlyURLSearchParams(_cachedSearch);
212
149
  let _cachedEmptyServerSearchParams = null;
213
150
  let _cachedPathname = !isServer ? stripBasePath(window.location.pathname, __basePath) : "/";
214
151
  function getPathnameSnapshot() {
215
- const current = stripBasePath(window.location.pathname, __basePath);
216
- if (current !== _cachedPathname) {
217
- _cachedPathname = current;
218
- }
219
- return _cachedPathname;
152
+ const current = stripBasePath(window.location.pathname, __basePath);
153
+ if (current !== _cachedPathname) _cachedPathname = current;
154
+ return _cachedPathname;
220
155
  }
221
156
  function getSearchParamsSnapshot() {
222
- const current = window.location.search;
223
- if (current !== _cachedSearch) {
224
- _cachedSearch = current;
225
- _cachedReadonlySearchParams = new ReadonlyURLSearchParams(current);
226
- }
227
- return _cachedReadonlySearchParams;
157
+ const current = window.location.search;
158
+ if (current !== _cachedSearch) {
159
+ _cachedSearch = current;
160
+ _cachedReadonlySearchParams = new ReadonlyURLSearchParams(current);
161
+ }
162
+ return _cachedReadonlySearchParams;
228
163
  }
229
164
  function getServerSearchParamsSnapshot() {
230
- const ctx = _getServerContext();
231
- if (ctx != null) {
232
- const searchParams = ctx.searchParams;
233
- if (ctx[_READONLY_SEARCH_PARAMS_SOURCE] !== searchParams) {
234
- ctx[_READONLY_SEARCH_PARAMS_SOURCE] = searchParams;
235
- ctx[_READONLY_SEARCH_PARAMS] = new ReadonlyURLSearchParams(searchParams);
236
- }
237
- return ctx[_READONLY_SEARCH_PARAMS];
238
- }
239
- if (_cachedEmptyServerSearchParams === null) {
240
- _cachedEmptyServerSearchParams = new ReadonlyURLSearchParams();
241
- }
242
- return _cachedEmptyServerSearchParams;
243
- }
244
- // Track client-side params (set during RSC hydration/navigation)
245
- // We cache the params object for referential stability — only create a new
246
- // object when the params actually change (shallow key/value comparison).
165
+ const ctx = _getServerContext();
166
+ if (ctx != null) {
167
+ const searchParams = ctx.searchParams;
168
+ if (ctx[_READONLY_SEARCH_PARAMS_SOURCE] !== searchParams) {
169
+ ctx[_READONLY_SEARCH_PARAMS_SOURCE] = searchParams;
170
+ ctx[_READONLY_SEARCH_PARAMS] = new ReadonlyURLSearchParams(searchParams);
171
+ }
172
+ return ctx[_READONLY_SEARCH_PARAMS];
173
+ }
174
+ if (_cachedEmptyServerSearchParams === null) _cachedEmptyServerSearchParams = new ReadonlyURLSearchParams();
175
+ return _cachedEmptyServerSearchParams;
176
+ }
247
177
  const _EMPTY_PARAMS = {};
248
178
  let _clientParams = _EMPTY_PARAMS;
249
179
  let _clientParamsJson = "{}";
250
- export function setClientParams(params) {
251
- const json = JSON.stringify(params);
252
- if (json !== _clientParamsJson) {
253
- _clientParams = params;
254
- _clientParamsJson = json;
255
- // Notify useSyncExternalStore subscribers so useParams() re-renders.
256
- notifyListeners();
257
- }
180
+ function setClientParams(params) {
181
+ const json = JSON.stringify(params);
182
+ if (json !== _clientParamsJson) {
183
+ _clientParams = params;
184
+ _clientParamsJson = json;
185
+ notifyListeners();
186
+ }
258
187
  }
259
188
  /** Get the current client params (for testing referential stability). */
260
- export function getClientParams() {
261
- return _clientParams;
189
+ function getClientParams() {
190
+ return _clientParams;
262
191
  }
263
192
  function getClientParamsSnapshot() {
264
- return _clientParams;
193
+ return _clientParams;
265
194
  }
266
195
  function getServerParamsSnapshot() {
267
- return _getServerContext()?.params ?? _EMPTY_PARAMS;
196
+ return _getServerContext()?.params ?? _EMPTY_PARAMS;
268
197
  }
269
198
  function subscribeToNavigation(cb) {
270
- _listeners.add(cb);
271
- return () => {
272
- _listeners.delete(cb);
273
- };
274
- }
275
- // ---------------------------------------------------------------------------
276
- // Hooks
277
- // ---------------------------------------------------------------------------
278
- /**
279
- * Returns the current pathname.
280
- * Server: from request context. Client: from window.location.
281
- */
282
- export function usePathname() {
283
- if (isServer) {
284
- // During SSR of "use client" components, the navigation context may not be set.
285
- // Return a safe fallback — the client will hydrate with the real value.
286
- return _getServerContext()?.pathname ?? "/";
287
- }
288
- // Client-side: use the hook system for reactivity
289
- return React.useSyncExternalStore(subscribeToNavigation, getPathnameSnapshot, () => _getServerContext()?.pathname ?? "/");
290
- }
291
- /**
292
- * Returns the current search params as a read-only URLSearchParams.
293
- */
294
- export function useSearchParams() {
295
- if (isServer) {
296
- // During SSR of "use client" components, the navigation context may not be set.
297
- // Return a safe fallback — the client will hydrate with the real value.
298
- return getServerSearchParamsSnapshot();
299
- }
300
- return React.useSyncExternalStore(subscribeToNavigation, getSearchParamsSnapshot, getServerSearchParamsSnapshot);
301
- }
302
- /**
303
- * Returns the dynamic params for the current route.
304
- */
305
- export function useParams() {
306
- if (isServer) {
307
- // During SSR of "use client" components, the navigation context may not be set.
308
- return (_getServerContext()?.params ?? _EMPTY_PARAMS);
309
- }
310
- return React.useSyncExternalStore(subscribeToNavigation, getClientParamsSnapshot, getServerParamsSnapshot);
311
- }
312
- /**
313
- * Check if a href is an external URL (any URL scheme per RFC 3986, or protocol-relative).
314
- */
199
+ _listeners.add(cb);
200
+ return () => {
201
+ _listeners.delete(cb);
202
+ };
203
+ }
204
+ /**
205
+ * Returns the current pathname.
206
+ * Server: from request context. Client: from window.location.
207
+ */
208
+ function usePathname() {
209
+ if (isServer) return _getServerContext()?.pathname ?? "/";
210
+ return React$1.useSyncExternalStore(subscribeToNavigation, getPathnameSnapshot, () => _getServerContext()?.pathname ?? "/");
211
+ }
212
+ /**
213
+ * Returns the current search params as a read-only URLSearchParams.
214
+ */
215
+ function useSearchParams() {
216
+ if (isServer) return getServerSearchParamsSnapshot();
217
+ return React$1.useSyncExternalStore(subscribeToNavigation, getSearchParamsSnapshot, getServerSearchParamsSnapshot);
218
+ }
219
+ /**
220
+ * Returns the dynamic params for the current route.
221
+ */
222
+ function useParams() {
223
+ if (isServer) return _getServerContext()?.params ?? _EMPTY_PARAMS;
224
+ return React$1.useSyncExternalStore(subscribeToNavigation, getClientParamsSnapshot, getServerParamsSnapshot);
225
+ }
226
+ /**
227
+ * Check if a href is an external URL (any URL scheme per RFC 3986, or protocol-relative).
228
+ */
315
229
  function isExternalUrl(href) {
316
- return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("//");
230
+ return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("//");
317
231
  }
318
232
  /**
319
- * Check if a href is only a hash change relative to the current URL.
320
- */
233
+ * Check if a href is only a hash change relative to the current URL.
234
+ */
321
235
  function isHashOnlyChange(href) {
322
- if (typeof window === "undefined")
323
- return false;
324
- if (href.startsWith("#"))
325
- return true;
326
- try {
327
- const current = new URL(window.location.href);
328
- const next = new URL(href, window.location.href);
329
- return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
330
- }
331
- catch {
332
- return false;
333
- }
334
- }
335
- /**
336
- * Scroll to a hash target element, or to the top if no hash.
337
- */
236
+ if (typeof window === "undefined") return false;
237
+ if (href.startsWith("#")) return true;
238
+ try {
239
+ const current = new URL(window.location.href);
240
+ const next = new URL(href, window.location.href);
241
+ return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
242
+ } catch {
243
+ return false;
244
+ }
245
+ }
246
+ /**
247
+ * Scroll to a hash target element, or to the top if no hash.
248
+ */
338
249
  function scrollToHash(hash) {
339
- if (!hash || hash === "#") {
340
- window.scrollTo(0, 0);
341
- return;
342
- }
343
- const id = hash.slice(1);
344
- const element = document.getElementById(id);
345
- if (element) {
346
- element.scrollIntoView({ behavior: "auto" });
347
- }
348
- }
349
- /**
350
- * Reference to the native history.replaceState before patching.
351
- * Used internally to avoid triggering the interception for internal operations
352
- * (e.g. saving scroll position shouldn't cause re-renders).
353
- * Captured before the history method patching at the bottom of this module.
354
- */
355
- const _nativeReplaceState = !isServer
356
- ? window.history.replaceState.bind(window.history)
357
- : null;
358
- /**
359
- * Save the current scroll position into the current history state.
360
- * Called before every navigation to enable scroll restoration on back/forward.
361
- *
362
- * Uses _nativeReplaceState to avoid triggering the history.replaceState
363
- * interception (which would cause spurious re-renders from notifyListeners).
364
- */
250
+ if (!hash || hash === "#") {
251
+ window.scrollTo(0, 0);
252
+ return;
253
+ }
254
+ const id = hash.slice(1);
255
+ const element = document.getElementById(id);
256
+ if (element) element.scrollIntoView({ behavior: "auto" });
257
+ }
258
+ /**
259
+ * Reference to the native history.replaceState before patching.
260
+ * Used internally to avoid triggering the interception for internal operations
261
+ * (e.g. saving scroll position shouldn't cause re-renders).
262
+ * Captured before the history method patching at the bottom of this module.
263
+ */
264
+ const _nativeReplaceState = !isServer ? window.history.replaceState.bind(window.history) : null;
265
+ /**
266
+ * Save the current scroll position into the current history state.
267
+ * Called before every navigation to enable scroll restoration on back/forward.
268
+ *
269
+ * Uses _nativeReplaceState to avoid triggering the history.replaceState
270
+ * interception (which would cause spurious re-renders from notifyListeners).
271
+ */
365
272
  function saveScrollPosition() {
366
- if (!_nativeReplaceState)
367
- return;
368
- const state = window.history.state ?? {};
369
- _nativeReplaceState.call(window.history, { ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY }, "");
370
- }
371
- /**
372
- * Restore scroll position from a history state object (used on popstate).
373
- *
374
- * When an RSC navigation is in flight (back/forward triggers both this
375
- * handler and the browser entry's popstate handler which calls
376
- * __VINEXT_RSC_NAVIGATE__), we must wait for the new content to render
377
- * before scrolling. Otherwise the user sees old content flash at the
378
- * restored scroll position.
379
- *
380
- * This handler fires before the browser entry's popstate handler (because
381
- * navigation.ts is loaded before hydration completes), so we defer via a
382
- * microtask to give the browser entry handler a chance to set
383
- * __VINEXT_RSC_PENDING__ first.
384
- */
273
+ if (!_nativeReplaceState) return;
274
+ const state = window.history.state ?? {};
275
+ _nativeReplaceState.call(window.history, {
276
+ ...state,
277
+ __vinext_scrollX: window.scrollX,
278
+ __vinext_scrollY: window.scrollY
279
+ }, "");
280
+ }
281
+ /**
282
+ * Restore scroll position from a history state object (used on popstate).
283
+ *
284
+ * When an RSC navigation is in flight (back/forward triggers both this
285
+ * handler and the browser entry's popstate handler which calls
286
+ * __VINEXT_RSC_NAVIGATE__), we must wait for the new content to render
287
+ * before scrolling. Otherwise the user sees old content flash at the
288
+ * restored scroll position.
289
+ *
290
+ * This handler fires before the browser entry's popstate handler (because
291
+ * navigation.ts is loaded before hydration completes), so we defer via a
292
+ * microtask to give the browser entry handler a chance to set
293
+ * __VINEXT_RSC_PENDING__ first.
294
+ */
385
295
  function restoreScrollPosition(state) {
386
- if (state && typeof state === "object" && "__vinext_scrollY" in state) {
387
- const { __vinext_scrollX: x, __vinext_scrollY: y } = state;
388
- // Defer to allow other popstate listeners (browser entry) to run first
389
- // and set __VINEXT_RSC_PENDING__. Promise.resolve() schedules a microtask
390
- // that runs after all synchronous event listeners have completed.
391
- void Promise.resolve().then(() => {
392
- const pending = window.__VINEXT_RSC_PENDING__ ?? null;
393
- if (pending) {
394
- // Wait for the RSC navigation to finish rendering, then scroll.
395
- void pending.then(() => {
396
- requestAnimationFrame(() => {
397
- window.scrollTo(x, y);
398
- });
399
- });
400
- }
401
- else {
402
- // No RSC navigation in flight (Pages Router or already settled).
403
- requestAnimationFrame(() => {
404
- window.scrollTo(x, y);
405
- });
406
- }
407
- });
408
- }
409
- }
410
- /**
411
- * Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.
412
- */
296
+ if (state && typeof state === "object" && "__vinext_scrollY" in state) {
297
+ const { __vinext_scrollX: x, __vinext_scrollY: y } = state;
298
+ Promise.resolve().then(() => {
299
+ const pending = window.__VINEXT_RSC_PENDING__ ?? null;
300
+ if (pending) pending.then(() => {
301
+ requestAnimationFrame(() => {
302
+ window.scrollTo(x, y);
303
+ });
304
+ });
305
+ else requestAnimationFrame(() => {
306
+ window.scrollTo(x, y);
307
+ });
308
+ });
309
+ }
310
+ }
311
+ /**
312
+ * Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.
313
+ */
413
314
  async function navigateImpl(href, mode, scroll) {
414
- // Normalize same-origin absolute URLs to local paths for SPA navigation
415
- let normalizedHref = href;
416
- if (isExternalUrl(href)) {
417
- const localPath = toSameOriginAppPath(href, __basePath);
418
- if (localPath == null) {
419
- // Truly external: use full page navigation
420
- if (mode === "replace") {
421
- window.location.replace(href);
422
- }
423
- else {
424
- window.location.assign(href);
425
- }
426
- return;
427
- }
428
- normalizedHref = localPath;
429
- }
430
- const fullHref = toBrowserNavigationHref(normalizedHref, window.location.href, __basePath);
431
- // Save scroll position before navigating (for back/forward restoration)
432
- if (mode === "push") {
433
- saveScrollPosition();
434
- }
435
- // Hash-only change: update URL and scroll to target, skip RSC fetch
436
- if (isHashOnlyChange(fullHref)) {
437
- const hash = fullHref.includes("#") ? fullHref.slice(fullHref.indexOf("#")) : "";
438
- if (mode === "replace") {
439
- window.history.replaceState(null, "", fullHref);
440
- }
441
- else {
442
- window.history.pushState(null, "", fullHref);
443
- }
444
- notifyListeners();
445
- if (scroll) {
446
- scrollToHash(hash);
447
- }
448
- return;
449
- }
450
- // Extract hash for post-navigation scrolling
451
- const hashIdx = fullHref.indexOf("#");
452
- const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : "";
453
- if (mode === "replace") {
454
- window.history.replaceState(null, "", fullHref);
455
- }
456
- else {
457
- window.history.pushState(null, "", fullHref);
458
- }
459
- notifyListeners();
460
- // Trigger RSC re-fetch if available, and wait for the new content to render
461
- // before scrolling. This prevents the old page from visibly jumping to the
462
- // top before the new content paints.
463
- if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") {
464
- await window.__VINEXT_RSC_NAVIGATE__(fullHref);
465
- }
466
- if (scroll) {
467
- if (hash) {
468
- scrollToHash(hash);
469
- }
470
- else {
471
- window.scrollTo(0, 0);
472
- }
473
- }
474
- }
475
- // ---------------------------------------------------------------------------
476
- // App Router router singleton
477
- //
478
- // All methods close over module-level state (navigateImpl, withBasePath, etc.)
479
- // and carry no per-render data, so the object can be created once and reused.
480
- // Next.js returns the same router reference on every call to useRouter(), which
481
- // matters for components that rely on referential equality (e.g. useMemo /
482
- // useEffect dependency arrays, React.memo bailouts).
483
- // ---------------------------------------------------------------------------
315
+ let normalizedHref = href;
316
+ if (isExternalUrl(href)) {
317
+ const localPath = toSameOriginAppPath(href, __basePath);
318
+ if (localPath == null) {
319
+ if (mode === "replace") window.location.replace(href);
320
+ else window.location.assign(href);
321
+ return;
322
+ }
323
+ normalizedHref = localPath;
324
+ }
325
+ const fullHref = toBrowserNavigationHref(normalizedHref, window.location.href, __basePath);
326
+ if (mode === "push") saveScrollPosition();
327
+ if (isHashOnlyChange(fullHref)) {
328
+ const hash = fullHref.includes("#") ? fullHref.slice(fullHref.indexOf("#")) : "";
329
+ if (mode === "replace") window.history.replaceState(null, "", fullHref);
330
+ else window.history.pushState(null, "", fullHref);
331
+ notifyListeners();
332
+ if (scroll) scrollToHash(hash);
333
+ return;
334
+ }
335
+ const hashIdx = fullHref.indexOf("#");
336
+ const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : "";
337
+ if (mode === "replace") window.history.replaceState(null, "", fullHref);
338
+ else window.history.pushState(null, "", fullHref);
339
+ notifyListeners();
340
+ if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") await window.__VINEXT_RSC_NAVIGATE__(fullHref);
341
+ if (scroll) if (hash) scrollToHash(hash);
342
+ else window.scrollTo(0, 0);
343
+ }
484
344
  const _appRouter = {
485
- push(href, options) {
486
- if (isServer)
487
- return;
488
- void navigateImpl(href, "push", options?.scroll !== false);
489
- },
490
- replace(href, options) {
491
- if (isServer)
492
- return;
493
- void navigateImpl(href, "replace", options?.scroll !== false);
494
- },
495
- back() {
496
- if (isServer)
497
- return;
498
- window.history.back();
499
- },
500
- forward() {
501
- if (isServer)
502
- return;
503
- window.history.forward();
504
- },
505
- refresh() {
506
- if (isServer)
507
- return;
508
- // Re-fetch the current page's RSC stream
509
- if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") {
510
- window.__VINEXT_RSC_NAVIGATE__(window.location.href);
511
- }
512
- },
513
- prefetch(href) {
514
- if (isServer)
515
- return;
516
- // Prefetch the RSC payload for the target route and store in cache
517
- const fullHref = toBrowserNavigationHref(href, window.location.href, __basePath);
518
- const rscUrl = toRscUrl(fullHref);
519
- const prefetched = getPrefetchedUrls();
520
- if (prefetched.has(rscUrl))
521
- return;
522
- prefetched.add(rscUrl);
523
- fetch(rscUrl, {
524
- headers: { Accept: "text/x-component" },
525
- credentials: "include",
526
- priority: "low",
527
- })
528
- .then((response) => {
529
- if (response.ok) {
530
- storePrefetchResponse(rscUrl, response);
531
- }
532
- else {
533
- // Non-ok response: allow retry on next prefetch() call
534
- prefetched.delete(rscUrl);
535
- }
536
- })
537
- .catch(() => {
538
- // Network error: allow retry on next prefetch() call
539
- prefetched.delete(rscUrl);
540
- });
541
- },
345
+ push(href, options) {
346
+ if (isServer) return;
347
+ navigateImpl(href, "push", options?.scroll !== false);
348
+ },
349
+ replace(href, options) {
350
+ if (isServer) return;
351
+ navigateImpl(href, "replace", options?.scroll !== false);
352
+ },
353
+ back() {
354
+ if (isServer) return;
355
+ window.history.back();
356
+ },
357
+ forward() {
358
+ if (isServer) return;
359
+ window.history.forward();
360
+ },
361
+ refresh() {
362
+ if (isServer) return;
363
+ if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") window.__VINEXT_RSC_NAVIGATE__(window.location.href);
364
+ },
365
+ prefetch(href) {
366
+ if (isServer) return;
367
+ const rscUrl = toRscUrl(toBrowserNavigationHref(href, window.location.href, __basePath));
368
+ const prefetched = getPrefetchedUrls();
369
+ if (prefetched.has(rscUrl)) return;
370
+ prefetched.add(rscUrl);
371
+ fetch(rscUrl, {
372
+ headers: { Accept: "text/x-component" },
373
+ credentials: "include",
374
+ priority: "low"
375
+ }).then((response) => {
376
+ if (response.ok) storePrefetchResponse(rscUrl, response);
377
+ else prefetched.delete(rscUrl);
378
+ }).catch(() => {
379
+ prefetched.delete(rscUrl);
380
+ });
381
+ }
542
382
  };
543
383
  /**
544
- * App Router's useRouter — returns push/replace/back/forward/refresh.
545
- * Different from Pages Router's useRouter (next/router).
546
- *
547
- * Returns a stable singleton: the same object reference on every call,
548
- * matching Next.js behavior so components using referential equality
549
- * (e.g. useMemo / useEffect deps, React.memo) don't re-render unnecessarily.
550
- */
551
- export function useRouter() {
552
- return _appRouter;
553
- }
554
- /**
555
- * Returns the active child segment one level below the layout where it's called.
556
- *
557
- * Returns the first segment from the route tree below this layout, including
558
- * route groups (e.g., "(marketing)") and resolved dynamic params. Returns null
559
- * if at the leaf (no child segments).
560
- *
561
- * @param parallelRoutesKey - Which parallel route to read (default: "children")
562
- */
563
- export function useSelectedLayoutSegment(
564
- // parallelRoutesKey is accepted for API compat but not yet supported —
565
- // vinext doesn't implement parallel routes with separate segment tracking.
566
- _parallelRoutesKey) {
567
- const segments = useSelectedLayoutSegments(_parallelRoutesKey);
568
- return segments.length > 0 ? segments[0] : null;
569
- }
570
- /**
571
- * Returns all active segments below the layout where it's called.
572
- *
573
- * Each layout in the App Router tree wraps its children with a
574
- * LayoutSegmentProvider whose value is the remaining route tree segments
575
- * (including route groups, with dynamic params resolved to actual values
576
- * and catch-all segments joined with "/"). This hook reads those segments
577
- * directly from context.
578
- *
579
- * @param parallelRoutesKey - Which parallel route to read (default: "children")
580
- */
581
- export function useSelectedLayoutSegments(
582
- // parallelRoutesKey is accepted for API compat but not yet supported —
583
- // vinext doesn't implement parallel routes with separate segment tracking.
584
- _parallelRoutesKey) {
585
- return useChildSegments();
586
- }
587
- export { ReadonlyURLSearchParams };
588
- /**
589
- * useServerInsertedHTML — inject HTML during SSR from client components.
590
- *
591
- * Used by CSS-in-JS libraries (styled-components, emotion, StyleX) to inject
592
- * <style> tags during SSR so styles appear in the initial HTML (no FOUC).
593
- *
594
- * The callback is called once after each SSR render pass. The returned JSX/HTML
595
- * is serialized and injected into the HTML stream.
596
- *
597
- * Usage (in a "use client" component wrapping children):
598
- * useServerInsertedHTML(() => {
599
- * const styles = sheet.getStyleElement();
600
- * sheet.instance.clearTag();
601
- * return <>{styles}</>;
602
- * });
603
- */
604
- export function useServerInsertedHTML(callback) {
605
- if (typeof document !== "undefined") {
606
- // Client-side: no-op (styles are already in the DOM)
607
- return;
608
- }
609
- _getInsertedHTMLCallbacks().push(callback);
610
- }
611
- /**
612
- * Flush all collected useServerInsertedHTML callbacks.
613
- * Returns an array of results (React elements or strings).
614
- * Clears the callback list so the next render starts fresh.
615
- *
616
- * Called by the SSR entry after renderToReadableStream completes.
617
- */
618
- export function flushServerInsertedHTML() {
619
- const callbacks = _getInsertedHTMLCallbacks();
620
- const results = [];
621
- for (const cb of callbacks) {
622
- try {
623
- const result = cb();
624
- if (result != null)
625
- results.push(result);
626
- }
627
- catch {
628
- // Ignore errors from individual callbacks
629
- }
630
- }
631
- callbacks.length = 0;
632
- return results;
633
- }
634
- /**
635
- * Clear all collected useServerInsertedHTML callbacks without flushing.
636
- * Used for cleanup between requests.
637
- */
638
- export function clearServerInsertedHTML() {
639
- _clearInsertedHTMLCallbacks();
640
- }
641
- // ---------------------------------------------------------------------------
642
- // Non-hook utilities (can be called from Server Components)
643
- // ---------------------------------------------------------------------------
644
- /**
645
- * HTTP Access Fallback error code shared prefix for notFound/forbidden/unauthorized.
646
- * Matches Next.js 16's unified error handling approach.
647
- */
648
- export const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
649
- /**
650
- * Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).
651
- */
652
- export function isHTTPAccessFallbackError(error) {
653
- if (error && typeof error === "object" && "digest" in error) {
654
- const digest = String(error.digest);
655
- return (digest === "NEXT_NOT_FOUND" || // legacy compat
656
- digest.startsWith(`${HTTP_ERROR_FALLBACK_ERROR_CODE};`));
657
- }
658
- return false;
659
- }
660
- /**
661
- * Extract the HTTP status code from an HTTP Access Fallback error.
662
- * Returns 404 for legacy NEXT_NOT_FOUND errors.
663
- */
664
- export function getAccessFallbackHTTPStatus(error) {
665
- if (error && typeof error === "object" && "digest" in error) {
666
- const digest = String(error.digest);
667
- if (digest === "NEXT_NOT_FOUND")
668
- return 404;
669
- if (digest.startsWith(`${HTTP_ERROR_FALLBACK_ERROR_CODE};`)) {
670
- return parseInt(digest.split(";")[1], 10);
671
- }
672
- }
673
- return 404;
674
- }
675
- /**
676
- * Enum matching Next.js RedirectType for type-safe redirect calls.
677
- */
678
- export var RedirectType;
679
- (function (RedirectType) {
680
- RedirectType["push"] = "push";
681
- RedirectType["replace"] = "replace";
682
- })(RedirectType || (RedirectType = {}));
683
- /**
684
- * Internal error class used by redirect/notFound/forbidden/unauthorized.
685
- * The `digest` field is the serialised control-flow signal read by the
686
- * framework's error boundary and server-side request handlers.
687
- */
688
- class VinextNavigationError extends Error {
689
- digest;
690
- constructor(message, digest) {
691
- super(message);
692
- this.digest = digest;
693
- }
694
- }
695
- /**
696
- * Throw a redirect. Caught by the framework to send a redirect response.
697
- */
698
- export function redirect(url, type) {
699
- throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? "replace"};${encodeURIComponent(url)}`);
700
- }
701
- /**
702
- * Trigger a permanent redirect (308).
703
- */
704
- export function permanentRedirect(url) {
705
- throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;replace;${encodeURIComponent(url)};308`);
706
- }
707
- /**
708
- * Trigger a not-found response (404). Caught by the framework.
709
- */
710
- export function notFound() {
711
- throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
712
- }
713
- /**
714
- * Trigger a forbidden response (403). Caught by the framework.
715
- * In Next.js, this is gated behind experimental.authInterrupts — we
716
- * support it unconditionally for maximum compatibility.
717
- */
718
- export function forbidden() {
719
- throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
720
- }
721
- /**
722
- * Trigger an unauthorized response (401). Caught by the framework.
723
- * In Next.js, this is gated behind experimental.authInterrupts — we
724
- * support it unconditionally for maximum compatibility.
725
- */
726
- export function unauthorized() {
727
- throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
728
- }
729
- // ---------------------------------------------------------------------------
730
- // Helpers
731
- // ---------------------------------------------------------------------------
732
- // React hooks are imported at the top level via ESM.
733
- // Listen for popstate on the client
734
- if (!isServer) {
735
- window.addEventListener("popstate", (event) => {
736
- notifyListeners();
737
- // Restore scroll position for back/forward navigation
738
- restoreScrollPosition(event.state);
739
- });
740
- // ---------------------------------------------------------------------------
741
- // history.pushState / replaceState interception (shallow routing)
742
- //
743
- // Next.js intercepts these native methods so that when user code calls
744
- // `window.history.pushState(null, '', '/new-path?filter=abc')` directly,
745
- // React hooks like usePathname() and useSearchParams() re-render with
746
- // the new URL. This is the foundation for shallow routing patterns
747
- // (filter UIs, tabs, URL search param state, etc.).
748
- //
749
- // We wrap the original methods, call through to the native implementation,
750
- // then notify our listener system so useSyncExternalStore picks up the
751
- // URL change.
752
- // ---------------------------------------------------------------------------
753
- const originalPushState = window.history.pushState.bind(window.history);
754
- const originalReplaceState = window.history.replaceState.bind(window.history);
755
- window.history.pushState = function patchedPushState(data, unused, url) {
756
- originalPushState(data, unused, url);
757
- notifyListeners();
758
- };
759
- window.history.replaceState = function patchedReplaceState(data, unused, url) {
760
- originalReplaceState(data, unused, url);
761
- notifyListeners();
762
- };
384
+ * App Router's useRouter — returns push/replace/back/forward/refresh.
385
+ * Different from Pages Router's useRouter (next/router).
386
+ *
387
+ * Returns a stable singleton: the same object reference on every call,
388
+ * matching Next.js behavior so components using referential equality
389
+ * (e.g. useMemo / useEffect deps, React.memo) don't re-render unnecessarily.
390
+ */
391
+ function useRouter() {
392
+ return _appRouter;
393
+ }
394
+ /**
395
+ * Returns the active child segment one level below the layout where it's called.
396
+ *
397
+ * Returns the first segment from the route tree below this layout, including
398
+ * route groups (e.g., "(marketing)") and resolved dynamic params. Returns null
399
+ * if at the leaf (no child segments).
400
+ *
401
+ * @param parallelRoutesKey - Which parallel route to read (default: "children")
402
+ */
403
+ function useSelectedLayoutSegment(_parallelRoutesKey) {
404
+ const segments = useSelectedLayoutSegments(_parallelRoutesKey);
405
+ return segments.length > 0 ? segments[0] : null;
406
+ }
407
+ /**
408
+ * Returns all active segments below the layout where it's called.
409
+ *
410
+ * Each layout in the App Router tree wraps its children with a
411
+ * LayoutSegmentProvider whose value is the remaining route tree segments
412
+ * (including route groups, with dynamic params resolved to actual values
413
+ * and catch-all segments joined with "/"). This hook reads those segments
414
+ * directly from context.
415
+ *
416
+ * @param parallelRoutesKey - Which parallel route to read (default: "children")
417
+ */
418
+ function useSelectedLayoutSegments(_parallelRoutesKey) {
419
+ return useChildSegments();
420
+ }
421
+ /**
422
+ * useServerInsertedHTML inject HTML during SSR from client components.
423
+ *
424
+ * Used by CSS-in-JS libraries (styled-components, emotion, StyleX) to inject
425
+ * <style> tags during SSR so styles appear in the initial HTML (no FOUC).
426
+ *
427
+ * The callback is called once after each SSR render pass. The returned JSX/HTML
428
+ * is serialized and injected into the HTML stream.
429
+ *
430
+ * Usage (in a "use client" component wrapping children):
431
+ * useServerInsertedHTML(() => {
432
+ * const styles = sheet.getStyleElement();
433
+ * sheet.instance.clearTag();
434
+ * return <>{styles}</>;
435
+ * });
436
+ */
437
+ function useServerInsertedHTML(callback) {
438
+ if (typeof document !== "undefined") return;
439
+ _getInsertedHTMLCallbacks().push(callback);
440
+ }
441
+ /**
442
+ * Flush all collected useServerInsertedHTML callbacks.
443
+ * Returns an array of results (React elements or strings).
444
+ * Clears the callback list so the next render starts fresh.
445
+ *
446
+ * Called by the SSR entry after renderToReadableStream completes.
447
+ */
448
+ function flushServerInsertedHTML() {
449
+ const callbacks = _getInsertedHTMLCallbacks();
450
+ const results = [];
451
+ for (const cb of callbacks) try {
452
+ const result = cb();
453
+ if (result != null) results.push(result);
454
+ } catch {}
455
+ callbacks.length = 0;
456
+ return results;
457
+ }
458
+ /**
459
+ * Clear all collected useServerInsertedHTML callbacks without flushing.
460
+ * Used for cleanup between requests.
461
+ */
462
+ function clearServerInsertedHTML() {
463
+ _clearInsertedHTMLCallbacks();
464
+ }
465
+ /**
466
+ * HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.
467
+ * Matches Next.js 16's unified error handling approach.
468
+ */
469
+ const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
470
+ /**
471
+ * Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).
472
+ */
473
+ function isHTTPAccessFallbackError(error) {
474
+ if (error && typeof error === "object" && "digest" in error) {
475
+ const digest = String(error.digest);
476
+ return digest === "NEXT_NOT_FOUND" || digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`);
477
+ }
478
+ return false;
479
+ }
480
+ /**
481
+ * Extract the HTTP status code from an HTTP Access Fallback error.
482
+ * Returns 404 for legacy NEXT_NOT_FOUND errors.
483
+ */
484
+ function getAccessFallbackHTTPStatus(error) {
485
+ if (error && typeof error === "object" && "digest" in error) {
486
+ const digest = String(error.digest);
487
+ if (digest === "NEXT_NOT_FOUND") return 404;
488
+ if (digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`)) return parseInt(digest.split(";")[1], 10);
489
+ }
490
+ return 404;
491
+ }
492
+ /**
493
+ * Enum matching Next.js RedirectType for type-safe redirect calls.
494
+ */
495
+ let RedirectType = /* @__PURE__ */ function(RedirectType) {
496
+ RedirectType["push"] = "push";
497
+ RedirectType["replace"] = "replace";
498
+ return RedirectType;
499
+ }({});
500
+ /**
501
+ * Internal error class used by redirect/notFound/forbidden/unauthorized.
502
+ * The `digest` field is the serialised control-flow signal read by the
503
+ * framework's error boundary and server-side request handlers.
504
+ */
505
+ var VinextNavigationError = class extends Error {
506
+ digest;
507
+ constructor(message, digest) {
508
+ super(message);
509
+ this.digest = digest;
510
+ }
511
+ };
512
+ /**
513
+ * Throw a redirect. Caught by the framework to send a redirect response.
514
+ */
515
+ function redirect(url, type) {
516
+ throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? "replace"};${encodeURIComponent(url)}`);
517
+ }
518
+ /**
519
+ * Trigger a permanent redirect (308).
520
+ */
521
+ function permanentRedirect(url) {
522
+ throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;replace;${encodeURIComponent(url)};308`);
763
523
  }
524
+ /**
525
+ * Trigger a not-found response (404). Caught by the framework.
526
+ */
527
+ function notFound() {
528
+ throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
529
+ }
530
+ /**
531
+ * Trigger a forbidden response (403). Caught by the framework.
532
+ * In Next.js, this is gated behind experimental.authInterrupts — we
533
+ * support it unconditionally for maximum compatibility.
534
+ */
535
+ function forbidden() {
536
+ throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
537
+ }
538
+ /**
539
+ * Trigger an unauthorized response (401). Caught by the framework.
540
+ * In Next.js, this is gated behind experimental.authInterrupts — we
541
+ * support it unconditionally for maximum compatibility.
542
+ */
543
+ function unauthorized() {
544
+ throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
545
+ }
546
+ if (!isServer) {
547
+ window.addEventListener("popstate", (event) => {
548
+ notifyListeners();
549
+ restoreScrollPosition(event.state);
550
+ });
551
+ const originalPushState = window.history.pushState.bind(window.history);
552
+ const originalReplaceState = window.history.replaceState.bind(window.history);
553
+ window.history.pushState = function patchedPushState(data, unused, url) {
554
+ originalPushState(data, unused, url);
555
+ notifyListeners();
556
+ };
557
+ window.history.replaceState = function patchedReplaceState(data, unused, url) {
558
+ originalReplaceState(data, unused, url);
559
+ notifyListeners();
560
+ };
561
+ }
562
+ //#endregion
563
+ export { HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, PREFETCH_CACHE_TTL, ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getClientParams, getLayoutSegmentContext, getNavigationContext, getPrefetchCache, getPrefetchedUrls, isHTTPAccessFallbackError, notFound, permanentRedirect, redirect, setClientParams, setNavigationContext, storePrefetchResponse, toRscUrl, unauthorized, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
564
+
764
565
  //# sourceMappingURL=navigation.js.map