vinext 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (428) hide show
  1. package/README.md +12 -6
  2. package/dist/build/prerender.d.ts +188 -0
  3. package/dist/build/prerender.js +675 -0
  4. package/dist/build/prerender.js.map +1 -0
  5. package/dist/build/report.d.ts +45 -46
  6. package/dist/build/report.js +247 -276
  7. package/dist/build/report.js.map +1 -1
  8. package/dist/build/run-prerender.d.ts +62 -0
  9. package/dist/build/run-prerender.js +183 -0
  10. package/dist/build/run-prerender.js.map +1 -0
  11. package/dist/build/server-manifest.d.ts +19 -0
  12. package/dist/build/server-manifest.js +29 -0
  13. package/dist/build/server-manifest.js.map +1 -0
  14. package/dist/build/static-export.d.ts +51 -66
  15. package/dist/build/static-export.js +51 -545
  16. package/dist/build/static-export.js.map +1 -1
  17. package/dist/check.d.ts +26 -24
  18. package/dist/check.js +591 -567
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +430 -491
  22. package/dist/cli.js.map +1 -1
  23. package/dist/client/entry.d.ts +1 -2
  24. package/dist/client/entry.js +49 -62
  25. package/dist/client/entry.js.map +1 -1
  26. package/dist/client/validate-module-path.d.ts +4 -1
  27. package/dist/client/validate-module-path.js +23 -28
  28. package/dist/client/validate-module-path.js.map +1 -1
  29. package/dist/client/vinext-next-data.d.ts +15 -20
  30. package/dist/client/vinext-next-data.js +0 -1
  31. package/dist/cloudflare/index.d.ts +3 -8
  32. package/dist/cloudflare/index.js +3 -8
  33. package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
  34. package/dist/cloudflare/kv-cache-handler.js +354 -366
  35. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  36. package/dist/cloudflare/tpr.d.ts +36 -34
  37. package/dist/cloudflare/tpr.js +460 -603
  38. package/dist/cloudflare/tpr.js.map +1 -1
  39. package/dist/config/config-matchers.d.ts +31 -40
  40. package/dist/config/config-matchers.js +727 -936
  41. package/dist/config/config-matchers.js.map +1 -1
  42. package/dist/config/dotenv.d.ts +18 -11
  43. package/dist/config/dotenv.js +79 -84
  44. package/dist/config/dotenv.js.map +1 -1
  45. package/dist/config/next-config.d.ts +156 -146
  46. package/dist/config/next-config.js +374 -464
  47. package/dist/config/next-config.js.map +1 -1
  48. package/dist/deploy.d.ts +87 -96
  49. package/dist/deploy.js +490 -628
  50. package/dist/deploy.js.map +1 -1
  51. package/dist/entries/app-browser-entry.d.ts +4 -1
  52. package/dist/entries/app-browser-entry.js +12 -8
  53. package/dist/entries/app-browser-entry.js.map +1 -1
  54. package/dist/entries/app-rsc-entry.d.ts +33 -20
  55. package/dist/entries/app-rsc-entry.js +618 -343
  56. package/dist/entries/app-rsc-entry.js.map +1 -1
  57. package/dist/entries/app-ssr-entry.d.ts +9 -1
  58. package/dist/entries/app-ssr-entry.js +61 -28
  59. package/dist/entries/app-ssr-entry.js.map +1 -1
  60. package/dist/entries/pages-client-entry.d.ts +6 -2
  61. package/dist/entries/pages-client-entry.js +30 -33
  62. package/dist/entries/pages-client-entry.js.map +1 -1
  63. package/dist/entries/pages-entry-helpers.d.ts +5 -1
  64. package/dist/entries/pages-entry-helpers.js +17 -14
  65. package/dist/entries/pages-entry-helpers.js.map +1 -1
  66. package/dist/entries/pages-server-entry.d.ts +6 -2
  67. package/dist/entries/pages-server-entry.js +229 -207
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +82 -62
  70. package/dist/index.js +2172 -3125
  71. package/dist/index.js.map +1 -1
  72. package/dist/init.d.ts +40 -37
  73. package/dist/init.js +201 -258
  74. package/dist/init.js.map +1 -1
  75. package/dist/plugins/async-hooks-stub.d.ts +7 -3
  76. package/dist/plugins/async-hooks-stub.js +39 -42
  77. package/dist/plugins/async-hooks-stub.js.map +1 -1
  78. package/dist/plugins/client-reference-dedup.d.ts +7 -3
  79. package/dist/plugins/client-reference-dedup.js +63 -88
  80. package/dist/plugins/client-reference-dedup.js.map +1 -1
  81. package/dist/routing/app-router.d.ts +100 -96
  82. package/dist/routing/app-router.js +563 -659
  83. package/dist/routing/app-router.js.map +1 -1
  84. package/dist/routing/file-matcher.d.ts +18 -15
  85. package/dist/routing/file-matcher.js +65 -65
  86. package/dist/routing/file-matcher.js.map +1 -1
  87. package/dist/routing/pages-router.d.ts +23 -24
  88. package/dist/routing/pages-router.js +147 -172
  89. package/dist/routing/pages-router.js.map +1 -1
  90. package/dist/routing/route-trie.d.ts +23 -20
  91. package/dist/routing/route-trie.js +131 -151
  92. package/dist/routing/route-trie.js.map +1 -1
  93. package/dist/routing/route-validation.d.ts +5 -2
  94. package/dist/routing/route-validation.js +98 -130
  95. package/dist/routing/route-validation.js.map +1 -1
  96. package/dist/routing/utils.d.ts +10 -7
  97. package/dist/routing/utils.js +75 -111
  98. package/dist/routing/utils.js.map +1 -1
  99. package/dist/server/api-handler.d.ts +8 -13
  100. package/dist/server/api-handler.js +161 -193
  101. package/dist/server/api-handler.js.map +1 -1
  102. package/dist/server/app-router-entry.d.ts +6 -16
  103. package/dist/server/app-router-entry.js +26 -54
  104. package/dist/server/app-router-entry.js.map +1 -1
  105. package/dist/server/dev-module-runner.d.ts +11 -64
  106. package/dist/server/dev-module-runner.js +89 -101
  107. package/dist/server/dev-module-runner.js.map +1 -1
  108. package/dist/server/dev-origin-check.d.ts +12 -10
  109. package/dist/server/dev-origin-check.js +98 -108
  110. package/dist/server/dev-origin-check.js.map +1 -1
  111. package/dist/server/dev-server.d.ts +17 -13
  112. package/dist/server/dev-server.js +547 -874
  113. package/dist/server/dev-server.js.map +1 -1
  114. package/dist/server/html.d.ts +4 -1
  115. package/dist/server/html.js +25 -26
  116. package/dist/server/html.js.map +1 -1
  117. package/dist/server/image-optimization.d.ts +31 -28
  118. package/dist/server/image-optimization.js +183 -200
  119. package/dist/server/image-optimization.js.map +1 -1
  120. package/dist/server/instrumentation.d.ts +25 -22
  121. package/dist/server/instrumentation.js +110 -122
  122. package/dist/server/instrumentation.js.map +1 -1
  123. package/dist/server/isr-cache.d.ts +16 -26
  124. package/dist/server/isr-cache.js +109 -126
  125. package/dist/server/isr-cache.js.map +1 -1
  126. package/dist/server/metadata-routes.d.ts +85 -88
  127. package/dist/server/metadata-routes.js +277 -286
  128. package/dist/server/metadata-routes.js.map +1 -1
  129. package/dist/server/middleware-codegen.d.ts +7 -4
  130. package/dist/server/middleware-codegen.js +98 -65
  131. package/dist/server/middleware-codegen.js.map +1 -1
  132. package/dist/server/middleware-request-headers.d.ts +8 -6
  133. package/dist/server/middleware-request-headers.js +47 -65
  134. package/dist/server/middleware-request-headers.js.map +1 -1
  135. package/dist/server/middleware.d.ts +31 -47
  136. package/dist/server/middleware.js +276 -363
  137. package/dist/server/middleware.js.map +1 -1
  138. package/dist/server/normalize-path.d.ts +4 -1
  139. package/dist/server/normalize-path.js +33 -47
  140. package/dist/server/normalize-path.js.map +1 -1
  141. package/dist/server/pages-i18n.d.ts +58 -0
  142. package/dist/server/pages-i18n.js +125 -0
  143. package/dist/server/pages-i18n.js.map +1 -0
  144. package/dist/server/prod-server.d.ts +19 -31
  145. package/dist/server/prod-server.js +714 -945
  146. package/dist/server/prod-server.js.map +1 -1
  147. package/dist/server/request-log.d.ts +18 -12
  148. package/dist/server/request-log.js +45 -52
  149. package/dist/server/request-log.js.map +1 -1
  150. package/dist/server/request-pipeline.d.ts +9 -17
  151. package/dist/server/request-pipeline.js +133 -184
  152. package/dist/server/request-pipeline.js.map +1 -1
  153. package/dist/server/worker-utils.d.ts +4 -1
  154. package/dist/server/worker-utils.js +31 -37
  155. package/dist/server/worker-utils.js.map +1 -1
  156. package/dist/shims/amp.d.ts +5 -2
  157. package/dist/shims/amp.js +19 -15
  158. package/dist/shims/amp.js.map +1 -1
  159. package/dist/shims/app.d.ts +8 -10
  160. package/dist/shims/app.js +0 -1
  161. package/dist/shims/cache-runtime.d.ts +21 -43
  162. package/dist/shims/cache-runtime.js +271 -405
  163. package/dist/shims/cache-runtime.js.map +1 -1
  164. package/dist/shims/cache.d.ts +131 -119
  165. package/dist/shims/cache.js +339 -418
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/client-only.d.ts +1 -18
  168. package/dist/shims/client-only.js +0 -17
  169. package/dist/shims/compat-router.d.ts +4 -1
  170. package/dist/shims/compat-router.js +23 -19
  171. package/dist/shims/compat-router.js.map +1 -1
  172. package/dist/shims/config.d.ts +7 -5
  173. package/dist/shims/config.js +16 -23
  174. package/dist/shims/config.js.map +1 -1
  175. package/dist/shims/constants.d.ts +119 -118
  176. package/dist/shims/constants.js +159 -165
  177. package/dist/shims/constants.js.map +1 -1
  178. package/dist/shims/document.d.ts +20 -16
  179. package/dist/shims/document.js +41 -22
  180. package/dist/shims/document.js.map +1 -1
  181. package/dist/shims/dynamic.d.ts +13 -22
  182. package/dist/shims/dynamic.js +122 -136
  183. package/dist/shims/dynamic.js.map +1 -1
  184. package/dist/shims/error-boundary.d.ts +22 -15
  185. package/dist/shims/error-boundary.js +81 -79
  186. package/dist/shims/error-boundary.js.map +1 -1
  187. package/dist/shims/error.d.ts +11 -12
  188. package/dist/shims/error.js +35 -39
  189. package/dist/shims/error.js.map +1 -1
  190. package/dist/shims/fetch-cache.d.ts +26 -10
  191. package/dist/shims/fetch-cache.js +443 -586
  192. package/dist/shims/fetch-cache.js.map +1 -1
  193. package/dist/shims/font-google-base.d.ts +28 -26
  194. package/dist/shims/font-google-base.js +238 -325
  195. package/dist/shims/font-google-base.js.map +1 -1
  196. package/dist/shims/font-google.d.ts +3 -3
  197. package/dist/shims/font-google.generated.d.ts +1928 -1924
  198. package/dist/shims/font-google.generated.js +1928 -2133
  199. package/dist/shims/font-google.generated.js.map +1 -1
  200. package/dist/shims/font-google.js +3 -3
  201. package/dist/shims/font-local.d.ts +28 -26
  202. package/dist/shims/font-local.js +204 -260
  203. package/dist/shims/font-local.js.map +1 -1
  204. package/dist/shims/form.d.ts +13 -27
  205. package/dist/shims/form.js +128 -180
  206. package/dist/shims/form.js.map +1 -1
  207. package/dist/shims/head-state.d.ts +9 -10
  208. package/dist/shims/head-state.js +25 -39
  209. package/dist/shims/head-state.js.map +1 -1
  210. package/dist/shims/head.d.ts +16 -18
  211. package/dist/shims/head.js +185 -153
  212. package/dist/shims/head.js.map +1 -1
  213. package/dist/shims/headers.d.ts +84 -71
  214. package/dist/shims/headers.js +447 -583
  215. package/dist/shims/headers.js.map +1 -1
  216. package/dist/shims/i18n-context.d.ts +23 -0
  217. package/dist/shims/i18n-context.js +44 -0
  218. package/dist/shims/i18n-context.js.map +1 -0
  219. package/dist/shims/i18n-state.d.ts +14 -0
  220. package/dist/shims/i18n-state.js +45 -0
  221. package/dist/shims/i18n-state.js.map +1 -0
  222. package/dist/shims/image-config.d.ts +11 -8
  223. package/dist/shims/image-config.js +50 -83
  224. package/dist/shims/image-config.js.map +1 -1
  225. package/dist/shims/image.d.ts +37 -44
  226. package/dist/shims/image.js +284 -301
  227. package/dist/shims/image.js.map +1 -1
  228. package/dist/shims/internal/api-utils.d.ts +7 -4
  229. package/dist/shims/internal/api-utils.js +0 -6
  230. package/dist/shims/internal/app-router-context.d.ts +22 -17
  231. package/dist/shims/internal/app-router-context.js +17 -13
  232. package/dist/shims/internal/app-router-context.js.map +1 -1
  233. package/dist/shims/internal/cookies.d.ts +2 -9
  234. package/dist/shims/internal/cookies.js +2 -9
  235. package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
  236. package/dist/shims/internal/parse-cookie-header.js +29 -29
  237. package/dist/shims/internal/parse-cookie-header.js.map +1 -1
  238. package/dist/shims/internal/router-context.d.ts +6 -1
  239. package/dist/shims/internal/router-context.js +11 -7
  240. package/dist/shims/internal/router-context.js.map +1 -1
  241. package/dist/shims/internal/utils.d.ts +40 -36
  242. package/dist/shims/internal/utils.js +24 -30
  243. package/dist/shims/internal/utils.js.map +1 -1
  244. package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
  245. package/dist/shims/internal/work-unit-async-storage.js +14 -11
  246. package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
  247. package/dist/shims/layout-segment-context.d.ts +11 -14
  248. package/dist/shims/layout-segment-context.js +24 -23
  249. package/dist/shims/layout-segment-context.js.map +1 -1
  250. package/dist/shims/legacy-image.d.ts +39 -46
  251. package/dist/shims/legacy-image.js +47 -42
  252. package/dist/shims/legacy-image.js.map +1 -1
  253. package/dist/shims/link.d.ts +32 -36
  254. package/dist/shims/link.js +262 -382
  255. package/dist/shims/link.js.map +1 -1
  256. package/dist/shims/metadata.d.ts +210 -202
  257. package/dist/shims/metadata.js +545 -544
  258. package/dist/shims/metadata.js.map +1 -1
  259. package/dist/shims/navigation-state.d.ts +19 -13
  260. package/dist/shims/navigation-state.js +68 -58
  261. package/dist/shims/navigation-state.js.map +1 -1
  262. package/dist/shims/navigation.d.ts +59 -63
  263. package/dist/shims/navigation.js +508 -690
  264. package/dist/shims/navigation.js.map +1 -1
  265. package/dist/shims/og.d.ts +2 -20
  266. package/dist/shims/og.js +2 -19
  267. package/dist/shims/readonly-url-search-params.d.ts +8 -5
  268. package/dist/shims/readonly-url-search-params.js +26 -22
  269. package/dist/shims/readonly-url-search-params.js.map +1 -1
  270. package/dist/shims/request-context.d.ts +8 -5
  271. package/dist/shims/request-context.js +50 -51
  272. package/dist/shims/request-context.js.map +1 -1
  273. package/dist/shims/request-state-types.d.ts +11 -0
  274. package/dist/shims/request-state-types.js +1 -0
  275. package/dist/shims/router-state.d.ts +15 -1
  276. package/dist/shims/router-state.js +34 -41
  277. package/dist/shims/router-state.js.map +1 -1
  278. package/dist/shims/router.d.ts +81 -81
  279. package/dist/shims/router.js +517 -543
  280. package/dist/shims/router.js.map +1 -1
  281. package/dist/shims/script.d.ts +39 -48
  282. package/dist/shims/script.js +107 -160
  283. package/dist/shims/script.js.map +1 -1
  284. package/dist/shims/server-only.d.ts +1 -19
  285. package/dist/shims/server-only.js +0 -18
  286. package/dist/shims/server.d.ts +175 -157
  287. package/dist/shims/server.js +462 -432
  288. package/dist/shims/server.js.map +1 -1
  289. package/dist/shims/unified-request-context.d.ts +66 -0
  290. package/dist/shims/unified-request-context.js +98 -0
  291. package/dist/shims/unified-request-context.js.map +1 -0
  292. package/dist/shims/url-safety.d.ts +4 -1
  293. package/dist/shims/url-safety.js +15 -11
  294. package/dist/shims/url-safety.js.map +1 -1
  295. package/dist/shims/url-utils.d.ts +8 -5
  296. package/dist/shims/url-utils.js +62 -93
  297. package/dist/shims/url-utils.js.map +1 -1
  298. package/dist/shims/web-vitals.d.ts +10 -8
  299. package/dist/shims/web-vitals.js +9 -15
  300. package/dist/shims/web-vitals.js.map +1 -1
  301. package/dist/utils/base-path.d.ts +5 -2
  302. package/dist/utils/base-path.js +21 -19
  303. package/dist/utils/base-path.js.map +1 -1
  304. package/dist/utils/domain-locale.d.ts +26 -0
  305. package/dist/utils/domain-locale.js +44 -0
  306. package/dist/utils/domain-locale.js.map +1 -0
  307. package/dist/utils/hash.d.ts +4 -1
  308. package/dist/utils/hash.js +19 -17
  309. package/dist/utils/hash.js.map +1 -1
  310. package/dist/utils/manifest-paths.d.ts +6 -3
  311. package/dist/utils/manifest-paths.js +15 -16
  312. package/dist/utils/manifest-paths.js.map +1 -1
  313. package/dist/utils/project.d.ts +13 -11
  314. package/dist/utils/project.js +169 -216
  315. package/dist/utils/project.js.map +1 -1
  316. package/dist/utils/query.d.ts +8 -6
  317. package/dist/utils/query.js +57 -67
  318. package/dist/utils/query.js.map +1 -1
  319. package/package.json +11 -10
  320. package/dist/build/report.d.ts.map +0 -1
  321. package/dist/build/static-export.d.ts.map +0 -1
  322. package/dist/check.d.ts.map +0 -1
  323. package/dist/cli.d.ts.map +0 -1
  324. package/dist/client/entry.d.ts.map +0 -1
  325. package/dist/client/validate-module-path.d.ts.map +0 -1
  326. package/dist/client/vinext-next-data.d.ts.map +0 -1
  327. package/dist/client/vinext-next-data.js.map +0 -1
  328. package/dist/cloudflare/index.d.ts.map +0 -1
  329. package/dist/cloudflare/index.js.map +0 -1
  330. package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
  331. package/dist/cloudflare/tpr.d.ts.map +0 -1
  332. package/dist/config/config-matchers.d.ts.map +0 -1
  333. package/dist/config/dotenv.d.ts.map +0 -1
  334. package/dist/config/next-config.d.ts.map +0 -1
  335. package/dist/deploy.d.ts.map +0 -1
  336. package/dist/entries/app-browser-entry.d.ts.map +0 -1
  337. package/dist/entries/app-rsc-entry.d.ts.map +0 -1
  338. package/dist/entries/app-ssr-entry.d.ts.map +0 -1
  339. package/dist/entries/pages-client-entry.d.ts.map +0 -1
  340. package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
  341. package/dist/entries/pages-server-entry.d.ts.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/init.d.ts.map +0 -1
  344. package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
  345. package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
  346. package/dist/routing/app-router.d.ts.map +0 -1
  347. package/dist/routing/file-matcher.d.ts.map +0 -1
  348. package/dist/routing/pages-router.d.ts.map +0 -1
  349. package/dist/routing/route-trie.d.ts.map +0 -1
  350. package/dist/routing/route-validation.d.ts.map +0 -1
  351. package/dist/routing/utils.d.ts.map +0 -1
  352. package/dist/server/api-handler.d.ts.map +0 -1
  353. package/dist/server/app-router-entry.d.ts.map +0 -1
  354. package/dist/server/dev-module-runner.d.ts.map +0 -1
  355. package/dist/server/dev-origin-check.d.ts.map +0 -1
  356. package/dist/server/dev-server.d.ts.map +0 -1
  357. package/dist/server/html.d.ts.map +0 -1
  358. package/dist/server/image-optimization.d.ts.map +0 -1
  359. package/dist/server/instrumentation.d.ts.map +0 -1
  360. package/dist/server/isr-cache.d.ts.map +0 -1
  361. package/dist/server/metadata-routes.d.ts.map +0 -1
  362. package/dist/server/middleware-codegen.d.ts.map +0 -1
  363. package/dist/server/middleware-request-headers.d.ts.map +0 -1
  364. package/dist/server/middleware.d.ts.map +0 -1
  365. package/dist/server/normalize-path.d.ts.map +0 -1
  366. package/dist/server/prod-server.d.ts.map +0 -1
  367. package/dist/server/request-log.d.ts.map +0 -1
  368. package/dist/server/request-pipeline.d.ts.map +0 -1
  369. package/dist/server/worker-utils.d.ts.map +0 -1
  370. package/dist/shims/amp.d.ts.map +0 -1
  371. package/dist/shims/app.d.ts.map +0 -1
  372. package/dist/shims/app.js.map +0 -1
  373. package/dist/shims/cache-runtime.d.ts.map +0 -1
  374. package/dist/shims/cache.d.ts.map +0 -1
  375. package/dist/shims/client-only.d.ts.map +0 -1
  376. package/dist/shims/client-only.js.map +0 -1
  377. package/dist/shims/compat-router.d.ts.map +0 -1
  378. package/dist/shims/config.d.ts.map +0 -1
  379. package/dist/shims/constants.d.ts.map +0 -1
  380. package/dist/shims/document.d.ts.map +0 -1
  381. package/dist/shims/dynamic.d.ts.map +0 -1
  382. package/dist/shims/error-boundary.d.ts.map +0 -1
  383. package/dist/shims/error.d.ts.map +0 -1
  384. package/dist/shims/fetch-cache.d.ts.map +0 -1
  385. package/dist/shims/font-google-base.d.ts.map +0 -1
  386. package/dist/shims/font-google.d.ts.map +0 -1
  387. package/dist/shims/font-google.generated.d.ts.map +0 -1
  388. package/dist/shims/font-google.js.map +0 -1
  389. package/dist/shims/font-local.d.ts.map +0 -1
  390. package/dist/shims/form.d.ts.map +0 -1
  391. package/dist/shims/head-state.d.ts.map +0 -1
  392. package/dist/shims/head.d.ts.map +0 -1
  393. package/dist/shims/headers.d.ts.map +0 -1
  394. package/dist/shims/image-config.d.ts.map +0 -1
  395. package/dist/shims/image.d.ts.map +0 -1
  396. package/dist/shims/internal/api-utils.d.ts.map +0 -1
  397. package/dist/shims/internal/api-utils.js.map +0 -1
  398. package/dist/shims/internal/app-router-context.d.ts.map +0 -1
  399. package/dist/shims/internal/cookies.d.ts.map +0 -1
  400. package/dist/shims/internal/cookies.js.map +0 -1
  401. package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
  402. package/dist/shims/internal/router-context.d.ts.map +0 -1
  403. package/dist/shims/internal/utils.d.ts.map +0 -1
  404. package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
  405. package/dist/shims/layout-segment-context.d.ts.map +0 -1
  406. package/dist/shims/legacy-image.d.ts.map +0 -1
  407. package/dist/shims/link.d.ts.map +0 -1
  408. package/dist/shims/metadata.d.ts.map +0 -1
  409. package/dist/shims/navigation-state.d.ts.map +0 -1
  410. package/dist/shims/navigation.d.ts.map +0 -1
  411. package/dist/shims/og.d.ts.map +0 -1
  412. package/dist/shims/og.js.map +0 -1
  413. package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
  414. package/dist/shims/request-context.d.ts.map +0 -1
  415. package/dist/shims/router-state.d.ts.map +0 -1
  416. package/dist/shims/router.d.ts.map +0 -1
  417. package/dist/shims/script.d.ts.map +0 -1
  418. package/dist/shims/server-only.d.ts.map +0 -1
  419. package/dist/shims/server-only.js.map +0 -1
  420. package/dist/shims/server.d.ts.map +0 -1
  421. package/dist/shims/url-safety.d.ts.map +0 -1
  422. package/dist/shims/url-utils.d.ts.map +0 -1
  423. package/dist/shims/web-vitals.d.ts.map +0 -1
  424. package/dist/utils/base-path.d.ts.map +0 -1
  425. package/dist/utils/hash.d.ts.map +0 -1
  426. package/dist/utils/manifest-paths.d.ts.map +0 -1
  427. package/dist/utils/project.d.ts.map +0 -1
  428. package/dist/utils/query.d.ts.map +0 -1
@@ -1,115 +1,117 @@
1
- /**
2
- * App Router RSC entry generator.
3
- *
4
- * Generates the virtual RSC entry module for the App Router.
5
- * The RSC entry does route matching and renders the component tree,
6
- * then delegates to the SSR entry for HTML generation.
7
- *
8
- * Previously housed in server/app-dev-server.ts.
9
- */
1
+ import { isProxyFile } from "../server/middleware.js";
2
+ import { generateMiddlewareMatcherCode, generateNormalizePathCode, generateRouteMatchNormalizationCode, generateSafeRegExpCode } from "../server/middleware-codegen.js";
3
+ import { generateDevOriginCheckCode } from "../server/dev-origin-check.js";
10
4
  import fs from "node:fs";
11
5
  import { fileURLToPath } from "node:url";
12
- import { generateDevOriginCheckCode } from "../server/dev-origin-check.js";
13
- import { generateSafeRegExpCode, generateMiddlewareMatcherCode, generateNormalizePathCode, generateRouteMatchNormalizationCode, } from "../server/middleware-codegen.js";
14
- import { isProxyFile } from "../server/middleware.js";
15
- // Pre-computed absolute paths for generated-code imports. The virtual RSC
16
- // entry can't use relative imports (it has no real file location), so we
17
- // resolve these at code-generation time and embed them as absolute paths.
6
+ //#region src/entries/app-rsc-entry.ts
7
+ /**
8
+ * App Router RSC entry generator.
9
+ *
10
+ * Generates the virtual RSC entry module for the App Router.
11
+ * The RSC entry does route matching and renders the component tree,
12
+ * then delegates to the SSR entry for HTML generation.
13
+ *
14
+ * Previously housed in server/app-dev-server.ts.
15
+ */
18
16
  const configMatchersPath = fileURLToPath(new URL("../config/config-matchers.js", import.meta.url)).replace(/\\/g, "/");
19
17
  const requestPipelinePath = fileURLToPath(new URL("../server/request-pipeline.js", import.meta.url)).replace(/\\/g, "/");
20
18
  const requestContextShimPath = fileURLToPath(new URL("../shims/request-context.js", import.meta.url)).replace(/\\/g, "/");
21
19
  const routeTriePath = fileURLToPath(new URL("../routing/route-trie.js", import.meta.url)).replace(/\\/g, "/");
20
+ const routeHandlerHelperCode = String.raw`
21
+ // Duplicated from the build-time constant above via JSON.stringify.
22
+ const ROUTE_HANDLER_HTTP_METHODS = ${JSON.stringify([
23
+ "GET",
24
+ "HEAD",
25
+ "POST",
26
+ "PUT",
27
+ "DELETE",
28
+ "PATCH",
29
+ "OPTIONS"
30
+ ])};
31
+
32
+ function collectRouteHandlerMethods(handler) {
33
+ const methods = ROUTE_HANDLER_HTTP_METHODS.filter((method) => typeof handler[method] === "function");
34
+ if (methods.includes("GET") && !methods.includes("HEAD")) {
35
+ methods.push("HEAD");
36
+ }
37
+ return methods;
38
+ }
39
+
40
+ function buildRouteHandlerAllowHeader(exportedMethods) {
41
+ const allow = new Set(exportedMethods);
42
+ allow.add("OPTIONS");
43
+ return Array.from(allow).sort().join(", ");
44
+ }
45
+ `;
22
46
  /**
23
- * Generate the virtual RSC entry module.
24
- *
25
- * This runs in the `rsc` Vite environment (react-server condition).
26
- * It matches the incoming request URL to an app route, builds the
27
- * nested layout + page tree, and renders it to an RSC stream.
28
- */
29
- export function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes, globalErrorPath, basePath, trailingSlash, config, instrumentationPath) {
30
- const bp = basePath ?? "";
31
- const ts = trailingSlash ?? false;
32
- const redirects = config?.redirects ?? [];
33
- const rewrites = config?.rewrites ?? { beforeFiles: [], afterFiles: [], fallback: [] };
34
- const headers = config?.headers ?? [];
35
- const allowedOrigins = config?.allowedOrigins ?? [];
36
- const bodySizeLimit = config?.bodySizeLimit ?? 1 * 1024 * 1024;
37
- const i18nConfig = config?.i18n ?? null;
38
- // Build import map for all page and layout files
39
- const imports = [];
40
- const importMap = new Map();
41
- let importIdx = 0;
42
- function getImportVar(filePath) {
43
- if (importMap.has(filePath))
44
- return importMap.get(filePath);
45
- const varName = `mod_${importIdx++}`;
46
- const absPath = filePath.replace(/\\/g, "/");
47
- imports.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
48
- importMap.set(filePath, varName);
49
- return varName;
50
- }
51
- // Pre-register all modules
52
- for (const route of routes) {
53
- if (route.pagePath)
54
- getImportVar(route.pagePath);
55
- if (route.routePath)
56
- getImportVar(route.routePath);
57
- for (const layout of route.layouts)
58
- getImportVar(layout);
59
- for (const tmpl of route.templates)
60
- getImportVar(tmpl);
61
- if (route.loadingPath)
62
- getImportVar(route.loadingPath);
63
- if (route.errorPath)
64
- getImportVar(route.errorPath);
65
- if (route.layoutErrorPaths)
66
- for (const ep of route.layoutErrorPaths) {
67
- if (ep)
68
- getImportVar(ep);
69
- }
70
- if (route.notFoundPath)
71
- getImportVar(route.notFoundPath);
72
- for (const nfp of route.notFoundPaths || []) {
73
- if (nfp)
74
- getImportVar(nfp);
75
- }
76
- if (route.forbiddenPath)
77
- getImportVar(route.forbiddenPath);
78
- if (route.unauthorizedPath)
79
- getImportVar(route.unauthorizedPath);
80
- // Register parallel slot modules
81
- for (const slot of route.parallelSlots) {
82
- if (slot.pagePath)
83
- getImportVar(slot.pagePath);
84
- if (slot.defaultPath)
85
- getImportVar(slot.defaultPath);
86
- if (slot.layoutPath)
87
- getImportVar(slot.layoutPath);
88
- if (slot.loadingPath)
89
- getImportVar(slot.loadingPath);
90
- if (slot.errorPath)
91
- getImportVar(slot.errorPath);
92
- // Register intercepting route page modules
93
- for (const ir of slot.interceptingRoutes) {
94
- getImportVar(ir.pagePath);
95
- }
96
- }
97
- }
98
- // Build route table as serialized JS
99
- const routeEntries = routes.map((route) => {
100
- const layoutVars = route.layouts.map((l) => getImportVar(l));
101
- const templateVars = route.templates.map((t) => getImportVar(t));
102
- const notFoundVars = (route.notFoundPaths || []).map((nf) => (nf ? getImportVar(nf) : "null"));
103
- const slotEntries = route.parallelSlots.map((slot) => {
104
- const interceptEntries = slot.interceptingRoutes.map((ir) => {
105
- return ` {
47
+ * Generate the virtual RSC entry module.
48
+ *
49
+ * This runs in the `rsc` Vite environment (react-server condition).
50
+ * It matches the incoming request URL to an app route, builds the
51
+ * nested layout + page tree, and renders it to an RSC stream.
52
+ */
53
+ function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes, globalErrorPath, basePath, trailingSlash, config, instrumentationPath) {
54
+ const bp = basePath ?? "";
55
+ const ts = trailingSlash ?? false;
56
+ const redirects = config?.redirects ?? [];
57
+ const rewrites = config?.rewrites ?? {
58
+ beforeFiles: [],
59
+ afterFiles: [],
60
+ fallback: []
61
+ };
62
+ const headers = config?.headers ?? [];
63
+ const allowedOrigins = config?.allowedOrigins ?? [];
64
+ const bodySizeLimit = config?.bodySizeLimit ?? 1 * 1024 * 1024;
65
+ const i18nConfig = config?.i18n ?? null;
66
+ const hasPagesDir = config?.hasPagesDir ?? false;
67
+ const imports = [];
68
+ const importMap = /* @__PURE__ */ new Map();
69
+ let importIdx = 0;
70
+ function getImportVar(filePath) {
71
+ if (importMap.has(filePath)) return importMap.get(filePath);
72
+ const varName = `mod_${importIdx++}`;
73
+ const absPath = filePath.replace(/\\/g, "/");
74
+ imports.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
75
+ importMap.set(filePath, varName);
76
+ return varName;
77
+ }
78
+ for (const route of routes) {
79
+ if (route.pagePath) getImportVar(route.pagePath);
80
+ if (route.routePath) getImportVar(route.routePath);
81
+ for (const layout of route.layouts) getImportVar(layout);
82
+ for (const tmpl of route.templates) getImportVar(tmpl);
83
+ if (route.loadingPath) getImportVar(route.loadingPath);
84
+ if (route.errorPath) getImportVar(route.errorPath);
85
+ if (route.layoutErrorPaths) {
86
+ for (const ep of route.layoutErrorPaths) if (ep) getImportVar(ep);
87
+ }
88
+ if (route.notFoundPath) getImportVar(route.notFoundPath);
89
+ for (const nfp of route.notFoundPaths || []) if (nfp) getImportVar(nfp);
90
+ if (route.forbiddenPath) getImportVar(route.forbiddenPath);
91
+ if (route.unauthorizedPath) getImportVar(route.unauthorizedPath);
92
+ for (const slot of route.parallelSlots) {
93
+ if (slot.pagePath) getImportVar(slot.pagePath);
94
+ if (slot.defaultPath) getImportVar(slot.defaultPath);
95
+ if (slot.layoutPath) getImportVar(slot.layoutPath);
96
+ if (slot.loadingPath) getImportVar(slot.loadingPath);
97
+ if (slot.errorPath) getImportVar(slot.errorPath);
98
+ for (const ir of slot.interceptingRoutes) getImportVar(ir.pagePath);
99
+ }
100
+ }
101
+ const routeEntries = routes.map((route) => {
102
+ const layoutVars = route.layouts.map((l) => getImportVar(l));
103
+ const templateVars = route.templates.map((t) => getImportVar(t));
104
+ const notFoundVars = (route.notFoundPaths || []).map((nf) => nf ? getImportVar(nf) : "null");
105
+ const slotEntries = route.parallelSlots.map((slot) => {
106
+ const interceptEntries = slot.interceptingRoutes.map((ir) => {
107
+ return ` {
106
108
  convention: ${JSON.stringify(ir.convention)},
107
109
  targetPattern: ${JSON.stringify(ir.targetPattern)},
108
110
  page: ${getImportVar(ir.pagePath)},
109
111
  params: ${JSON.stringify(ir.params)},
110
112
  }`;
111
- });
112
- return ` ${JSON.stringify(slot.name)}: {
113
+ });
114
+ return ` ${JSON.stringify(slot.name)}: {
113
115
  page: ${slot.pagePath ? getImportVar(slot.pagePath) : "null"},
114
116
  default: ${slot.defaultPath ? getImportVar(slot.defaultPath) : "null"},
115
117
  layout: ${slot.layoutPath ? getImportVar(slot.layoutPath) : "null"},
@@ -120,9 +122,9 @@ export function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes,
120
122
  ${interceptEntries.join(",\n")}
121
123
  ],
122
124
  }`;
123
- });
124
- const layoutErrorVars = (route.layoutErrorPaths || []).map((ep) => ep ? getImportVar(ep) : "null");
125
- return ` {
125
+ });
126
+ const layoutErrorVars = (route.layoutErrorPaths || []).map((ep) => ep ? getImportVar(ep) : "null");
127
+ return ` {
126
128
  pattern: ${JSON.stringify(route.pattern)},
127
129
  patternParts: ${JSON.stringify(route.patternParts)},
128
130
  isDynamic: ${route.isDynamic},
@@ -144,66 +146,83 @@ ${slotEntries.join(",\n")}
144
146
  forbidden: ${route.forbiddenPath ? getImportVar(route.forbiddenPath) : "null"},
145
147
  unauthorized: ${route.unauthorizedPath ? getImportVar(route.unauthorizedPath) : "null"},
146
148
  }`;
147
- });
148
- // Find root not-found/forbidden/unauthorized pages and root layouts for global error handling
149
- const rootRoute = routes.find((r) => r.pattern === "/");
150
- const rootNotFoundVar = rootRoute?.notFoundPath ? getImportVar(rootRoute.notFoundPath) : null;
151
- const rootForbiddenVar = rootRoute?.forbiddenPath ? getImportVar(rootRoute.forbiddenPath) : null;
152
- const rootUnauthorizedVar = rootRoute?.unauthorizedPath
153
- ? getImportVar(rootRoute.unauthorizedPath)
154
- : null;
155
- const rootLayoutVars = rootRoute ? rootRoute.layouts.map((l) => getImportVar(l)) : [];
156
- // Global error boundary (app/global-error.tsx)
157
- const globalErrorVar = globalErrorPath ? getImportVar(globalErrorPath) : null;
158
- // Build metadata route handling
159
- const effectiveMetaRoutes = metadataRoutes ?? [];
160
- const dynamicMetaRoutes = effectiveMetaRoutes.filter((r) => r.isDynamic);
161
- // Import dynamic metadata modules
162
- for (const mr of dynamicMetaRoutes) {
163
- getImportVar(mr.filePath);
164
- }
165
- // Build metadata route table
166
- // For static metadata files, read the file content at code-generation time
167
- // and embed it as base64. This ensures static metadata files work on runtimes
168
- // without filesystem access (e.g., Cloudflare Workers).
169
- const metaRouteEntries = effectiveMetaRoutes.map((mr) => {
170
- if (mr.isDynamic) {
171
- return ` {
149
+ });
150
+ const rootRoute = routes.find((r) => r.pattern === "/");
151
+ const rootNotFoundVar = rootRoute?.notFoundPath ? getImportVar(rootRoute.notFoundPath) : null;
152
+ const rootForbiddenVar = rootRoute?.forbiddenPath ? getImportVar(rootRoute.forbiddenPath) : null;
153
+ const rootUnauthorizedVar = rootRoute?.unauthorizedPath ? getImportVar(rootRoute.unauthorizedPath) : null;
154
+ const rootLayoutVars = rootRoute ? rootRoute.layouts.map((l) => getImportVar(l)) : [];
155
+ const globalErrorVar = globalErrorPath ? getImportVar(globalErrorPath) : null;
156
+ const effectiveMetaRoutes = metadataRoutes ?? [];
157
+ const dynamicMetaRoutes = effectiveMetaRoutes.filter((r) => r.isDynamic);
158
+ for (const mr of dynamicMetaRoutes) getImportVar(mr.filePath);
159
+ const metaRouteEntries = effectiveMetaRoutes.map((mr) => {
160
+ const patternParts = mr.isDynamic && mr.servedUrl.includes("[") ? JSON.stringify(mr.servedUrl.split("/").filter(Boolean).map((seg) => {
161
+ if (seg.startsWith("[[...") && seg.endsWith("]]")) return ":" + seg.slice(5, -2) + "*";
162
+ if (seg.startsWith("[...") && seg.endsWith("]")) return ":" + seg.slice(4, -1) + "+";
163
+ if (seg.startsWith("[") && seg.endsWith("]")) return ":" + seg.slice(1, -1);
164
+ return seg;
165
+ })) : null;
166
+ if (mr.isDynamic) return ` {
172
167
  type: ${JSON.stringify(mr.type)},
173
168
  isDynamic: true,
174
169
  servedUrl: ${JSON.stringify(mr.servedUrl)},
175
170
  contentType: ${JSON.stringify(mr.contentType)},
176
- module: ${getImportVar(mr.filePath)},
171
+ module: ${getImportVar(mr.filePath)},${patternParts ? `\n patternParts: ${patternParts},` : ""}
177
172
  }`;
178
- }
179
- // Static: read file and embed as base64
180
- let fileDataBase64 = "";
181
- try {
182
- const buf = fs.readFileSync(mr.filePath);
183
- fileDataBase64 = buf.toString("base64");
184
- }
185
- catch {
186
- // File unreadable — will serve empty response at runtime
187
- }
188
- return ` {
173
+ let fileDataBase64 = "";
174
+ try {
175
+ fileDataBase64 = fs.readFileSync(mr.filePath).toString("base64");
176
+ } catch {}
177
+ return ` {
189
178
  type: ${JSON.stringify(mr.type)},
190
179
  isDynamic: false,
191
180
  servedUrl: ${JSON.stringify(mr.servedUrl)},
192
181
  contentType: ${JSON.stringify(mr.contentType)},
193
182
  fileDataBase64: ${JSON.stringify(fileDataBase64)},
194
183
  }`;
195
- });
196
- return `
184
+ });
185
+ return `
197
186
  import {
198
- renderToReadableStream,
187
+ renderToReadableStream as _renderToReadableStream,
199
188
  decodeReply,
200
189
  loadServerAction,
201
190
  createTemporaryReferenceSet,
202
191
  } from "@vitejs/plugin-rsc/rsc";
203
192
  import { AsyncLocalStorage } from "node:async_hooks";
193
+
194
+ // React Flight emits HL hints with "stylesheet" for CSS, but the HTML spec
195
+ // requires "style" for <link rel="preload">. Fix at the source so every
196
+ // consumer (SSR embed, client-side navigation, server actions) gets clean data.
197
+ //
198
+ // Flight lines are newline-delimited, so we buffer partial lines across chunks
199
+ // to guarantee the regex never sees a split hint.
200
+ function renderToReadableStream(model, options) {
201
+ const _hlFixRe = /(\\d+:HL\\[.*?),"stylesheet"(\\]|,)/g;
202
+ const stream = _renderToReadableStream(model, options);
203
+ const decoder = new TextDecoder();
204
+ const encoder = new TextEncoder();
205
+ let carry = "";
206
+ return stream.pipeThrough(new TransformStream({
207
+ transform(chunk, controller) {
208
+ const text = carry + decoder.decode(chunk, { stream: true });
209
+ const lastNl = text.lastIndexOf("\\n");
210
+ if (lastNl === -1) {
211
+ carry = text;
212
+ return;
213
+ }
214
+ carry = text.slice(lastNl + 1);
215
+ controller.enqueue(encoder.encode(text.slice(0, lastNl + 1).replace(_hlFixRe, '$1,"style"$2')));
216
+ },
217
+ flush(controller) {
218
+ const text = carry + decoder.decode();
219
+ if (text) controller.enqueue(encoder.encode(text.replace(_hlFixRe, '$1,"style"$2')));
220
+ }
221
+ }));
222
+ }
204
223
  import { createElement, Suspense, Fragment } from "react";
205
224
  import { setNavigationContext as _setNavigationContextOrig, getNavigationContext as _getNavigationContext } from "next/navigation";
206
- import { setHeadersContext, headersContextFromRequest, getDraftModeCookieHeader, getAndClearPendingCookies, consumeDynamicUsage, markDynamicUsage, runWithHeadersContext, applyMiddlewareRequestHeaders, getHeadersContext, setHeadersAccessPhase } from "next/headers";
225
+ import { setHeadersContext, headersContextFromRequest, getDraftModeCookieHeader, getAndClearPendingCookies, consumeDynamicUsage, markDynamicUsage, applyMiddlewareRequestHeaders, getHeadersContext, setHeadersAccessPhase } from "next/headers";
207
226
  import { NextRequest, NextFetchEvent } from "next/server";
208
227
  import { ErrorBoundary, NotFoundBoundary } from "vinext/error-boundary";
209
228
  import { LayoutSegmentProvider } from "vinext/layout-segment-context";
@@ -213,18 +232,20 @@ ${instrumentationPath ? `import * as _instrumentation from ${JSON.stringify(inst
213
232
  ${effectiveMetaRoutes.length > 0 ? `import { sitemapToXml, robotsToText, manifestToJson } from ${JSON.stringify(fileURLToPath(new URL("../server/metadata-routes.js", import.meta.url)).replace(/\\/g, "/"))};` : ""}
214
233
  import { requestContextFromRequest, normalizeHost, matchRedirect, matchRewrite, matchHeaders, isExternalUrl, proxyExternalRequest, sanitizeDestination } from ${JSON.stringify(configMatchersPath)};
215
234
  import { validateCsrfOrigin, validateImageUrl, guardProtocolRelativeUrl, hasBasePath, stripBasePath, normalizeTrailingSlash, processMiddlewareHeaders } from ${JSON.stringify(requestPipelinePath)};
216
- import { _consumeRequestScopedCacheLife, _runWithCacheState, getCacheHandler } from "next/cache";
217
- import { runWithExecutionContext as _runWithExecutionContext, getRequestExecutionContext as _getRequestExecutionContext } from ${JSON.stringify(requestContextShimPath)};
218
- import { getCollectedFetchTags, runWithFetchCache } from "vinext/fetch-cache";
235
+ import { _consumeRequestScopedCacheLife, getCacheHandler } from "next/cache";
236
+ import { getRequestExecutionContext as _getRequestExecutionContext } from ${JSON.stringify(requestContextShimPath)};
237
+ import { ensureFetchPatch as _ensureFetchPatch, getCollectedFetchTags } from "vinext/fetch-cache";
219
238
  import { buildRouteTrie as _buildRouteTrie, trieMatch as _trieMatch } from ${JSON.stringify(routeTriePath)};
220
- import { runWithPrivateCache as _runWithPrivateCache } from "vinext/cache-runtime";
221
239
  // Import server-only state module to register ALS-backed accessors.
222
- import { runWithNavigationContext as _runWithNavigationContext } from "vinext/navigation-state";
240
+ import "vinext/navigation-state";
241
+ import { runWithRequestContext as _runWithUnifiedCtx, createRequestContext as _createUnifiedCtx } from "vinext/unified-request-context";
223
242
  import { reportRequestError as _reportRequestError } from "vinext/instrumentation";
224
243
  import { getSSRFontLinks as _getSSRFontLinks, getSSRFontStyles as _getSSRFontStylesGoogle, getSSRFontPreloads as _getSSRFontPreloadsGoogle } from "next/font/google";
225
244
  import { getSSRFontStyles as _getSSRFontStylesLocal, getSSRFontPreloads as _getSSRFontPreloadsLocal } from "next/font/local";
226
245
  function _getSSRFontStyles() { return [..._getSSRFontStylesGoogle(), ..._getSSRFontStylesLocal()]; }
227
246
  function _getSSRFontPreloads() { return [..._getSSRFontPreloadsGoogle(), ..._getSSRFontPreloadsLocal()]; }
247
+ ${hasPagesDir ? `// Note: pageRoutes loaded lazily via SSR env in /__vinext/prerender/pages-static-paths handler` : ""}
248
+ ${routeHandlerHelperCode}
228
249
 
229
250
  // ALS used to suppress the expected "Invalid hook call" dev warning when
230
251
  // layout/page components are probed outside React's render cycle. Patching
@@ -270,6 +291,18 @@ async function __isrSet(key, data, revalidateSeconds, tags) {
270
291
  }
271
292
  function __pageCacheTags(pathname, extraTags) {
272
293
  const tags = [pathname, "_N_T_" + pathname];
294
+ // Layout hierarchy tags — matches Next.js getDerivedTags.
295
+ tags.push("_N_T_/layout");
296
+ const segments = pathname.split("/");
297
+ let built = "";
298
+ for (let i = 1; i < segments.length; i++) {
299
+ if (segments[i]) {
300
+ built += "/" + segments[i];
301
+ tags.push("_N_T_" + built + "/layout");
302
+ }
303
+ }
304
+ // Leaf page tag — revalidatePath(path, "page") targets this.
305
+ tags.push("_N_T_" + built + "/page");
273
306
  if (Array.isArray(extraTags)) {
274
307
  for (const tag of extraTags) {
275
308
  if (!tags.includes(tag)) tags.push(tag);
@@ -334,6 +367,7 @@ function __isrCacheKey(pathname, suffix) {
334
367
  }
335
368
  function __isrHtmlKey(pathname) { return __isrCacheKey(pathname, "html"); }
336
369
  function __isrRscKey(pathname) { return __isrCacheKey(pathname, "rsc"); }
370
+ function __isrRouteKey(pathname) { return __isrCacheKey(pathname, "route"); }
337
371
  // Verbose cache logging — opt in with NEXT_PRIVATE_DEBUG_CACHE=1.
338
372
  // Matches the env var Next.js uses for its own cache debug output so operators
339
373
  // have a single knob for all cache tracing.
@@ -516,8 +550,7 @@ function createRscOnErrorHandler(request, pathname, routePath) {
516
550
 
517
551
  ${imports.join("\n")}
518
552
 
519
- ${instrumentationPath
520
- ? `// Run instrumentation register() exactly once, lazily on the first request.
553
+ ${instrumentationPath ? `// Run instrumentation register() exactly once, lazily on the first request.
521
554
  // Previously this was a top-level await, which blocked the entire module graph
522
555
  // from finishing initialization until register() resolved — adding that latency
523
556
  // to every cold start. Moving it here preserves the "runs before any request is
@@ -528,6 +561,7 @@ ${instrumentationPath
528
561
  let __instrumentationInitialized = false;
529
562
  let __instrumentationInitPromise = null;
530
563
  async function __ensureInstrumentation() {
564
+ if (process.env.VINEXT_PRERENDER === "1") return;
531
565
  if (__instrumentationInitialized) return;
532
566
  if (__instrumentationInitPromise) return __instrumentationInitPromise;
533
567
  __instrumentationInitPromise = (async () => {
@@ -546,8 +580,7 @@ async function __ensureInstrumentation() {
546
580
  __instrumentationInitialized = true;
547
581
  })();
548
582
  return __instrumentationInitPromise;
549
- }`
550
- : ""}
583
+ }` : ""}
551
584
 
552
585
  const routes = [
553
586
  ${routeEntries.join(",\n")}
@@ -644,8 +677,7 @@ async function renderHTTPAccessFallbackPage(route, statusCode, isRscRequest, req
644
677
  element = createElement(LayoutSegmentProvider, { childSegments: _cs }, element);
645
678
  }
646
679
  }
647
- ${globalErrorVar
648
- ? `
680
+ ${globalErrorVar ? `
649
681
  const _GlobalErrorComponent = ${globalErrorVar}.default;
650
682
  if (_GlobalErrorComponent) {
651
683
  element = createElement(ErrorBoundary, {
@@ -653,8 +685,7 @@ async function renderHTTPAccessFallbackPage(route, statusCode, isRscRequest, req
653
685
  children: element,
654
686
  });
655
687
  }
656
- `
657
- : ""}
688
+ ` : ""}
658
689
  const _pathname = new URL(request.url).pathname;
659
690
  const onRenderError = createRscOnErrorHandler(
660
691
  request,
@@ -667,7 +698,7 @@ async function renderHTTPAccessFallbackPage(route, statusCode, isRscRequest, req
667
698
  // that run during stream consumption to see null headers/navigation context and throw,
668
699
  // resulting in missing provider context on the client (e.g. next-intl useTranslations fails
669
700
  // with "context from NextIntlClientProvider was not found").
670
- // Context is cleared naturally when the ALS scope from runWithHeadersContext unwinds.
701
+ // Context is cleared naturally when the ALS scope from runWithRequestContext unwinds.
671
702
  return new Response(rscStream, {
672
703
  status: statusCode,
673
704
  headers: { "Content-Type": "text/x-component; charset=utf-8", "Vary": "RSC, Accept" },
@@ -734,14 +765,12 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
734
765
  }
735
766
  }
736
767
  }
737
- ${globalErrorVar
738
- ? `
768
+ ${globalErrorVar ? `
739
769
  if (!ErrorComponent) {
740
770
  ErrorComponent = ${globalErrorVar}?.default ?? null;
741
771
  _isGlobalError = !!ErrorComponent;
742
772
  }
743
- `
744
- : ""}
773
+ ` : ""}
745
774
  if (!ErrorComponent) return null;
746
775
 
747
776
  const rawError = error instanceof Error ? error : new Error(String(error));
@@ -779,8 +808,7 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
779
808
  element = createElement(LayoutSegmentProvider, { childSegments: _ecs }, element);
780
809
  }
781
810
  }
782
- ${globalErrorVar
783
- ? `
811
+ ${globalErrorVar ? `
784
812
  const _ErrGlobalComponent = ${globalErrorVar}.default;
785
813
  if (_ErrGlobalComponent) {
786
814
  element = createElement(ErrorBoundary, {
@@ -788,8 +816,7 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
788
816
  children: element,
789
817
  });
790
818
  }
791
- `
792
- : ""}
819
+ ` : ""}
793
820
  } else {
794
821
  // For HTML (full page load) responses, wrap with layouts only.
795
822
  const _errParamsHtml = matchedParams ?? route?.params ?? {};
@@ -817,7 +844,7 @@ async function renderErrorBoundaryPage(route, error, isRscRequest, request, matc
817
844
  // that run during stream consumption to see null headers/navigation context and throw,
818
845
  // resulting in missing provider context on the client (e.g. next-intl useTranslations fails
819
846
  // with "context from NextIntlClientProvider was not found").
820
- // Context is cleared naturally when the ALS scope from runWithHeadersContext unwinds.
847
+ // Context is cleared naturally when the ALS scope from runWithRequestContext unwinds.
821
848
  return new Response(rscStream, {
822
849
  status: 200,
823
850
  headers: { "Content-Type": "text/x-component; charset=utf-8", "Vary": "RSC, Accept" },
@@ -1199,8 +1226,7 @@ async function buildPageElement(route, params, opts, searchParams) {
1199
1226
  // For HTML requests (initial page load), the ErrorBoundary catches during SSR
1200
1227
  // but produces double <html>/<body> (root layout + global-error). The request
1201
1228
  // handler detects this via the rscOnError flag and re-renders without layouts.
1202
- ${globalErrorVar
1203
- ? `
1229
+ ${globalErrorVar ? `
1204
1230
  const GlobalErrorComponent = ${globalErrorVar}.default;
1205
1231
  if (GlobalErrorComponent) {
1206
1232
  element = createElement(ErrorBoundary, {
@@ -1208,8 +1234,7 @@ async function buildPageElement(route, params, opts, searchParams) {
1208
1234
  children: element,
1209
1235
  });
1210
1236
  }
1211
- `
1212
- : ""}
1237
+ ` : ""}
1213
1238
 
1214
1239
  return element;
1215
1240
  }
@@ -1328,67 +1353,67 @@ async function __readFormDataWithLimit(request, maxBytes) {
1328
1353
  return new Response(combined, { headers: { "Content-Type": contentType } }).formData();
1329
1354
  }
1330
1355
 
1356
+ // Map from route pattern to generateStaticParams function.
1357
+ // Used by the prerender phase to enumerate dynamic route URLs without
1358
+ // loading route modules via the dev server.
1359
+ export const generateStaticParamsMap = {
1360
+ // TODO: layout-level generateStaticParams — this map only includes routes that
1361
+ // have a pagePath (leaf pages). Layout segments can also export generateStaticParams
1362
+ // to provide parent params for nested dynamic routes, but they don't have a pagePath
1363
+ // so they are excluded here. Supporting layout-level generateStaticParams requires
1364
+ // scanning layout.tsx files separately and including them in this map.
1365
+ ${routes.filter((r) => r.isDynamic && r.pagePath).map((r) => ` ${JSON.stringify(r.pattern)}: ${getImportVar(r.pagePath)}?.generateStaticParams ?? null,`).join("\n")}
1366
+ };
1367
+
1331
1368
  export default async function handler(request, ctx) {
1332
- ${instrumentationPath
1333
- ? `// Ensure instrumentation.register() has run before handling the first request.
1369
+ ${instrumentationPath ? `// Ensure instrumentation.register() has run before handling the first request.
1334
1370
  // This is a no-op after the first call (guarded by __instrumentationInitialized).
1335
1371
  await __ensureInstrumentation();
1336
- `
1337
- : ""}
1338
- // Wrap the entire request in nested AsyncLocalStorage.run() scopes to ensure
1339
- // per-request isolation for all state modules. Each runWith*() creates an
1340
- // ALS scope that propagates through all async continuations (including RSC
1341
- // streaming), preventing state leakage between concurrent requests on
1342
- // Cloudflare Workers and other concurrent runtimes.
1343
- //
1344
- // runWithExecutionContext stores the Workers ExecutionContext (ctx) in ALS so
1345
- // that KVCacheHandler._putInBackground can register background KV puts with
1346
- // ctx.waitUntil() without needing ctx passed at construction time.
1372
+ ` : ""}
1373
+ // Wrap the entire request in a single unified ALS scope for per-request
1374
+ // isolation. All state modules (headers, navigation, cache, fetch-cache,
1375
+ // execution-context) read from this store via isInsideUnifiedScope().
1347
1376
  const headersCtx = headersContextFromRequest(request);
1348
- const _run = () => runWithHeadersContext(headersCtx, () =>
1349
- _runWithNavigationContext(() =>
1350
- _runWithCacheState(() =>
1351
- _runWithPrivateCache(() =>
1352
- runWithFetchCache(async () => {
1353
- const __reqCtx = requestContextFromRequest(request);
1354
- // Per-request container for middleware state. Passed into
1355
- // _handleRequest which fills in .headers and .status;
1356
- // avoids module-level variables that race on Workers.
1357
- const _mwCtx = { headers: null, status: null };
1358
- const response = await _handleRequest(request, __reqCtx, _mwCtx);
1359
- // Apply custom headers from next.config.js to non-redirect responses.
1360
- // Skip redirects (3xx) because Response.redirect() creates immutable headers,
1361
- // and Next.js doesn't apply custom headers to redirects anyway.
1362
- if (response && response.headers && !(response.status >= 300 && response.status < 400)) {
1363
- if (__configHeaders.length) {
1364
- const url = new URL(request.url);
1365
- let pathname;
1366
- try { pathname = __normalizePath(__normalizePathnameForRouteMatch(url.pathname)); } catch { pathname = url.pathname; }
1367
- ${bp ? `if (pathname.startsWith(${JSON.stringify(bp)})) pathname = pathname.slice(${JSON.stringify(bp)}.length) || "/";` : ""}
1368
- const extraHeaders = matchHeaders(pathname, __configHeaders, __reqCtx);
1369
- for (const h of extraHeaders) {
1370
- // Use append() for headers where multiple values must coexist
1371
- // (Vary, Set-Cookie). Using set() on these would destroy
1372
- // existing values like "Vary: RSC, Accept" which are critical
1373
- // for correct CDN caching behavior.
1374
- const lk = h.key.toLowerCase();
1375
- if (lk === "vary" || lk === "set-cookie") {
1376
- response.headers.append(h.key, h.value);
1377
- } else if (!response.headers.has(lk)) {
1378
- // Middleware headers take precedence: skip config keys already
1379
- // set by middleware so middleware headers always win.
1380
- response.headers.set(h.key, h.value);
1381
- }
1382
- }
1383
- }
1384
- }
1385
- return response;
1386
- })
1387
- )
1388
- )
1389
- )
1390
- );
1391
- return ctx ? _runWithExecutionContext(ctx, _run) : _run();
1377
+ const __uCtx = _createUnifiedCtx({
1378
+ headersContext: headersCtx,
1379
+ executionContext: ctx ?? _getRequestExecutionContext() ?? null,
1380
+ });
1381
+ return _runWithUnifiedCtx(__uCtx, async () => {
1382
+ _ensureFetchPatch();
1383
+ const __reqCtx = requestContextFromRequest(request);
1384
+ // Per-request container for middleware state. Passed into
1385
+ // _handleRequest which fills in .headers and .status;
1386
+ // avoids module-level variables that race on Workers.
1387
+ const _mwCtx = { headers: null, status: null };
1388
+ const response = await _handleRequest(request, __reqCtx, _mwCtx);
1389
+ // Apply custom headers from next.config.js to non-redirect responses.
1390
+ // Skip redirects (3xx) because Response.redirect() creates immutable headers,
1391
+ // and Next.js doesn't apply custom headers to redirects anyway.
1392
+ if (response && response.headers && !(response.status >= 300 && response.status < 400)) {
1393
+ if (__configHeaders.length) {
1394
+ const url = new URL(request.url);
1395
+ let pathname;
1396
+ try { pathname = __normalizePath(__normalizePathnameForRouteMatch(url.pathname)); } catch { pathname = url.pathname; }
1397
+ ${bp ? `if (pathname.startsWith(${JSON.stringify(bp)})) pathname = pathname.slice(${JSON.stringify(bp)}.length) || "/";` : ""}
1398
+ const extraHeaders = matchHeaders(pathname, __configHeaders, __reqCtx);
1399
+ for (const h of extraHeaders) {
1400
+ // Use append() for headers where multiple values must coexist
1401
+ // (Vary, Set-Cookie). Using set() on these would destroy
1402
+ // existing values like "Vary: RSC, Accept" which are critical
1403
+ // for correct CDN caching behavior.
1404
+ const lk = h.key.toLowerCase();
1405
+ if (lk === "vary" || lk === "set-cookie") {
1406
+ response.headers.append(h.key, h.value);
1407
+ } else if (!response.headers.has(lk)) {
1408
+ // Middleware headers take precedence: skip config keys already
1409
+ // set by middleware so middleware headers always win.
1410
+ response.headers.set(h.key, h.value);
1411
+ }
1412
+ }
1413
+ }
1414
+ }
1415
+ return response;
1416
+ });
1392
1417
  }
1393
1418
 
1394
1419
  async function _handleRequest(request, __reqCtx, _mwCtx) {
@@ -1421,12 +1446,79 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1421
1446
  }
1422
1447
  let pathname = __normalizePath(decodedUrlPathname);
1423
1448
 
1424
- ${bp
1425
- ? `
1449
+ ${bp ? `
1426
1450
  // Strip basePath prefix
1427
1451
  pathname = stripBasePath(pathname, __basePath);
1428
- `
1429
- : ""}
1452
+ ` : ""}
1453
+
1454
+ // ── Prerender: static-params endpoint ────────────────────────────────
1455
+ // Internal endpoint used by prerenderApp() during build to fetch
1456
+ // generateStaticParams results via wrangler unstable_startWorker.
1457
+ // Gated on VINEXT_PRERENDER=1 to prevent exposure in normal deployments.
1458
+ // For Node builds, process.env.VINEXT_PRERENDER is set directly by the
1459
+ // prerender orchestrator. For CF Workers builds, wrangler unstable_startWorker
1460
+ // injects VINEXT_PRERENDER as a binding which Miniflare exposes via process.env
1461
+ // in bundled workers. The /__vinext/ prefix ensures no user route ever conflicts.
1462
+ if (pathname === "/__vinext/prerender/static-params") {
1463
+ if (process.env.VINEXT_PRERENDER !== "1") {
1464
+ return new Response("Not Found", { status: 404 });
1465
+ }
1466
+ const pattern = url.searchParams.get("pattern");
1467
+ if (!pattern) return new Response("missing pattern", { status: 400 });
1468
+ const fn = generateStaticParamsMap[pattern];
1469
+ if (typeof fn !== "function") return new Response("null", { status: 200, headers: { "content-type": "application/json" } });
1470
+ try {
1471
+ const parentParams = url.searchParams.get("parentParams");
1472
+ const raw = parentParams ? JSON.parse(parentParams) : {};
1473
+ // Ensure params is a plain object — reject primitives, arrays, and null
1474
+ // so user-authored generateStaticParams always receives { params: {} }
1475
+ // rather than { params: 5 } or similar if input is malformed.
1476
+ const params = (typeof raw === "object" && raw !== null && !Array.isArray(raw)) ? raw : {};
1477
+ const result = await fn({ params });
1478
+ return new Response(JSON.stringify(result), { status: 200, headers: { "content-type": "application/json" } });
1479
+ } catch (e) {
1480
+ return new Response(JSON.stringify({ error: String(e) }), { status: 500, headers: { "content-type": "application/json" } });
1481
+ }
1482
+ }
1483
+
1484
+ ${hasPagesDir ? `
1485
+ // ── Prerender: pages-static-paths endpoint ───────────────────────────
1486
+ // Internal endpoint used by prerenderPages() during a CF Workers hybrid
1487
+ // build to call getStaticPaths() for dynamic Pages Router routes via
1488
+ // wrangler unstable_startWorker. Returns JSON-serialised getStaticPaths result.
1489
+ // Gated on VINEXT_PRERENDER=1 to prevent exposure in normal deployments.
1490
+ // See static-params endpoint above for process.env vs CF vars notes.
1491
+ //
1492
+ // pageRoutes lives in the SSR environment (virtual:vinext-server-entry).
1493
+ // We load it lazily via import.meta.viteRsc.loadModule — the same pattern
1494
+ // used by handleSsr() elsewhere in this template. At build time, Vite's RSC
1495
+ // plugin transforms this call into a bundled cross-environment import, so it
1496
+ // works correctly in the CF Workers production bundle running in Miniflare.
1497
+ if (pathname === "/__vinext/prerender/pages-static-paths") {
1498
+ if (process.env.VINEXT_PRERENDER !== "1") {
1499
+ return new Response("Not Found", { status: 404 });
1500
+ }
1501
+ const __gspPattern = url.searchParams.get("pattern");
1502
+ if (!__gspPattern) return new Response("missing pattern", { status: 400 });
1503
+ try {
1504
+ const __gspSsrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
1505
+ const __pagesRoutes = __gspSsrEntry.pageRoutes;
1506
+ const __gspRoute = Array.isArray(__pagesRoutes)
1507
+ ? __pagesRoutes.find((r) => r.pattern === __gspPattern)
1508
+ : undefined;
1509
+ if (!__gspRoute || typeof __gspRoute.module?.getStaticPaths !== "function") {
1510
+ return new Response("null", { status: 200, headers: { "content-type": "application/json" } });
1511
+ }
1512
+ const __localesParam = url.searchParams.get("locales");
1513
+ const __locales = __localesParam ? JSON.parse(__localesParam) : [];
1514
+ const __defaultLocale = url.searchParams.get("defaultLocale") ?? "";
1515
+ const __gspResult = await __gspRoute.module.getStaticPaths({ locales: __locales, defaultLocale: __defaultLocale });
1516
+ return new Response(JSON.stringify(__gspResult), { status: 200, headers: { "content-type": "application/json" } });
1517
+ } catch (e) {
1518
+ return new Response(JSON.stringify({ error: String(e) }), { status: 500, headers: { "content-type": "application/json" } });
1519
+ }
1520
+ }
1521
+ ` : ""}
1430
1522
 
1431
1523
  // Trailing slash normalization (redirect to canonical form)
1432
1524
  const __tsRedirect = normalizeTrailingSlash(pathname, __basePath, __trailingSlash, url.search);
@@ -1461,8 +1553,48 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1461
1553
  // _mwCtx (per-request container) so handler() can merge them into
1462
1554
  // every response path without module-level state that races on Workers.
1463
1555
 
1464
- ${middlewarePath
1465
- ? `
1556
+ ${middlewarePath ? `
1557
+ // In hybrid app+pages dev mode the connect handler already ran middleware
1558
+ // and forwarded the results via x-vinext-mw-ctx. Reconstruct _mwCtx from
1559
+ // the forwarded data instead of re-running the middleware function.
1560
+ // Guarded by NODE_ENV because this header only exists in dev (the connect
1561
+ // handler sets it). In production there is no connect handler, so an
1562
+ // attacker-supplied header must not be trusted.
1563
+ let __mwCtxApplied = false;
1564
+ if (process.env.NODE_ENV !== "production") {
1565
+ const __mwCtxHeader = request.headers.get("x-vinext-mw-ctx");
1566
+ if (__mwCtxHeader) {
1567
+ try {
1568
+ const __mwCtxData = JSON.parse(__mwCtxHeader);
1569
+ if (__mwCtxData.h && __mwCtxData.h.length > 0) {
1570
+ // Note: h may include x-middleware-request-* internal headers so
1571
+ // applyMiddlewareRequestHeaders() can unpack them below.
1572
+ // processMiddlewareHeaders() strips them before any response.
1573
+ _mwCtx.headers = new Headers();
1574
+ for (const [key, value] of __mwCtxData.h) {
1575
+ _mwCtx.headers.append(key, value);
1576
+ }
1577
+ }
1578
+ if (__mwCtxData.s != null) {
1579
+ _mwCtx.status = __mwCtxData.s;
1580
+ }
1581
+ // Apply forwarded middleware rewrite so routing uses the rewritten path.
1582
+ // The RSC plugin constructs its Request from the original HTTP request,
1583
+ // not from req.url, so the connect handler's req.url rewrite is invisible.
1584
+ if (__mwCtxData.r) {
1585
+ const __rewriteParsed = new URL(__mwCtxData.r, request.url);
1586
+ cleanPathname = __rewriteParsed.pathname;
1587
+ url.search = __rewriteParsed.search;
1588
+ }
1589
+ // Flag set after full context application — if any step fails (e.g. malformed
1590
+ // rewrite URL), we fall back to re-running middleware as a safety net.
1591
+ __mwCtxApplied = true;
1592
+ } catch (e) {
1593
+ console.error("[vinext] Failed to parse forwarded middleware context:", e);
1594
+ }
1595
+ }
1596
+ }
1597
+ if (!__mwCtxApplied) {
1466
1598
  // Run proxy/middleware if present and path matches.
1467
1599
  // Validate exports match the file type (proxy.ts vs middleware.ts), matching Next.js behavior.
1468
1600
  // https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts
@@ -1487,7 +1619,9 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1487
1619
  const nextRequest = mwRequest instanceof NextRequest ? mwRequest : new NextRequest(mwRequest);
1488
1620
  const mwFetchEvent = new NextFetchEvent({ page: cleanPathname });
1489
1621
  const mwResponse = await middlewareFn(nextRequest, mwFetchEvent);
1490
- mwFetchEvent.drainWaitUntil();
1622
+ const _mwWaitUntil = mwFetchEvent.drainWaitUntil();
1623
+ const _mwExecCtx = _getRequestExecutionContext();
1624
+ if (_mwExecCtx && typeof _mwExecCtx.waitUntil === "function") { _mwExecCtx.waitUntil(_mwWaitUntil); }
1491
1625
  if (mwResponse) {
1492
1626
  // Check for x-middleware-next (continue)
1493
1627
  if (mwResponse.headers.get("x-middleware-next") === "1") {
@@ -1512,6 +1646,10 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1512
1646
  if (rewriteUrl) {
1513
1647
  const rewriteParsed = new URL(rewriteUrl, request.url);
1514
1648
  cleanPathname = rewriteParsed.pathname;
1649
+ // Carry over query params from the rewrite URL so that
1650
+ // searchParams props, useSearchParams(), and navigation context
1651
+ // reflect the rewrite destination, not the original request.
1652
+ url.search = rewriteParsed.search;
1515
1653
  // Capture custom status code from rewrite (e.g. NextResponse.rewrite(url, { status: 403 }))
1516
1654
  if (mwResponse.status !== 200) {
1517
1655
  _mwCtx.status = mwResponse.status;
@@ -1534,6 +1672,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1534
1672
  return new Response("Internal Server Error", { status: 500 });
1535
1673
  }
1536
1674
  }
1675
+ } // end of if (!__mwCtxApplied)
1537
1676
 
1538
1677
  // Unpack x-middleware-request-* headers into the request context so that
1539
1678
  // headers() returns the middleware-modified headers instead of the original
@@ -1544,8 +1683,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1544
1683
  applyMiddlewareRequestHeaders(_mwCtx.headers);
1545
1684
  processMiddlewareHeaders(_mwCtx.headers);
1546
1685
  }
1547
- `
1548
- : ""}
1686
+ ` : ""}
1549
1687
 
1550
1688
  // Build post-middleware request context for afterFiles/fallback rewrites.
1551
1689
  // These run after middleware in the App Router execution order and should
@@ -1606,45 +1744,53 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1606
1744
  // Skip — the base servedUrl is not served when generateSitemaps exists
1607
1745
  continue;
1608
1746
  }
1609
- if (cleanPathname === metaRoute.servedUrl) {
1610
- if (metaRoute.isDynamic) {
1611
- // Dynamic metadata route — call the default export and serialize
1612
- const metaFn = metaRoute.module.default;
1613
- if (typeof metaFn === "function") {
1614
- const result = await metaFn();
1615
- let body;
1616
- // If it's already a Response (e.g., ImageResponse), return directly
1617
- if (result instanceof Response) return result;
1618
- // Serialize based on type
1619
- if (metaRoute.type === "sitemap") body = sitemapToXml(result);
1620
- else if (metaRoute.type === "robots") body = robotsToText(result);
1621
- else if (metaRoute.type === "manifest") body = manifestToJson(result);
1622
- else body = JSON.stringify(result);
1623
- return new Response(body, {
1624
- headers: { "Content-Type": metaRoute.contentType },
1625
- });
1626
- }
1627
- } else {
1628
- // Static metadata file decode from embedded base64 data
1629
- try {
1630
- const binary = atob(metaRoute.fileDataBase64);
1631
- const bytes = new Uint8Array(binary.length);
1632
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
1633
- return new Response(bytes, {
1634
- headers: {
1635
- "Content-Type": metaRoute.contentType,
1636
- "Cache-Control": "public, max-age=0, must-revalidate",
1637
- },
1638
- });
1639
- } catch {
1640
- return new Response("Not Found", { status: 404 });
1641
- }
1747
+ // Match metadata route — use pattern matching for dynamic segments,
1748
+ // strict equality for static paths.
1749
+ var _metaParams = null;
1750
+ if (metaRoute.patternParts) {
1751
+ var _metaUrlParts = cleanPathname.split("/").filter(Boolean);
1752
+ _metaParams = matchPattern(_metaUrlParts, metaRoute.patternParts);
1753
+ if (!_metaParams) continue;
1754
+ } else if (cleanPathname !== metaRoute.servedUrl) {
1755
+ continue;
1756
+ }
1757
+ if (metaRoute.isDynamic) {
1758
+ // Dynamic metadata route call the default export and serialize
1759
+ const metaFn = metaRoute.module.default;
1760
+ if (typeof metaFn === "function") {
1761
+ const result = await metaFn({ params: makeThenableParams(_metaParams || {}) });
1762
+ let body;
1763
+ // If it's already a Response (e.g., ImageResponse), return directly
1764
+ if (result instanceof Response) return result;
1765
+ // Serialize based on type
1766
+ if (metaRoute.type === "sitemap") body = sitemapToXml(result);
1767
+ else if (metaRoute.type === "robots") body = robotsToText(result);
1768
+ else if (metaRoute.type === "manifest") body = manifestToJson(result);
1769
+ else body = JSON.stringify(result);
1770
+ return new Response(body, {
1771
+ headers: { "Content-Type": metaRoute.contentType },
1772
+ });
1773
+ }
1774
+ } else {
1775
+ // Static metadata file — decode from embedded base64 data
1776
+ try {
1777
+ const binary = atob(metaRoute.fileDataBase64);
1778
+ const bytes = new Uint8Array(binary.length);
1779
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
1780
+ return new Response(bytes, {
1781
+ headers: {
1782
+ "Content-Type": metaRoute.contentType,
1783
+ "Cache-Control": "public, max-age=0, must-revalidate",
1784
+ },
1785
+ });
1786
+ } catch {
1787
+ return new Response("Not Found", { status: 404 });
1642
1788
  }
1643
1789
  }
1644
1790
  }
1645
1791
 
1646
1792
  // Set navigation context for Server Components.
1647
- // Note: Headers context is already set by runWithHeadersContext in the handler wrapper.
1793
+ // Note: Headers context is already set by runWithRequestContext in the handler wrapper.
1648
1794
  setNavigationContext({
1649
1795
  pathname: cleanPathname,
1650
1796
  searchParams: url.searchParams,
@@ -1784,7 +1930,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1784
1930
  // Collect cookies set during the action synchronously (before stream is consumed).
1785
1931
  // Do NOT clear headers/navigation context here — the RSC stream is consumed lazily
1786
1932
  // by the client, and async server components that run during consumption need the
1787
- // context to still be live. The AsyncLocalStorage scope from runWithHeadersContext
1933
+ // context to still be live. The AsyncLocalStorage scope from runWithRequestContext
1788
1934
  // handles cleanup naturally when all async continuations complete.
1789
1935
  const actionPendingCookies = getAndClearPendingCookies();
1790
1936
  const actionDraftCookie = getDraftModeCookieHeader();
@@ -1847,6 +1993,28 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1847
1993
  }
1848
1994
 
1849
1995
  if (!match) {
1996
+ ${hasPagesDir ? `
1997
+ // ── Pages Router fallback ────────────────────────────────────────────
1998
+ // When a request doesn't match any App Router route, delegate to the
1999
+ // Pages Router handler (available in the SSR environment). This covers
2000
+ // both production request serving and prerender fetches from wrangler.
2001
+ // RSC requests (.rsc suffix or Accept: text/x-component) cannot be
2002
+ // handled by the Pages Router, so skip the delegation for those.
2003
+ if (!isRscRequest) {
2004
+ const __pagesEntry = await import.meta.viteRsc.loadModule("ssr", "index");
2005
+ if (typeof __pagesEntry.renderPage === "function") {
2006
+ const __pagesRes = await __pagesEntry.renderPage(request, decodeURIComponent(url.pathname) + (url.search || ""), {});
2007
+ // Only return the Pages Router response if it matched a route
2008
+ // (non-404). A 404 means the path isn't a Pages route either,
2009
+ // so fall through to the App Router not-found page below.
2010
+ if (__pagesRes.status !== 404) {
2011
+ setHeadersContext(null);
2012
+ setNavigationContext(null);
2013
+ return __pagesRes;
2014
+ }
2015
+ }
2016
+ }
2017
+ ` : ""}
1850
2018
  // Render custom not-found page if available, otherwise plain 404
1851
2019
  const notFoundResponse = await renderNotFoundPage(null, isRscRequest, request);
1852
2020
  if (notFoundResponse) return notFoundResponse;
@@ -1868,16 +2036,16 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1868
2036
  if (route.routeHandler) {
1869
2037
  const handler = route.routeHandler;
1870
2038
  const method = request.method.toUpperCase();
1871
- const revalidateSeconds = typeof handler.revalidate === "number" && handler.revalidate > 0 ? handler.revalidate : null;
2039
+ const revalidateSeconds = typeof handler.revalidate === "number" && handler.revalidate > 0 && handler.revalidate !== Infinity ? handler.revalidate : null;
2040
+ if (typeof handler["default"] === "function" && process.env.NODE_ENV === "development") {
2041
+ console.error(
2042
+ "[vinext] Detected default export in route handler " + route.pattern + ". Export a named export for each HTTP method instead.",
2043
+ );
2044
+ }
1872
2045
 
1873
2046
  // Collect exported HTTP methods for OPTIONS auto-response and Allow header
1874
- const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
1875
- const exportedMethods = HTTP_METHODS.filter((m) => typeof handler[m] === "function");
1876
- // If GET is exported, HEAD is implicitly supported
1877
- if (exportedMethods.includes("GET") && !exportedMethods.includes("HEAD")) {
1878
- exportedMethods.push("HEAD");
1879
- }
1880
- const hasDefault = typeof handler["default"] === "function";
2047
+ const exportedMethods = collectRouteHandlerMethods(handler);
2048
+ const allowHeaderForOptions = buildRouteHandlerAllowHeader(exportedMethods);
1881
2049
 
1882
2050
  // Route handlers need the same middleware header/status merge behavior as
1883
2051
  // page responses. This keeps middleware response headers visible on API
@@ -1904,29 +2072,107 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1904
2072
 
1905
2073
  // OPTIONS auto-implementation: respond with Allow header and 204
1906
2074
  if (method === "OPTIONS" && typeof handler["OPTIONS"] !== "function") {
1907
- const allowMethods = hasDefault ? HTTP_METHODS : exportedMethods;
1908
- if (!allowMethods.includes("OPTIONS")) allowMethods.push("OPTIONS");
1909
2075
  setHeadersContext(null);
1910
2076
  setNavigationContext(null);
1911
2077
  return attachRouteHandlerMiddlewareContext(new Response(null, {
1912
2078
  status: 204,
1913
- headers: { "Allow": allowMethods.join(", ") },
2079
+ headers: { "Allow": allowHeaderForOptions },
1914
2080
  }));
1915
2081
  }
1916
2082
 
1917
2083
  // HEAD auto-implementation: run GET handler and strip body
1918
- let handlerFn = handler[method] || handler["default"];
2084
+ let handlerFn = handler[method];
1919
2085
  let isAutoHead = false;
1920
2086
  if (method === "HEAD" && typeof handler["HEAD"] !== "function" && typeof handler["GET"] === "function") {
1921
2087
  handlerFn = handler["GET"];
1922
2088
  isAutoHead = true;
1923
2089
  }
1924
2090
 
2091
+ // ISR cache read for route handlers (production only).
2092
+ // Only GET/HEAD (auto-HEAD) with finite revalidate > 0 are ISR-eligible.
2093
+ // This runs before handler execution so a cache HIT skips the handler entirely.
2094
+ if (
2095
+ process.env.NODE_ENV === "production" &&
2096
+ revalidateSeconds !== null &&
2097
+ handler.dynamic !== "force-dynamic" &&
2098
+ (method === "GET" || isAutoHead) &&
2099
+ typeof handlerFn === "function"
2100
+ ) {
2101
+ const __routeKey = __isrRouteKey(cleanPathname);
2102
+ try {
2103
+ const __cached = await __isrGet(__routeKey);
2104
+ if (__cached && !__cached.isStale && __cached.value.value && __cached.value.value.kind === "APP_ROUTE") {
2105
+ // HIT — return cached response immediately
2106
+ const __cv = __cached.value.value;
2107
+ __isrDebug?.("HIT (route)", cleanPathname);
2108
+ setHeadersContext(null);
2109
+ setNavigationContext(null);
2110
+ const __hitHeaders = Object.assign({}, __cv.headers || {});
2111
+ __hitHeaders["X-Vinext-Cache"] = "HIT";
2112
+ __hitHeaders["Cache-Control"] = "s-maxage=" + revalidateSeconds + ", stale-while-revalidate";
2113
+ if (isAutoHead) {
2114
+ return attachRouteHandlerMiddlewareContext(new Response(null, { status: __cv.status, headers: __hitHeaders }));
2115
+ }
2116
+ return attachRouteHandlerMiddlewareContext(new Response(__cv.body, { status: __cv.status, headers: __hitHeaders }));
2117
+ }
2118
+ if (__cached && __cached.isStale && __cached.value.value && __cached.value.value.kind === "APP_ROUTE") {
2119
+ // STALE — serve stale response, trigger background regeneration
2120
+ const __sv = __cached.value.value;
2121
+ const __revalSecs = revalidateSeconds;
2122
+ const __revalHandlerFn = handlerFn;
2123
+ const __revalParams = params;
2124
+ const __revalUrl = request.url;
2125
+ const __revalSearchParams = new URLSearchParams(url.searchParams);
2126
+ __triggerBackgroundRegeneration(__routeKey, async function() {
2127
+ const __revalHeadCtx = { headers: new Headers(), cookies: new Map() };
2128
+ const __revalUCtx = _createUnifiedCtx({
2129
+ headersContext: __revalHeadCtx,
2130
+ executionContext: _getRequestExecutionContext(),
2131
+ });
2132
+ await _runWithUnifiedCtx(__revalUCtx, async () => {
2133
+ _ensureFetchPatch();
2134
+ setNavigationContext({ pathname: cleanPathname, searchParams: __revalSearchParams, params: __revalParams });
2135
+ const __syntheticReq = new Request(__revalUrl, { method: "GET" });
2136
+ const __revalResponse = await __revalHandlerFn(__syntheticReq, { params: __revalParams });
2137
+ const __regenDynamic = consumeDynamicUsage();
2138
+ setNavigationContext(null);
2139
+ if (__regenDynamic) {
2140
+ __isrDebug?.("route regen skipped (dynamic usage)", cleanPathname);
2141
+ return;
2142
+ }
2143
+ const __freshBody = await __revalResponse.arrayBuffer();
2144
+ const __freshHeaders = {};
2145
+ __revalResponse.headers.forEach(function(v, k) {
2146
+ if (k !== "x-vinext-cache" && k !== "cache-control") __freshHeaders[k] = v;
2147
+ });
2148
+ const __routeTags = __pageCacheTags(cleanPathname, getCollectedFetchTags());
2149
+ await __isrSet(__routeKey, { kind: "APP_ROUTE", body: __freshBody, status: __revalResponse.status, headers: __freshHeaders }, __revalSecs, __routeTags);
2150
+ __isrDebug?.("route regen complete", __routeKey);
2151
+ });
2152
+ });
2153
+ __isrDebug?.("STALE (route)", cleanPathname);
2154
+ setHeadersContext(null);
2155
+ setNavigationContext(null);
2156
+ const __staleHeaders = Object.assign({}, __sv.headers || {});
2157
+ __staleHeaders["X-Vinext-Cache"] = "STALE";
2158
+ __staleHeaders["Cache-Control"] = "s-maxage=0, stale-while-revalidate";
2159
+ if (isAutoHead) {
2160
+ return attachRouteHandlerMiddlewareContext(new Response(null, { status: __sv.status, headers: __staleHeaders }));
2161
+ }
2162
+ return attachRouteHandlerMiddlewareContext(new Response(__sv.body, { status: __sv.status, headers: __staleHeaders }));
2163
+ }
2164
+ } catch (__routeCacheErr) {
2165
+ // Cache read failure — fall through to normal handler execution
2166
+ console.error("[vinext] ISR route cache read error:", __routeCacheErr);
2167
+ }
2168
+ }
2169
+
1925
2170
  if (typeof handlerFn === "function") {
1926
2171
  const previousHeadersPhase = setHeadersAccessPhase("route-handler");
1927
2172
  try {
1928
2173
  const response = await handlerFn(request, { params });
1929
2174
  const dynamicUsedInHandler = consumeDynamicUsage();
2175
+ const handlerSetCacheControl = response.headers.has("cache-control");
1930
2176
 
1931
2177
  // Apply Cache-Control from route segment config (export const revalidate = N).
1932
2178
  // Runtime request APIs like headers() / cookies() make GET handlers dynamic,
@@ -1935,11 +2181,43 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1935
2181
  revalidateSeconds !== null &&
1936
2182
  !dynamicUsedInHandler &&
1937
2183
  (method === "GET" || isAutoHead) &&
1938
- !response.headers.has("cache-control")
2184
+ !handlerSetCacheControl
1939
2185
  ) {
1940
2186
  response.headers.set("cache-control", "s-maxage=" + revalidateSeconds + ", stale-while-revalidate");
1941
2187
  }
1942
2188
 
2189
+ // ISR cache write for route handlers (production, MISS).
2190
+ // Store the raw handler response before cookie/middleware transforms
2191
+ // (those are request-specific and shouldn't be cached).
2192
+ if (
2193
+ process.env.NODE_ENV === "production" &&
2194
+ revalidateSeconds !== null &&
2195
+ handler.dynamic !== "force-dynamic" &&
2196
+ !dynamicUsedInHandler &&
2197
+ (method === "GET" || isAutoHead) &&
2198
+ !handlerSetCacheControl
2199
+ ) {
2200
+ response.headers.set("X-Vinext-Cache", "MISS");
2201
+ const __routeClone = response.clone();
2202
+ const __routeKey = __isrRouteKey(cleanPathname);
2203
+ const __revalSecs = revalidateSeconds;
2204
+ const __routeTags = __pageCacheTags(cleanPathname, getCollectedFetchTags());
2205
+ const __routeWritePromise = (async () => {
2206
+ try {
2207
+ const __buf = await __routeClone.arrayBuffer();
2208
+ const __hdrs = {};
2209
+ __routeClone.headers.forEach(function(v, k) {
2210
+ if (k !== "x-vinext-cache" && k !== "cache-control") __hdrs[k] = v;
2211
+ });
2212
+ await __isrSet(__routeKey, { kind: "APP_ROUTE", body: __buf, status: __routeClone.status, headers: __hdrs }, __revalSecs, __routeTags);
2213
+ __isrDebug?.("route cache written", __routeKey);
2214
+ } catch (__cacheErr) {
2215
+ console.error("[vinext] ISR route cache write error:", __cacheErr);
2216
+ }
2217
+ })();
2218
+ _getRequestExecutionContext()?.waitUntil(__routeWritePromise);
2219
+ }
2220
+
1943
2221
  // Collect any Set-Cookie headers from cookies().set()/delete() calls
1944
2222
  const pendingCookies = getAndClearPendingCookies();
1945
2223
  const draftCookie = getDraftModeCookieHeader();
@@ -2017,7 +2295,6 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
2017
2295
  setNavigationContext(null);
2018
2296
  return attachRouteHandlerMiddlewareContext(new Response(null, {
2019
2297
  status: 405,
2020
- headers: { Allow: exportedMethods.join(", ") },
2021
2298
  }));
2022
2299
  }
2023
2300
 
@@ -2137,57 +2414,54 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
2137
2414
  // user request — to prevent user-specific cookies/auth headers from leaking
2138
2415
  // into content that is cached and served to all subsequent users.
2139
2416
  const __revalHeadCtx = { headers: new Headers(), cookies: new Map() };
2140
- const __revalResult = await runWithHeadersContext(__revalHeadCtx, () =>
2141
- _runWithNavigationContext(() =>
2142
- _runWithCacheState(() =>
2143
- _runWithPrivateCache(() =>
2144
- runWithFetchCache(async () => {
2145
- setNavigationContext({ pathname: cleanPathname, searchParams: url.searchParams, params });
2146
- const __revalElement = await buildPageElement(route, params, undefined, url.searchParams);
2147
- const __revalOnError = createRscOnErrorHandler(request, cleanPathname, route.pattern);
2148
- const __revalRscStream = renderToReadableStream(__revalElement, { onError: __revalOnError });
2149
- // Tee RSC stream: one for SSR, one to capture rscData
2150
- const [__revalRscForSsr, __revalRscForCapture] = __revalRscStream.tee();
2151
- // Capture rscData bytes in parallel with SSR
2152
- const __rscDataPromise = (async () => {
2153
- const __rscReader = __revalRscForCapture.getReader();
2154
- const __rscChunks = [];
2155
- let __rscTotal = 0;
2156
- for (;;) {
2157
- const { done, value } = await __rscReader.read();
2158
- if (done) break;
2159
- __rscChunks.push(value);
2160
- __rscTotal += value.byteLength;
2161
- }
2162
- const __rscBuf = new Uint8Array(__rscTotal);
2163
- let __rscOff = 0;
2164
- for (const c of __rscChunks) { __rscBuf.set(c, __rscOff); __rscOff += c.byteLength; }
2165
- return __rscBuf.buffer;
2166
- })();
2167
- const __revalFontData = { links: _getSSRFontLinks(), styles: _getSSRFontStyles(), preloads: _getSSRFontPreloads() };
2168
- const __revalSsrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
2169
- const __revalHtmlStream = await __revalSsrEntry.handleSsr(__revalRscForSsr, _getNavigationContext(), __revalFontData);
2170
- setHeadersContext(null);
2171
- setNavigationContext(null);
2172
- // Collect the full HTML string from the stream
2173
- const __revalReader = __revalHtmlStream.getReader();
2174
- const __revalDecoder = new TextDecoder();
2175
- const __revalChunks = [];
2176
- for (;;) {
2177
- const { done, value } = await __revalReader.read();
2178
- if (done) break;
2179
- __revalChunks.push(__revalDecoder.decode(value, { stream: true }));
2180
- }
2181
- __revalChunks.push(__revalDecoder.decode());
2182
- const __freshHtml = __revalChunks.join("");
2183
- const __freshRscData = await __rscDataPromise;
2184
- const __pageTags = __pageCacheTags(cleanPathname, getCollectedFetchTags());
2185
- return { html: __freshHtml, rscData: __freshRscData, tags: __pageTags };
2186
- })
2187
- )
2188
- )
2189
- )
2190
- );
2417
+ const __revalUCtx = _createUnifiedCtx({
2418
+ headersContext: __revalHeadCtx,
2419
+ executionContext: _getRequestExecutionContext(),
2420
+ });
2421
+ const __revalResult = await _runWithUnifiedCtx(__revalUCtx, async () => {
2422
+ _ensureFetchPatch();
2423
+ setNavigationContext({ pathname: cleanPathname, searchParams: new URLSearchParams(), params });
2424
+ const __revalElement = await buildPageElement(route, params, undefined, new URLSearchParams());
2425
+ const __revalOnError = createRscOnErrorHandler(request, cleanPathname, route.pattern);
2426
+ const __revalRscStream = renderToReadableStream(__revalElement, { onError: __revalOnError });
2427
+ // Tee RSC stream: one for SSR, one to capture rscData
2428
+ const [__revalRscForSsr, __revalRscForCapture] = __revalRscStream.tee();
2429
+ // Capture rscData bytes in parallel with SSR
2430
+ const __rscDataPromise = (async () => {
2431
+ const __rscReader = __revalRscForCapture.getReader();
2432
+ const __rscChunks = [];
2433
+ let __rscTotal = 0;
2434
+ for (;;) {
2435
+ const { done, value } = await __rscReader.read();
2436
+ if (done) break;
2437
+ __rscChunks.push(value);
2438
+ __rscTotal += value.byteLength;
2439
+ }
2440
+ const __rscBuf = new Uint8Array(__rscTotal);
2441
+ let __rscOff = 0;
2442
+ for (const c of __rscChunks) { __rscBuf.set(c, __rscOff); __rscOff += c.byteLength; }
2443
+ return __rscBuf.buffer;
2444
+ })();
2445
+ const __revalFontData = { links: _getSSRFontLinks(), styles: _getSSRFontStyles(), preloads: _getSSRFontPreloads() };
2446
+ const __revalSsrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
2447
+ const __revalHtmlStream = await __revalSsrEntry.handleSsr(__revalRscForSsr, _getNavigationContext(), __revalFontData);
2448
+ setHeadersContext(null);
2449
+ setNavigationContext(null);
2450
+ // Collect the full HTML string from the stream
2451
+ const __revalReader = __revalHtmlStream.getReader();
2452
+ const __revalDecoder = new TextDecoder();
2453
+ const __revalChunks = [];
2454
+ for (;;) {
2455
+ const { done, value } = await __revalReader.read();
2456
+ if (done) break;
2457
+ __revalChunks.push(__revalDecoder.decode(value, { stream: true }));
2458
+ }
2459
+ __revalChunks.push(__revalDecoder.decode());
2460
+ const __freshHtml = __revalChunks.join("");
2461
+ const __freshRscData = await __rscDataPromise;
2462
+ const __pageTags = __pageCacheTags(cleanPathname, getCollectedFetchTags());
2463
+ return { html: __freshHtml, rscData: __freshRscData, tags: __pageTags };
2464
+ });
2191
2465
  // Write HTML and RSC to their own keys independently — no races
2192
2466
  await Promise.all([
2193
2467
  __isrSet(__isrHtmlKey(cleanPathname), { kind: "APP_PAGE", html: __revalResult.html, rscData: undefined, headers: undefined, postponed: undefined, status: 200 }, __revalSecs, __revalResult.tags),
@@ -2296,7 +2570,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
2296
2570
  const interceptStream = renderToReadableStream(interceptElement, { onError: interceptOnError });
2297
2571
  // Do NOT clear headers/navigation context here — the RSC stream is consumed lazily
2298
2572
  // by the client, and async server components that run during consumption need the
2299
- // context to still be live. The AsyncLocalStorage scope from runWithHeadersContext
2573
+ // context to still be live. The AsyncLocalStorage scope from runWithRequestContext
2300
2574
  // handles cleanup naturally when all async continuations complete.
2301
2575
  return new Response(interceptStream, {
2302
2576
  headers: { "Content-Type": "text/x-component; charset=utf-8", "Vary": "RSC, Accept" },
@@ -2531,7 +2805,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
2531
2805
  // NOTE: Do NOT clear headers/navigation context here!
2532
2806
  // The RSC stream is consumed lazily - components render when chunks are read.
2533
2807
  // If we clear context now, headers()/cookies() will fail during rendering.
2534
- // Context will be cleared when the next request starts (via runWithHeadersContext).
2808
+ // Context will be cleared when the next request starts (via runWithRequestContext).
2535
2809
  const responseHeaders = { "Content-Type": "text/x-component; charset=utf-8", "Vary": "RSC, Accept" };
2536
2810
  // Include matched route params so the client can hydrate useParams()
2537
2811
  if (params && Object.keys(params).length > 0) {
@@ -2659,8 +2933,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
2659
2933
  // the HTML output has double <html>/<body> (root layout + global-error.tsx).
2660
2934
  // Discard it and re-render using renderErrorBoundaryPage which skips layouts
2661
2935
  // when the error falls through to global-error.tsx.
2662
- ${globalErrorVar
2663
- ? `
2936
+ ${globalErrorVar ? `
2664
2937
  if (_rscErrorForRerender && !isRscRequest) {
2665
2938
  const _hasLocalBoundary = !!(route?.error?.default) || !!(route?.errors && route.errors.some(function(e) { return e?.default; }));
2666
2939
  if (!_hasLocalBoundary) {
@@ -2668,8 +2941,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
2668
2941
  if (cleanResp) return cleanResp;
2669
2942
  }
2670
2943
  }
2671
- `
2672
- : ""}
2944
+ ` : ""}
2673
2945
 
2674
2946
  // Check for draftMode Set-Cookie header (from draftMode().enable()/disable())
2675
2947
  const draftCookie = getDraftModeCookieHeader();
@@ -2870,4 +3142,7 @@ if (import.meta.hot) {
2870
3142
  }
2871
3143
  `;
2872
3144
  }
3145
+ //#endregion
3146
+ export { generateRscEntry };
3147
+
2873
3148
  //# sourceMappingURL=app-rsc-entry.js.map