@rangojs/router 0.0.0-experimental.8 → 0.0.0-experimental.80daa23e

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 (1746) hide show
  1. package/AGENTS.md +13 -0
  2. package/README.md +472 -7
  3. package/dist/__internal.d.ts +83 -0
  4. package/dist/__internal.d.ts.map +1 -0
  5. package/dist/__internal.js +19 -0
  6. package/dist/__internal.js.map +1 -0
  7. package/dist/__mocks__/version.d.ts +7 -0
  8. package/dist/__mocks__/version.d.ts.map +1 -0
  9. package/dist/__mocks__/version.js +7 -0
  10. package/dist/__mocks__/version.js.map +1 -0
  11. package/dist/__tests__/client-href.test.d.ts +2 -0
  12. package/dist/__tests__/client-href.test.d.ts.map +1 -0
  13. package/dist/__tests__/client-href.test.js +74 -0
  14. package/dist/__tests__/client-href.test.js.map +1 -0
  15. package/dist/__tests__/component-utils.test.d.ts +2 -0
  16. package/dist/__tests__/component-utils.test.d.ts.map +1 -0
  17. package/dist/__tests__/component-utils.test.js +51 -0
  18. package/dist/__tests__/component-utils.test.js.map +1 -0
  19. package/dist/__tests__/event-controller.test.d.ts +2 -0
  20. package/dist/__tests__/event-controller.test.d.ts.map +1 -0
  21. package/dist/__tests__/event-controller.test.js +538 -0
  22. package/dist/__tests__/event-controller.test.js.map +1 -0
  23. package/dist/__tests__/helpers/route-tree.d.ts +118 -0
  24. package/dist/__tests__/helpers/route-tree.d.ts.map +1 -0
  25. package/dist/__tests__/helpers/route-tree.js +374 -0
  26. package/dist/__tests__/helpers/route-tree.js.map +1 -0
  27. package/dist/__tests__/match-result.test.d.ts +2 -0
  28. package/dist/__tests__/match-result.test.d.ts.map +1 -0
  29. package/dist/__tests__/match-result.test.js +154 -0
  30. package/dist/__tests__/match-result.test.js.map +1 -0
  31. package/dist/__tests__/navigation-store.test.d.ts +2 -0
  32. package/dist/__tests__/navigation-store.test.d.ts.map +1 -0
  33. package/dist/__tests__/navigation-store.test.js +440 -0
  34. package/dist/__tests__/navigation-store.test.js.map +1 -0
  35. package/dist/__tests__/partial-update.test.d.ts +2 -0
  36. package/dist/__tests__/partial-update.test.d.ts.map +1 -0
  37. package/dist/__tests__/partial-update.test.js +1009 -0
  38. package/dist/__tests__/partial-update.test.js.map +1 -0
  39. package/dist/__tests__/reverse-types.test.d.ts +8 -0
  40. package/dist/__tests__/reverse-types.test.d.ts.map +1 -0
  41. package/dist/__tests__/reverse-types.test.js +656 -0
  42. package/dist/__tests__/reverse-types.test.js.map +1 -0
  43. package/dist/__tests__/route-definition.test.d.ts +2 -0
  44. package/dist/__tests__/route-definition.test.d.ts.map +1 -0
  45. package/dist/__tests__/route-definition.test.js +55 -0
  46. package/dist/__tests__/route-definition.test.js.map +1 -0
  47. package/dist/__tests__/router-helpers.test.d.ts +2 -0
  48. package/dist/__tests__/router-helpers.test.d.ts.map +1 -0
  49. package/dist/__tests__/router-helpers.test.js +377 -0
  50. package/dist/__tests__/router-helpers.test.js.map +1 -0
  51. package/dist/__tests__/router-integration-2.test.d.ts +2 -0
  52. package/dist/__tests__/router-integration-2.test.d.ts.map +1 -0
  53. package/dist/__tests__/router-integration-2.test.js +426 -0
  54. package/dist/__tests__/router-integration-2.test.js.map +1 -0
  55. package/dist/__tests__/router-integration.test.d.ts +2 -0
  56. package/dist/__tests__/router-integration.test.d.ts.map +1 -0
  57. package/dist/__tests__/router-integration.test.js +1051 -0
  58. package/dist/__tests__/router-integration.test.js.map +1 -0
  59. package/dist/__tests__/search-params.test.d.ts +5 -0
  60. package/dist/__tests__/search-params.test.d.ts.map +1 -0
  61. package/dist/__tests__/search-params.test.js +306 -0
  62. package/dist/__tests__/search-params.test.js.map +1 -0
  63. package/dist/__tests__/segment-system.test.d.ts +2 -0
  64. package/dist/__tests__/segment-system.test.d.ts.map +1 -0
  65. package/dist/__tests__/segment-system.test.js +627 -0
  66. package/dist/__tests__/segment-system.test.js.map +1 -0
  67. package/dist/__tests__/static-handler-types.test.d.ts +8 -0
  68. package/dist/__tests__/static-handler-types.test.d.ts.map +1 -0
  69. package/dist/__tests__/static-handler-types.test.js +63 -0
  70. package/dist/__tests__/static-handler-types.test.js.map +1 -0
  71. package/dist/__tests__/urls.test.d.ts +2 -0
  72. package/dist/__tests__/urls.test.d.ts.map +1 -0
  73. package/dist/__tests__/urls.test.js +421 -0
  74. package/dist/__tests__/urls.test.js.map +1 -0
  75. package/dist/__tests__/use-mount.test.d.ts +2 -0
  76. package/dist/__tests__/use-mount.test.d.ts.map +1 -0
  77. package/dist/__tests__/use-mount.test.js +35 -0
  78. package/dist/__tests__/use-mount.test.js.map +1 -0
  79. package/dist/bin/rango.d.ts +2 -0
  80. package/dist/bin/rango.d.ts.map +1 -0
  81. package/dist/bin/rango.js +2343 -0
  82. package/dist/bin/rango.js.map +1 -0
  83. package/dist/browser/event-controller.d.ts +191 -0
  84. package/dist/browser/event-controller.d.ts.map +1 -0
  85. package/dist/browser/event-controller.js +559 -0
  86. package/dist/browser/event-controller.js.map +1 -0
  87. package/dist/browser/index.d.ts +2 -0
  88. package/dist/browser/index.d.ts.map +1 -0
  89. package/dist/browser/index.js +14 -0
  90. package/dist/browser/index.js.map +1 -0
  91. package/dist/browser/link-interceptor.d.ts +38 -0
  92. package/dist/browser/link-interceptor.d.ts.map +1 -0
  93. package/dist/browser/link-interceptor.js +99 -0
  94. package/dist/browser/link-interceptor.js.map +1 -0
  95. package/dist/browser/logging.d.ts +10 -0
  96. package/dist/browser/logging.d.ts.map +1 -0
  97. package/dist/browser/logging.js +29 -0
  98. package/dist/browser/logging.js.map +1 -0
  99. package/dist/browser/lru-cache.d.ts +17 -0
  100. package/dist/browser/lru-cache.d.ts.map +1 -0
  101. package/dist/browser/lru-cache.js +50 -0
  102. package/dist/browser/lru-cache.js.map +1 -0
  103. package/dist/browser/merge-segment-loaders.d.ts +39 -0
  104. package/dist/browser/merge-segment-loaders.d.ts.map +1 -0
  105. package/dist/browser/merge-segment-loaders.js +102 -0
  106. package/dist/browser/merge-segment-loaders.js.map +1 -0
  107. package/dist/browser/navigation-bridge.d.ts +102 -0
  108. package/dist/browser/navigation-bridge.d.ts.map +1 -0
  109. package/dist/browser/navigation-bridge.js +708 -0
  110. package/dist/browser/navigation-bridge.js.map +1 -0
  111. package/dist/browser/navigation-client.d.ts +25 -0
  112. package/dist/browser/navigation-client.d.ts.map +1 -0
  113. package/dist/browser/navigation-client.js +157 -0
  114. package/dist/browser/navigation-client.js.map +1 -0
  115. package/dist/browser/navigation-store.d.ts +101 -0
  116. package/dist/browser/navigation-store.d.ts.map +1 -0
  117. package/dist/browser/navigation-store.js +625 -0
  118. package/dist/browser/navigation-store.js.map +1 -0
  119. package/dist/browser/partial-update.d.ts +75 -0
  120. package/dist/browser/partial-update.d.ts.map +1 -0
  121. package/dist/browser/partial-update.js +426 -0
  122. package/dist/browser/partial-update.js.map +1 -0
  123. package/dist/browser/react/Link.d.ts +86 -0
  124. package/dist/browser/react/Link.d.ts.map +1 -0
  125. package/dist/browser/react/Link.js +128 -0
  126. package/dist/browser/react/Link.js.map +1 -0
  127. package/dist/browser/react/NavigationProvider.d.ts +63 -0
  128. package/dist/browser/react/NavigationProvider.d.ts.map +1 -0
  129. package/dist/browser/react/NavigationProvider.js +216 -0
  130. package/dist/browser/react/NavigationProvider.js.map +1 -0
  131. package/dist/browser/react/ScrollRestoration.d.ts +75 -0
  132. package/dist/browser/react/ScrollRestoration.d.ts.map +1 -0
  133. package/dist/browser/react/ScrollRestoration.js +57 -0
  134. package/dist/browser/react/ScrollRestoration.js.map +1 -0
  135. package/dist/browser/react/context.d.ts +46 -0
  136. package/dist/browser/react/context.d.ts.map +1 -0
  137. package/dist/browser/react/context.js +10 -0
  138. package/dist/browser/react/context.js.map +1 -0
  139. package/dist/browser/react/index.d.ts +11 -0
  140. package/dist/browser/react/index.d.ts.map +1 -0
  141. package/dist/browser/react/index.js +22 -0
  142. package/dist/browser/react/index.js.map +1 -0
  143. package/dist/browser/react/location-state-shared.d.ts +63 -0
  144. package/dist/browser/react/location-state-shared.d.ts.map +1 -0
  145. package/dist/browser/react/location-state-shared.js +81 -0
  146. package/dist/browser/react/location-state-shared.js.map +1 -0
  147. package/dist/browser/react/location-state.d.ts +23 -0
  148. package/dist/browser/react/location-state.d.ts.map +1 -0
  149. package/dist/browser/react/location-state.js +29 -0
  150. package/dist/browser/react/location-state.js.map +1 -0
  151. package/dist/browser/react/mount-context.d.ts +24 -0
  152. package/dist/browser/react/mount-context.d.ts.map +1 -0
  153. package/dist/browser/react/mount-context.js +24 -0
  154. package/dist/browser/react/mount-context.js.map +1 -0
  155. package/dist/browser/react/use-action.d.ts +64 -0
  156. package/dist/browser/react/use-action.d.ts.map +1 -0
  157. package/dist/browser/react/use-action.js +134 -0
  158. package/dist/browser/react/use-action.js.map +1 -0
  159. package/dist/browser/react/use-client-cache.d.ts +41 -0
  160. package/dist/browser/react/use-client-cache.d.ts.map +1 -0
  161. package/{src/browser/react/use-client-cache.ts → dist/browser/react/use-client-cache.js} +9 -26
  162. package/dist/browser/react/use-client-cache.js.map +1 -0
  163. package/dist/browser/react/use-handle.d.ts +31 -0
  164. package/dist/browser/react/use-handle.d.ts.map +1 -0
  165. package/dist/browser/react/use-handle.js +144 -0
  166. package/dist/browser/react/use-handle.js.map +1 -0
  167. package/dist/browser/react/use-href.d.ts +33 -0
  168. package/dist/browser/react/use-href.d.ts.map +1 -0
  169. package/dist/browser/react/use-href.js +39 -0
  170. package/dist/browser/react/use-href.js.map +1 -0
  171. package/dist/browser/react/use-link-status.d.ts +37 -0
  172. package/dist/browser/react/use-link-status.d.ts.map +1 -0
  173. package/dist/browser/react/use-link-status.js +99 -0
  174. package/dist/browser/react/use-link-status.js.map +1 -0
  175. package/dist/browser/react/use-mount.d.ts +25 -0
  176. package/dist/browser/react/use-mount.d.ts.map +1 -0
  177. package/dist/browser/react/use-mount.js +30 -0
  178. package/dist/browser/react/use-mount.js.map +1 -0
  179. package/dist/browser/react/use-navigation.d.ts +27 -0
  180. package/dist/browser/react/use-navigation.d.ts.map +1 -0
  181. package/dist/browser/react/use-navigation.js +87 -0
  182. package/dist/browser/react/use-navigation.js.map +1 -0
  183. package/dist/browser/react/use-segments.d.ts +38 -0
  184. package/dist/browser/react/use-segments.d.ts.map +1 -0
  185. package/dist/browser/react/use-segments.js +130 -0
  186. package/dist/browser/react/use-segments.js.map +1 -0
  187. package/dist/browser/request-controller.d.ts +26 -0
  188. package/dist/browser/request-controller.d.ts.map +1 -0
  189. package/dist/browser/request-controller.js +147 -0
  190. package/dist/browser/request-controller.js.map +1 -0
  191. package/dist/browser/rsc-router.d.ts +129 -0
  192. package/dist/browser/rsc-router.d.ts.map +1 -0
  193. package/dist/browser/rsc-router.js +195 -0
  194. package/dist/browser/rsc-router.js.map +1 -0
  195. package/dist/browser/scroll-restoration.d.ts +93 -0
  196. package/dist/browser/scroll-restoration.d.ts.map +1 -0
  197. package/dist/browser/scroll-restoration.js +321 -0
  198. package/dist/browser/scroll-restoration.js.map +1 -0
  199. package/dist/browser/segment-structure-assert.d.ts +17 -0
  200. package/dist/browser/segment-structure-assert.d.ts.map +1 -0
  201. package/dist/browser/segment-structure-assert.js +59 -0
  202. package/dist/browser/segment-structure-assert.js.map +1 -0
  203. package/dist/browser/server-action-bridge.d.ts +26 -0
  204. package/dist/browser/server-action-bridge.d.ts.map +1 -0
  205. package/dist/browser/server-action-bridge.js +668 -0
  206. package/dist/browser/server-action-bridge.js.map +1 -0
  207. package/dist/browser/shallow.d.ts +12 -0
  208. package/dist/browser/shallow.d.ts.map +1 -0
  209. package/dist/browser/shallow.js +34 -0
  210. package/dist/browser/shallow.js.map +1 -0
  211. package/dist/browser/types.d.ts +369 -0
  212. package/dist/browser/types.d.ts.map +1 -0
  213. package/dist/browser/types.js +2 -0
  214. package/dist/browser/types.js.map +1 -0
  215. package/dist/build/__tests__/generate-cli.test.d.ts +2 -0
  216. package/dist/build/__tests__/generate-cli.test.d.ts.map +1 -0
  217. package/dist/build/__tests__/generate-cli.test.js +237 -0
  218. package/dist/build/__tests__/generate-cli.test.js.map +1 -0
  219. package/dist/build/__tests__/generate-manifest.test.d.ts +2 -0
  220. package/dist/build/__tests__/generate-manifest.test.d.ts.map +1 -0
  221. package/dist/build/__tests__/generate-manifest.test.js +119 -0
  222. package/dist/build/__tests__/generate-manifest.test.js.map +1 -0
  223. package/dist/build/__tests__/generate-route-types.test.d.ts +2 -0
  224. package/dist/build/__tests__/generate-route-types.test.d.ts.map +1 -0
  225. package/dist/build/__tests__/generate-route-types.test.js +620 -0
  226. package/dist/build/__tests__/generate-route-types.test.js.map +1 -0
  227. package/dist/build/__tests__/per-router-manifest.test.d.ts +2 -0
  228. package/dist/build/__tests__/per-router-manifest.test.d.ts.map +1 -0
  229. package/dist/build/__tests__/per-router-manifest.test.js +308 -0
  230. package/dist/build/__tests__/per-router-manifest.test.js.map +1 -0
  231. package/dist/build/generate-manifest.d.ts +81 -0
  232. package/dist/build/generate-manifest.d.ts.map +1 -0
  233. package/dist/build/generate-manifest.js +276 -0
  234. package/dist/build/generate-manifest.js.map +1 -0
  235. package/dist/build/generate-route-types.d.ts +115 -0
  236. package/dist/build/generate-route-types.d.ts.map +1 -0
  237. package/dist/build/generate-route-types.js +740 -0
  238. package/dist/build/generate-route-types.js.map +1 -0
  239. package/dist/build/index.d.ts +21 -0
  240. package/dist/build/index.d.ts.map +1 -0
  241. package/dist/build/index.js +21 -0
  242. package/dist/build/index.js.map +1 -0
  243. package/dist/build/route-trie.d.ts +71 -0
  244. package/dist/build/route-trie.d.ts.map +1 -0
  245. package/dist/build/route-trie.js +175 -0
  246. package/dist/build/route-trie.js.map +1 -0
  247. package/dist/cache/__tests__/cache-scope.test.d.ts +2 -0
  248. package/dist/cache/__tests__/cache-scope.test.d.ts.map +1 -0
  249. package/dist/cache/__tests__/cache-scope.test.js +208 -0
  250. package/dist/cache/__tests__/cache-scope.test.js.map +1 -0
  251. package/dist/cache/__tests__/document-cache.test.d.ts +2 -0
  252. package/dist/cache/__tests__/document-cache.test.d.ts.map +1 -0
  253. package/dist/cache/__tests__/document-cache.test.js +345 -0
  254. package/dist/cache/__tests__/document-cache.test.js.map +1 -0
  255. package/dist/cache/__tests__/memory-segment-store.test.d.ts +2 -0
  256. package/dist/cache/__tests__/memory-segment-store.test.d.ts.map +1 -0
  257. package/dist/cache/__tests__/memory-segment-store.test.js +425 -0
  258. package/dist/cache/__tests__/memory-segment-store.test.js.map +1 -0
  259. package/dist/cache/__tests__/memory-store.test.d.ts +2 -0
  260. package/dist/cache/__tests__/memory-store.test.d.ts.map +1 -0
  261. package/dist/cache/__tests__/memory-store.test.js +367 -0
  262. package/dist/cache/__tests__/memory-store.test.js.map +1 -0
  263. package/dist/cache/cache-scope.d.ts +102 -0
  264. package/dist/cache/cache-scope.d.ts.map +1 -0
  265. package/dist/cache/cache-scope.js +440 -0
  266. package/dist/cache/cache-scope.js.map +1 -0
  267. package/dist/cache/cf/__tests__/cf-cache-store.test.d.ts +2 -0
  268. package/dist/cache/cf/__tests__/cf-cache-store.test.d.ts.map +1 -0
  269. package/dist/cache/cf/__tests__/cf-cache-store.test.js +330 -0
  270. package/dist/cache/cf/__tests__/cf-cache-store.test.js.map +1 -0
  271. package/dist/cache/cf/cf-cache-store.d.ts +165 -0
  272. package/dist/cache/cf/cf-cache-store.d.ts.map +1 -0
  273. package/dist/cache/cf/cf-cache-store.js +242 -0
  274. package/dist/cache/cf/cf-cache-store.js.map +1 -0
  275. package/dist/cache/cf/index.d.ts +14 -0
  276. package/dist/cache/cf/index.d.ts.map +1 -0
  277. package/dist/cache/cf/index.js +17 -0
  278. package/dist/cache/cf/index.js.map +1 -0
  279. package/dist/cache/document-cache.d.ts +64 -0
  280. package/dist/cache/document-cache.d.ts.map +1 -0
  281. package/dist/cache/document-cache.js +228 -0
  282. package/dist/cache/document-cache.js.map +1 -0
  283. package/dist/cache/index.d.ts +19 -0
  284. package/dist/cache/index.d.ts.map +1 -0
  285. package/dist/cache/index.js +21 -0
  286. package/dist/cache/index.js.map +1 -0
  287. package/dist/cache/memory-segment-store.d.ts +110 -0
  288. package/dist/cache/memory-segment-store.d.ts.map +1 -0
  289. package/dist/cache/memory-segment-store.js +117 -0
  290. package/dist/cache/memory-segment-store.js.map +1 -0
  291. package/dist/cache/memory-store.d.ts +41 -0
  292. package/dist/cache/memory-store.d.ts.map +1 -0
  293. package/dist/cache/memory-store.js +191 -0
  294. package/dist/cache/memory-store.js.map +1 -0
  295. package/dist/cache/types.d.ts +317 -0
  296. package/dist/cache/types.d.ts.map +1 -0
  297. package/dist/cache/types.js +12 -0
  298. package/dist/cache/types.js.map +1 -0
  299. package/dist/client.d.ts +248 -0
  300. package/dist/client.d.ts.map +1 -0
  301. package/dist/client.js +367 -0
  302. package/dist/client.js.map +1 -0
  303. package/dist/client.rsc.d.ts +26 -0
  304. package/dist/client.rsc.d.ts.map +1 -0
  305. package/dist/client.rsc.js +46 -0
  306. package/dist/client.rsc.js.map +1 -0
  307. package/dist/component-utils.d.ts +36 -0
  308. package/dist/component-utils.d.ts.map +1 -0
  309. package/dist/component-utils.js +61 -0
  310. package/dist/component-utils.js.map +1 -0
  311. package/dist/components/DefaultDocument.d.ts +13 -0
  312. package/dist/components/DefaultDocument.d.ts.map +1 -0
  313. package/dist/components/DefaultDocument.js +15 -0
  314. package/dist/components/DefaultDocument.js.map +1 -0
  315. package/dist/debug.d.ts +58 -0
  316. package/dist/debug.d.ts.map +1 -0
  317. package/dist/debug.js +157 -0
  318. package/dist/debug.js.map +1 -0
  319. package/dist/default-error-boundary.d.ts +11 -0
  320. package/dist/default-error-boundary.d.ts.map +1 -0
  321. package/dist/default-error-boundary.js +45 -0
  322. package/dist/default-error-boundary.js.map +1 -0
  323. package/dist/deps/browser.d.ts +2 -0
  324. package/dist/deps/browser.d.ts.map +1 -0
  325. package/dist/deps/browser.js +3 -0
  326. package/dist/deps/browser.js.map +1 -0
  327. package/dist/deps/html-stream-client.d.ts +2 -0
  328. package/dist/deps/html-stream-client.d.ts.map +1 -0
  329. package/dist/deps/html-stream-client.js +3 -0
  330. package/dist/deps/html-stream-client.js.map +1 -0
  331. package/dist/deps/html-stream-server.d.ts +2 -0
  332. package/dist/deps/html-stream-server.d.ts.map +1 -0
  333. package/dist/deps/html-stream-server.js +3 -0
  334. package/dist/deps/html-stream-server.js.map +1 -0
  335. package/dist/deps/rsc.d.ts +2 -0
  336. package/dist/deps/rsc.d.ts.map +1 -0
  337. package/dist/deps/rsc.js +4 -0
  338. package/dist/deps/rsc.js.map +1 -0
  339. package/dist/deps/ssr.d.ts +2 -0
  340. package/dist/deps/ssr.d.ts.map +1 -0
  341. package/dist/deps/ssr.js +3 -0
  342. package/dist/deps/ssr.js.map +1 -0
  343. package/dist/errors.d.ts +174 -0
  344. package/dist/errors.d.ts.map +1 -0
  345. package/dist/errors.js +241 -0
  346. package/dist/errors.js.map +1 -0
  347. package/dist/handle.d.ts +78 -0
  348. package/dist/handle.d.ts.map +1 -0
  349. package/dist/handle.js +82 -0
  350. package/dist/handle.js.map +1 -0
  351. package/dist/handles/MetaTags.d.ts +14 -0
  352. package/dist/handles/MetaTags.d.ts.map +1 -0
  353. package/dist/handles/MetaTags.js +136 -0
  354. package/dist/handles/MetaTags.js.map +1 -0
  355. package/dist/handles/index.d.ts +6 -0
  356. package/dist/handles/index.d.ts.map +1 -0
  357. package/{src/handles/index.ts → dist/handles/index.js} +1 -1
  358. package/dist/handles/index.js.map +1 -0
  359. package/dist/handles/meta.d.ts +39 -0
  360. package/dist/handles/meta.d.ts.map +1 -0
  361. package/dist/handles/meta.js +202 -0
  362. package/dist/handles/meta.js.map +1 -0
  363. package/dist/host/__tests__/errors.test.d.ts +2 -0
  364. package/dist/host/__tests__/errors.test.d.ts.map +1 -0
  365. package/dist/host/__tests__/errors.test.js +76 -0
  366. package/dist/host/__tests__/errors.test.js.map +1 -0
  367. package/dist/host/__tests__/pattern-comprehensive.test.d.ts +2 -0
  368. package/dist/host/__tests__/pattern-comprehensive.test.d.ts.map +1 -0
  369. package/dist/host/__tests__/pattern-comprehensive.test.js +732 -0
  370. package/dist/host/__tests__/pattern-comprehensive.test.js.map +1 -0
  371. package/dist/host/__tests__/pattern-matcher.test.d.ts +2 -0
  372. package/dist/host/__tests__/pattern-matcher.test.d.ts.map +1 -0
  373. package/dist/host/__tests__/pattern-matcher.test.js +251 -0
  374. package/dist/host/__tests__/pattern-matcher.test.js.map +1 -0
  375. package/dist/host/__tests__/router.test.d.ts +2 -0
  376. package/dist/host/__tests__/router.test.d.ts.map +1 -0
  377. package/dist/host/__tests__/router.test.js +241 -0
  378. package/dist/host/__tests__/router.test.js.map +1 -0
  379. package/dist/host/__tests__/testing.test.d.ts +2 -0
  380. package/dist/host/__tests__/testing.test.d.ts.map +1 -0
  381. package/dist/host/__tests__/testing.test.js +64 -0
  382. package/dist/host/__tests__/testing.test.js.map +1 -0
  383. package/dist/host/__tests__/utils.test.d.ts +2 -0
  384. package/dist/host/__tests__/utils.test.d.ts.map +1 -0
  385. package/dist/host/__tests__/utils.test.js +29 -0
  386. package/dist/host/__tests__/utils.test.js.map +1 -0
  387. package/dist/host/cookie-handler.d.ts +34 -0
  388. package/dist/host/cookie-handler.d.ts.map +1 -0
  389. package/dist/host/cookie-handler.js +124 -0
  390. package/dist/host/cookie-handler.js.map +1 -0
  391. package/dist/host/errors.d.ts +56 -0
  392. package/dist/host/errors.d.ts.map +1 -0
  393. package/dist/host/errors.js +79 -0
  394. package/dist/host/errors.js.map +1 -0
  395. package/dist/host/index.d.ts +29 -0
  396. package/dist/host/index.d.ts.map +1 -0
  397. package/dist/host/index.js +32 -0
  398. package/dist/host/index.js.map +1 -0
  399. package/dist/host/pattern-matcher.d.ts +36 -0
  400. package/dist/host/pattern-matcher.d.ts.map +1 -0
  401. package/dist/host/pattern-matcher.js +172 -0
  402. package/dist/host/pattern-matcher.js.map +1 -0
  403. package/dist/host/router.d.ts +26 -0
  404. package/dist/host/router.d.ts.map +1 -0
  405. package/dist/host/router.js +218 -0
  406. package/dist/host/router.js.map +1 -0
  407. package/dist/host/testing.d.ts +36 -0
  408. package/dist/host/testing.d.ts.map +1 -0
  409. package/dist/host/testing.js +55 -0
  410. package/dist/host/testing.js.map +1 -0
  411. package/dist/host/types.d.ts +115 -0
  412. package/dist/host/types.d.ts.map +1 -0
  413. package/dist/host/types.js +7 -0
  414. package/dist/host/types.js.map +1 -0
  415. package/dist/host/utils.d.ts +21 -0
  416. package/dist/host/utils.d.ts.map +1 -0
  417. package/dist/host/utils.js +23 -0
  418. package/dist/host/utils.js.map +1 -0
  419. package/dist/href-client.d.ts +131 -0
  420. package/dist/href-client.d.ts.map +1 -0
  421. package/dist/href-client.js +64 -0
  422. package/dist/href-client.js.map +1 -0
  423. package/{src/href-context.ts → dist/href-context.d.ts} +7 -11
  424. package/dist/href-context.d.ts.map +1 -0
  425. package/dist/href-context.js +21 -0
  426. package/dist/href-context.js.map +1 -0
  427. package/dist/index.d.ts +73 -0
  428. package/dist/index.d.ts.map +1 -0
  429. package/dist/index.js +91 -0
  430. package/dist/index.js.map +1 -0
  431. package/dist/index.rsc.d.ts +32 -0
  432. package/dist/index.rsc.d.ts.map +1 -0
  433. package/dist/index.rsc.js +40 -0
  434. package/dist/index.rsc.js.map +1 -0
  435. package/dist/internal-debug.d.ts +2 -0
  436. package/dist/internal-debug.d.ts.map +1 -0
  437. package/dist/internal-debug.js +5 -0
  438. package/dist/internal-debug.js.map +1 -0
  439. package/dist/loader.d.ts +14 -0
  440. package/dist/loader.d.ts.map +1 -0
  441. package/dist/loader.js +20 -0
  442. package/dist/loader.js.map +1 -0
  443. package/dist/loader.rsc.d.ts +19 -0
  444. package/dist/loader.rsc.d.ts.map +1 -0
  445. package/dist/loader.rsc.js +99 -0
  446. package/dist/loader.rsc.js.map +1 -0
  447. package/{src/network-error-thrower.tsx → dist/network-error-thrower.d.ts} +4 -8
  448. package/dist/network-error-thrower.d.ts.map +1 -0
  449. package/dist/network-error-thrower.js +14 -0
  450. package/dist/network-error-thrower.js.map +1 -0
  451. package/dist/outlet-context.d.ts +13 -0
  452. package/dist/outlet-context.d.ts.map +1 -0
  453. package/dist/outlet-context.js +3 -0
  454. package/dist/outlet-context.js.map +1 -0
  455. package/dist/prerender/__tests__/param-hash.test.d.ts +2 -0
  456. package/dist/prerender/__tests__/param-hash.test.d.ts.map +1 -0
  457. package/dist/prerender/__tests__/param-hash.test.js +148 -0
  458. package/dist/prerender/__tests__/param-hash.test.js.map +1 -0
  459. package/dist/prerender/param-hash.d.ts +16 -0
  460. package/dist/prerender/param-hash.d.ts.map +1 -0
  461. package/dist/prerender/param-hash.js +36 -0
  462. package/dist/prerender/param-hash.js.map +1 -0
  463. package/dist/prerender/store.d.ts +38 -0
  464. package/dist/prerender/store.d.ts.map +1 -0
  465. package/dist/prerender/store.js +61 -0
  466. package/dist/prerender/store.js.map +1 -0
  467. package/dist/prerender.d.ts +66 -0
  468. package/dist/prerender.d.ts.map +1 -0
  469. package/dist/prerender.js +57 -0
  470. package/dist/prerender.js.map +1 -0
  471. package/dist/reverse.d.ts +196 -0
  472. package/dist/reverse.d.ts.map +1 -0
  473. package/dist/reverse.js +78 -0
  474. package/dist/reverse.js.map +1 -0
  475. package/dist/root-error-boundary.d.ts +33 -0
  476. package/dist/root-error-boundary.d.ts.map +1 -0
  477. package/dist/root-error-boundary.js +165 -0
  478. package/dist/root-error-boundary.js.map +1 -0
  479. package/dist/route-content-wrapper.d.ts +46 -0
  480. package/dist/route-content-wrapper.d.ts.map +1 -0
  481. package/dist/route-content-wrapper.js +77 -0
  482. package/dist/route-content-wrapper.js.map +1 -0
  483. package/dist/route-definition.d.ts +421 -0
  484. package/dist/route-definition.d.ts.map +1 -0
  485. package/dist/route-definition.js +868 -0
  486. package/dist/route-definition.js.map +1 -0
  487. package/dist/route-map-builder.d.ts +155 -0
  488. package/dist/route-map-builder.d.ts.map +1 -0
  489. package/dist/route-map-builder.js +237 -0
  490. package/dist/route-map-builder.js.map +1 -0
  491. package/dist/route-types.d.ts +165 -0
  492. package/dist/route-types.d.ts.map +1 -0
  493. package/dist/route-types.js +7 -0
  494. package/dist/route-types.js.map +1 -0
  495. package/dist/router/__tests__/handler-context.test.d.ts +2 -0
  496. package/dist/router/__tests__/handler-context.test.d.ts.map +1 -0
  497. package/dist/router/__tests__/handler-context.test.js +65 -0
  498. package/dist/router/__tests__/handler-context.test.js.map +1 -0
  499. package/dist/router/__tests__/loader-cycle-detection.test.d.ts +2 -0
  500. package/dist/router/__tests__/loader-cycle-detection.test.d.ts.map +1 -0
  501. package/dist/router/__tests__/loader-cycle-detection.test.js +221 -0
  502. package/dist/router/__tests__/loader-cycle-detection.test.js.map +1 -0
  503. package/dist/router/__tests__/match-context.test.d.ts +2 -0
  504. package/dist/router/__tests__/match-context.test.d.ts.map +1 -0
  505. package/dist/router/__tests__/match-context.test.js +92 -0
  506. package/dist/router/__tests__/match-context.test.js.map +1 -0
  507. package/dist/router/__tests__/match-pipelines.test.d.ts +2 -0
  508. package/dist/router/__tests__/match-pipelines.test.d.ts.map +1 -0
  509. package/dist/router/__tests__/match-pipelines.test.js +417 -0
  510. package/dist/router/__tests__/match-pipelines.test.js.map +1 -0
  511. package/dist/router/__tests__/match-result.test.d.ts +2 -0
  512. package/dist/router/__tests__/match-result.test.d.ts.map +1 -0
  513. package/dist/router/__tests__/match-result.test.js +457 -0
  514. package/dist/router/__tests__/match-result.test.js.map +1 -0
  515. package/dist/router/__tests__/on-error.test.d.ts +2 -0
  516. package/dist/router/__tests__/on-error.test.d.ts.map +1 -0
  517. package/dist/router/__tests__/on-error.test.js +678 -0
  518. package/dist/router/__tests__/on-error.test.js.map +1 -0
  519. package/dist/router/__tests__/pattern-matching.test.d.ts +2 -0
  520. package/dist/router/__tests__/pattern-matching.test.d.ts.map +1 -0
  521. package/dist/router/__tests__/pattern-matching.test.js +629 -0
  522. package/dist/router/__tests__/pattern-matching.test.js.map +1 -0
  523. package/dist/router/__tests__/segment-resolution-parallel-loading.test.d.ts +2 -0
  524. package/dist/router/__tests__/segment-resolution-parallel-loading.test.d.ts.map +1 -0
  525. package/dist/router/__tests__/segment-resolution-parallel-loading.test.js +155 -0
  526. package/dist/router/__tests__/segment-resolution-parallel-loading.test.js.map +1 -0
  527. package/dist/router/error-handling.d.ts +77 -0
  528. package/dist/router/error-handling.d.ts.map +1 -0
  529. package/dist/router/error-handling.js +202 -0
  530. package/dist/router/error-handling.js.map +1 -0
  531. package/dist/router/handler-context.d.ts +20 -0
  532. package/dist/router/handler-context.d.ts.map +1 -0
  533. package/dist/router/handler-context.js +198 -0
  534. package/dist/router/handler-context.js.map +1 -0
  535. package/dist/router/intercept-resolution.d.ts +66 -0
  536. package/dist/router/intercept-resolution.d.ts.map +1 -0
  537. package/dist/router/intercept-resolution.js +246 -0
  538. package/dist/router/intercept-resolution.js.map +1 -0
  539. package/dist/router/loader-resolution.d.ts +64 -0
  540. package/dist/router/loader-resolution.d.ts.map +1 -0
  541. package/dist/router/loader-resolution.js +284 -0
  542. package/dist/router/loader-resolution.js.map +1 -0
  543. package/dist/router/logging.d.ts +15 -0
  544. package/dist/router/logging.d.ts.map +1 -0
  545. package/dist/router/logging.js +99 -0
  546. package/dist/router/logging.js.map +1 -0
  547. package/dist/router/manifest.d.ts +22 -0
  548. package/dist/router/manifest.d.ts.map +1 -0
  549. package/dist/router/manifest.js +181 -0
  550. package/dist/router/manifest.js.map +1 -0
  551. package/dist/router/match-api.d.ts +35 -0
  552. package/dist/router/match-api.d.ts.map +1 -0
  553. package/dist/router/match-api.js +406 -0
  554. package/dist/router/match-api.js.map +1 -0
  555. package/dist/router/match-context.d.ts +206 -0
  556. package/dist/router/match-context.d.ts.map +1 -0
  557. package/dist/router/match-context.js +17 -0
  558. package/dist/router/match-context.js.map +1 -0
  559. package/dist/router/match-middleware/background-revalidation.d.ts +127 -0
  560. package/dist/router/match-middleware/background-revalidation.d.ts.map +1 -0
  561. package/dist/router/match-middleware/background-revalidation.js +75 -0
  562. package/dist/router/match-middleware/background-revalidation.js.map +1 -0
  563. package/dist/router/match-middleware/cache-lookup.d.ts +112 -0
  564. package/dist/router/match-middleware/cache-lookup.d.ts.map +1 -0
  565. package/dist/router/match-middleware/cache-lookup.js +257 -0
  566. package/dist/router/match-middleware/cache-lookup.js.map +1 -0
  567. package/dist/router/match-middleware/cache-store.d.ts +113 -0
  568. package/dist/router/match-middleware/cache-store.d.ts.map +1 -0
  569. package/dist/router/match-middleware/cache-store.js +108 -0
  570. package/dist/router/match-middleware/cache-store.js.map +1 -0
  571. package/dist/router/match-middleware/index.d.ts +81 -0
  572. package/dist/router/match-middleware/index.d.ts.map +1 -0
  573. package/dist/router/match-middleware/index.js +80 -0
  574. package/dist/router/match-middleware/index.js.map +1 -0
  575. package/dist/router/match-middleware/intercept-resolution.d.ts +117 -0
  576. package/dist/router/match-middleware/intercept-resolution.d.ts.map +1 -0
  577. package/dist/router/match-middleware/intercept-resolution.js +134 -0
  578. package/dist/router/match-middleware/intercept-resolution.js.map +1 -0
  579. package/dist/router/match-middleware/segment-resolution.d.ts +99 -0
  580. package/dist/router/match-middleware/segment-resolution.d.ts.map +1 -0
  581. package/dist/router/match-middleware/segment-resolution.js +53 -0
  582. package/dist/router/match-middleware/segment-resolution.js.map +1 -0
  583. package/dist/router/match-pipelines.d.ts +147 -0
  584. package/dist/router/match-pipelines.d.ts.map +1 -0
  585. package/dist/router/match-pipelines.js +82 -0
  586. package/dist/router/match-pipelines.js.map +1 -0
  587. package/dist/router/match-result.d.ts +126 -0
  588. package/dist/router/match-result.d.ts.map +1 -0
  589. package/dist/router/match-result.js +93 -0
  590. package/dist/router/match-result.js.map +1 -0
  591. package/dist/router/metrics.d.ts +20 -0
  592. package/dist/router/metrics.d.ts.map +1 -0
  593. package/dist/router/metrics.js +47 -0
  594. package/dist/router/metrics.js.map +1 -0
  595. package/dist/router/middleware.d.ts +249 -0
  596. package/dist/router/middleware.d.ts.map +1 -0
  597. package/dist/router/middleware.js +434 -0
  598. package/dist/router/middleware.js.map +1 -0
  599. package/dist/router/middleware.test.d.ts +2 -0
  600. package/dist/router/middleware.test.d.ts.map +1 -0
  601. package/dist/router/middleware.test.js +816 -0
  602. package/dist/router/middleware.test.js.map +1 -0
  603. package/dist/router/pattern-matching.d.ts +149 -0
  604. package/dist/router/pattern-matching.d.ts.map +1 -0
  605. package/dist/router/pattern-matching.js +349 -0
  606. package/dist/router/pattern-matching.js.map +1 -0
  607. package/dist/router/revalidation.d.ts +44 -0
  608. package/dist/router/revalidation.d.ts.map +1 -0
  609. package/dist/router/revalidation.js +147 -0
  610. package/dist/router/revalidation.js.map +1 -0
  611. package/dist/router/router-context.d.ts +135 -0
  612. package/dist/router/router-context.d.ts.map +1 -0
  613. package/dist/router/router-context.js +36 -0
  614. package/dist/router/router-context.js.map +1 -0
  615. package/dist/router/segment-resolution.d.ts +127 -0
  616. package/dist/router/segment-resolution.d.ts.map +1 -0
  617. package/dist/router/segment-resolution.js +919 -0
  618. package/dist/router/segment-resolution.js.map +1 -0
  619. package/dist/router/trie-matching.d.ts +40 -0
  620. package/dist/router/trie-matching.d.ts.map +1 -0
  621. package/dist/router/trie-matching.js +127 -0
  622. package/dist/router/trie-matching.js.map +1 -0
  623. package/dist/router/types.d.ts +136 -0
  624. package/dist/router/types.d.ts.map +1 -0
  625. package/dist/router/types.js +7 -0
  626. package/dist/router/types.js.map +1 -0
  627. package/dist/router.d.ts +753 -0
  628. package/dist/router.d.ts.map +1 -0
  629. package/dist/router.gen.d.ts +6 -0
  630. package/dist/router.gen.d.ts.map +1 -0
  631. package/dist/router.gen.js +6 -0
  632. package/dist/router.gen.js.map +1 -0
  633. package/dist/router.js +1304 -0
  634. package/dist/router.js.map +1 -0
  635. package/dist/rsc/__tests__/helpers.test.d.ts +2 -0
  636. package/dist/rsc/__tests__/helpers.test.d.ts.map +1 -0
  637. package/dist/rsc/__tests__/helpers.test.js +140 -0
  638. package/dist/rsc/__tests__/helpers.test.js.map +1 -0
  639. package/dist/rsc/handler.d.ts +45 -0
  640. package/dist/rsc/handler.d.ts.map +1 -0
  641. package/dist/rsc/handler.js +1172 -0
  642. package/dist/rsc/handler.js.map +1 -0
  643. package/dist/rsc/helpers.d.ts +16 -0
  644. package/dist/rsc/helpers.d.ts.map +1 -0
  645. package/dist/rsc/helpers.js +55 -0
  646. package/dist/rsc/helpers.js.map +1 -0
  647. package/dist/rsc/index.d.ts +22 -0
  648. package/dist/rsc/index.d.ts.map +1 -0
  649. package/dist/rsc/index.js +23 -0
  650. package/dist/rsc/index.js.map +1 -0
  651. package/dist/rsc/nonce.d.ts +9 -0
  652. package/dist/rsc/nonce.d.ts.map +1 -0
  653. package/dist/rsc/nonce.js +18 -0
  654. package/dist/rsc/nonce.js.map +1 -0
  655. package/dist/rsc/types.d.ts +206 -0
  656. package/dist/rsc/types.d.ts.map +1 -0
  657. package/dist/rsc/types.js +8 -0
  658. package/dist/rsc/types.js.map +1 -0
  659. package/dist/search-params.d.ts +103 -0
  660. package/dist/search-params.d.ts.map +1 -0
  661. package/dist/search-params.js +74 -0
  662. package/dist/search-params.js.map +1 -0
  663. package/dist/segment-system.d.ts +75 -0
  664. package/dist/segment-system.d.ts.map +1 -0
  665. package/dist/segment-system.js +336 -0
  666. package/dist/segment-system.js.map +1 -0
  667. package/dist/server/context.d.ts +245 -0
  668. package/dist/server/context.d.ts.map +1 -0
  669. package/dist/server/context.js +197 -0
  670. package/dist/server/context.js.map +1 -0
  671. package/dist/server/fetchable-loader-store.d.ts +18 -0
  672. package/dist/server/fetchable-loader-store.d.ts.map +1 -0
  673. package/dist/server/fetchable-loader-store.js +18 -0
  674. package/dist/server/fetchable-loader-store.js.map +1 -0
  675. package/dist/server/handle-store.d.ts +85 -0
  676. package/dist/server/handle-store.d.ts.map +1 -0
  677. package/dist/server/handle-store.js +142 -0
  678. package/dist/server/handle-store.js.map +1 -0
  679. package/dist/server/loader-registry.d.ts +55 -0
  680. package/dist/server/loader-registry.d.ts.map +1 -0
  681. package/dist/server/loader-registry.js +132 -0
  682. package/dist/server/loader-registry.js.map +1 -0
  683. package/dist/server/request-context.d.ts +226 -0
  684. package/dist/server/request-context.d.ts.map +1 -0
  685. package/dist/server/request-context.js +290 -0
  686. package/dist/server/request-context.js.map +1 -0
  687. package/dist/server/root-layout.d.ts +4 -0
  688. package/dist/server/root-layout.d.ts.map +1 -0
  689. package/dist/server/root-layout.js +5 -0
  690. package/dist/server/root-layout.js.map +1 -0
  691. package/dist/server.d.ts +15 -0
  692. package/dist/server.d.ts.map +1 -0
  693. package/dist/server.js +20 -0
  694. package/dist/server.js.map +1 -0
  695. package/dist/ssr/__tests__/ssr-handler.test.d.ts +2 -0
  696. package/dist/ssr/__tests__/ssr-handler.test.d.ts.map +1 -0
  697. package/dist/ssr/__tests__/ssr-handler.test.js +132 -0
  698. package/dist/ssr/__tests__/ssr-handler.test.js.map +1 -0
  699. package/dist/ssr/index.d.ts +98 -0
  700. package/dist/ssr/index.d.ts.map +1 -0
  701. package/dist/ssr/index.js +158 -0
  702. package/dist/ssr/index.js.map +1 -0
  703. package/dist/static-handler.d.ts +50 -0
  704. package/dist/static-handler.d.ts.map +1 -0
  705. package/dist/static-handler.gen.d.ts +5 -0
  706. package/dist/static-handler.gen.d.ts.map +1 -0
  707. package/dist/static-handler.gen.js +5 -0
  708. package/dist/static-handler.gen.js.map +1 -0
  709. package/dist/static-handler.js +29 -0
  710. package/dist/static-handler.js.map +1 -0
  711. package/dist/testing/vitest.js +82 -0
  712. package/dist/theme/ThemeProvider.d.ts +20 -0
  713. package/dist/theme/ThemeProvider.d.ts.map +1 -0
  714. package/dist/theme/ThemeProvider.js +240 -0
  715. package/dist/theme/ThemeProvider.js.map +1 -0
  716. package/dist/theme/ThemeScript.d.ts +48 -0
  717. package/dist/theme/ThemeScript.d.ts.map +1 -0
  718. package/dist/theme/ThemeScript.js +13 -0
  719. package/dist/theme/ThemeScript.js.map +1 -0
  720. package/dist/theme/__tests__/theme.test.d.ts +2 -0
  721. package/dist/theme/__tests__/theme.test.d.ts.map +1 -0
  722. package/dist/theme/__tests__/theme.test.js +103 -0
  723. package/dist/theme/__tests__/theme.test.js.map +1 -0
  724. package/dist/theme/constants.d.ts +29 -0
  725. package/dist/theme/constants.d.ts.map +1 -0
  726. package/dist/theme/constants.js +48 -0
  727. package/dist/theme/constants.js.map +1 -0
  728. package/dist/theme/index.d.ts +31 -0
  729. package/dist/theme/index.d.ts.map +1 -0
  730. package/dist/theme/index.js +36 -0
  731. package/dist/theme/index.js.map +1 -0
  732. package/dist/theme/theme-context.d.ts +40 -0
  733. package/dist/theme/theme-context.d.ts.map +1 -0
  734. package/dist/theme/theme-context.js +60 -0
  735. package/dist/theme/theme-context.js.map +1 -0
  736. package/dist/theme/theme-script.d.ts +27 -0
  737. package/dist/theme/theme-script.d.ts.map +1 -0
  738. package/dist/theme/theme-script.js +147 -0
  739. package/dist/theme/theme-script.js.map +1 -0
  740. package/dist/theme/types.d.ts +163 -0
  741. package/dist/theme/types.d.ts.map +1 -0
  742. package/dist/theme/types.js +11 -0
  743. package/dist/theme/types.js.map +1 -0
  744. package/dist/theme/use-theme.d.ts +12 -0
  745. package/dist/theme/use-theme.d.ts.map +1 -0
  746. package/dist/theme/use-theme.js +40 -0
  747. package/dist/theme/use-theme.js.map +1 -0
  748. package/dist/types/__internal.d.ts +127 -0
  749. package/dist/types/bin/rango.d.ts +1 -0
  750. package/dist/types/browser/action-coordinator.d.ts +57 -0
  751. package/dist/types/browser/action-fence.d.ts +33 -0
  752. package/dist/types/browser/app-shell.d.ts +34 -0
  753. package/dist/types/browser/app-version.d.ts +6 -0
  754. package/dist/types/browser/connection-warmup.d.ts +31 -0
  755. package/dist/types/browser/cookie-name.d.ts +66 -0
  756. package/dist/types/browser/dev-discovery.d.ts +11 -0
  757. package/dist/types/browser/event-controller.d.ts +231 -0
  758. package/dist/types/browser/history-state.d.ts +26 -0
  759. package/dist/types/browser/index.d.ts +1 -0
  760. package/dist/types/browser/intercept-utils.d.ts +30 -0
  761. package/dist/types/browser/invalidate-client-cache.d.ts +17 -0
  762. package/dist/types/browser/link-interceptor.d.ts +53 -0
  763. package/dist/types/browser/logging.d.ts +33 -0
  764. package/dist/types/browser/merge-segment-loaders.d.ts +38 -0
  765. package/dist/types/browser/navigation-bridge.d.ts +39 -0
  766. package/dist/types/browser/navigation-client.d.ts +17 -0
  767. package/dist/types/browser/navigation-store-handle.d.ts +25 -0
  768. package/dist/types/browser/navigation-store.d.ts +85 -0
  769. package/dist/types/browser/navigation-transaction.d.ts +75 -0
  770. package/dist/types/browser/network-error-handler.d.ts +35 -0
  771. package/dist/types/browser/notify-listeners.d.ts +2 -0
  772. package/dist/types/browser/partial-update.d.ts +61 -0
  773. package/dist/types/browser/prefetch/cache.d.ts +224 -0
  774. package/dist/types/browser/prefetch/default-strategy.d.ts +31 -0
  775. package/dist/types/browser/prefetch/fetch.d.ts +52 -0
  776. package/dist/types/browser/prefetch/invalidation.d.ts +6 -0
  777. package/dist/types/browser/prefetch/loader.d.ts +12 -0
  778. package/dist/types/browser/prefetch/observer.d.ts +24 -0
  779. package/dist/types/browser/prefetch/policy.d.ts +13 -0
  780. package/dist/types/browser/prefetch/queue.d.ts +48 -0
  781. package/dist/types/browser/prefetch/resource-ready.d.ts +28 -0
  782. package/dist/types/browser/prefetch/runtime.d.ts +2 -0
  783. package/dist/types/browser/rango-state.d.ts +56 -0
  784. package/dist/types/browser/react/Link.d.ts +132 -0
  785. package/dist/types/browser/react/NavigationProvider.d.ts +88 -0
  786. package/dist/types/browser/react/ScrollRestoration.d.ts +78 -0
  787. package/dist/types/browser/react/context.d.ts +57 -0
  788. package/dist/types/browser/react/filter-segment-order.d.ts +35 -0
  789. package/dist/types/browser/react/index.d.ts +1 -0
  790. package/dist/types/browser/react/location-state-shared.d.ts +162 -0
  791. package/dist/types/browser/react/location-state.d.ts +29 -0
  792. package/dist/types/browser/react/mount-context.d.ts +23 -0
  793. package/dist/types/browser/react/nonce-context.d.ts +14 -0
  794. package/dist/types/browser/react/shallow-equal.d.ts +5 -0
  795. package/dist/types/browser/react/use-action.d.ts +61 -0
  796. package/dist/types/browser/react/use-handle.d.ts +21 -0
  797. package/dist/types/browser/react/use-href.d.ts +32 -0
  798. package/dist/types/browser/react/use-link-status.d.ts +36 -0
  799. package/dist/types/browser/react/use-mount.d.ts +24 -0
  800. package/dist/types/browser/react/use-navigation.d.ts +15 -0
  801. package/dist/types/browser/react/use-params.d.ts +21 -0
  802. package/dist/types/browser/react/use-pathname.d.ts +13 -0
  803. package/dist/types/browser/react/use-reverse.d.ts +40 -0
  804. package/dist/types/browser/react/use-router.d.ts +30 -0
  805. package/dist/types/browser/react/use-search-params.d.ts +66 -0
  806. package/dist/types/browser/react/use-segments.d.ts +29 -0
  807. package/dist/types/browser/response-adapter.d.ts +58 -0
  808. package/dist/types/browser/rsc-router.d.ts +146 -0
  809. package/dist/types/browser/scroll-restoration.d.ts +103 -0
  810. package/dist/types/browser/segment-reconciler.d.ts +74 -0
  811. package/dist/types/browser/segment-structure-assert.d.ts +16 -0
  812. package/dist/types/browser/server-action-bridge.d.ts +29 -0
  813. package/dist/types/browser/types.d.ts +546 -0
  814. package/dist/types/browser/validate-redirect-origin.d.ts +28 -0
  815. package/dist/types/build/collect-fallback-refs.d.ts +5 -0
  816. package/dist/types/build/generate-manifest.d.ts +106 -0
  817. package/dist/types/build/generate-route-types.d.ts +8 -0
  818. package/dist/types/build/index.d.ts +21 -0
  819. package/dist/types/build/merge-full-manifests.d.ts +3 -0
  820. package/dist/types/build/prefix-tree-utils.d.ts +56 -0
  821. package/dist/types/build/route-trie.d.ts +20 -0
  822. package/dist/types/build/route-types/ast-helpers.d.ts +3 -0
  823. package/dist/types/build/route-types/ast-route-extraction.d.ts +13 -0
  824. package/dist/types/build/route-types/codegen.d.ts +16 -0
  825. package/dist/types/build/route-types/include-resolution.d.ts +74 -0
  826. package/dist/types/build/route-types/param-extraction.d.ts +13 -0
  827. package/dist/types/build/route-types/per-module-writer.d.ts +20 -0
  828. package/dist/types/build/route-types/router-processing.d.ts +81 -0
  829. package/dist/types/build/route-types/scan-filter.d.ts +17 -0
  830. package/dist/types/build/route-types/source-scan.d.ts +13 -0
  831. package/dist/types/build/runtime-discovery.d.ts +24 -0
  832. package/dist/types/cache/background-task.d.ts +21 -0
  833. package/dist/types/cache/cache-error.d.ts +71 -0
  834. package/dist/types/cache/cache-exec-scope.d.ts +31 -0
  835. package/dist/types/cache/cache-key-utils.d.ts +43 -0
  836. package/dist/types/cache/cache-policy.d.ts +59 -0
  837. package/dist/types/cache/cache-runtime.d.ts +51 -0
  838. package/dist/types/cache/cache-scope.d.ts +215 -0
  839. package/dist/types/cache/cache-tag.d.ts +79 -0
  840. package/dist/types/cache/cf/cf-base64.d.ts +4 -0
  841. package/dist/types/cache/cf/cf-cache-constants.d.ts +112 -0
  842. package/dist/types/cache/cf/cf-cache-store.d.ts +630 -0
  843. package/dist/types/cache/cf/cf-cache-types.d.ts +365 -0
  844. package/dist/types/cache/cf/cf-kv-utils.d.ts +43 -0
  845. package/dist/types/cache/cf/cf-tag-marker-memo.d.ts +15 -0
  846. package/dist/types/cache/cf/cf-zone-purge.d.ts +31 -0
  847. package/dist/types/cache/cf/index.d.ts +4 -0
  848. package/dist/types/cache/document-cache.d.ts +71 -0
  849. package/dist/types/cache/handle-capture.d.ts +23 -0
  850. package/dist/types/cache/handle-snapshot.d.ts +39 -0
  851. package/dist/types/cache/index.d.ts +9 -0
  852. package/dist/types/cache/memory-segment-store.d.ts +163 -0
  853. package/dist/types/cache/profile-registry.d.ts +40 -0
  854. package/dist/types/cache/read-through-swr.d.ts +61 -0
  855. package/dist/types/cache/search-params-filter.d.ts +64 -0
  856. package/dist/types/cache/segment-codec.d.ts +78 -0
  857. package/dist/types/cache/shell-snapshot.d.ts +186 -0
  858. package/dist/types/cache/tag-invalidation.d.ts +74 -0
  859. package/dist/types/cache/taint.d.ts +77 -0
  860. package/dist/types/cache/types.d.ts +522 -0
  861. package/dist/types/cache/vercel/index.d.ts +1 -0
  862. package/dist/types/cache/vercel/vercel-cache-store.d.ts +268 -0
  863. package/dist/types/client-urls/client-root.d.ts +38 -0
  864. package/dist/types/client-urls/client-urls.d.ts +5 -0
  865. package/dist/types/client-urls/navigation.d.ts +38 -0
  866. package/dist/types/client-urls/revalidation-protocol.d.ts +25 -0
  867. package/dist/types/client-urls/server-projection.d.ts +71 -0
  868. package/dist/types/client-urls/types.d.ts +148 -0
  869. package/dist/types/client.d.ts +192 -0
  870. package/dist/types/client.rsc.d.ts +42 -0
  871. package/dist/types/cloudflare/index.d.ts +7 -0
  872. package/dist/types/cloudflare/tracing.d.ts +57 -0
  873. package/dist/types/component-utils.d.ts +46 -0
  874. package/dist/types/components/DefaultDocument.d.ts +13 -0
  875. package/dist/types/context-var.d.ts +84 -0
  876. package/dist/types/debug.d.ts +57 -0
  877. package/dist/types/decode-loader-results.d.ts +42 -0
  878. package/dist/types/default-error-boundary.d.ts +10 -0
  879. package/dist/types/defer.d.ts +89 -0
  880. package/dist/types/deps/browser.d.ts +1 -0
  881. package/dist/types/deps/html-stream-client.d.ts +1 -0
  882. package/dist/types/deps/html-stream-server.d.ts +1 -0
  883. package/dist/types/deps/rsc.d.ts +1 -0
  884. package/dist/types/deps/ssr.d.ts +1 -0
  885. package/dist/types/dev-discovery-protocol.d.ts +5 -0
  886. package/dist/types/encode-kv.d.ts +35 -0
  887. package/dist/types/errors.d.ts +227 -0
  888. package/dist/types/escape-script.d.ts +44 -0
  889. package/dist/types/handle.d.ts +93 -0
  890. package/dist/types/handles/MetaTags.d.ts +17 -0
  891. package/dist/types/handles/Scripts.d.ts +38 -0
  892. package/dist/types/handles/breadcrumbs.d.ts +43 -0
  893. package/dist/types/handles/deferred-resolution.d.ts +53 -0
  894. package/dist/types/handles/is-thenable.d.ts +10 -0
  895. package/dist/types/handles/meta.d.ts +43 -0
  896. package/dist/types/handles/script.d.ts +139 -0
  897. package/dist/types/host/cookie-handler.d.ts +8 -0
  898. package/dist/types/host/errors.d.ts +40 -0
  899. package/dist/types/host/index.d.ts +33 -0
  900. package/dist/types/host/pattern-matcher.d.ts +30 -0
  901. package/dist/types/host/router.d.ts +12 -0
  902. package/dist/types/host/testing.d.ts +41 -0
  903. package/dist/types/host/types.d.ts +148 -0
  904. package/dist/types/host/utils.d.ts +20 -0
  905. package/dist/types/href-client.d.ts +214 -0
  906. package/dist/types/index.d.ts +113 -0
  907. package/dist/types/index.rsc.d.ts +52 -0
  908. package/dist/types/internal-debug.d.ts +1 -0
  909. package/dist/types/loader-redirect.d.ts +27 -0
  910. package/dist/types/loader-store.d.ts +193 -0
  911. package/dist/types/loader.d.ts +18 -0
  912. package/dist/types/loader.rsc.d.ts +18 -0
  913. package/dist/types/missing-id-error.d.ts +1 -0
  914. package/dist/types/outlet-context.d.ts +32 -0
  915. package/dist/types/outlet-provider.d.ts +15 -0
  916. package/dist/types/prerender/build-shell-capture.d.ts +104 -0
  917. package/dist/types/prerender/param-hash.d.ts +6 -0
  918. package/dist/types/prerender/shell-manifest-key.d.ts +18 -0
  919. package/dist/types/prerender/store.d.ts +63 -0
  920. package/dist/types/prerender.d.ts +292 -0
  921. package/dist/types/redirect-origin.d.ts +71 -0
  922. package/dist/types/regex-escape.d.ts +6 -0
  923. package/dist/types/render-error-thrower.d.ts +13 -0
  924. package/dist/types/response-utils.d.ts +35 -0
  925. package/dist/types/reverse.d.ts +206 -0
  926. package/dist/types/root-error-boundary.d.ts +32 -0
  927. package/dist/types/route-content-wrapper.d.ts +84 -0
  928. package/dist/types/route-definition/dsl-helpers.d.ts +130 -0
  929. package/dist/types/route-definition/helper-factories.d.ts +22 -0
  930. package/dist/types/route-definition/helpers-types.d.ts +405 -0
  931. package/dist/types/route-definition/index.d.ts +7 -0
  932. package/dist/types/route-definition/redirect.d.ts +48 -0
  933. package/dist/types/route-definition/resolve-handler-use.d.ts +19 -0
  934. package/dist/types/route-definition/use-item-types.d.ts +1 -0
  935. package/dist/types/route-definition.d.ts +1 -0
  936. package/dist/types/route-map-builder.d.ts +102 -0
  937. package/dist/types/route-name.d.ts +27 -0
  938. package/dist/types/route-types.d.ts +172 -0
  939. package/dist/types/router/basename.d.ts +10 -0
  940. package/dist/types/router/content-negotiation.d.ts +91 -0
  941. package/dist/types/router/debug-manifest.d.ts +7 -0
  942. package/dist/types/router/error-handling.d.ts +110 -0
  943. package/dist/types/router/find-match.d.ts +19 -0
  944. package/dist/types/router/handler-context.d.ts +41 -0
  945. package/dist/types/router/instrument.d.ts +191 -0
  946. package/dist/types/router/intercept-resolution.d.ts +91 -0
  947. package/dist/types/router/lazy-includes.d.ts +26 -0
  948. package/dist/types/router/loader-resolution.d.ts +85 -0
  949. package/dist/types/router/logging.d.ts +41 -0
  950. package/dist/types/router/manifest.d.ts +8 -0
  951. package/dist/types/router/match-api.d.ts +19 -0
  952. package/dist/types/router/match-context.d.ts +184 -0
  953. package/dist/types/router/match-handlers.d.ts +48 -0
  954. package/dist/types/router/match-middleware/background-revalidation.d.ts +113 -0
  955. package/dist/types/router/match-middleware/cache-lookup.d.ts +126 -0
  956. package/dist/types/router/match-middleware/cache-store.d.ts +112 -0
  957. package/dist/types/router/match-middleware/index.d.ts +80 -0
  958. package/dist/types/router/match-middleware/intercept-resolution.d.ts +116 -0
  959. package/dist/types/router/match-middleware/segment-resolution.d.ts +94 -0
  960. package/dist/types/router/match-pipelines.d.ts +103 -0
  961. package/dist/types/router/match-result.d.ts +114 -0
  962. package/dist/types/router/metrics.d.ts +6 -0
  963. package/dist/types/router/middleware-types.d.ts +74 -0
  964. package/dist/types/router/middleware.d.ts +116 -0
  965. package/dist/types/router/navigation-snapshot.d.ts +51 -0
  966. package/dist/types/router/params-util.d.ts +8 -0
  967. package/dist/types/router/parse-pattern.d.ts +38 -0
  968. package/dist/types/router/pattern-matching.d.ts +169 -0
  969. package/dist/types/router/prefetch-cache-ttl.d.ts +27 -0
  970. package/dist/types/router/prefetch-default.d.ts +28 -0
  971. package/dist/types/router/prefetch-limits.d.ts +20 -0
  972. package/dist/types/router/prerender-match.d.ts +53 -0
  973. package/dist/types/router/preview-match.d.ts +22 -0
  974. package/dist/types/router/request-classification.d.ts +104 -0
  975. package/dist/types/router/revalidation.d.ts +64 -0
  976. package/dist/types/router/route-snapshot.d.ts +112 -0
  977. package/dist/types/router/route-trie-builder.d.ts +77 -0
  978. package/dist/types/router/router-context.d.ts +137 -0
  979. package/dist/types/router/router-interfaces.d.ts +461 -0
  980. package/dist/types/router/router-options.d.ts +792 -0
  981. package/dist/types/router/router-registry.d.ts +15 -0
  982. package/dist/types/router/segment-resolution/fresh.d.ts +55 -0
  983. package/dist/types/router/segment-resolution/helpers.d.ts +93 -0
  984. package/dist/types/router/segment-resolution/loader-cache.d.ts +33 -0
  985. package/dist/types/router/segment-resolution/loader-mask.d.ts +44 -0
  986. package/dist/types/router/segment-resolution/loader-snapshot.d.ts +90 -0
  987. package/dist/types/router/segment-resolution/mask-nested.d.ts +53 -0
  988. package/dist/types/router/segment-resolution/revalidation.d.ts +85 -0
  989. package/dist/types/router/segment-resolution/static-store.d.ts +17 -0
  990. package/dist/types/router/segment-resolution/streamed-handler-telemetry.d.ts +16 -0
  991. package/dist/types/router/segment-resolution/view-transition-default.d.ts +27 -0
  992. package/dist/types/router/segment-resolution.d.ts +3 -0
  993. package/dist/types/router/segment-wrappers.d.ts +53 -0
  994. package/dist/types/router/state-cookie-name.d.ts +1 -0
  995. package/dist/types/router/substitute-pattern-params.d.ts +23 -0
  996. package/dist/types/router/telemetry-otel.d.ts +113 -0
  997. package/dist/types/router/telemetry.d.ts +216 -0
  998. package/dist/types/router/timeout.d.ts +107 -0
  999. package/dist/types/router/tracing.d.ts +139 -0
  1000. package/dist/types/router/transition-when.d.ts +13 -0
  1001. package/dist/types/router/trie-matching.d.ts +32 -0
  1002. package/dist/types/router/types.d.ts +98 -0
  1003. package/dist/types/router/url-params.d.ts +26 -0
  1004. package/dist/types/router.d.ts +7 -0
  1005. package/dist/types/rsc/capture-queue.d.ts +49 -0
  1006. package/dist/types/rsc/full-payload.d.ts +22 -0
  1007. package/dist/types/rsc/handler-context.d.ts +32 -0
  1008. package/dist/types/rsc/handler.d.ts +9 -0
  1009. package/dist/types/rsc/helpers.d.ts +127 -0
  1010. package/dist/types/rsc/index.d.ts +17 -0
  1011. package/dist/types/rsc/json-route-result.d.ts +20 -0
  1012. package/dist/types/rsc/loader-fetch.d.ts +14 -0
  1013. package/dist/types/rsc/manifest-init.d.ts +18 -0
  1014. package/dist/types/rsc/nonce.d.ts +38 -0
  1015. package/dist/types/rsc/origin-guard.d.ts +50 -0
  1016. package/dist/types/rsc/progressive-enhancement.d.ts +19 -0
  1017. package/dist/types/rsc/redirect-guard.d.ts +37 -0
  1018. package/dist/types/rsc/render-pipeline.d.ts +148 -0
  1019. package/dist/types/rsc/response-cache-serve.d.ts +46 -0
  1020. package/dist/types/rsc/response-error.d.ts +19 -0
  1021. package/dist/types/rsc/response-route-handler.d.ts +29 -0
  1022. package/dist/types/rsc/routine-plan.d.ts +124 -0
  1023. package/dist/types/rsc/rsc-rendering.d.ts +18 -0
  1024. package/dist/types/rsc/runtime-warnings.d.ts +22 -0
  1025. package/dist/types/rsc/server-action.d.ts +68 -0
  1026. package/dist/types/rsc/shell-build-manifest.d.ts +90 -0
  1027. package/dist/types/rsc/shell-capture-constants.d.ts +44 -0
  1028. package/dist/types/rsc/shell-capture.d.ts +425 -0
  1029. package/dist/types/rsc/shell-serve.d.ts +200 -0
  1030. package/dist/types/rsc/ssr-setup.d.ts +73 -0
  1031. package/dist/types/rsc/stream-idle.d.ts +60 -0
  1032. package/dist/types/rsc/transition-gate.d.ts +23 -0
  1033. package/dist/types/rsc/types.d.ts +353 -0
  1034. package/dist/types/runtime-env.d.ts +1 -0
  1035. package/dist/types/search-params.d.ts +125 -0
  1036. package/dist/types/segment-content-promise.d.ts +13 -0
  1037. package/dist/types/segment-fragments.d.ts +79 -0
  1038. package/dist/types/segment-loader-promise.d.ts +22 -0
  1039. package/dist/types/segment-system.d.ts +86 -0
  1040. package/dist/types/serialize.d.ts +164 -0
  1041. package/dist/types/server/context.d.ts +520 -0
  1042. package/dist/types/server/cookie-parse.d.ts +10 -0
  1043. package/dist/types/server/cookie-store.d.ts +107 -0
  1044. package/dist/types/server/fetchable-loader-store.d.ts +20 -0
  1045. package/dist/types/server/handle-store.d.ts +131 -0
  1046. package/dist/types/server/loader-registry.d.ts +32 -0
  1047. package/dist/types/server/request-context.d.ts +717 -0
  1048. package/dist/types/server/root-layout.d.ts +3 -0
  1049. package/dist/types/server.d.ts +16 -0
  1050. package/dist/types/ssr/index.d.ts +271 -0
  1051. package/dist/types/ssr/inject-rsc-eager.d.ts +3 -0
  1052. package/dist/types/ssr/preinit-client-references.d.ts +71 -0
  1053. package/dist/types/ssr/ssr-root.d.ts +84 -0
  1054. package/dist/types/ssr-suspension-warning.d.ts +19 -0
  1055. package/dist/types/static-handler.d.ts +71 -0
  1056. package/dist/types/testing/cache-status.d.ts +63 -0
  1057. package/dist/types/testing/collect-handle.d.ts +20 -0
  1058. package/dist/types/testing/dispatch.d.ts +127 -0
  1059. package/dist/types/testing/dom.entry.d.ts +15 -0
  1060. package/dist/types/testing/e2e/fixture.d.ts +37 -0
  1061. package/dist/types/testing/e2e/index.d.ts +31 -0
  1062. package/dist/types/testing/e2e/matchers.d.ts +17 -0
  1063. package/dist/types/testing/e2e/page-helpers.d.ts +86 -0
  1064. package/dist/types/testing/e2e/parity.d.ts +111 -0
  1065. package/dist/types/testing/e2e/server.d.ts +35 -0
  1066. package/dist/types/testing/flight-matchers.d.ts +55 -0
  1067. package/dist/types/testing/flight-normalize.d.ts +1 -0
  1068. package/dist/types/testing/flight-tree.d.ts +192 -0
  1069. package/dist/types/testing/flight.d.ts +115 -0
  1070. package/dist/types/testing/flight.entry.d.ts +27 -0
  1071. package/dist/types/testing/generated-routes.d.ts +66 -0
  1072. package/dist/types/testing/index.d.ts +54 -0
  1073. package/dist/types/testing/internal/context.d.ts +225 -0
  1074. package/dist/types/testing/internal/flight-client-globals.d.ts +1 -0
  1075. package/dist/types/testing/internal/seed-vars.d.ts +30 -0
  1076. package/dist/types/testing/render-handler.d.ts +160 -0
  1077. package/dist/types/testing/render-route.d.ts +265 -0
  1078. package/dist/types/testing/run-loader.d.ts +195 -0
  1079. package/dist/types/testing/run-middleware.d.ts +132 -0
  1080. package/dist/types/testing/run-transition-when.d.ts +78 -0
  1081. package/dist/types/testing/shell-status.d.ts +81 -0
  1082. package/dist/types/testing/vitest-stubs/cloudflare-email.d.ts +6 -0
  1083. package/dist/types/testing/vitest-stubs/cloudflare-workers.d.ts +13 -0
  1084. package/dist/types/testing/vitest-stubs/plugin-rsc.d.ts +7 -0
  1085. package/dist/types/testing/vitest-stubs/version.d.ts +1 -0
  1086. package/dist/types/testing/vitest.d.ts +205 -0
  1087. package/dist/types/theme/ThemeProvider.d.ts +13 -0
  1088. package/dist/types/theme/ThemeScript.d.ts +45 -0
  1089. package/dist/types/theme/constants.d.ts +39 -0
  1090. package/dist/types/theme/index.d.ts +29 -0
  1091. package/dist/types/theme/theme-context.d.ts +21 -0
  1092. package/dist/types/theme/theme-script.d.ts +26 -0
  1093. package/dist/types/theme/types.d.ts +162 -0
  1094. package/dist/types/theme/use-theme.d.ts +8 -0
  1095. package/dist/types/types/boundaries.d.ts +115 -0
  1096. package/dist/types/types/cache-types.d.ts +191 -0
  1097. package/dist/types/types/error-types.d.ts +114 -0
  1098. package/dist/types/types/global-namespace.d.ts +90 -0
  1099. package/dist/types/types/handler-context.d.ts +658 -0
  1100. package/dist/types/types/index.d.ts +11 -0
  1101. package/dist/types/types/loader-types.d.ts +240 -0
  1102. package/dist/types/types/request-scope.d.ts +93 -0
  1103. package/dist/types/types/route-config.d.ts +105 -0
  1104. package/dist/types/types/route-entry.d.ts +98 -0
  1105. package/dist/types/types/segments.d.ts +254 -0
  1106. package/dist/types/types.d.ts +1 -0
  1107. package/dist/types/urls/include-helper.d.ts +17 -0
  1108. package/dist/types/urls/include-provider.d.ts +27 -0
  1109. package/dist/types/urls/index.d.ts +6 -0
  1110. package/dist/types/urls/path-helper-types.d.ts +207 -0
  1111. package/dist/types/urls/path-helper.d.ts +12 -0
  1112. package/dist/types/urls/pattern-types.d.ts +166 -0
  1113. package/dist/types/urls/response-types.d.ts +67 -0
  1114. package/dist/types/urls/type-extraction.d.ts +157 -0
  1115. package/dist/types/urls/urls-function.d.ts +24 -0
  1116. package/dist/types/urls.d.ts +1 -0
  1117. package/dist/types/use-loader.d.ts +150 -0
  1118. package/dist/types/vercel/index.d.ts +10 -0
  1119. package/dist/types/vercel/tracing.d.ts +71 -0
  1120. package/dist/types/vite/debug.d.ts +80 -0
  1121. package/dist/types/vite/discovery/bundle-postprocess.d.ts +12 -0
  1122. package/dist/types/vite/discovery/client-urls-projection.d.ts +53 -0
  1123. package/dist/types/vite/discovery/dev-prerender-cache.d.ts +65 -0
  1124. package/dist/types/vite/discovery/discover-routers.d.ts +17 -0
  1125. package/dist/types/vite/discovery/discovery-errors.d.ts +113 -0
  1126. package/dist/types/vite/discovery/gate-state.d.ts +79 -0
  1127. package/dist/types/vite/discovery/prerender-collection.d.ts +24 -0
  1128. package/dist/types/vite/discovery/route-types-writer.d.ts +32 -0
  1129. package/dist/types/vite/discovery/self-gen-tracking.d.ts +22 -0
  1130. package/dist/types/vite/discovery/shell-prerender-phase.d.ts +40 -0
  1131. package/dist/types/vite/discovery/state.d.ts +170 -0
  1132. package/dist/types/vite/discovery/virtual-module-codegen.d.ts +15 -0
  1133. package/dist/types/vite/encryption-key.d.ts +2 -0
  1134. package/dist/types/vite/index.d.ts +11 -0
  1135. package/dist/types/vite/inject-client-debug.d.ts +56 -0
  1136. package/dist/types/vite/plugin-types.d.ts +298 -0
  1137. package/dist/types/vite/plugins/cjs-to-esm.d.ts +6 -0
  1138. package/dist/types/vite/plugins/client-ref-dedup.d.ts +29 -0
  1139. package/dist/types/vite/plugins/client-ref-hashing.d.ts +35 -0
  1140. package/dist/types/vite/plugins/cloudflare-protocol-stub.d.ts +64 -0
  1141. package/dist/types/vite/plugins/expose-action-id.d.ts +18 -0
  1142. package/dist/types/vite/plugins/expose-id-utils.d.ts +37 -0
  1143. package/dist/types/vite/plugins/expose-ids/export-analysis.d.ts +19 -0
  1144. package/dist/types/vite/plugins/expose-ids/handler-transform.d.ts +10 -0
  1145. package/dist/types/vite/plugins/expose-ids/loader-transform.d.ts +8 -0
  1146. package/dist/types/vite/plugins/expose-ids/router-transform.d.ts +13 -0
  1147. package/dist/types/vite/plugins/expose-ids/types.d.ts +29 -0
  1148. package/dist/types/vite/plugins/expose-internal-ids.d.ts +16 -0
  1149. package/dist/types/vite/plugins/performance-tracks.d.ts +25 -0
  1150. package/dist/types/vite/plugins/refresh-cmd.d.ts +20 -0
  1151. package/dist/types/vite/plugins/server-ref-hashing.d.ts +24 -0
  1152. package/dist/types/vite/plugins/server-reference-pattern.d.ts +1 -0
  1153. package/dist/types/vite/plugins/use-cache-transform.d.ts +20 -0
  1154. package/dist/types/vite/plugins/vercel-output.d.ts +85 -0
  1155. package/dist/types/vite/plugins/version-injector.d.ts +21 -0
  1156. package/dist/types/vite/plugins/version-plugin.d.ts +19 -0
  1157. package/dist/types/vite/plugins/virtual-entries.d.ts +36 -0
  1158. package/dist/types/vite/plugins/virtual-stub-plugin.d.ts +7 -0
  1159. package/dist/types/vite/rango.d.ts +29 -0
  1160. package/dist/types/vite/router-discovery.d.ts +23 -0
  1161. package/dist/types/vite/utils/ast-handler-extract.d.ts +64 -0
  1162. package/dist/types/vite/utils/banner.d.ts +2 -0
  1163. package/dist/types/vite/utils/bundle-analysis.d.ts +28 -0
  1164. package/dist/types/vite/utils/client-chunks.d.ts +55 -0
  1165. package/dist/types/vite/utils/directive-prologue.d.ts +16 -0
  1166. package/dist/types/vite/utils/forward-user-plugins.d.ts +37 -0
  1167. package/dist/types/vite/utils/manifest-utils.d.ts +7 -0
  1168. package/dist/types/vite/utils/package-resolution.d.ts +6 -0
  1169. package/dist/types/vite/utils/prerender-utils.d.ts +32 -0
  1170. package/dist/types/vite/utils/shared-utils.d.ts +67 -0
  1171. package/dist/types.d.ts +1479 -0
  1172. package/dist/types.d.ts.map +1 -0
  1173. package/dist/types.js +10 -0
  1174. package/dist/types.js.map +1 -0
  1175. package/dist/urls.d.ts +441 -0
  1176. package/dist/urls.d.ts.map +1 -0
  1177. package/dist/urls.gen.d.ts +8 -0
  1178. package/dist/urls.gen.d.ts.map +1 -0
  1179. package/dist/urls.gen.js +8 -0
  1180. package/dist/urls.gen.js.map +1 -0
  1181. package/dist/urls.js +443 -0
  1182. package/dist/urls.js.map +1 -0
  1183. package/dist/use-loader.d.ts +127 -0
  1184. package/dist/use-loader.d.ts.map +1 -0
  1185. package/dist/use-loader.js +237 -0
  1186. package/dist/use-loader.js.map +1 -0
  1187. package/dist/vite/__tests__/ast-handler-extract.test.d.ts +2 -0
  1188. package/dist/vite/__tests__/ast-handler-extract.test.d.ts.map +1 -0
  1189. package/dist/vite/__tests__/ast-handler-extract.test.js +294 -0
  1190. package/dist/vite/__tests__/ast-handler-extract.test.js.map +1 -0
  1191. package/dist/vite/__tests__/expose-id-utils.test.d.ts +2 -0
  1192. package/dist/vite/__tests__/expose-id-utils.test.d.ts.map +1 -0
  1193. package/dist/vite/__tests__/expose-id-utils.test.js +224 -0
  1194. package/dist/vite/__tests__/expose-id-utils.test.js.map +1 -0
  1195. package/dist/vite/__tests__/expose-internal-ids.test.d.ts +2 -0
  1196. package/dist/vite/__tests__/expose-internal-ids.test.d.ts.map +1 -0
  1197. package/dist/vite/__tests__/expose-internal-ids.test.js +647 -0
  1198. package/dist/vite/__tests__/expose-internal-ids.test.js.map +1 -0
  1199. package/dist/vite/__tests__/expose-router-id.test.d.ts +2 -0
  1200. package/dist/vite/__tests__/expose-router-id.test.d.ts.map +1 -0
  1201. package/dist/vite/__tests__/expose-router-id.test.js +39 -0
  1202. package/dist/vite/__tests__/expose-router-id.test.js.map +1 -0
  1203. package/dist/vite/ast-handler-extract.d.ts +49 -0
  1204. package/dist/vite/ast-handler-extract.d.ts.map +1 -0
  1205. package/dist/vite/ast-handler-extract.js +249 -0
  1206. package/dist/vite/ast-handler-extract.js.map +1 -0
  1207. package/dist/vite/expose-action-id.d.ts +19 -0
  1208. package/dist/vite/expose-action-id.d.ts.map +1 -0
  1209. package/dist/vite/expose-action-id.js +250 -0
  1210. package/dist/vite/expose-action-id.js.map +1 -0
  1211. package/dist/vite/expose-id-utils.d.ts +69 -0
  1212. package/dist/vite/expose-id-utils.d.ts.map +1 -0
  1213. package/dist/vite/expose-id-utils.js +289 -0
  1214. package/dist/vite/expose-id-utils.js.map +1 -0
  1215. package/dist/vite/expose-internal-ids.d.ts +22 -0
  1216. package/dist/vite/expose-internal-ids.d.ts.map +1 -0
  1217. package/dist/vite/expose-internal-ids.js +886 -0
  1218. package/dist/vite/expose-internal-ids.js.map +1 -0
  1219. package/dist/vite/index.d.ts +149 -0
  1220. package/dist/vite/index.d.ts.map +1 -0
  1221. package/dist/vite/index.js +12042 -1346
  1222. package/dist/vite/index.js.bak +5448 -0
  1223. package/dist/vite/index.js.map +1 -0
  1224. package/dist/vite/index.named-routes.gen.ts +103 -0
  1225. package/dist/vite/package-resolution.d.ts +43 -0
  1226. package/dist/vite/package-resolution.d.ts.map +1 -0
  1227. package/{src/vite/package-resolution.ts → dist/vite/package-resolution.js} +53 -66
  1228. package/dist/vite/package-resolution.js.map +1 -0
  1229. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  1230. package/dist/vite/virtual-entries.d.ts +25 -0
  1231. package/dist/vite/virtual-entries.d.ts.map +1 -0
  1232. package/{src/vite/virtual-entries.ts → dist/vite/virtual-entries.js} +12 -16
  1233. package/dist/vite/virtual-entries.js.map +1 -0
  1234. package/package.json +170 -77
  1235. package/skills/api-client/SKILL.md +211 -0
  1236. package/skills/breadcrumbs/SKILL.md +359 -0
  1237. package/skills/bundle-analysis/SKILL.md +159 -0
  1238. package/skills/cache-guide/SKILL.md +492 -0
  1239. package/skills/caching/SKILL.md +452 -26
  1240. package/skills/catalog.json +289 -0
  1241. package/skills/client-urls/SKILL.md +339 -0
  1242. package/skills/cloudflare/SKILL.md +153 -0
  1243. package/skills/cloudflare/agents/openai.yaml +4 -0
  1244. package/skills/cloudflare/references/d1-and-local-dev.md +131 -0
  1245. package/skills/cloudflare/references/streaming-and-deploy.md +107 -0
  1246. package/skills/cloudflare/references/webhooks-and-crypto.md +147 -0
  1247. package/skills/comparison/SKILL.md +50 -0
  1248. package/skills/comparison/agents/openai.yaml +4 -0
  1249. package/skills/comparison/references/framework-comparison.md +858 -0
  1250. package/skills/composability/SKILL.md +292 -0
  1251. package/skills/css/SKILL.md +76 -0
  1252. package/skills/debug-manifest/SKILL.md +16 -18
  1253. package/skills/defer-hydration/SKILL.md +235 -0
  1254. package/skills/deployment-caching/SKILL.md +176 -0
  1255. package/skills/document-cache/SKILL.md +125 -65
  1256. package/skills/fonts/SKILL.md +167 -0
  1257. package/skills/handler-use/SKILL.md +364 -0
  1258. package/skills/hooks/SKILL.md +76 -432
  1259. package/skills/hooks/data.md +282 -0
  1260. package/skills/hooks/handle-and-actions.md +110 -0
  1261. package/skills/hooks/navigation.md +110 -0
  1262. package/skills/hooks/outlets.md +62 -0
  1263. package/skills/hooks/state.md +228 -0
  1264. package/skills/hooks/urls.md +172 -0
  1265. package/skills/host-router/SKILL.md +320 -0
  1266. package/skills/i18n/SKILL.md +276 -0
  1267. package/skills/intercept/SKILL.md +215 -16
  1268. package/skills/layout/SKILL.md +147 -7
  1269. package/skills/links/SKILL.md +360 -33
  1270. package/skills/loader/SKILL.md +762 -51
  1271. package/skills/middleware/SKILL.md +251 -38
  1272. package/skills/migrate-nextjs/SKILL.md +854 -0
  1273. package/skills/migrate-nextjs/backend-host-swap.md +120 -0
  1274. package/skills/migrate-react-router/SKILL.md +189 -0
  1275. package/skills/migrate-react-router/component-migration.md +201 -0
  1276. package/skills/migrate-react-router/data-and-actions.md +236 -0
  1277. package/skills/migrate-react-router/route-mapping.md +284 -0
  1278. package/skills/mime-routes/SKILL.md +165 -0
  1279. package/skills/observability/SKILL.md +231 -0
  1280. package/skills/parallel/SKILL.md +327 -4
  1281. package/skills/ppr/SKILL.md +918 -0
  1282. package/skills/prerender/SKILL.md +751 -0
  1283. package/skills/rango/SKILL.md +387 -17
  1284. package/skills/react-compiler/SKILL.md +168 -0
  1285. package/skills/response-routes/SKILL.md +539 -0
  1286. package/skills/route/SKILL.md +399 -15
  1287. package/skills/router-setup/SKILL.md +270 -34
  1288. package/skills/scripts/SKILL.md +189 -0
  1289. package/skills/server-actions/SKILL.md +776 -0
  1290. package/skills/shell-manifest/SKILL.md +194 -0
  1291. package/skills/streams-and-websockets/SKILL.md +283 -0
  1292. package/skills/tailwind/SKILL.md +153 -0
  1293. package/skills/testing/SKILL.md +131 -0
  1294. package/skills/testing/bindings.md +103 -0
  1295. package/skills/testing/cache-prerender.md +172 -0
  1296. package/skills/testing/client-components.md +131 -0
  1297. package/skills/testing/e2e-parity.md +125 -0
  1298. package/skills/testing/flight.md +91 -0
  1299. package/skills/testing/handles.md +153 -0
  1300. package/skills/testing/loader.md +130 -0
  1301. package/skills/testing/middleware.md +99 -0
  1302. package/skills/testing/render-handler.md +122 -0
  1303. package/skills/testing/response-routes.md +95 -0
  1304. package/skills/testing/reverse-and-types.md +85 -0
  1305. package/skills/testing/server-actions.md +107 -0
  1306. package/skills/testing/server-tree.md +128 -0
  1307. package/skills/testing/setup.md +123 -0
  1308. package/skills/theme/SKILL.md +16 -12
  1309. package/skills/typesafety/SKILL.md +45 -387
  1310. package/skills/typesafety/env-and-bindings.md +254 -0
  1311. package/skills/typesafety/generated-files-and-cli.md +342 -0
  1312. package/skills/typesafety/params-and-search.md +153 -0
  1313. package/skills/typesafety/route-types.md +213 -0
  1314. package/skills/use-cache/SKILL.md +430 -0
  1315. package/skills/vercel/SKILL.md +149 -0
  1316. package/skills/view-transitions/SKILL.md +341 -0
  1317. package/src/__augment-tests__/augment.ts +81 -0
  1318. package/src/__augment-tests__/augmented.check.ts +116 -0
  1319. package/src/__internal.ts +77 -44
  1320. package/src/bin/rango.ts +325 -0
  1321. package/src/browser/action-coordinator.ts +114 -0
  1322. package/src/browser/action-fence.ts +47 -0
  1323. package/src/browser/app-shell.ts +39 -0
  1324. package/src/browser/app-version.ts +14 -0
  1325. package/src/browser/connection-warmup.ts +134 -0
  1326. package/src/browser/cookie-name.ts +140 -0
  1327. package/src/browser/dev-discovery.ts +66 -0
  1328. package/src/browser/event-controller.ts +477 -217
  1329. package/src/browser/history-state.ts +101 -0
  1330. package/src/browser/index.ts +3 -3
  1331. package/src/browser/intercept-utils.ts +52 -0
  1332. package/src/browser/invalidate-client-cache.ts +52 -0
  1333. package/src/browser/link-interceptor.ts +487 -18
  1334. package/src/browser/logging.ts +83 -0
  1335. package/src/browser/merge-segment-loaders.ts +23 -13
  1336. package/src/browser/navigation-bridge.ts +471 -570
  1337. package/src/browser/navigation-client.ts +343 -79
  1338. package/src/browser/navigation-store-handle.ts +38 -0
  1339. package/src/browser/navigation-store.ts +228 -366
  1340. package/src/browser/navigation-transaction.ts +247 -0
  1341. package/src/browser/network-error-handler.ts +88 -0
  1342. package/src/browser/notify-listeners.ts +22 -0
  1343. package/src/browser/partial-update.ts +491 -365
  1344. package/src/browser/prefetch/cache.ts +457 -0
  1345. package/src/browser/prefetch/default-strategy.ts +74 -0
  1346. package/src/browser/prefetch/fetch.ts +548 -0
  1347. package/src/browser/prefetch/invalidation.ts +30 -0
  1348. package/src/browser/prefetch/loader.ts +111 -0
  1349. package/src/browser/prefetch/observer.ts +93 -0
  1350. package/src/browser/prefetch/policy.ts +48 -0
  1351. package/src/browser/prefetch/queue.ts +209 -0
  1352. package/src/browser/prefetch/resource-ready.ts +77 -0
  1353. package/src/browser/prefetch/runtime.ts +6 -0
  1354. package/src/browser/rango-state.ts +215 -0
  1355. package/src/browser/react/Link.tsx +332 -85
  1356. package/src/browser/react/NavigationProvider.tsx +275 -109
  1357. package/src/browser/react/ScrollRestoration.tsx +10 -6
  1358. package/src/browser/react/context.ts +15 -0
  1359. package/src/browser/react/filter-segment-order.ts +70 -0
  1360. package/src/browser/react/index.ts +0 -48
  1361. package/src/browser/react/location-state-shared.ts +272 -60
  1362. package/src/browser/react/location-state.ts +90 -20
  1363. package/src/browser/react/mount-context.ts +6 -1
  1364. package/src/browser/react/nonce-context.ts +23 -0
  1365. package/src/browser/react/shallow-equal.ts +27 -0
  1366. package/src/browser/react/use-action.ts +35 -66
  1367. package/src/browser/react/use-handle.ts +39 -132
  1368. package/src/browser/react/use-href.tsx +9 -2
  1369. package/src/browser/react/use-link-status.ts +39 -13
  1370. package/src/browser/react/use-navigation.ts +53 -69
  1371. package/src/browser/react/use-params.ts +75 -0
  1372. package/src/browser/react/use-pathname.ts +47 -0
  1373. package/src/browser/react/use-reverse.ts +106 -0
  1374. package/src/browser/react/use-router.ts +127 -0
  1375. package/src/browser/react/use-search-params.ts +174 -0
  1376. package/src/browser/react/use-segments.ts +72 -99
  1377. package/src/browser/response-adapter.ts +164 -0
  1378. package/src/browser/rsc-router.tsx +446 -74
  1379. package/src/browser/scroll-restoration.ts +140 -50
  1380. package/src/browser/segment-reconciler.ts +253 -0
  1381. package/src/browser/segment-structure-assert.ts +17 -1
  1382. package/src/browser/server-action-bridge.ts +707 -603
  1383. package/src/browser/types.ts +266 -75
  1384. package/src/browser/validate-redirect-origin.ts +56 -0
  1385. package/src/build/collect-fallback-refs.ts +107 -0
  1386. package/src/build/generate-manifest.ts +324 -84
  1387. package/src/build/generate-route-types.ts +41 -0
  1388. package/src/build/index.ts +22 -1
  1389. package/src/build/merge-full-manifests.ts +161 -0
  1390. package/src/build/prefix-tree-utils.ts +123 -0
  1391. package/src/build/route-trie.ts +54 -0
  1392. package/src/build/route-types/ast-helpers.ts +25 -0
  1393. package/src/build/route-types/ast-route-extraction.ts +105 -0
  1394. package/src/build/route-types/codegen.ts +113 -0
  1395. package/src/build/route-types/include-resolution.ts +867 -0
  1396. package/src/build/route-types/param-extraction.ts +51 -0
  1397. package/src/build/route-types/per-module-writer.ts +149 -0
  1398. package/src/build/route-types/router-processing.ts +726 -0
  1399. package/src/build/route-types/scan-filter.ts +85 -0
  1400. package/src/build/route-types/source-scan.ts +216 -0
  1401. package/src/build/runtime-discovery.ts +234 -0
  1402. package/src/cache/background-task.ts +34 -0
  1403. package/src/cache/cache-error.ts +104 -0
  1404. package/src/cache/cache-exec-scope.ts +47 -0
  1405. package/src/cache/cache-key-utils.ts +102 -0
  1406. package/src/cache/cache-policy.ts +199 -0
  1407. package/src/cache/cache-runtime.ts +787 -0
  1408. package/src/cache/cache-scope.ts +478 -342
  1409. package/src/cache/cache-tag.ts +149 -0
  1410. package/src/cache/cf/cf-base64.ts +33 -0
  1411. package/src/cache/cf/cf-cache-constants.ts +134 -0
  1412. package/src/cache/cf/cf-cache-store.ts +3397 -152
  1413. package/src/cache/cf/cf-cache-types.ts +417 -0
  1414. package/src/cache/cf/cf-kv-utils.ts +84 -0
  1415. package/src/cache/cf/cf-tag-marker-memo.ts +108 -0
  1416. package/src/cache/cf/cf-zone-purge.ts +101 -0
  1417. package/src/cache/cf/index.ts +21 -16
  1418. package/src/cache/document-cache.ts +275 -105
  1419. package/src/cache/handle-capture.ts +81 -0
  1420. package/src/cache/handle-snapshot.ts +132 -0
  1421. package/src/cache/index.ts +33 -35
  1422. package/src/cache/memory-segment-store.ts +457 -30
  1423. package/src/cache/profile-registry.ts +88 -0
  1424. package/src/cache/read-through-swr.ts +184 -0
  1425. package/src/cache/search-params-filter.ts +118 -0
  1426. package/src/cache/segment-codec.ts +311 -0
  1427. package/src/cache/shell-snapshot.ts +516 -0
  1428. package/src/cache/tag-invalidation.ts +230 -0
  1429. package/src/cache/taint.ts +172 -0
  1430. package/src/cache/types.ts +405 -212
  1431. package/src/cache/vercel/index.ts +11 -0
  1432. package/src/cache/vercel/vercel-cache-store.ts +1264 -0
  1433. package/src/client-urls/client-root.tsx +168 -0
  1434. package/src/client-urls/client-urls.ts +779 -0
  1435. package/src/client-urls/navigation.ts +237 -0
  1436. package/src/client-urls/revalidation-protocol.ts +56 -0
  1437. package/src/client-urls/server-projection.ts +670 -0
  1438. package/src/client-urls/types.ts +202 -0
  1439. package/src/client.rsc.tsx +55 -21
  1440. package/src/client.tsx +179 -330
  1441. package/src/cloudflare/index.ts +11 -0
  1442. package/src/cloudflare/tracing.ts +112 -0
  1443. package/src/component-utils.ts +23 -4
  1444. package/src/components/DefaultDocument.tsx +13 -3
  1445. package/src/context-var.ts +168 -0
  1446. package/src/debug.ts +19 -9
  1447. package/src/decode-loader-results.ts +165 -0
  1448. package/src/defer.ts +185 -0
  1449. package/src/deps/ssr.ts +4 -2
  1450. package/src/dev-discovery-protocol.ts +11 -0
  1451. package/src/encode-kv.ts +49 -0
  1452. package/src/errors.ts +149 -3
  1453. package/src/escape-script.ts +52 -0
  1454. package/src/handle.ts +111 -55
  1455. package/src/handles/MetaTags.tsx +83 -59
  1456. package/src/handles/Scripts.tsx +183 -0
  1457. package/src/handles/breadcrumbs.ts +93 -0
  1458. package/src/handles/deferred-resolution.ts +134 -0
  1459. package/src/handles/is-thenable.ts +16 -0
  1460. package/src/handles/meta.ts +44 -53
  1461. package/src/handles/script.ts +244 -0
  1462. package/src/host/cookie-handler.ts +20 -65
  1463. package/src/host/errors.ts +21 -30
  1464. package/src/host/index.ts +13 -9
  1465. package/src/host/pattern-matcher.ts +50 -79
  1466. package/src/host/router.ts +151 -121
  1467. package/src/host/testing.ts +45 -32
  1468. package/src/host/types.ts +52 -11
  1469. package/src/host/utils.ts +2 -2
  1470. package/src/href-client.ts +236 -31
  1471. package/src/index.rsc.ts +252 -20
  1472. package/src/index.ts +343 -30
  1473. package/src/internal-debug.ts +12 -0
  1474. package/src/loader-redirect.tsx +64 -0
  1475. package/src/loader-store.ts +500 -0
  1476. package/src/loader.rsc.ts +39 -163
  1477. package/src/loader.ts +31 -13
  1478. package/src/missing-id-error.ts +68 -0
  1479. package/src/outlet-context.ts +21 -1
  1480. package/src/outlet-provider.tsx +59 -0
  1481. package/src/prerender/build-shell-capture.ts +453 -0
  1482. package/src/prerender/param-hash.ts +37 -0
  1483. package/src/prerender/shell-manifest-key.ts +20 -0
  1484. package/src/prerender/store.ts +195 -0
  1485. package/src/prerender.ts +592 -0
  1486. package/src/redirect-origin.ts +172 -0
  1487. package/src/regex-escape.ts +8 -0
  1488. package/src/render-error-thrower.tsx +20 -0
  1489. package/src/response-utils.ts +62 -0
  1490. package/src/reverse.ts +380 -0
  1491. package/src/root-error-boundary.tsx +42 -48
  1492. package/src/route-content-wrapper.tsx +123 -78
  1493. package/src/route-definition/dsl-helpers.ts +1150 -0
  1494. package/src/route-definition/helper-factories.ts +88 -0
  1495. package/src/route-definition/helpers-types.ts +522 -0
  1496. package/src/route-definition/index.ts +54 -0
  1497. package/src/route-definition/redirect.ts +133 -0
  1498. package/src/route-definition/resolve-handler-use.ts +160 -0
  1499. package/src/route-definition/use-item-types.ts +29 -0
  1500. package/src/route-definition.ts +1 -1428
  1501. package/src/route-map-builder.ts +249 -127
  1502. package/src/route-name.ts +53 -0
  1503. package/src/route-types.ts +87 -45
  1504. package/src/router/basename.ts +14 -0
  1505. package/src/router/content-negotiation.ts +305 -0
  1506. package/src/router/debug-manifest.ts +72 -0
  1507. package/src/router/error-handling.ts +119 -38
  1508. package/src/router/find-match.ts +259 -0
  1509. package/src/router/handler-context.ts +439 -86
  1510. package/src/router/instrument.ts +401 -0
  1511. package/src/router/intercept-resolution.ts +479 -0
  1512. package/src/router/lazy-includes.ts +261 -0
  1513. package/src/router/loader-resolution.ts +714 -142
  1514. package/src/router/logging.ts +245 -0
  1515. package/src/router/manifest.ts +225 -63
  1516. package/src/router/match-api.ts +591 -0
  1517. package/src/router/match-context.ts +5 -25
  1518. package/src/router/match-handlers.ts +537 -0
  1519. package/src/router/match-middleware/background-revalidation.ts +128 -97
  1520. package/src/router/match-middleware/cache-lookup.ts +537 -73
  1521. package/src/router/match-middleware/cache-store.ts +214 -60
  1522. package/src/router/match-middleware/intercept-resolution.ts +56 -38
  1523. package/src/router/match-middleware/segment-resolution.ts +71 -19
  1524. package/src/router/match-pipelines.ts +11 -87
  1525. package/src/router/match-result.ts +150 -53
  1526. package/src/router/metrics.ts +235 -29
  1527. package/src/router/middleware-types.ts +110 -0
  1528. package/src/router/middleware.ts +526 -441
  1529. package/src/router/navigation-snapshot.ts +173 -0
  1530. package/src/router/params-util.ts +23 -0
  1531. package/src/router/parse-pattern.ts +115 -0
  1532. package/src/router/pattern-matching.ts +348 -149
  1533. package/src/router/prefetch-cache-ttl.ts +51 -0
  1534. package/src/router/prefetch-default.ts +59 -0
  1535. package/src/router/prefetch-limits.ts +37 -0
  1536. package/src/router/prerender-match.ts +592 -0
  1537. package/src/router/preview-match.ts +102 -0
  1538. package/src/router/request-classification.ts +291 -0
  1539. package/src/router/revalidation.ts +252 -90
  1540. package/src/router/route-snapshot.ts +256 -0
  1541. package/src/router/route-trie-builder.ts +334 -0
  1542. package/src/router/router-context.ts +45 -48
  1543. package/src/router/router-interfaces.ts +614 -0
  1544. package/src/router/router-options.ts +842 -0
  1545. package/src/router/router-registry.ts +21 -0
  1546. package/src/router/segment-resolution/fresh.ts +879 -0
  1547. package/src/router/segment-resolution/helpers.ts +346 -0
  1548. package/src/router/segment-resolution/loader-cache.ts +368 -0
  1549. package/src/router/segment-resolution/loader-mask.ts +60 -0
  1550. package/src/router/segment-resolution/loader-snapshot.ts +259 -0
  1551. package/src/router/segment-resolution/mask-nested.ts +99 -0
  1552. package/src/router/segment-resolution/revalidation.ts +1376 -0
  1553. package/src/router/segment-resolution/static-store.ts +107 -0
  1554. package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
  1555. package/src/router/segment-resolution/view-transition-default.ts +60 -0
  1556. package/src/router/segment-resolution.ts +25 -0
  1557. package/src/router/segment-wrappers.ts +292 -0
  1558. package/src/router/state-cookie-name.ts +33 -0
  1559. package/src/router/substitute-pattern-params.ts +75 -0
  1560. package/src/router/telemetry-otel.ts +270 -0
  1561. package/src/router/telemetry.ts +386 -0
  1562. package/src/router/timeout.ts +179 -0
  1563. package/src/router/tracing.ts +235 -0
  1564. package/src/router/transition-when.ts +76 -0
  1565. package/src/router/trie-matching.ts +351 -0
  1566. package/src/router/types.ts +60 -39
  1567. package/src/router/url-params.ts +57 -0
  1568. package/src/router.ts +911 -4253
  1569. package/src/rsc/capture-queue.ts +218 -0
  1570. package/src/rsc/full-payload.ts +77 -0
  1571. package/src/rsc/handler-context.ts +47 -0
  1572. package/src/rsc/handler.ts +1226 -834
  1573. package/src/rsc/helpers.ts +351 -19
  1574. package/src/rsc/index.ts +2 -25
  1575. package/src/rsc/json-route-result.ts +38 -0
  1576. package/src/rsc/loader-fetch.ts +305 -0
  1577. package/src/rsc/manifest-init.ts +89 -0
  1578. package/src/rsc/nonce.ts +39 -0
  1579. package/src/rsc/origin-guard.ts +155 -0
  1580. package/src/rsc/progressive-enhancement.ts +686 -0
  1581. package/src/rsc/redirect-guard.ts +102 -0
  1582. package/src/rsc/render-pipeline.ts +611 -0
  1583. package/src/rsc/response-cache-serve.ts +259 -0
  1584. package/src/rsc/response-error.ts +104 -0
  1585. package/src/rsc/response-route-handler.ts +221 -0
  1586. package/src/rsc/routine-plan.ts +359 -0
  1587. package/src/rsc/rsc-rendering.ts +1729 -0
  1588. package/src/rsc/runtime-warnings.ts +55 -0
  1589. package/src/rsc/server-action.ts +639 -0
  1590. package/src/rsc/shell-build-manifest.ts +343 -0
  1591. package/src/rsc/shell-capture-constants.ts +45 -0
  1592. package/src/rsc/shell-capture.ts +2135 -0
  1593. package/src/rsc/shell-serve.ts +350 -0
  1594. package/src/rsc/ssr-setup.ts +236 -0
  1595. package/src/rsc/stream-idle.ts +137 -0
  1596. package/src/rsc/transition-gate.ts +86 -0
  1597. package/src/rsc/types.ts +167 -14
  1598. package/src/runtime-env.ts +18 -0
  1599. package/src/search-params.ts +235 -0
  1600. package/src/segment-content-promise.ts +67 -0
  1601. package/src/segment-fragments.ts +165 -0
  1602. package/src/segment-loader-promise.ts +167 -0
  1603. package/src/segment-system.tsx +544 -136
  1604. package/src/serialize.ts +243 -0
  1605. package/src/server/context.ts +741 -90
  1606. package/src/server/cookie-parse.ts +32 -0
  1607. package/src/server/cookie-store.ts +337 -0
  1608. package/src/server/fetchable-loader-store.ts +37 -0
  1609. package/src/server/handle-store.ts +278 -60
  1610. package/src/server/loader-registry.ts +51 -100
  1611. package/src/server/request-context.ts +1296 -161
  1612. package/src/server.ts +38 -128
  1613. package/src/ssr/index.tsx +716 -140
  1614. package/src/ssr/inject-rsc-eager.ts +167 -0
  1615. package/src/ssr/preinit-client-references.ts +106 -0
  1616. package/src/ssr/ssr-root.tsx +305 -0
  1617. package/src/ssr-suspension-warning.ts +67 -0
  1618. package/src/static-handler.ts +139 -0
  1619. package/src/testing/cache-status.ts +162 -0
  1620. package/src/testing/collect-handle.ts +46 -0
  1621. package/src/testing/dispatch.ts +951 -0
  1622. package/src/testing/dom.entry.ts +22 -0
  1623. package/src/testing/e2e/fixture.ts +188 -0
  1624. package/src/testing/e2e/index.ts +147 -0
  1625. package/src/testing/e2e/matchers.ts +35 -0
  1626. package/src/testing/e2e/page-helpers.ts +319 -0
  1627. package/src/testing/e2e/parity.ts +400 -0
  1628. package/src/testing/e2e/server.ts +195 -0
  1629. package/src/testing/flight-matchers.ts +97 -0
  1630. package/src/testing/flight-normalize.ts +11 -0
  1631. package/src/testing/flight-runtime.d.ts +57 -0
  1632. package/src/testing/flight-tree.ts +682 -0
  1633. package/src/testing/flight.entry.ts +52 -0
  1634. package/src/testing/flight.ts +257 -0
  1635. package/src/testing/generated-routes.ts +199 -0
  1636. package/src/testing/index.ts +121 -0
  1637. package/src/testing/internal/context.ts +380 -0
  1638. package/src/testing/internal/flight-client-globals.ts +30 -0
  1639. package/src/testing/internal/seed-vars.ts +54 -0
  1640. package/src/testing/render-handler.ts +371 -0
  1641. package/src/testing/render-route.tsx +667 -0
  1642. package/src/testing/run-loader.ts +423 -0
  1643. package/src/testing/run-middleware.ts +219 -0
  1644. package/src/testing/run-transition-when.ts +197 -0
  1645. package/src/testing/shell-status.ts +206 -0
  1646. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  1647. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  1648. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  1649. package/src/testing/vitest-stubs/version.ts +5 -0
  1650. package/src/testing/vitest.ts +305 -0
  1651. package/src/theme/ThemeProvider.tsx +76 -98
  1652. package/src/theme/ThemeScript.tsx +12 -14
  1653. package/src/theme/constants.ts +57 -15
  1654. package/src/theme/index.ts +3 -20
  1655. package/src/theme/theme-context.ts +5 -35
  1656. package/src/theme/theme-script.ts +43 -39
  1657. package/src/theme/use-theme.ts +0 -3
  1658. package/src/types/boundaries.ts +142 -0
  1659. package/src/types/cache-types.ts +207 -0
  1660. package/src/types/error-types.ts +132 -0
  1661. package/src/types/global-namespace.ts +113 -0
  1662. package/src/types/handler-context.ts +850 -0
  1663. package/src/types/index.ts +82 -0
  1664. package/src/types/loader-types.ts +273 -0
  1665. package/src/types/request-scope.ts +112 -0
  1666. package/src/types/route-config.ts +138 -0
  1667. package/src/types/route-entry.ts +117 -0
  1668. package/src/types/segments.ts +291 -0
  1669. package/src/types.ts +1 -1623
  1670. package/src/urls/include-helper.ts +181 -0
  1671. package/src/urls/include-provider.ts +71 -0
  1672. package/src/urls/index.ts +44 -0
  1673. package/src/urls/path-helper-types.ts +435 -0
  1674. package/src/urls/path-helper.ts +284 -0
  1675. package/src/urls/pattern-types.ts +189 -0
  1676. package/src/urls/response-types.ts +109 -0
  1677. package/src/urls/type-extraction.ts +316 -0
  1678. package/src/urls/urls-function.ts +80 -0
  1679. package/src/urls.ts +1 -802
  1680. package/src/use-loader.tsx +487 -138
  1681. package/src/vercel/index.ts +11 -0
  1682. package/src/vercel/tracing.ts +89 -0
  1683. package/src/vite/debug.ts +185 -0
  1684. package/src/vite/discovery/bundle-postprocess.ts +185 -0
  1685. package/src/vite/discovery/client-urls-projection.ts +322 -0
  1686. package/src/vite/discovery/dev-prerender-cache.ts +117 -0
  1687. package/src/vite/discovery/discover-routers.ts +375 -0
  1688. package/src/vite/discovery/discovery-errors.ts +255 -0
  1689. package/src/vite/discovery/gate-state.ts +171 -0
  1690. package/src/vite/discovery/prerender-collection.ts +494 -0
  1691. package/src/vite/discovery/route-types-writer.ts +214 -0
  1692. package/src/vite/discovery/self-gen-tracking.ts +73 -0
  1693. package/src/vite/discovery/shell-prerender-phase.ts +397 -0
  1694. package/src/vite/discovery/state.ts +215 -0
  1695. package/src/vite/discovery/virtual-module-codegen.ts +342 -0
  1696. package/src/vite/encryption-key.ts +29 -0
  1697. package/src/vite/index.ts +31 -1137
  1698. package/src/vite/inject-client-debug.ts +88 -0
  1699. package/src/vite/plugin-types.ts +336 -0
  1700. package/src/vite/plugins/cjs-to-esm.ts +90 -0
  1701. package/src/vite/plugins/client-ref-dedup.ts +382 -0
  1702. package/src/vite/plugins/client-ref-hashing.ts +118 -0
  1703. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  1704. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  1705. package/src/vite/plugins/cloudflare-protocol-stub.ts +194 -0
  1706. package/src/vite/{expose-action-id.ts → plugins/expose-action-id.ts} +130 -136
  1707. package/src/vite/plugins/expose-id-utils.ts +332 -0
  1708. package/src/vite/plugins/expose-ids/export-analysis.ts +363 -0
  1709. package/src/vite/plugins/expose-ids/handler-transform.ts +130 -0
  1710. package/src/vite/plugins/expose-ids/loader-transform.ts +64 -0
  1711. package/src/vite/plugins/expose-ids/router-transform.ts +199 -0
  1712. package/src/vite/plugins/expose-ids/types.ts +45 -0
  1713. package/src/vite/plugins/expose-internal-ids.ts +851 -0
  1714. package/src/vite/plugins/performance-tracks.ts +89 -0
  1715. package/src/vite/plugins/refresh-cmd.ts +127 -0
  1716. package/src/vite/plugins/server-ref-hashing.ts +74 -0
  1717. package/src/vite/plugins/server-reference-pattern.ts +10 -0
  1718. package/src/vite/plugins/use-cache-transform.ts +313 -0
  1719. package/src/vite/plugins/vercel-output.ts +384 -0
  1720. package/src/vite/plugins/version-injector.ts +93 -0
  1721. package/src/vite/plugins/version-plugin.ts +271 -0
  1722. package/src/vite/plugins/virtual-entries.ts +286 -0
  1723. package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
  1724. package/src/vite/rango.ts +609 -0
  1725. package/src/vite/router-discovery.ts +2400 -0
  1726. package/src/vite/utils/ast-handler-extract.ts +508 -0
  1727. package/src/vite/utils/banner.ts +36 -0
  1728. package/src/vite/utils/bundle-analysis.ts +132 -0
  1729. package/src/vite/utils/client-chunks.ts +184 -0
  1730. package/src/vite/utils/directive-prologue.ts +40 -0
  1731. package/src/vite/utils/forward-user-plugins.ts +171 -0
  1732. package/src/vite/utils/manifest-utils.ts +12 -0
  1733. package/src/vite/utils/package-resolution.ts +90 -0
  1734. package/src/vite/utils/prerender-utils.ts +268 -0
  1735. package/src/vite/utils/shared-utils.ts +283 -0
  1736. package/CLAUDE.md +0 -43
  1737. package/src/browser/lru-cache.ts +0 -69
  1738. package/src/browser/request-controller.ts +0 -164
  1739. package/src/browser/shallow.ts +0 -35
  1740. package/src/cache/memory-store.ts +0 -253
  1741. package/src/href.ts +0 -255
  1742. package/src/server/route-manifest-cache.ts +0 -173
  1743. package/src/vite/expose-handle-id.ts +0 -209
  1744. package/src/vite/expose-loader-id.ts +0 -426
  1745. package/src/vite/expose-location-state-id.ts +0 -177
  1746. /package/src/vite/{version.d.ts → plugins/version.d.ts} +0 -0
@@ -0,0 +1,2135 @@
1
+ /**
2
+ * PPR shell capture orchestration (Axis 2, see docs/design/ppr-shell-resume.md).
3
+ *
4
+ * Capture does NOT flow through the HTTP middleware pipeline. The integrated PPR
5
+ * serve path (rsc-rendering.ts + shell-serve.ts) builds a ShellCaptureDescriptor
6
+ * from the route's `ppr` path option after the served response is built and calls
7
+ * scheduleShellCapture. The capture then runs as a background task that re-derives
8
+ * the page via `ctx.router.match()` under its OWN derived request context — fresh
9
+ * handle store, `_shellCaptureRun: true` so loaders mask (loader-mask.ts) and every
10
+ * loading() subtree postpones. The render is MIXED-CHAIN: cache()'d segments replay
11
+ * from ring 3, uncached segments execute their handlers fresh. It drives the static
12
+ * prerender to a quiescent shell, aborts to freeze the prelude + postponed state,
13
+ * and stores the pair via putShell. Because it uses match() rather than the HTTP
14
+ * pipeline, the middleware chain (auth, logging) never re-runs — it already ran for
15
+ * the triggering request, and the derived context inherits its post-middleware
16
+ * state (variables, cache store). Guarding is serve-time.
17
+ */
18
+
19
+ import React from "react";
20
+ import { bufferToBase64 } from "../cache/cf/cf-base64.js";
21
+ import { reportCacheError } from "../cache/cache-error.js";
22
+ import { runBackground } from "../cache/background-task.js";
23
+ import {
24
+ CaptureQueueFullError,
25
+ CaptureQueueWaitTimeoutError,
26
+ captureQueueDepths,
27
+ enqueueSerializedCapture,
28
+ } from "./capture-queue.js";
29
+ import {
30
+ SHELL_CAPTURE_MAX_WAIT_MS,
31
+ SHELL_CAPTURE_TASK_HARD_CAP_MS,
32
+ } from "./shell-capture-constants.js";
33
+ import { INTERNAL_RANGO_DEBUG } from "../internal-debug.js";
34
+ import { observePhase, PHASES } from "../router/instrument.js";
35
+ import type { TraceSpan } from "../router/tracing.js";
36
+ import {
37
+ runWithRequestContext,
38
+ setRequestContextParams,
39
+ wireRenderBarrier,
40
+ UNTRACKED_BACKGROUND_TASK,
41
+ type RequestContext,
42
+ } from "../server/request-context.js";
43
+ import { createHandleStore, type HandleStore } from "../server/handle-store.js";
44
+ import {
45
+ maskNestedContainerThenables,
46
+ type MaskReport,
47
+ } from "../router/segment-resolution/mask-nested.js";
48
+ import {
49
+ getCurrentLoaderBodyId,
50
+ isInsideLoaderScope,
51
+ } from "../server/context.js";
52
+ import { isThenable } from "../handles/is-thenable.js";
53
+ import type {
54
+ ShellCacheEntry,
55
+ SegmentCacheStore,
56
+ ShellSnapshotRecord,
57
+ } from "../cache/types.js";
58
+ import {
59
+ elideLoaderContainer,
60
+ isLoaderHoleMarker,
61
+ } from "../router/segment-resolution/loader-snapshot.js";
62
+ import {
63
+ RecordingShellStore,
64
+ SnapshotOnlySegmentStore,
65
+ getRecordingStore,
66
+ } from "../cache/shell-snapshot.js";
67
+ import type { HandlerContext } from "./handler-context.js";
68
+ import type { SSRModule } from "./types.js";
69
+ import { buildFullPayload } from "./full-payload.js";
70
+ import { resolveDeferredHandleValues } from "../handles/deferred-resolution.js";
71
+ import { renderRscFlightStage } from "./render-pipeline.js";
72
+ import { stripInternalParams } from "../router/handler-context.js";
73
+
74
+ /**
75
+ * Task-quantized quiesce: the number of consecutive macrotask hops with zero new
76
+ * Flight bytes that marks the shell "quiet". This replaces the old 50ms
77
+ * wall-clock debounce.
78
+ *
79
+ * The capture Flight render is a REGULAR renderToReadableStream (not a static
80
+ * prerender), so React schedules both its retries and its byte-flush on
81
+ * setTimeout(0) MACROTASKS (verified against the vendored edge production
82
+ * react-server-dom build: pingTask uses scheduleMicrotask only when
83
+ * request.type === PRERENDER, otherwise setTimeout; enqueueFlush is always
84
+ * setTimeout). Masked loaders are the live lane — their rows never emit — so once
85
+ * the shell rows finish flushing the stream goes permanently byte-silent, and K
86
+ * consecutive quiet macrotask hops after the last observed byte declare quiesce.
87
+ *
88
+ * K=2 gives a race window of ~two event-loop turns: shell work still producing
89
+ * bytes keeps resetting the counter; anything not producing bytes within the
90
+ * window (the masked loaders, and any genuinely pending I/O) becomes a hole. The
91
+ * only residual is raw per-request I/O rendered directly in shell (not via a
92
+ * loader) that resolves inside the window — a documented shell anti-pattern; put
93
+ * per-request data in loaders. See docs/design/ppr-shell-resume.md.
94
+ */
95
+ const FLIGHT_QUIET_HOPS = 2;
96
+
97
+ /**
98
+ * Default capture budget. Canonical value, raise rationale, and ceiling math
99
+ * live on the leaf module (shell-capture-constants.ts, importable from the ssr
100
+ * graph too). Re-exported here so shell-build-manifest.ts's envelope math
101
+ * keeps its existing import site and cannot drift from the capture.
102
+ */
103
+ export { SHELL_CAPTURE_MAX_WAIT_MS };
104
+
105
+ /**
106
+ * Upper bound on waiting for the capture's DEFERRED cache writes to settle before
107
+ * draining the snapshot. Cache writes run under waitUntil (fire-and-forget on
108
+ * Node, executionContext on workerd), so a MISS-at-capture value's setItem/set —
109
+ * hence its snapshot record — can land after the shell has quiesced. We collect
110
+ * those write promises and await them here so the written value is pinned. Kept
111
+ * short: a pathological slow write must never stall the background capture; a key
112
+ * that does not settle in time is simply left unpinned (it drifts, the
113
+ * pre-snapshot behavior) rather than hanging. Reads that HIT are recorded
114
+ * synchronously during the render and do not depend on this.
115
+ */
116
+ const SHELL_SNAPSHOT_WRITE_SETTLE_MS = 1000;
117
+
118
+ /**
119
+ * Upper bound on the pre-render WRITE BARRIER: before the capture's match/render,
120
+ * settle the background tasks the FOREGROUND request already scheduled — its
121
+ * deferred ring-3 cacheRoute and ring-1 setItem writes all go through
122
+ * reqCtx.waitUntil, and every one of them is scheduled BEFORE scheduleShellCapture
123
+ * runs (the response, and its onResponse callbacks, are committed first). Draining
124
+ * them turns the capture's cache reads from a RACE into an ORDERING EDGE: the
125
+ * capture deterministically observes the foreground's cache generation, replays it
126
+ * (handler skipped, module-level side effects untouched), and records THAT
127
+ * generation into the snapshot — so prelude, snapshot, and ring-3 all agree on the
128
+ * foreground's generation and the capture can never clobber a foreground-produced
129
+ * entry with a re-render of its own. Scar tissue: without this, the capture's
130
+ * ring-3 lookup could land between the foreground write chain's serialization and
131
+ * its store.set, MISS, re-execute the route handler (bumping module-level
132
+ * counters), and — via the synthetic onResponse fire below — overwrite the
133
+ * foreground's entry (the mini shell-manifest regression). Bounded: a slow
134
+ * consumer waitUntil task must never stall the background capture; on timeout the
135
+ * capture proceeds with the pre-barrier (racy) behavior.
136
+ */
137
+ const SHELL_CAPTURE_WRITE_BARRIER_MS = 1500;
138
+
139
+ /**
140
+ * Settle the tracked background tasks on `reqCtx._pendingBackgroundTasks`,
141
+ * ITERATIVELY: a settled task can have scheduled a nested one (cache-store's
142
+ * cacheRoute outer task schedules the actual store.set in a second waitUntil), so
143
+ * each awaited batch may append more. Loop until no new tasks appear or the
144
+ * deadline passes. The capture's own task never enters the list
145
+ * (UNTRACKED_BACKGROUND_TASK), so the loop terminates.
146
+ */
147
+ async function settleTrackedBackgroundTasks(
148
+ reqCtx: RequestContext<any>,
149
+ timeoutMs: number,
150
+ ): Promise<void> {
151
+ const tasks = reqCtx._pendingBackgroundTasks;
152
+ if (!tasks) return;
153
+ const deadline = Date.now() + timeoutMs;
154
+ let seen = 0;
155
+ while (tasks.length > seen) {
156
+ const remaining = deadline - Date.now();
157
+ if (remaining <= 0) return;
158
+ const batch = tasks.slice(seen);
159
+ seen = tasks.length;
160
+ let timer: ReturnType<typeof setTimeout> | undefined;
161
+ const guard = new Promise<void>((resolve) => {
162
+ timer = setTimeout(resolve, remaining);
163
+ (timer as { unref?: () => void }).unref?.();
164
+ });
165
+ await Promise.race([Promise.allSettled(batch).then(() => {}), guard]);
166
+ if (timer) clearTimeout(timer);
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Delay before the in-place retry of a capture that produced no usable shell.
172
+ *
173
+ * The dominant reason a first capture comes back with a trivial prelude is a
174
+ * COLD render: in dev the module transform graph (route modules, the SSR/Flight
175
+ * transforms) is being built lazily and outlasts the task-quantized quiesce, so
176
+ * the shell has not finished rendering when we freeze it; on a cold worker the
177
+ * first invocation pays the same one-time cost. The first attempt WARMS that
178
+ * graph, so a second attempt a short beat later usually completes the shell in
179
+ * the SAME background task — no extra HTTP request needed. Short enough to feel
180
+ * instant, long enough for the module graph to settle. See
181
+ * docs/design/ppr-shell-resume.md ("Capture retry-in-place").
182
+ */
183
+ const SHELL_CAPTURE_RETRY_DELAY_MS = 400;
184
+
185
+ /** Sleep `ms`, unref'd so a Node dev process is never kept alive by the timer. */
186
+ function delay(ms: number): Promise<void> {
187
+ return new Promise((resolve) => {
188
+ const t = setTimeout(resolve, ms);
189
+ (t as { unref?: () => void }).unref?.();
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Bound one capture task at {@link SHELL_CAPTURE_TASK_HARD_CAP_MS}. Rejects on
195
+ * expiry so the caller's existing catch applies backoff + reporting and its
196
+ * settle path releases the stampede guard and queue slot; resolves/rejects
197
+ * transparently otherwise. The timer is unref'd so a pending cap never holds a
198
+ * Node dev process open.
199
+ */
200
+ function raceTaskHardCap<T>(task: Promise<T>, key: string): Promise<T> {
201
+ return new Promise<T>((resolve, reject) => {
202
+ const timer = setTimeout(() => {
203
+ reject(
204
+ new Error(
205
+ `capture task for ${key} exceeded the ${SHELL_CAPTURE_TASK_HARD_CAP_MS}ms hard cap; ` +
206
+ `a handler is likely wedged on a never-settling await`,
207
+ ),
208
+ );
209
+ }, SHELL_CAPTURE_TASK_HARD_CAP_MS);
210
+ (timer as { unref?: () => void }).unref?.();
211
+ task.then(
212
+ (value) => {
213
+ clearTimeout(timer);
214
+ resolve(value);
215
+ },
216
+ (error: unknown) => {
217
+ clearTimeout(timer);
218
+ reject(error);
219
+ },
220
+ );
221
+ });
222
+ }
223
+
224
+ /**
225
+ * Module-level in-flight key map: the stampede guard for background captures, and
226
+ * its single owner. One capture runs per key per isolate; concurrent MISS/stale
227
+ * requests for the same key coalesce onto the first (the rest see the key present
228
+ * in scheduleShellCapture and skip). Added when a capture is scheduled and cleared
229
+ * in the task's settle paths via a token-guarded release, so a later request can
230
+ * recapture when TTL rolls. Living here (not split across the middleware) keeps
231
+ * the add/clear lifecycle in one layer.
232
+ *
233
+ * The value is the owning task's token ({@link CaptureGuardToken}) rather than
234
+ * a bare set entry: workerd can kill a capture's waitUntil context before its
235
+ * finally runs (or the task can wedge past every deadline), stranding the key.
236
+ * scheduleShellCapture treats an entry older than
237
+ * SHELL_CAPTURE_TASK_HARD_CAP_MS as abandoned and reclaims it; the token guard
238
+ * keeps a late-settling stale task from releasing its replacement's entry.
239
+ */
240
+ interface CaptureGuardToken {
241
+ startedAt: number;
242
+ }
243
+
244
+ const inFlightCaptures = new Map<string, CaptureGuardToken>();
245
+
246
+ /** Token-guarded release: only the entry's owning task may clear it. */
247
+ function releaseCaptureGuard(key: string, token: CaptureGuardToken): void {
248
+ if (inFlightCaptures.get(key) === token) {
249
+ inFlightCaptures.delete(key);
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Refused-capture backoff bounds. The window is EXPONENTIAL in the consecutive
255
+ * failure count: `min(BASE * 2^(failures-1), ceiling)` — 1s, 2s, 4s, … up to the
256
+ * mode's ceiling (60s in production, {@link REFUSED_CAPTURE_DEV_MAX_MS} in dev).
257
+ *
258
+ * Why exponential and not a flat 60s: a flat long window conflates two very
259
+ * different failures. A STRUCTURALLY ineligible route (no loading(), a cookie
260
+ * reader) fails forever and wants the long 60s cap. But a cold-but-ELIGIBLE route
261
+ * can also fail the in-place retry under a truly cold graph (dev module transform,
262
+ * or a cold worker under parallel load) — and it must recover FAST, on the next
263
+ * request or two, not be frozen for 60s (that would re-break the very cold-start DX
264
+ * the retry fixes; it bit the cloudflare dev e2e). Escalating from 1s means the
265
+ * eligible route re-probes almost immediately (warm now → HIT and clear), while the
266
+ * doomed route ramps to the ceiling within a handful of failures. Either way an
267
+ * app-wide mount never re-renders a doomed route on EVERY request.
268
+ */
269
+ const REFUSED_CAPTURE_BASE_MS = 1_000;
270
+ const REFUSED_CAPTURE_MAX_MS = 60_000;
271
+
272
+ /**
273
+ * DEV-only backoff ceiling. In dev the 60s production cap is pure harm: the
274
+ * dominant no-shell cause is a COLD module graph (route modules, SSR/Flight
275
+ * transforms built lazily), and the very attempt that failed WARMS that graph, so
276
+ * the next attempt a beat later usually completes the shell. Capping the dev window
277
+ * low keeps a cold-but-eligible route re-probing every ~2s instead of freezing for
278
+ * up to 60s once the exponential climbs (1s→2s→4s→…→60s). A 60s freeze outlasts the
279
+ * e2e warm windows on cold CI runners: the capture races an unfinished shell,
280
+ * escalates the backoff past the poll window, and every subsequent request inside
281
+ * that window is skipped as backed-off — an eternal MISS for the test even though
282
+ * the modules are warm by then. Production keeps the full 60s cap: there the
283
+ * no-shell cause is far more likely to be a genuinely ineligible route (no
284
+ * loading()), which SHOULD be re-probed rarely. See #652 (item 3) and
285
+ * docs/design/ppr-shell-resume.md ("Refused-capture backoff").
286
+ */
287
+ const REFUSED_CAPTURE_DEV_MAX_MS = 2_000;
288
+
289
+ /**
290
+ * Dev signal, matching the rest of the RSC runtime (handler.ts, server-action.ts,
291
+ * progressive-enhancement.ts): treat anything but an explicit production build as
292
+ * dev. The build folds `process.env.NODE_ENV` to a literal, so this is a compile-
293
+ * time constant in the shipped worker — no runtime probe.
294
+ */
295
+ function isDevMode(): boolean {
296
+ return process.env.NODE_ENV !== "production";
297
+ }
298
+
299
+ /** The active backoff ceiling for the current mode (dev capped low, prod at 60s). */
300
+ function refusedCaptureCeilingMs(): number {
301
+ return isDevMode() ? REFUSED_CAPTURE_DEV_MAX_MS : REFUSED_CAPTURE_MAX_MS;
302
+ }
303
+
304
+ /**
305
+ * Refused-capture backoff: key -> { consecutive failure count, epoch ms until which
306
+ * the key is not re-probed }. A key enters backoff only after runShellCapture's
307
+ * in-place retry ALSO failed (or a genuine error). A successful capture clears the
308
+ * entry outright (failure count resets). Module-level (same lifetime as
309
+ * inFlightCaptures) so the whole lifecycle lives in one layer.
310
+ */
311
+ const refusedCaptures = new Map<string, { failures: number; until: number }>();
312
+
313
+ /** True iff `key` is still inside its (exponential) backoff window. */
314
+ function isCaptureBackedOff(key: string): boolean {
315
+ const entry = refusedCaptures.get(key);
316
+ if (entry === undefined) return false;
317
+ // Window elapsed: allow a re-probe. Keep the entry (its failure count drives the
318
+ // NEXT window's escalation if the re-probe also fails); a success clears it.
319
+ return Date.now() < entry.until;
320
+ }
321
+
322
+ /**
323
+ * Record a refused/failed capture, escalating the backoff window exponentially up
324
+ * to the current mode's ceiling. The failure count keeps climbing across attempts
325
+ * (so a genuinely doomed route still ramps toward its cap), but the WINDOW is
326
+ * clamped: 60s in production, {@link REFUSED_CAPTURE_DEV_MAX_MS} in dev so a
327
+ * cold-but-eligible route re-probes fast instead of freezing out the e2e warm
328
+ * window on a cold CI runner (#652 item 3).
329
+ */
330
+ function markCaptureBackoff(key: string): void {
331
+ const failures = (refusedCaptures.get(key)?.failures ?? 0) + 1;
332
+ const window = Math.min(
333
+ REFUSED_CAPTURE_BASE_MS * 2 ** (failures - 1),
334
+ refusedCaptureCeilingMs(),
335
+ );
336
+ refusedCaptures.set(key, { failures, until: Date.now() + window });
337
+ }
338
+
339
+ /** Clear any backoff for a key that just captured successfully. */
340
+ function clearCaptureBackoff(key: string): void {
341
+ refusedCaptures.delete(key);
342
+ }
343
+
344
+ /**
345
+ * Keys already warned about a refused (null) capture, so the eternal-MISS shape
346
+ * logs once per key per isolate instead of on every request.
347
+ */
348
+ const warnedNullCaptures = new Set<string>();
349
+
350
+ /**
351
+ * Warn once per key that a capture produced no usable shell EVEN AFTER the
352
+ * in-place retry (runShellCapture attempt 2). Naming both causes with the
353
+ * distinguishing signal — does the route ever flip to HIT — is the whole point:
354
+ * the pre-retry version blamed "a loader route without loading()" unconditionally
355
+ * and misled users whose route DID have loading() and was merely cold. Because the
356
+ * retry already absorbs the cold-start case, by the time this fires cold-start has
357
+ * usually healed, so a firing warning leans toward the structural cause — but we
358
+ * still name both so a cold-start straggler is not misdiagnosed.
359
+ *
360
+ * The pointer is shipped-path-safe (a05c8251 convention): the /ppr skill ships in
361
+ * the npm tarball, but docs/design/ is repo-only, so link it by absolute GitHub URL
362
+ * rather than a relative path that dead-ends for consumers.
363
+ */
364
+ function warnNullCaptureOnce(key: string): void {
365
+ if (warnedNullCaptures.has(key)) return;
366
+ warnedNullCaptures.add(key);
367
+ console.warn(
368
+ `[rango] Shell capture for "${key}" produced no usable shell after an in-place ` +
369
+ "retry; nothing was stored, so this request stays on MISS. Causes, told apart " +
370
+ "by whether the route ever flips to HIT:\n" +
371
+ " 1. Cold-start warmup (dev module transform, or a cold worker): the capture raced " +
372
+ "an unfinished shell render. This SELF-HEALS — the route flips to HIT once a later " +
373
+ "request warms the modules. Usually nothing to do.\n" +
374
+ " 2. Something suspends above <body> with no Suspense boundary and never settles " +
375
+ "within the capture window: a slower-than-the-capture-guard bake-lane loader " +
376
+ "(loaders on entries WITHOUT loading() execute at capture and their containers " +
377
+ "bake — the boundary-less await must settle for a shell to exist), or a pending " +
378
+ "promise consumed without a <Suspense> above it. The boundary belongs on the " +
379
+ "entry/component that OWNS the data: loading() on the entry that registers the " +
380
+ "loader (a child route's loading() does not unpin a parent layout's loaders), or " +
381
+ "a <Suspense> above the consuming component.\n" +
382
+ 'See the /ppr skill (node_modules/@rangojs/router/skills/ppr/SKILL.md), "The hole ' +
383
+ 'doctrine" and "The layout-with-loaders playbook", or the design docs: ' +
384
+ "https://github.com/ivogt/vite-rsc/blob/main/packages/rangojs-router/docs/design/ppr-shell-resume.md",
385
+ );
386
+ }
387
+
388
+ /** Keys already warned about a deterministic capture refusal (once per key). */
389
+ const warnedRefusedCaptures = new Set<string>();
390
+
391
+ /**
392
+ * Warn once per key that the capture was REFUSED for a deterministic reason
393
+ * (identity-guard trip or a rejected bake-lane loader). Distinct from
394
+ * warnNullCaptureOnce: these are not cold-start shapes, the retry is skipped,
395
+ * and the message carries the concrete cause instead of a differential.
396
+ */
397
+ function warnCaptureRefusedOnce(key: string, reason: string): void {
398
+ if (warnedRefusedCaptures.has(key)) return;
399
+ warnedRefusedCaptures.add(key);
400
+ console.warn(
401
+ `[rango] Shell capture for "${key}" was refused: ${reason}\n` +
402
+ "The route stays on MISS (axis 1) — the page keeps working, only the shell " +
403
+ "cache is off. See the /ppr skill " +
404
+ "(node_modules/@rangojs/router/skills/ppr/SKILL.md) and " +
405
+ "docs/design/loader-container-bake.md.",
406
+ );
407
+ }
408
+
409
+ /**
410
+ * Default cap (serialized UTF-8 bytes) on the capture data snapshot riding
411
+ * inside a shell entry, when the route's `ppr` option does not set
412
+ * `maxSnapshotBytes`. 8 MiB: the snapshot shares the stored envelope with the
413
+ * base64 prelude and the postponed blob, and the tightest store value limit is
414
+ * Cloudflare KV's 25 MiB — 8 MiB of snapshot leaves the envelope well under it
415
+ * while still fitting any sane pinned-ring payload. Applied ONLY in
416
+ * captureAndStoreShell (the single defaulting site — resolvePprConfig passes
417
+ * the option through undefaulted), so every producer and direct caller gets
418
+ * the same policy. Over the cap the snapshot is skipped (shell still stored;
419
+ * pinned reads drift — see PartialPrerenderProps.maxSnapshotBytes).
420
+ */
421
+ export const DEFAULT_PPR_MAX_SNAPSHOT_BYTES: number = 8 * 1024 * 1024;
422
+
423
+ /** Cached encoder for the snapshot byte measurement (one per module, not per capture). */
424
+ const SNAPSHOT_BYTE_ENCODER = new TextEncoder();
425
+
426
+ /** Keys already warned about an over-cap snapshot (once per key per isolate). */
427
+ const warnedOverCapSnapshots = new Set<string>();
428
+
429
+ /**
430
+ * Warn once per key that the capture data snapshot exceeded the route's
431
+ * `maxSnapshotBytes` cap and was skipped. The shell entry is still stored and
432
+ * served — only the pinned-read replay is lost, so shell-baked cached content
433
+ * can drift from the frozen prelude between capture and HIT and hydration
434
+ * repairs it client-side (the pre-snapshot behavior). Once per key: the same
435
+ * page recaptures on every TTL roll and would otherwise re-warn forever.
436
+ */
437
+ function warnSnapshotOverCapOnce(
438
+ key: string,
439
+ snapshotBytes: number,
440
+ capBytes: number,
441
+ ): void {
442
+ if (warnedOverCapSnapshots.has(key)) return;
443
+ warnedOverCapSnapshots.add(key);
444
+ console.warn(
445
+ `[rango] Shell capture for "${key}" recorded a ${snapshotBytes}-byte data ` +
446
+ `snapshot, over the ${capBytes}-byte cap — the snapshot was skipped and ` +
447
+ "the shell was stored without it. The page keeps serving, but cached " +
448
+ "content baked into the shell is no longer pinned: if it drifts before " +
449
+ "the shell's TTL, hydration repairs the mismatch client-side. Raise the " +
450
+ "cap via the route's ppr option ({ maxSnapshotBytes }) if the entry " +
451
+ "still fits your store's value limit (Cloudflare KV: 25 MiB per value), " +
452
+ "or shrink the cache()'d data the shell bakes.",
453
+ );
454
+ }
455
+
456
+ /**
457
+ * Dev warning threshold (ms) for the slowest bake-source settlement wait. Bake
458
+ * time is by-design shell latency (top-level pushed handle promises and
459
+ * bake-lane loader containers settle before the freeze), but it recurs on
460
+ * EVERY capture of the route and occupies the per-isolate serialized capture
461
+ * queue — silently: the served response's own timing never shows it (a route
462
+ * can read 13ms TTFB while each of its captures holds the queue for seconds).
463
+ * Past this threshold the source gets named once per key with the remedy
464
+ * ladder.
465
+ */
466
+ const SHELL_CAPTURE_BAKE_WARN_MS = 2_000;
467
+
468
+ /** Keys already warned about an expensive bake source (once per key). */
469
+ const warnedBakeCosts = new Set<string>();
470
+
471
+ /**
472
+ * Dev-only, once per key: name the slowest bake source and the three remedies
473
+ * in preference order. The doctrine ("nesting = liveness") makes the cost
474
+ * legitimate, so this is a cost report with an exit, not a deprecation.
475
+ */
476
+ function warnBakeCostOnce(key: string, source: string, ms: number): void {
477
+ if (warnedBakeCosts.has(key)) return;
478
+ warnedBakeCosts.add(key);
479
+ console.warn(
480
+ `[rango] Shell capture for "${key}" waited ${ms}ms for ${source} to ` +
481
+ "settle before the shell could freeze. This cost recurs on every capture " +
482
+ "of the route and occupies the per-isolate capture queue; the served " +
483
+ "response never shows it. Top-level promises BAKE by design (the " +
484
+ "container settles; nested promises stay live). To make the value " +
485
+ "per-request instead, nest it ({ data: promise }) and read it with use() " +
486
+ "under Suspense; to keep it baked but cheap, wrap the work in cache() " +
487
+ "(the capture replays the cached value); for a segment loader, add a " +
488
+ "loading() boundary to its entry (live lane, masked at capture). See the " +
489
+ "/ppr skill (node_modules/@rangojs/router/skills/ppr/SKILL.md).",
490
+ );
491
+ }
492
+
493
+ /**
494
+ * One structured event from the background capture pipeline, mirroring the
495
+ * CFCacheReadDebugEvent pattern (cache/cf/cf-cache-types.ts): typed fields an
496
+ * operator can assert against, emitted per attempt and per skip, so the
497
+ * stored / no-shell / refused / backed-off lifecycle is observable outside
498
+ * dev console warnings. Configured via `createRouter({ debugShellCapture })`.
499
+ */
500
+ export interface ShellCaptureDebugEvent {
501
+ /** Shell cache key the event is about. */
502
+ key: string;
503
+ /**
504
+ * What happened:
505
+ * - stored / redirect / no-shell / refused: one capture ATTEMPT's outcome
506
+ * (see CaptureAttemptOutcome for the semantics of each)
507
+ * - error: the capture task failed with a genuine error (also routed through
508
+ * reportCacheError; the key is backed off)
509
+ * - skip-in-flight: scheduleShellCapture found a capture already running for
510
+ * the key (stampede guard) and scheduled nothing
511
+ * - skip-backoff: the key is inside its refused-capture backoff window and
512
+ * the capture was not attempted
513
+ * - skip-capacity: the isolate capture queue is full; a later request may retry
514
+ * - skip-inert-store: the resolved store's shell family is missing or
515
+ * declared inert (SegmentCacheStore.shellFamilyInert — a custom store
516
+ * whose backing tier is unavailable; built-in stores never declare it);
517
+ * nothing could store the result, so the background render was not
518
+ * scheduled at all
519
+ * - skip-queue-timeout: the capture waited past CAPTURE_QUEUE_WAIT_BUDGET_MS
520
+ * behind other captures and was dropped unrun (no backoff — the route is
521
+ * not doomed, the isolate was busy; a later request re-probes). Carries
522
+ * queueWaitMs.
523
+ * - backoff: the key entered (or escalated) backoff after a terminal
524
+ * no-shell — carries the new backoff state
525
+ */
526
+ outcome:
527
+ | "stored"
528
+ | "redirect"
529
+ | "no-shell"
530
+ | "refused"
531
+ | "error"
532
+ | "skip-in-flight"
533
+ | "skip-backoff"
534
+ | "skip-capacity"
535
+ | "skip-inert-store"
536
+ | "skip-queue-timeout"
537
+ | "backoff";
538
+ /** Attempt number (1 = first, 2 = in-place retry). Absent on skips. */
539
+ attempt?: number;
540
+ /** Wall-clock ms of the whole attempt (barrier + render + drain + put). */
541
+ attemptMs?: number;
542
+ /**
543
+ * Wall-clock ms the pre-render WRITE BARRIER waited on the foreground
544
+ * request's deferred cache writes (bounded by SHELL_CAPTURE_WRITE_BARRIER_MS).
545
+ */
546
+ barrierWaitMs?: number;
547
+ /**
548
+ * Wall-clock ms spent awaiting the capture's own deferred cache writes
549
+ * before the snapshot drain (bounded by SHELL_SNAPSHOT_WRITE_SETTLE_MS).
550
+ */
551
+ writeSettleMs?: number;
552
+ /** Stored prelude size in bytes (pre-base64). */
553
+ preludeBytes?: number;
554
+ /** Serialized snapshot size in UTF-8 bytes. Absent when nothing was recorded. */
555
+ snapshotBytes?: number;
556
+ /** True when the snapshot exceeded maxSnapshotBytes and was dropped. */
557
+ snapshotSkipped?: boolean;
558
+ /** A bake-lane loader settled into a shell that uses TTL/SWR-only invalidation. */
559
+ untaggedBake?: true;
560
+ /** Outcome reported by a store that supports shell-write acknowledgements. */
561
+ storeWrite?: "stored" | "invalidated" | "uncacheable";
562
+ /** Consecutive failure count in the key's backoff entry, when one exists. */
563
+ backoffFailures?: number;
564
+ /** Ms remaining in the key's backoff window, when one exists. */
565
+ backoffRemainingMs?: number;
566
+ /** Ms the capture waited in the serialized queue (skip-queue-timeout). */
567
+ queueWaitMs?: number;
568
+ /** Queue priority class at enqueue: document outranks queued navigation. */
569
+ queuePriority?: "document" | "navigation";
570
+ /**
571
+ * Captures ahead at enqueue: the active one plus every waiting capture of
572
+ * same-or-higher priority. 0 = this capture starts immediately.
573
+ */
574
+ queueAhead?: number;
575
+ /**
576
+ * Ms the capture gate was HELD waiting for the slowest bake source — a
577
+ * top-level pushed handle promise or a bake-lane loader container — to
578
+ * settle, measured from capture start. Bake time is by-design shell latency
579
+ * (the hole doctrine: top-level promises bake), but it recurs on EVERY
580
+ * capture of the route and occupies the serialized queue; this field makes
581
+ * it attributable. Absent when nothing held the gate.
582
+ */
583
+ bakeWaitMs?: number;
584
+ }
585
+
586
+ /**
587
+ * Debug sink for the capture pipeline, mirroring {@link CFCacheDebug}: `true`
588
+ * logs each event to console (visible via `wrangler tail`), a function
589
+ * receives the events for programmatic capture. Off by default.
590
+ */
591
+ export type ShellCaptureDebug =
592
+ | boolean
593
+ | ((event: ShellCaptureDebugEvent) => void);
594
+
595
+ /**
596
+ * Compact single-line form of an event's fields, shared by the console sink
597
+ * and the dev Server-Timing mirror's `desc` (rsc-rendering). Plain
598
+ * alphanumerics/`=`/`-`/`()` only, so it needs no quoted-string escaping.
599
+ */
600
+ export function describeShellCaptureEvent(
601
+ event: ShellCaptureDebugEvent,
602
+ ): string {
603
+ const parts: string[] = [event.outcome];
604
+ if (event.attempt !== undefined) parts.push(`attempt=${event.attempt}`);
605
+ if (event.attemptMs !== undefined) parts.push(`${event.attemptMs}ms`);
606
+ if (event.barrierWaitMs !== undefined) {
607
+ parts.push(`barrier=${event.barrierWaitMs}ms`);
608
+ }
609
+ if (event.writeSettleMs !== undefined) {
610
+ parts.push(`write-settle=${event.writeSettleMs}ms`);
611
+ }
612
+ if (event.preludeBytes !== undefined) {
613
+ parts.push(`prelude=${event.preludeBytes}b`);
614
+ }
615
+ if (event.snapshotBytes !== undefined) {
616
+ parts.push(
617
+ `snapshot=${event.snapshotBytes}b${event.snapshotSkipped ? " (over cap, skipped)" : ""}`,
618
+ );
619
+ }
620
+ if (event.untaggedBake) parts.push("untagged-bake");
621
+ if (event.storeWrite !== undefined) {
622
+ parts.push(`store-write=${event.storeWrite}`);
623
+ }
624
+ if (event.backoffFailures !== undefined) {
625
+ parts.push(`backoff-failures=${event.backoffFailures}`);
626
+ }
627
+ if (event.backoffRemainingMs !== undefined) {
628
+ parts.push(`backoff-remaining=${event.backoffRemainingMs}ms`);
629
+ }
630
+ if (event.queueWaitMs !== undefined) {
631
+ parts.push(`queue-wait=${event.queueWaitMs}ms`);
632
+ }
633
+ if (event.queuePriority !== undefined) {
634
+ parts.push(`queue-priority=${event.queuePriority}`);
635
+ }
636
+ if (event.queueAhead !== undefined) {
637
+ parts.push(`queue-ahead=${event.queueAhead}`);
638
+ }
639
+ if (event.bakeWaitMs !== undefined) {
640
+ parts.push(`bake=${event.bakeWaitMs}ms`);
641
+ }
642
+ return parts.join(" ");
643
+ }
644
+
645
+ /** The `debugShellCapture: true` console sink: one compact line per event. */
646
+ function consoleCaptureDebugSink(event: ShellCaptureDebugEvent): void {
647
+ console.log(
648
+ `[ShellCache][debug] ${event.key} ${describeShellCaptureEvent(event)}`,
649
+ );
650
+ }
651
+
652
+ /**
653
+ * Resolve the `debugShellCapture` router option to a callable sink, or
654
+ * undefined when off. The INTERNAL_RANGO_DEBUG env-flag fallback lives HERE
655
+ * (not at a call site) so every producer that resolves a sink inherits it;
656
+ * an explicit `false` wins over the env flag.
657
+ */
658
+ export function resolveShellCaptureDebugSink(
659
+ option: ShellCaptureDebug | undefined,
660
+ ): ((event: ShellCaptureDebugEvent) => void) | undefined {
661
+ if (option === false) return undefined;
662
+ if (option === true) return consoleCaptureDebugSink;
663
+ if (typeof option === "function") return option;
664
+ return INTERNAL_RANGO_DEBUG ? consoleCaptureDebugSink : undefined;
665
+ }
666
+
667
+ /**
668
+ * Attempt-terminal outcomes recorded for the dev Server-Timing mirror. Skip
669
+ * events are excluded so a later request's skip cannot overwrite the
670
+ * interesting terminal event before a metrics-enabled request reads it.
671
+ */
672
+ const TIMING_RECORDED_OUTCOMES = new Set<ShellCaptureDebugEvent["outcome"]>([
673
+ "stored",
674
+ "redirect",
675
+ "no-shell",
676
+ "refused",
677
+ "error",
678
+ ]);
679
+
680
+ /**
681
+ * Dev-only last-terminal-event-per-key buffer backing the Server-Timing
682
+ * mirror: the capture runs AFTER its triggering response is committed, so its
683
+ * outcome can only ride a LATER response's header. rsc-rendering consumes this
684
+ * on the next ppr GET for the key when the metrics store is active
685
+ * (debugPerformance) and appends a `ppr:capture` Server-Timing entry. Dev-only
686
+ * (isDevMode) so production isolates never grow the map; FIFO-capped because
687
+ * with debugPerformance OFF nothing ever drains it, and a long dev session
688
+ * sweeping many URLs would otherwise accumulate one entry per shell key
689
+ * forever.
690
+ */
691
+ const lastCaptureEventsForTiming = new Map<string, ShellCaptureDebugEvent>();
692
+ const MAX_TIMING_EVENT_KEYS = 100;
693
+
694
+ /**
695
+ * Consume (read-and-clear) the buffered terminal capture event for `key`, so
696
+ * one capture reports into exactly one later response's Server-Timing.
697
+ */
698
+ export function takeCaptureDebugEventForTiming(
699
+ key: string,
700
+ ): ShellCaptureDebugEvent | undefined {
701
+ const event = lastCaptureEventsForTiming.get(key);
702
+ if (event) lastCaptureEventsForTiming.delete(key);
703
+ return event;
704
+ }
705
+
706
+ /**
707
+ * Publish one capture debug event: buffer terminal outcomes for the dev
708
+ * Server-Timing mirror, then hand the event to the configured sink. A
709
+ * throwing sink is swallowed — diagnostics must never fail a capture.
710
+ */
711
+ function publishCaptureDebugEvent(
712
+ descriptor: Pick<ShellCaptureDescriptor, "debugSink">,
713
+ event: ShellCaptureDebugEvent,
714
+ ): void {
715
+ if (isDevMode() && TIMING_RECORDED_OUTCOMES.has(event.outcome)) {
716
+ // Refresh insertion order for the FIFO cap, then evict the oldest key.
717
+ lastCaptureEventsForTiming.delete(event.key);
718
+ if (lastCaptureEventsForTiming.size >= MAX_TIMING_EVENT_KEYS) {
719
+ const oldest = lastCaptureEventsForTiming.keys().next().value;
720
+ if (oldest !== undefined) lastCaptureEventsForTiming.delete(oldest);
721
+ }
722
+ lastCaptureEventsForTiming.set(event.key, event);
723
+ }
724
+ const sink = descriptor.debugSink;
725
+ if (!sink) return;
726
+ try {
727
+ sink(event);
728
+ } catch {
729
+ // Diagnostics only: a throwing consumer sink must never fail the capture.
730
+ }
731
+ }
732
+
733
+ /** Current backoff state fields for `key` (empty when no backoff entry). */
734
+ function backoffFields(
735
+ key: string,
736
+ ): Pick<ShellCaptureDebugEvent, "backoffFailures" | "backoffRemainingMs"> {
737
+ const entry = refusedCaptures.get(key);
738
+ if (!entry) return {};
739
+ return {
740
+ backoffFailures: entry.failures,
741
+ backoffRemainingMs: Math.max(0, entry.until - Date.now()),
742
+ };
743
+ }
744
+
745
+ export interface FlightCaptureGate {
746
+ /** Identity passthrough of the source stream; feed this to captureShellHTML. */
747
+ stream: ReadableStream<Uint8Array>;
748
+ /**
749
+ * Resolves once the source has been byte-quiet for FLIGHT_QUIET_HOPS macrotask
750
+ * hops (or has closed — the DATA variant). At that instant the gate FREEZES:
751
+ * no further source byte reaches the fizz side, and the readable is left open
752
+ * (never closed / errored) so fizz postpones the still-pending references
753
+ * instead of seeing "Connection closed".
754
+ */
755
+ quiesce: Promise<void>;
756
+ /**
757
+ * Stop the internal macrotask-hop loop. captureShellHTML's maxWaitMs bounds the
758
+ * overall wait; dispose() is the clean shutdown for the pathological case where
759
+ * the source never goes byte-quiet (quiesce never fires), so the hop loop would
760
+ * otherwise keep rescheduling after captureShellHTML has already aborted and
761
+ * returned.
762
+ */
763
+ dispose(): void;
764
+ }
765
+
766
+ /**
767
+ * Wrap the capture Flight stream so the fizz shell prerender reads a stream that
768
+ * (a) forwards the shell rows unchanged, (b) resolves `quiesce` after the rows go
769
+ * byte-silent for FLIGHT_QUIET_HOPS macrotask hops, and (c) FREEZES at that
770
+ * instant — dropping any later byte without closing or erroring the readable, so
771
+ * the pending masked-loader references stay pending and fizz postpones them (the
772
+ * "unclosing stream" property, here for free because the masked rows never emit).
773
+ * Freezing also guarantees no post-quiesce byte — including an error row from any
774
+ * later abort/cancel of the underlying render — can corrupt the frozen prelude.
775
+ *
776
+ * Quiet is measured in TASKS, not wall-clock: after the first byte a macrotask
777
+ * hop loop compares a byte counter each turn and fires after K quiet turns. The
778
+ * hop timers are unref'd so they never keep a Node process alive, and the source
779
+ * closing (no holes) fires quiesce immediately for the DATA variant — the
780
+ * TransformStream then closes the readable, so fizz completes with postponed null.
781
+ *
782
+ * `holdUntil` keeps the gate from FREEZING before shell material with real latency
783
+ * has emitted. The hole doctrine bakes TOP-LEVEL pushed handle promises into the
784
+ * shell (resolvedHandleStream awaits them before the handles row emits), but a
785
+ * pushed promise that takes longer than the quiet window would otherwise be frozen
786
+ * out — the handles row would never reach fizz and the prelude would come back
787
+ * trivial. While `holdUntil` is pending, byte-quiet detection keeps running but the
788
+ * gate neither fires nor freezes; once it resolves, the quiet counter restarts so a
789
+ * burst of rows unblocked by it (the resolved handles row) is still captured. It
790
+ * never delays a HOLE from postponing: holes are pending promises that emit no
791
+ * bytes, so holding the gate open longer only ever admits shell rows. Bounded by
792
+ * captureShellHTML's maxWaitMs like every other quiesce input.
793
+ */
794
+ export function gateFlightForCapture(
795
+ source: ReadableStream<Uint8Array>,
796
+ quietHops: number = FLIGHT_QUIET_HOPS,
797
+ holdUntil?: Promise<unknown>,
798
+ ): FlightCaptureGate {
799
+ let resolveQuiet!: () => void;
800
+ const quiesce = new Promise<void>((resolve) => {
801
+ resolveQuiet = resolve;
802
+ });
803
+
804
+ let bytesSeen = 0;
805
+ let armed = false;
806
+ let settled = false;
807
+ let disposed = false;
808
+ let frozen = false;
809
+ let held = holdUntil !== undefined;
810
+ let heldFirePending = false;
811
+
812
+ if (holdUntil !== undefined) {
813
+ const release = (): void => {
814
+ held = false;
815
+ if (heldFirePending && !settled && !disposed) {
816
+ // Quiet elapsed while held: restart the quiet count instead of firing
817
+ // immediately, so rows unblocked by the hold (the baked handles row)
818
+ // still flow before the freeze.
819
+ heldFirePending = false;
820
+ armed = false;
821
+ arm();
822
+ }
823
+ };
824
+ // Resolve OR reject releases the hold (a rejected handle value is dropped by
825
+ // resolveDeferredHandleValues; the capture must not hang on it).
826
+ holdUntil.then(release, release);
827
+ }
828
+
829
+ const fire = (): void => {
830
+ if (settled) return;
831
+ if (held) {
832
+ heldFirePending = true;
833
+ return;
834
+ }
835
+ settled = true;
836
+ frozen = true;
837
+ resolveQuiet();
838
+ };
839
+
840
+ const scheduleHop = (fn: () => void): void => {
841
+ const t = setTimeout(fn, 0);
842
+ // Never let the quiet-detection hop alone keep a Node process alive
843
+ // (no-op on workerd).
844
+ (t as { unref?: () => void }).unref?.();
845
+ };
846
+
847
+ // The hop loop starts only after the first byte, so it can never declare
848
+ // quiesce before fizz has begun pulling rows through the transform.
849
+ const arm = (): void => {
850
+ if (armed || settled || disposed) return;
851
+ armed = true;
852
+ let lastSeen = bytesSeen;
853
+ let quiet = 0;
854
+ const hop = (): void => {
855
+ if (settled || disposed) return;
856
+ if (bytesSeen === lastSeen) {
857
+ quiet += 1;
858
+ if (quiet >= quietHops) {
859
+ fire();
860
+ return;
861
+ }
862
+ } else {
863
+ lastSeen = bytesSeen;
864
+ quiet = 0;
865
+ }
866
+ scheduleHop(hop);
867
+ };
868
+ scheduleHop(hop);
869
+ };
870
+
871
+ const monitor = new TransformStream<Uint8Array, Uint8Array>({
872
+ transform(chunk, controller) {
873
+ // Post-quiesce: drop the byte. Do NOT enqueue and do NOT close/error — the
874
+ // frozen fizz input must stay a fixed byte set behind an open (unclosing)
875
+ // readable so still-pending references postpone.
876
+ if (frozen) return;
877
+ bytesSeen += chunk.length;
878
+ arm();
879
+ controller.enqueue(chunk);
880
+ },
881
+ flush() {
882
+ // Source closed with no freeze => DATA variant (no holes): quiet
883
+ // immediately. The TransformStream then closes the readable, so fizz
884
+ // completes and postponed comes back null.
885
+ fire();
886
+ },
887
+ });
888
+
889
+ return {
890
+ stream: source.pipeThrough(monitor),
891
+ quiesce,
892
+ dispose(): void {
893
+ disposed = true;
894
+ },
895
+ };
896
+ }
897
+
898
+ /**
899
+ * The background shell-capture descriptor: everything the capture task needs to
900
+ * store the shell. Built by the integrated PPR serve path (rsc-rendering.ts) from
901
+ * the route's `ppr` path option (`PartialPrerenderProps`) and the app-level cache
902
+ * store, and passed to scheduleShellCapture directly — it is NOT threaded through
903
+ * the request context. `tags` carries the route's OPERATIONAL `ppr.tags`; the
904
+ * capture UNIONS them with the shell's own auto-collected (non-loader) request
905
+ * tags from its derived render (the collected set stays authoritative). That
906
+ * union happens at the putShell WRITE BARRIER in captureAndStoreShell — after the
907
+ * capture quiesces — not at stream construction, so a tag recorded after an await
908
+ * in async shell content is still collected (issue #676). `store` is the same
909
+ * store the serve path resolved for its getShell read (requestCtx._cacheStore),
910
+ * so the capture writes where the serve reads.
911
+ */
912
+ export interface ShellCaptureDescriptor {
913
+ key: string;
914
+ /**
915
+ * The key's search portion (shellSearchSeed: `?`-prefixed sorted search,
916
+ * cache.searchParams filter applied, or ""). Seeds the capture render's SSR
917
+ * store so static-part `useSearchParams` reads bake markup consistent with
918
+ * the shell's own key; the resume pass derives the identical string from
919
+ * the HIT request. Computed next to the key so the two cannot drift.
920
+ * Omitted (build-time bare-pathname captures) = search-less, same as "".
921
+ */
922
+ searchSeed?: string;
923
+ /**
924
+ * The scheduling request's origin, seeding the capture render's SSR store
925
+ * location. Shell keys are host-scoped, so the resume pass's request
926
+ * agrees modulo protocol drift; the seed keeps origin-dependent static
927
+ * markup (Link's data-external) identical across capture, resume, and
928
+ * browser hydration. Omitted (build-time host-agnostic captures) falls
929
+ * back to the internal host.
930
+ */
931
+ originSeed?: string;
932
+ /**
933
+ * The RSC handler's build version (HandlerContext.version), stamped into the
934
+ * stored entry as ShellCacheEntry.buildVersion — the serve-side
935
+ * isValidShellHit gate compares it against the running build so a persistent
936
+ * store can never resume a stale build's postponed blob.
937
+ */
938
+ buildVersion: string;
939
+ ttl?: number;
940
+ swr?: number;
941
+ tags?: string[];
942
+ /**
943
+ * Per-route capture settle budget in ms (`ppr.captureTimeout`, resolved by
944
+ * resolvePprConfig). Feeds captureShellHTML's maxWaitMs — the ONE deadline
945
+ * bounding the whole capture, so it covers BOTH the fizz prerender AND the
946
+ * deferred-material settle window (the handlesBaked/loader-container
947
+ * holdUntil that keeps the gate from freezing while top-level pushes are
948
+ * pending). Undefined = SHELL_CAPTURE_MAX_WAIT_MS (15_000).
949
+ */
950
+ captureTimeout?: number;
951
+ store?: SegmentCacheStore<any>;
952
+ /** Gates the concise per-attempt capture breadcrumbs (INTERNAL_RANGO_DEBUG). */
953
+ debug?: boolean;
954
+ /**
955
+ * Cap (serialized UTF-8 bytes) on the entry's capture data snapshot; over it
956
+ * the snapshot is skipped and the shell stored without it (reported once per
957
+ * key). Absent = DEFAULT_PPR_MAX_SNAPSHOT_BYTES, applied in
958
+ * captureAndStoreShell — the single defaulting site.
959
+ */
960
+ maxSnapshotBytes?: number;
961
+ /**
962
+ * Structured capture-pipeline debug sink, resolved from
963
+ * `createRouter({ debugShellCapture })` (or INTERNAL_RANGO_DEBUG) via
964
+ * {@link resolveShellCaptureDebugSink}. Receives one
965
+ * {@link ShellCaptureDebugEvent} per attempt/skip.
966
+ */
967
+ debugSink?: (event: ShellCaptureDebugEvent) => void;
968
+ /** Store the snapshot for navigation replay, never the captured HTML prelude. */
969
+ navigationOnly?: true;
970
+ }
971
+
972
+ /**
973
+ * Schedule the background shell capture for a served document. Stampede-guarded:
974
+ * one capture per key per isolate. Runs via runBackground (waitUntil on workerd,
975
+ * fire-and-forget in Node dev), so the served response is never blocked on it. Any
976
+ * error is routed through reportCacheError — capture is best-effort; a failure just
977
+ * means the next request recaptures.
978
+ *
979
+ * Eligibility (nonce/partial/status/strategy) is decided by the caller. An SSR
980
+ * module loader may be passed for cold partial requests; it runs only after the
981
+ * capture enters the guarded background queue, never on response latency.
982
+ */
983
+ export function scheduleShellCapture(
984
+ ctx: HandlerContext<any>,
985
+ request: Request,
986
+ env: any,
987
+ url: URL,
988
+ reqCtx: RequestContext<any>,
989
+ ssrModule:
990
+ | SSRModule
991
+ | ((request: Request, url: URL) => Promise<SSRModule | null>),
992
+ descriptor: ShellCaptureDescriptor,
993
+ ): void {
994
+ const key = descriptor.key;
995
+ const inFlight = inFlightCaptures.get(key);
996
+ if (inFlight) {
997
+ if (Date.now() - inFlight.startedAt <= SHELL_CAPTURE_TASK_HARD_CAP_MS) {
998
+ publishCaptureDebugEvent(descriptor, { key, outcome: "skip-in-flight" });
999
+ return;
1000
+ }
1001
+ // Older than the task hard cap: the owning task never settled (wedged
1002
+ // render, or workerd killed its context before the release ran). Treat the
1003
+ // key as abandoned and schedule a replacement — the set() below installs a
1004
+ // new token, and the stale task's token-guarded release can no longer
1005
+ // touch it.
1006
+ }
1007
+ // Refused/failed within the window → skip the doomed re-render (one probe per
1008
+ // key per window per isolate). Expired entries self-evict inside the check.
1009
+ if (isCaptureBackedOff(key)) {
1010
+ publishCaptureDebugEvent(descriptor, {
1011
+ key,
1012
+ outcome: "skip-backoff",
1013
+ ...backoffFields(key),
1014
+ });
1015
+ return;
1016
+ }
1017
+ // A capture whose write can only no-op is dead work that still occupies the
1018
+ // serialized queue (a promise-heavy route bakes for seconds per MISS),
1019
+ // starving captures that CAN store. Skip scheduling entirely when the
1020
+ // resolved store (same defaulting as captureAndStoreShell) has no shell
1021
+ // family or declared it inert (a custom-store escape hatch; built-in
1022
+ // stores never declare it — a KV-less CFCacheStore stores L1-only).
1023
+ const scheduledStore = descriptor.store ?? reqCtx._cacheStore;
1024
+ if (!scheduledStore?.putShell || scheduledStore.shellFamilyInert) {
1025
+ publishCaptureDebugEvent(descriptor, { key, outcome: "skip-inert-store" });
1026
+ return;
1027
+ }
1028
+ const guardToken: CaptureGuardToken = { startedAt: Date.now() };
1029
+ inFlightCaptures.set(key, guardToken);
1030
+ const captureTask = async (span: TraceSpan) => {
1031
+ try {
1032
+ const setupUrl = descriptor.navigationOnly
1033
+ ? stripInternalParams(url)
1034
+ : url;
1035
+ const setupRequest = descriptor.navigationOnly
1036
+ ? createNavigationCaptureRequest(request, setupUrl)
1037
+ : request;
1038
+ const resolvedSsrModule =
1039
+ typeof ssrModule === "function"
1040
+ ? await ssrModule(setupRequest, setupUrl)
1041
+ : ssrModule;
1042
+ if (
1043
+ !resolvedSsrModule ||
1044
+ !resolvedSsrModule.resumeShellHTML ||
1045
+ !resolvedSsrModule.captureShellHTML
1046
+ ) {
1047
+ return;
1048
+ }
1049
+ // Hard-capped: SHELL_CAPTURE_MAX_WAIT_MS arms only inside
1050
+ // captureShellHTML, AFTER the capture's router.match() — a handler
1051
+ // wedged on a never-settling upstream await has no deadline in force
1052
+ // and would strand the stampede guard and the queue slot (autobarn
1053
+ // pilot). The cap rejects, riding the existing catch: backoff +
1054
+ // reportCacheError + token-guarded release. The abandoned attempt keeps
1055
+ // running until its context dies; nothing awaits it.
1056
+ const outcome = await raceTaskHardCap(
1057
+ runShellCapture(
1058
+ ctx,
1059
+ request,
1060
+ env,
1061
+ url,
1062
+ reqCtx,
1063
+ resolvedSsrModule,
1064
+ descriptor,
1065
+ ),
1066
+ key,
1067
+ );
1068
+ span.setAttribute("rango.background.outcome", outcome);
1069
+ // Update the negative cache off the terminal outcome. A stored shell clears
1070
+ // any prior backoff; a `no-shell` (after the in-place retry) backs the key
1071
+ // off so the next requests don't re-probe it. A `redirect` has no shell but
1072
+ // is not a doomed render — leave the backoff untouched.
1073
+ if (outcome === "stored") clearCaptureBackoff(key);
1074
+ else if (outcome === "no-shell") {
1075
+ markCaptureBackoff(key);
1076
+ publishCaptureDebugEvent(descriptor, {
1077
+ key,
1078
+ outcome: "backoff",
1079
+ ...backoffFields(key),
1080
+ });
1081
+ }
1082
+ } catch (error) {
1083
+ // Detached background task — pass reqCtx so onError still fires when the ALS
1084
+ // context is gone. A genuine failure recurs, so back it off too (re-probe
1085
+ // once per window, not every request) and report it once.
1086
+ markCaptureBackoff(key);
1087
+ span.setAttribute("rango.background.outcome", "error");
1088
+ publishCaptureDebugEvent(descriptor, {
1089
+ key,
1090
+ outcome: "error",
1091
+ ...backoffFields(key),
1092
+ });
1093
+ reportCacheError(error, "cache-write", "[ShellCache] capture", reqCtx);
1094
+ } finally {
1095
+ releaseCaptureGuard(key, guardToken);
1096
+ }
1097
+ };
1098
+ // Serialize capture EXECUTION per isolate (capture-queue.ts): concurrent
1099
+ // captures starve each other's task-quantized quiet windows — one grinding
1100
+ // capture makes the sibling freeze a trivial prelude and store nothing
1101
+ // (rotating eternal-MISS victims on GH runners). The stampede guard above
1102
+ // stays per-key (dedupe while queued); the queue is cross-key.
1103
+ //
1104
+ // The whole serialized task — queue wait INCLUDED — is wrapped in the
1105
+ // rango.background span (kind=shell-capture). The span is the explanatory
1106
+ // parent for the capture's platform KV/fetch/cache spans (the capture's own
1107
+ // rango.* phase spans stay suppressed — deriveShellCaptureContext strips
1108
+ // _tracing), and queue_wait_ms makes a capture parked behind a slow
1109
+ // predecessor link visible instead of reading as an unexplained dead gap
1110
+ // (observed in production: ~24s of zero I/O before capture start).
1111
+ // observePhase reads tracing off the ALS context captured when runBackground
1112
+ // registered the task — the foreground request context, tracing intact.
1113
+ const serializedTask = async () => {
1114
+ await observePhase(PHASES.background("shell-capture"), async (span) => {
1115
+ span.setAttribute("rango.shell_key", key);
1116
+ // A production page can enqueue several navigation-only captures through
1117
+ // viewport prefetching. Let a later document MISS overtake that queued
1118
+ // speculative work so it can become a shell HIT before the 15s queue
1119
+ // budget expires. Never preempts the active capture. Priority and the
1120
+ // backlog ahead at enqueue ride the span (and the skip event below), so
1121
+ // a skip-queue-timeout diagnoses itself instead of needing a trace dive.
1122
+ const queuePriority = descriptor.navigationOnly
1123
+ ? ("navigation" as const)
1124
+ : ("document" as const);
1125
+ const depths = captureQueueDepths();
1126
+ const queueAhead =
1127
+ (depths.running ? 1 : 0) +
1128
+ depths.document +
1129
+ (queuePriority === "navigation" ? depths.navigation : 0);
1130
+ span.setAttribute("rango.background.queue_priority", queuePriority);
1131
+ span.setAttribute("rango.background.queue_ahead", queueAhead);
1132
+ const queueStart = performance.now();
1133
+ try {
1134
+ await enqueueSerializedCapture(
1135
+ () => {
1136
+ span.setAttribute(
1137
+ "rango.background.queue_wait_ms",
1138
+ Math.round(performance.now() - queueStart),
1139
+ );
1140
+ return captureTask(span);
1141
+ },
1142
+ { priority: queuePriority },
1143
+ );
1144
+ } catch (error) {
1145
+ if (error instanceof CaptureQueueFullError) {
1146
+ releaseCaptureGuard(key, guardToken);
1147
+ span.setAttribute("rango.background.outcome", "skip-capacity");
1148
+ publishCaptureDebugEvent(descriptor, {
1149
+ key,
1150
+ outcome: "skip-capacity",
1151
+ });
1152
+ return;
1153
+ }
1154
+ if (error instanceof CaptureQueueWaitTimeoutError) {
1155
+ // Dropped unrun after waiting past the queue budget: no backoff (the
1156
+ // route is not doomed, the isolate was busy) — a later request
1157
+ // re-probes the key.
1158
+ releaseCaptureGuard(key, guardToken);
1159
+ span.setAttribute("rango.background.outcome", "skip-queue-timeout");
1160
+ span.setAttribute(
1161
+ "rango.background.queue_wait_ms",
1162
+ Math.round(error.waitedMs),
1163
+ );
1164
+ publishCaptureDebugEvent(descriptor, {
1165
+ key,
1166
+ outcome: "skip-queue-timeout",
1167
+ queueWaitMs: Math.round(error.waitedMs),
1168
+ queuePriority,
1169
+ queueAhead,
1170
+ });
1171
+ return;
1172
+ }
1173
+ throw error;
1174
+ }
1175
+ });
1176
+ };
1177
+ // The capture's own task must NOT enter reqCtx._pendingBackgroundTasks: the
1178
+ // capture drains that list before rendering (the write-barrier ordering edge),
1179
+ // and awaiting its own still-running promise would burn the whole barrier
1180
+ // deadline on every capture.
1181
+ (serializedTask as { [UNTRACKED_BACKGROUND_TASK]?: boolean })[
1182
+ UNTRACKED_BACKGROUND_TASK
1183
+ ] = true;
1184
+ runBackground(reqCtx, serializedTask);
1185
+ }
1186
+
1187
+ /**
1188
+ * The outcome of one capture attempt.
1189
+ * - `stored`: a usable shell was captured (and a putShell was attempted; a store
1190
+ * I/O failure is reported separately and does NOT make the attempt retryable —
1191
+ * the capture itself worked).
1192
+ * - `redirect`: the matched route redirects, so there is no shell to capture.
1193
+ * - `no-shell`: captureShellHTML returned null because the prelude was unusable
1194
+ * or its private capture abort landed before the shell completed. This is the
1195
+ * only RETRYABLE outcome.
1196
+ */
1197
+ type CaptureAttemptOutcome = "stored" | "redirect" | "no-shell" | "refused";
1198
+
1199
+ function createNavigationCaptureRequest(request: Request, url: URL): Request {
1200
+ const headers = new Headers(request.headers);
1201
+ headers.set("accept", "text/html");
1202
+ for (const name of [
1203
+ "rsc-action",
1204
+ "x-rango-prefetch",
1205
+ "x-rango-state",
1206
+ "x-rsc-hmr",
1207
+ "x-rsc-router-client-path",
1208
+ "x-rsc-router-intercept-source",
1209
+ ]) {
1210
+ headers.delete(name);
1211
+ }
1212
+ return new Request(url, { method: request.method, headers });
1213
+ }
1214
+
1215
+ /**
1216
+ * Per-attempt observability fields, filled along the capture path (barrier in
1217
+ * attemptCapture, the rest in captureAndStoreShell) and folded into the
1218
+ * attempt's {@link ShellCaptureDebugEvent} by runShellCapture. A plain mutable
1219
+ * bag, not a return value: captureAndStoreShell's outcome type stays a string
1220
+ * union its existing callers (producer B, tests) consume unchanged.
1221
+ */
1222
+ type CaptureAttemptStats = Pick<
1223
+ ShellCaptureDebugEvent,
1224
+ | "barrierWaitMs"
1225
+ | "writeSettleMs"
1226
+ | "preludeBytes"
1227
+ | "snapshotBytes"
1228
+ | "snapshotSkipped"
1229
+ | "untaggedBake"
1230
+ | "storeWrite"
1231
+ | "bakeWaitMs"
1232
+ >;
1233
+
1234
+ /**
1235
+ * Run the shell capture with a single in-place retry, then store the result.
1236
+ *
1237
+ * Each attempt re-derives EVERYTHING (fresh context, fresh router.match, fresh
1238
+ * Flight render) via {@link attemptCapture} — a capture consumes its handle store,
1239
+ * its request-tag set, and its one-shot Flight stream, so none of them are
1240
+ * reusable across attempts. A first attempt that comes back `no-shell` is almost
1241
+ * always a cold render (dev module transform / cold worker) that had not finished
1242
+ * when we froze the shell; the attempt itself warmed the module graph, so a second
1243
+ * attempt a short beat later usually completes the shell in the SAME background
1244
+ * task. That kills the old multi-request warmup where the caller had to re-issue
1245
+ * several HTTP requests before a capture stuck. We retry ONLY on `no-shell`; a
1246
+ * genuine render error is NOT retried — it propagates to scheduleShellCapture's
1247
+ * reportCacheError. See docs/design/ppr-shell-resume.md.
1248
+ *
1249
+ * `retryDelayMs` is a parameter (defaulting to the module const) so unit tests can
1250
+ * drive the retry without a real 400ms wall-clock wait.
1251
+ */
1252
+ async function runShellCapture(
1253
+ ctx: HandlerContext<any>,
1254
+ request: Request,
1255
+ env: any,
1256
+ url: URL,
1257
+ reqCtx: RequestContext<any>,
1258
+ ssrModule: SSRModule,
1259
+ descriptor: ShellCaptureDescriptor,
1260
+ retryDelayMs: number = SHELL_CAPTURE_RETRY_DELAY_MS,
1261
+ ): Promise<CaptureAttemptOutcome> {
1262
+ const captureUrl = descriptor.navigationOnly ? stripInternalParams(url) : url;
1263
+ const captureRequest = descriptor.navigationOnly
1264
+ ? createNavigationCaptureRequest(request, captureUrl)
1265
+ : request;
1266
+ const log = descriptor.debug
1267
+ ? (message: string) => console.log(message)
1268
+ : () => {};
1269
+
1270
+ // One attempt + its structured debug event: the stats object rides through
1271
+ // attemptCapture/captureAndStoreShell collecting the observability fields
1272
+ // (barrier wait, write-settle wait, prelude/snapshot bytes), and the event
1273
+ // folds them with the outcome. A genuine render error skips the attempt
1274
+ // event — scheduleShellCapture's catch publishes the terminal `error` event.
1275
+ const timedAttempt = async (
1276
+ attempt: number,
1277
+ ): Promise<CaptureAttemptOutcome> => {
1278
+ const stats: CaptureAttemptStats = {};
1279
+ const start = performance.now();
1280
+ const outcome = await attemptCapture(
1281
+ ctx,
1282
+ captureRequest,
1283
+ env,
1284
+ captureUrl,
1285
+ reqCtx,
1286
+ ssrModule,
1287
+ descriptor,
1288
+ stats,
1289
+ );
1290
+ publishCaptureDebugEvent(descriptor, {
1291
+ key: descriptor.key,
1292
+ outcome,
1293
+ attempt,
1294
+ attemptMs: Math.round(performance.now() - start),
1295
+ ...stats,
1296
+ });
1297
+ return outcome;
1298
+ };
1299
+
1300
+ const first = await timedAttempt(1);
1301
+ // "refused" is deterministic (identity guard / rejected bake-lane loader —
1302
+ // its own warning already fired): no retry, and the caller backs the key off
1303
+ // exactly like a structural no-shell.
1304
+ if (first === "refused") return "no-shell";
1305
+ // "stored" (success) or "redirect" (no shell exists): nothing to retry.
1306
+ if (first !== "no-shell") return first;
1307
+
1308
+ // Attempt 1 produced no usable shell. Retry ONCE in place — the first attempt
1309
+ // warmed the dev transform graph / cold worker, so attempt 2 typically completes
1310
+ // the shell without another HTTP request. The concise line is gated on the
1311
+ // middleware's debug flag (threaded via the descriptor) so it replaces the old
1312
+ // full DOMException dump with one readable breadcrumb.
1313
+ log(
1314
+ `[ShellCache] capture attempt 1/2 for ${descriptor.key} aborted before shell completed (cold modules?) — retrying`,
1315
+ );
1316
+ await delay(retryDelayMs);
1317
+ const second = await timedAttempt(2);
1318
+ if (second === "refused") return "no-shell";
1319
+ if (second !== "no-shell") return second;
1320
+
1321
+ // Both attempts came back with no usable shell. Cold-start would have healed by
1322
+ // now, so the eternal-MISS structural shape (a loader route without loading()) is
1323
+ // the likely cause — warn once per key. Ordering matters: because the retry
1324
+ // absorbs cold-start, cold-start routes almost never reach this warning. The
1325
+ // caller (scheduleShellCapture) reads this `no-shell` return to back the key off.
1326
+ log(
1327
+ `[ShellCache] capture attempt 2/2 for ${descriptor.key} aborted — giving up until next request`,
1328
+ );
1329
+ warnNullCaptureOnce(descriptor.key);
1330
+ return "no-shell";
1331
+ }
1332
+
1333
+ /** Fold the capture's handle-liveness record into the entry flag (true | undefined). */
1334
+ function handlerLayerIsLive(
1335
+ liveness: RequestContext["_shellCaptureHandleLiveness"],
1336
+ ): true | undefined {
1337
+ if (!liveness) return undefined;
1338
+ return liveness.holes ||
1339
+ liveness.pendingPushes > 0 ||
1340
+ liveness.handlerInvokedLoader
1341
+ ? true
1342
+ : undefined;
1343
+ }
1344
+
1345
+ /**
1346
+ * One capture attempt in a DERIVED request context.
1347
+ *
1348
+ * The derived context is `Object.create(reqCtx)` so it inherits the foreground's
1349
+ * post-middleware state (variables, cache store, env/request/url, waitUntil) while
1350
+ * overriding the render-scoped accumulators as own properties:
1351
+ * - _handleStore: a fresh store. The foreground store is already drained to
1352
+ * completion (its stream() flipped `completed` on settle) and would throw
1353
+ * LateHandlePushError on any re-push. Every downstream reader resolves the
1354
+ * store off the ambient context (setupLoaderAccess captures
1355
+ * _getRequestContext()._handleStore; trackHandler reads it), so the fresh
1356
+ * store on the derived context is what the capture match() writes handles to.
1357
+ * - _requestTags: a fresh Set. The capture collects its OWN shell tags here —
1358
+ * non-loader tags only, since loaders are masked — which is exactly the tag
1359
+ * set a shell entry should be invalidatable by (loader tags belong to holes).
1360
+ * - _transitionWhen: a fresh [] so the capture's transition gating is its own.
1361
+ * - _shellCaptureRun: true — the switch loaders/cookies/headers guards read.
1362
+ * - _metricsStore: undefined so the capture never appends to the foreground's
1363
+ * (already-finalized) metrics.
1364
+ * - _renderBarrier family: an own barrier wired to the fresh handle store
1365
+ * (wireRenderBarrier), plus _treeHasStreaming/deadlock-guard resets — the
1366
+ * capture's rendered() lifecycle is its own, not the foreground's.
1367
+ *
1368
+ * The capture is MIXED-CHAIN: its match() behaves like a normal render with
1369
+ * respect to the segment cache — cache()'d segments replay from ring 3, UNCACHED
1370
+ * segments execute their handlers fresh (which is why the cookies()/headers()
1371
+ * capture guard is load-bearing). Middleware is NOT re-run: it already ran for the
1372
+ * triggering request, and the derived context inherits its post-middleware state
1373
+ * (guarding is serve-time; the shell is never served without the full chain).
1374
+ *
1375
+ * A FRESH context (and match/render) per attempt is what makes the retry sound:
1376
+ * the second attempt is a clean capture, not a resumption of the first.
1377
+ */
1378
+ async function attemptCapture(
1379
+ ctx: HandlerContext<any>,
1380
+ request: Request,
1381
+ env: any,
1382
+ url: URL,
1383
+ reqCtx: RequestContext<any>,
1384
+ ssrModule: SSRModule,
1385
+ descriptor: ShellCaptureDescriptor,
1386
+ stats: CaptureAttemptStats,
1387
+ ): Promise<CaptureAttemptOutcome> {
1388
+ // WRITE BARRIER (ordering edge, not a narrower race): settle the foreground's
1389
+ // already-scheduled background tasks — its deferred ring-3/ring-1 cache writes —
1390
+ // BEFORE this attempt's match/render, so the capture's cache reads observe the
1391
+ // foreground's generation deterministically. Contract: a capture must never
1392
+ // clobber a ring-3 entry the foreground produced; with the barrier, the
1393
+ // capture's ring-3 lookup HITs the foreground's entry and REPLAYS it (handler
1394
+ // skipped, cache-store middleware's write path gated off by state.cacheHit), so
1395
+ // prelude, snapshot, and ring-3 agree on the foreground's generation. Runs per
1396
+ // attempt (the retry re-checks; already-settled promises are free).
1397
+ const barrierStart = performance.now();
1398
+ await settleTrackedBackgroundTasks(reqCtx, SHELL_CAPTURE_WRITE_BARRIER_MS);
1399
+ stats.barrierWaitMs = Math.round(performance.now() - barrierStart);
1400
+
1401
+ const { derivedCtx, freshHandleStore } = deriveShellCaptureContext(
1402
+ reqCtx,
1403
+ descriptor,
1404
+ descriptor.navigationOnly ? { request, url } : undefined,
1405
+ );
1406
+ const captureStartedAt = Date.now();
1407
+
1408
+ return runWithRequestContext(derivedCtx, async () => {
1409
+ const match = await ctx.router.match(request, { env });
1410
+ // A route that redirects has no shell to capture — bail (no store write, no
1411
+ // retry: a redirect is deterministic).
1412
+ if (match.redirect) return "redirect";
1413
+
1414
+ setRequestContextParams(match.params, match.routeName);
1415
+
1416
+ const payload = buildFullPayload(
1417
+ match,
1418
+ ctx,
1419
+ url,
1420
+ derivedCtx,
1421
+ freshHandleStore,
1422
+ );
1423
+ const flightStage = renderRscFlightStage({
1424
+ ctx,
1425
+ request,
1426
+ env,
1427
+ url,
1428
+ payload,
1429
+ tracking: {
1430
+ mode: "full",
1431
+ routeKey: derivedCtx._routeName,
1432
+ },
1433
+ });
1434
+
1435
+ // Pass the descriptor with its STATIC ppr.tags unchanged. The shell's own
1436
+ // render-recorded tags are snapshotted at the putShell WRITE BARRIER inside
1437
+ // captureAndStoreShell, not here: a tag recorded AFTER an await in async shell
1438
+ // content (and tags propagated by async cache()/"use cache" reads) lands after
1439
+ // this synchronous construction point, so snapshotting here dropped it — the
1440
+ // shell-tag snapshot must sit behind the quiesce gate (issue #676).
1441
+ return captureAndStoreShell(
1442
+ ssrModule,
1443
+ flightStage.stream,
1444
+ freshHandleStore,
1445
+ derivedCtx,
1446
+ descriptor,
1447
+ stats,
1448
+ captureStartedAt,
1449
+ );
1450
+ });
1451
+ }
1452
+
1453
+ /**
1454
+ * The derived capture context and its fresh (mask-funneled) handle store,
1455
+ * shared by BOTH shell producers: the runtime background capture
1456
+ * (attemptCapture, producer A) and the build-time prerender shell capture
1457
+ * (prerender/build-shell-capture.ts, producer B — issue #699). One
1458
+ * implementation so the capture semantics — the nested-thenable mask funnel,
1459
+ * handler-liveness bookkeeping, snapshot recording, the implicit doc-cache
1460
+ * scope — cannot drift between producers.
1461
+ */
1462
+ export interface CaptureContextDerivation {
1463
+ derivedCtx: RequestContext;
1464
+ freshHandleStore: HandleStore;
1465
+ }
1466
+
1467
+ /**
1468
+ * Derive the capture request context from a base context. Producer A passes
1469
+ * the foreground request's post-middleware context (the derived context
1470
+ * inherits its variables/env/cookie machinery through the prototype);
1471
+ * producer B passes a synthetic build-request context created by
1472
+ * createRequestContext over the build env, with a fresh MemorySegmentCacheStore
1473
+ * as `_cacheStore` so the recording/snapshot machinery arms identically.
1474
+ */
1475
+ export function deriveShellCaptureContext(
1476
+ reqCtx: RequestContext<any>,
1477
+ descriptor: Pick<ShellCaptureDescriptor, "ttl" | "swr">,
1478
+ identity?: { request: Request; url: URL },
1479
+ ): CaptureContextDerivation {
1480
+ const freshHandleStore = createHandleStore();
1481
+ freshHandleStore.onError = reqCtx._handleStore.onError;
1482
+ // Shape = liveness for handles, exactly as for bake-lane loader containers
1483
+ // (mask-nested.ts): nested thenables in a pushed handle container are
1484
+ // per-request by declaration, so the CAPTURE's copy masks them — the
1485
+ // consuming boundary postpones as a hole regardless of settle timing,
1486
+ // instead of a fast-settling nested value baking into the shared shell. A
1487
+ // TOP-LEVEL promise push keeps its documented bake contract (awaited
1488
+ // pre-SSR, gate held open for it), but the container it RESOLVES to gets
1489
+ // the same nested masking. Wrapping THIS store's push is the single funnel:
1490
+ // the store exists only for this capture attempt, so every push wrapper
1491
+ // (setupLoaderAccess, createUseFunction, prerender) inherits the policy and
1492
+ // the foreground store is untouched.
1493
+ // Shell fast path bookkeeping on the same funnel:
1494
+ // - handleLiveness: a nested thenable in a push made OUTSIDE a DSL loader
1495
+ // scope (attribution read synchronously at push time — handler bodies,
1496
+ // handler-invoked ctx.use(loader) callbacks, defers) declares
1497
+ // handler-layer per-request data. Its mask is a hole only a handler
1498
+ // re-run can fill, so the entry must not serve handler-free
1499
+ // (ShellCacheEntry.handlerLiveHoles). Still-pending top-level handler
1500
+ // pushes at the putShell barrier count too — their liveness is unknowable.
1501
+ // - loaderScopedPushValues: DSL-loader pushes re-run fresh on every HIT, so
1502
+ // their captured values must NOT enter a segment record's handle snapshot
1503
+ // (replay would duplicate the fresh push, and their masked nested
1504
+ // promises would stall the Flight handle encode to its timeout). The set
1505
+ // rides the derived context (_shellCaptureLoaderHandleValues) and is
1506
+ // applied ONLY at the captureHandles cache-write call site — every other
1507
+ // getDataForSegment consumer (the render-barrier snapshot, prerender)
1508
+ // sees every push.
1509
+ // EXCEPTION — bake-lane { ssr: false } loaders: they execute at capture
1510
+ // and never re-run on a HIT, so neither exclusion rationale applies. The
1511
+ // capture awaits them (fresh.ts), their pushes are in the captured HTML
1512
+ // (<head> title/meta, useHandle echoes), and the stored snapshot MUST
1513
+ // carry the same values or HIT hydration mismatches against its own
1514
+ // prelude (server text present, client handle empty). Only their
1515
+ // settled, thenable-free pushes qualify — a deferred (thenable) push or
1516
+ // one with masked nested promises keeps the exclusion so the handle
1517
+ // encode cannot stall on a never-resolving mask.
1518
+ const handleLiveness = {
1519
+ holes: false,
1520
+ pendingPushes: 0,
1521
+ handlerInvokedLoader: false,
1522
+ };
1523
+ const loaderScopedPushValues = new WeakSet<object>();
1524
+ const rawCapturePush = freshHandleStore.push.bind(freshHandleStore);
1525
+ freshHandleStore.push = (
1526
+ handleName: string,
1527
+ segmentId: string,
1528
+ value: unknown,
1529
+ ) => {
1530
+ const pushedInLoaderScope = isInsideLoaderScope();
1531
+ // Single walk: the mask reports whether it masked any nested thenable
1532
+ // (the liveness declaration) while building the capture copy.
1533
+ let maskedNestedThenable = false;
1534
+ const maskWithLiveness = (v: unknown): unknown => {
1535
+ const report: MaskReport = { thenable: false };
1536
+ const masked = maskNestedContainerThenables(v, undefined, report);
1537
+ if (report.thenable) {
1538
+ maskedNestedThenable = true;
1539
+ if (!pushedInLoaderScope) handleLiveness.holes = true;
1540
+ }
1541
+ return masked;
1542
+ };
1543
+ let masked: unknown;
1544
+ if (isThenable(value)) {
1545
+ if (!pushedInLoaderScope) {
1546
+ handleLiveness.pendingPushes++;
1547
+ const settle = () => handleLiveness.pendingPushes--;
1548
+ value.then(settle, settle);
1549
+ }
1550
+ masked = value.then(maskWithLiveness);
1551
+ // Deferred (thenable) loader pushes always keep the exclusion — the
1552
+ // bake-lane carve-out below is for settled values only.
1553
+ if (pushedInLoaderScope) {
1554
+ loaderScopedPushValues.add(masked as object);
1555
+ }
1556
+ } else {
1557
+ masked = maskWithLiveness(value);
1558
+ if (
1559
+ pushedInLoaderScope &&
1560
+ typeof masked === "object" &&
1561
+ masked !== null
1562
+ ) {
1563
+ // Bake-lane { ssr: false } loader pushes are shell material (see the
1564
+ // funnel comment above): keep them IN the stored snapshot when
1565
+ // settled and thenable-free; everything else stays excluded.
1566
+ const bodyLoaderId = getCurrentLoaderBodyId();
1567
+ const baked =
1568
+ bodyLoaderId !== undefined &&
1569
+ !maskedNestedThenable &&
1570
+ derivedCtx._awaitBeforeFlushLoaderIds?.has(bodyLoaderId) === true;
1571
+ if (!baked) {
1572
+ loaderScopedPushValues.add(masked);
1573
+ }
1574
+ }
1575
+ }
1576
+ rawCapturePush(handleName, segmentId, masked);
1577
+ };
1578
+
1579
+ const derivedCtx: RequestContext = Object.create(reqCtx);
1580
+ if (identity) {
1581
+ derivedCtx.request = identity.request;
1582
+ derivedCtx.url = identity.url;
1583
+ derivedCtx.originalUrl = new URL(identity.url);
1584
+ derivedCtx.pathname = identity.url.pathname;
1585
+ derivedCtx.searchParams = identity.url.searchParams;
1586
+ }
1587
+ derivedCtx._handleStore = freshHandleStore;
1588
+ // Own render barrier, closure-bound to the derived ctx and the fresh store
1589
+ // (issue #684, plan 009). Without this every _renderBarrier* read fell
1590
+ // through the prototype to the foreground's ALREADY-RESOLVED barrier: a
1591
+ // bake-lane loader's `await ctx.rendered()` resolved instantly and
1592
+ // ctx.use(handle) read the FOREGROUND handle snapshot — foreground
1593
+ // per-request handle data could bake into the shared shell. wireRenderBarrier
1594
+ // also resets _treeHasStreaming (recomputed for the capture's tree) and the
1595
+ // deadlock-guard fields as own properties.
1596
+ wireRenderBarrier(derivedCtx, freshHandleStore);
1597
+ derivedCtx._shellCaptureLoaderHandleValues = loaderScopedPushValues;
1598
+ derivedCtx._requestTags = new Set<string>();
1599
+ // Own explicit-store registry: cache-store resolutions during the capture
1600
+ // (the implicit scope's SnapshotOnlySegmentStore, any per-capture explicit
1601
+ // store instance) must NOT register into the handler-lifetime
1602
+ // _explicitTaggedStores set — a capture-ephemeral store pinned there would
1603
+ // trip the partial-tag-store warning on every later updateTag() and retain
1604
+ // the whole capture snapshot in memory. Capture registrations die with this
1605
+ // context; module-singleton stores stay registered by normal renders.
1606
+ derivedCtx._explicitTaggedStores = new Set();
1607
+ derivedCtx._transitionWhen = [];
1608
+ derivedCtx._shellCaptureRun = true;
1609
+ // Own-property reset: an inherited flag would make serializeSegments store
1610
+ // a double-encoded fragment. No current arming site reaches a capture
1611
+ // render (kept as defense-in-depth for a future one).
1612
+ derivedCtx._shellFragmentPayload = false;
1613
+ derivedCtx._metricsStore = undefined;
1614
+ // Spans, like perf metrics above, are a FOREGROUND surface: the capture
1615
+ // re-render must not emit a second rango.render/loader/ssr set after the
1616
+ // foreground rango.request span ended (orphan spans in the trace).
1617
+ // _tracing is otherwise inherited through Object.create(reqCtx).
1618
+ derivedCtx._tracing = undefined;
1619
+ // Bake-lane loader containers (loaders on entries with no renderable
1620
+ // loading() execute during capture — docs/design/loader-container-bake.md).
1621
+ // resolveLoaderData registers each container promise here; the drain in
1622
+ // captureAndStoreShell elides + pins them into the snapshot's loader family.
1623
+ derivedCtx._shellCaptureLoaderRecords = new Map();
1624
+ // Own onResponse list so the capture's match-middleware callbacks (the ring-3
1625
+ // segment cache write registers here) are ISOLATED from the foreground's shared
1626
+ // array AND can be fired by captureAndStoreShell. The segment write is gated
1627
+ // behind onResponse, which the capture never triggers (it builds no Response) —
1628
+ // without firing it, a ring-3 cache() MISS at capture renders fresh into the
1629
+ // prelude but is never written, so it is never recorded and drifts on a HIT.
1630
+ derivedCtx._onResponseCallbacks = [];
1631
+
1632
+ // Capture data snapshot: read every cache-store hit/write through a recording
1633
+ // wrapper on the DERIVED context's store (own property, so the shared
1634
+ // reqCtx._cacheStore is untouched — the snapshot is per-capture). Its records
1635
+ // ride inside the ShellCacheEntry so a HIT can reproduce the shell's cached
1636
+ // content byte-identically. See cache/shell-snapshot.ts and the design doc.
1637
+ //
1638
+ // Cache writes are deferred (waitUntil): a MISS-at-capture value's setItem/set
1639
+ // — hence its record — would otherwise land after the shell quiesces. Override
1640
+ // the derived context's waitUntil to COLLECT those write promises (still
1641
+ // forwarding to the parent so the write persists and the worker stays alive),
1642
+ // then captureAndStoreShell awaits them before draining. Reads that HIT are
1643
+ // recorded synchronously during the render and need none of this.
1644
+ derivedCtx._shellCaptureHandleLiveness = handleLiveness;
1645
+ if (reqCtx._cacheStore) {
1646
+ const recordingStore = new RecordingShellStore(reqCtx._cacheStore);
1647
+ derivedCtx._cacheStore = recordingStore;
1648
+ derivedCtx.waitUntil = (fn: () => Promise<void>): void => {
1649
+ const p = Promise.resolve().then(fn);
1650
+ recordingStore.trackWrite(p);
1651
+ reqCtx.waitUntil(() => p);
1652
+ };
1653
+ // Shell fast path (capture side): the implicit doc-cache scope makes the
1654
+ // capture's match write ALL matched non-loader segments as one doc-keyed
1655
+ // segment record — into the snapshot only (SnapshotOnlySegmentStore), so
1656
+ // the record dies with the shell entry and the next capture's lookup
1657
+ // still misses (handlers re-run on recapture). Routes deriving their own
1658
+ // cache scope are untouched (resolveShellImplicitCacheScope).
1659
+ derivedCtx._shellImplicitCache = {
1660
+ ttl: descriptor.ttl,
1661
+ swr: descriptor.swr,
1662
+ store: new SnapshotOnlySegmentStore(recordingStore),
1663
+ keyPrefix: "doc",
1664
+ };
1665
+ }
1666
+
1667
+ return { derivedCtx, freshHandleStore };
1668
+ }
1669
+
1670
+ /**
1671
+ * Seal handles, derive the quiesce signal, prerender + abort via the SSR module's
1672
+ * captureShellHTML, and store the result. Returns the attempt outcome (the caller
1673
+ * owns retry/warn decisions — this function no longer warns). Never throws out of
1674
+ * the store write: a failed putShell is routed through reportCacheError so the
1675
+ * background task stays best-effort, and the attempt still counts as `stored` (the
1676
+ * capture worked; only the store I/O failed). `ssrModule.captureShellHTML` MUST be
1677
+ * present (eligibility is checked before scheduling).
1678
+ *
1679
+ * A `no-shell` result from captureShellHTML is the only retryable outcome. Every
1680
+ * captureShellHTML error propagates to reportCacheError and is NOT retried. The
1681
+ * capture handler converts only its own private abort sentinel to null before this
1682
+ * layer sees it.
1683
+ */
1684
+ async function captureAndStoreShell(
1685
+ ssrModule: SSRModule,
1686
+ rscStream: ReadableStream<Uint8Array>,
1687
+ handleStore: HandleStore,
1688
+ reqCtx: RequestContext<any>,
1689
+ capture: ShellCaptureDescriptor,
1690
+ stats?: CaptureAttemptStats,
1691
+ captureStartedAt: number = Date.now(),
1692
+ ): Promise<Exclude<CaptureAttemptOutcome, "redirect">> {
1693
+ const captureShellHTML = ssrModule.captureShellHTML!;
1694
+
1695
+ // Seal the handle store so the payload's handles generator (resolvedHandleStream
1696
+ // -> handleStore.stream()) converges and completes even though masked loaders
1697
+ // never resolve. handleStore.settled gates ONLY on tracked HANDLER promises
1698
+ // (handleStore.track, via trackHandler) — NOT on deferred handle VALUES pushed
1699
+ // through ctx.use(Handle).defer(), which are plain pushed promises. So seal()
1700
+ // does not reject or hang on outstanding defers: settled resolves once the
1701
+ // handlers settle, and each deferred slot resolves on its own createDeferred
1702
+ // timeout (defer.ts, default 10s) or when its resolver fires. A defer whose
1703
+ // resolver depends on a masked loader can never fire, so it stays pending until
1704
+ // that 10s timeout — longer than maxWaitMs (5s). At the abort the handles
1705
+ // generator has not yielded, SsrRoot suspends at the root (consumeAsyncGenerator
1706
+ // sits above every boundary), the prelude comes back trivial, and
1707
+ // captureShellHTML's sanity gate returns null: the designed fail-safe no-op, not
1708
+ // an error. This mirrors the __prerender_collect seal+settled regime, which also
1709
+ // excludes loaders. See docs/design/ppr-shell-resume.md ("Loaders and handles").
1710
+ handleStore.seal();
1711
+
1712
+ // Handles contract, shell half ("nesting = liveness"): TOP-LEVEL pushed handle
1713
+ // promises are BAKED into the shell — resolvedHandleStream awaits them before
1714
+ // the payload's handles row emits. A pushed promise with real latency would lose
1715
+ // the byte-quiet race (the pending handles row emits no bytes, the gate freezes,
1716
+ // the row is dropped, SsrRoot suspends at the root), so the gate is HELD open
1717
+ // until the same await completes: handlesBaked mirrors resolvedHandleStream's
1718
+ // resolution (getData waits the tracked-handler barrier; resolveDeferredHandleValues
1719
+ // awaits the top-level thenables). NESTED promises inside pushed containers are
1720
+ // shallow-skipped by isThenable and never hold the gate — they stay holes.
1721
+ // Bounded by maxWaitMs like every quiesce input (a defer hanging on a masked
1722
+ // loader still ends in the sanity-gate refusal).
1723
+ const handlesBaked = handleStore.getData().then(resolveDeferredHandleValues);
1724
+ // Bake-lane loader containers hold the gate the same way (loader-container-
1725
+ // bake): a boundary-less container with real latency (a 100ms layout loader)
1726
+ // would otherwise lose the 2-hop byte-quiet race — the pending loaderData row
1727
+ // emits no bytes, the gate freezes, and the awaiting tree pins above <body>.
1728
+ // The records map is fully populated before this point (loader promises are
1729
+ // created during the capture's match()), so the hold covers every bake-lane
1730
+ // container. allSettled: a REJECTED container releases the hold (the drain
1731
+ // below refuses the capture); nested promises INSIDE a container never hold
1732
+ // the gate — they stay holes. Bounded by maxWaitMs like every quiesce input.
1733
+ const loaderRecordsForHold = reqCtx._shellCaptureLoaderRecords;
1734
+ const holdUntil =
1735
+ loaderRecordsForHold && loaderRecordsForHold.size > 0
1736
+ ? Promise.allSettled([handlesBaked, ...loaderRecordsForHold.values()])
1737
+ : handlesBaked;
1738
+ // Bake-cost attribution: record how long each bake source held the gate,
1739
+ // measured from capture start. Side-channel observers only — holdUntil and
1740
+ // its consumers are untouched, and a rejected source is recorded the same
1741
+ // (allSettled swallows it; the drain below owns the refusal). Folded into
1742
+ // stats.bakeWaitMs (+ a once-per-key dev warning) after a successful
1743
+ // capture; on a refusal the other warnings own the story.
1744
+ const bakeStart = performance.now();
1745
+ const bakeWaits: { source: string; ms: number }[] = [];
1746
+ const observeBake = (source: string, promise: Promise<unknown>): void => {
1747
+ const record = (): void => {
1748
+ bakeWaits.push({
1749
+ source,
1750
+ ms: Math.round(performance.now() - bakeStart),
1751
+ });
1752
+ };
1753
+ promise.then(record, record);
1754
+ };
1755
+ observeBake("top-level pushed handle promises", handlesBaked);
1756
+ if (loaderRecordsForHold) {
1757
+ for (const [loaderId, promise] of loaderRecordsForHold) {
1758
+ observeBake(`bake-lane segment loader "${loaderId}"`, promise);
1759
+ }
1760
+ }
1761
+ const gate = gateFlightForCapture(rscStream, undefined, holdUntil);
1762
+ // Quiesce = handles settled AND the Flight shell rows went task-quiet. Either
1763
+ // half stalling is bounded by captureShellHTML's maxWaitMs.
1764
+ const quiesce = Promise.all([handleStore.settled, gate.quiesce]).then(
1765
+ () => {},
1766
+ );
1767
+
1768
+ // Deterministic identity-guard refusal, checked at BOTH exits below: the
1769
+ // guard error either rejects the prerender itself (boundary-less segment —
1770
+ // lands in the catch) or is swallowed into per-loader error UI (the render
1771
+ // completes — caught after the try). One helper so the message and the
1772
+ // "refused" mapping cannot drift between the two sites.
1773
+ const refuseOnGuardTrip = (): "refused" | undefined => {
1774
+ const fnName = reqCtx._shellCaptureGuardTripped;
1775
+ if (!fnName) return undefined;
1776
+ // Name the recorded source instead of hardcoding a lane. Under the
1777
+ // consumption-lane rule, handler-INVOKED loader bodies are exempt from
1778
+ // the guard (their value is a baked shared copy, mirroring cache()), so a
1779
+ // trip can only come from a bake-lane SEGMENT loader or from non-loader
1780
+ // handler/render code — the old blanket "bake-lane loader" attribution
1781
+ // sent a live-lane debugging session down the wrong lane (issue #672).
1782
+ const loaderId = reqCtx._shellCaptureGuardTrippedLoaderId;
1783
+ const origin = loaderId
1784
+ ? `segment loader "${loaderId}"`
1785
+ : "handler/render code (no loader body was executing)";
1786
+ warnCaptureRefusedOnce(
1787
+ capture.key,
1788
+ `${origin} called ${fnName}() during capture. Identity must not bake into a shared shell. ` +
1789
+ "For a segment loader (bake lane, no loading()): give its entry a loading() boundary " +
1790
+ "(the live lane, masked at capture) or move the identity-dependent part into a nested " +
1791
+ "promise. For handler/render code: keep the value live by consuming a loader " +
1792
+ 'client-side (useLoader in a "use client" component). Note: `await ctx.use(loader)` ' +
1793
+ "inside a HANDLER is exempt from this guard — its value bakes into the shared shell " +
1794
+ "as a capture-time copy, mirroring cache() semantics (the consumption-lane rule).",
1795
+ );
1796
+ return "refused";
1797
+ };
1798
+
1799
+ try {
1800
+ // captureShellHTML CONSUMES the (gated) stream — it is not also SSR'd.
1801
+ let result: Awaited<ReturnType<typeof captureShellHTML>>;
1802
+ try {
1803
+ // One deadline for the whole capture — semantics spec'd on the option
1804
+ // (PartialPrerenderProps.captureTimeout, urls/pattern-types.ts).
1805
+ result = await observePhase(PHASES.ssr, () =>
1806
+ captureShellHTML(gate.stream, {
1807
+ quiesce,
1808
+ maxWaitMs: capture.captureTimeout ?? SHELL_CAPTURE_MAX_WAIT_MS,
1809
+ // The shell key's own search seeds the capture render's store —
1810
+ // static-part search reads bake what the key names.
1811
+ search: capture.searchSeed,
1812
+ origin: capture.originSeed,
1813
+ }),
1814
+ );
1815
+ } catch (error) {
1816
+ // Guard-tripped rejection arrives here (not at the drain), so refuse it
1817
+ // before propagating other capture errors.
1818
+ const refused = refuseOnGuardTrip();
1819
+ if (refused) return refused;
1820
+ // captureShellHTML converts its OWN deliberate abort to null by sentinel
1821
+ // identity. An escaped AbortError can therefore be a component's real
1822
+ // cancellation and must not be hidden or retried by name.
1823
+ throw error;
1824
+ }
1825
+
1826
+ // null = sanity gate refused (trivial/empty prelude, no <body>). Store nothing
1827
+ // and report `no-shell` so the caller (runShellCapture) can retry once and, if
1828
+ // that also fails, warn once per key. On a cold render this is the shell not
1829
+ // yet finished; on a loader route WITHOUT a route-level loading() boundary it is
1830
+ // the structural eternal-MISS shape (the masked loader pins the tree above
1831
+ // <body> at tree-build). The caller's warning names both.
1832
+ // Guard check first — BEFORE the trivial-prelude retry path. A guard trip
1833
+ // is deterministic (retrying re-trips it), and when the tripping loader's
1834
+ // error UI still completed a shell, storing it would bake the failure into
1835
+ // a shared page.
1836
+ const refused = refuseOnGuardTrip();
1837
+ if (refused) return refused;
1838
+
1839
+ if (result === null) {
1840
+ return "no-shell";
1841
+ }
1842
+ if (stats) stats.preludeBytes = result.prelude.length;
1843
+
1844
+ // Every bake source has settled by here (quiesce gates on holdUntil).
1845
+ // Surface the slowest one: sub-ms settles are noise, threshold-crossers
1846
+ // get the dev warning with the remedy ladder.
1847
+ let slowestBake: { source: string; ms: number } | undefined;
1848
+ for (const wait of bakeWaits) {
1849
+ if (!slowestBake || wait.ms > slowestBake.ms) slowestBake = wait;
1850
+ }
1851
+ if (slowestBake && slowestBake.ms > 0) {
1852
+ if (stats) stats.bakeWaitMs = slowestBake.ms;
1853
+ if (
1854
+ process.env.NODE_ENV !== "production" &&
1855
+ slowestBake.ms >= SHELL_CAPTURE_BAKE_WARN_MS
1856
+ ) {
1857
+ warnBakeCostOnce(capture.key, slowestBake.source, slowestBake.ms);
1858
+ }
1859
+ }
1860
+
1861
+ // Store per the flag's key/ttl/swr/tags, into the flag's store: the middleware
1862
+ // threads the SAME store it resolved for its getShell read (options.store ??
1863
+ // _cacheStore), so a store-attached middleware writes captures where it reads
1864
+ // them. The _cacheStore fallback covers a flag armed without a store (tests).
1865
+ // reactVersion is read from the same React.version import the middleware
1866
+ // validates reads against, so capture and serve always agree.
1867
+ // Fire the capture's isolated onResponse callbacks with a synthetic 200 so
1868
+ // the ring-3 segment cache write (cacheScope.cacheRoute, registered via
1869
+ // onResponse by the cache-store match-middleware and gated on a 200) runs
1870
+ // DURING capture, routed through the recording store. The foreground path
1871
+ // never fires for the capture — it builds no Response — so without this a
1872
+ // cache() SEGMENT that MISSED at capture would be rendered fresh into the
1873
+ // prelude yet never written, hence never recorded, and would drift on a HIT
1874
+ // (an item-family "use cache" write already runs inline during the render, so
1875
+ // it needs none of this; only segment writes are onResponse-gated). The
1876
+ // derived context's own _onResponseCallbacks holds only capture match-
1877
+ // middleware callbacks (HTTP middleware never runs for a capture), so firing
1878
+ // them is safe. Best-effort: a throwing callback must not fail the capture.
1879
+ const responseCallbacks = reqCtx._onResponseCallbacks;
1880
+ if (responseCallbacks && responseCallbacks.length > 0) {
1881
+ const synthetic = new Response(null, { status: 200 });
1882
+ for (const cb of responseCallbacks) {
1883
+ try {
1884
+ cb(synthetic);
1885
+ } catch {
1886
+ // A capture-time cache write that throws is degradation, not failure.
1887
+ }
1888
+ }
1889
+ }
1890
+
1891
+ // Drain the capture data snapshot from the recording store on the derived
1892
+ // context. Await the deferred cache writes first so a MISS-at-capture value
1893
+ // (setItem/set scheduled under waitUntil, including the segment write just
1894
+ // fired) is pinned, not just read-hits. When no recording store is installed
1895
+ // (unit tests that call this directly), there is simply no snapshot.
1896
+ const recording = getRecordingStore(reqCtx._cacheStore);
1897
+ let snapshot: ShellSnapshotRecord[] | undefined;
1898
+ if (recording) {
1899
+ const settleStart = performance.now();
1900
+ await recording.settleWrites(SHELL_SNAPSHOT_WRITE_SETTLE_MS);
1901
+ if (stats) {
1902
+ stats.writeSettleMs = Math.round(performance.now() - settleStart);
1903
+ }
1904
+ snapshot = recording.drainSnapshot();
1905
+ }
1906
+
1907
+ // Pin the bake-lane loader containers (loader family). Settled containers
1908
+ // are promise-elided (a still-pending nested promise is a hole marker, not
1909
+ // shell material) and Flight-serialized; a REJECTED container refuses the
1910
+ // capture — per-loader error UI must never bake into the shared shell. A
1911
+ // container still pending here either pinned the tree (the trivial-prelude
1912
+ // gate above already returned no-shell) or postponed under an ANCESTOR
1913
+ // boundary (it is a hole; omitting the record keeps it live).
1914
+ const loaderRecords = reqCtx._shellCaptureLoaderRecords;
1915
+ // Set once a bake-lane loader settles with real (non-hole) material: its data
1916
+ // is frozen into the shell prelude regardless of whether snapshot
1917
+ // serialization succeeds. Drives the opt-in debug metadata below.
1918
+ let bakedLoaderMaterial = false;
1919
+ if (loaderRecords && loaderRecords.size > 0) {
1920
+ // The codec import is deferred past the elide probes: a rejected record
1921
+ // refuses and a never-settled record is omitted WITHOUT touching Flight
1922
+ // (also keeps the virtual @vitejs/plugin-rsc import out of unit configs).
1923
+ let serializeContainer:
1924
+ | typeof import("../cache/segment-codec.js").serializeResult
1925
+ | undefined;
1926
+ for (const [segmentKey, containerPromise] of loaderRecords) {
1927
+ const elided = await elideLoaderContainer(containerPromise);
1928
+ if (elided.state === "rejected") {
1929
+ warnCaptureRefusedOnce(
1930
+ capture.key,
1931
+ `the loader for segment "${segmentKey}" rejected during capture; its error UI must not bake into the shared shell. ` +
1932
+ "Fix the loader, or give its entry a loading() boundary so it stays on the live lane.",
1933
+ );
1934
+ return "refused";
1935
+ }
1936
+ // The container itself never settled: it is a hole (under an ancestor
1937
+ // boundary) or the trivial-prelude gate already fired. Omit — no pin.
1938
+ if (isLoaderHoleMarker(elided.value)) continue;
1939
+ // Past the hole check: this container settled with real material that
1940
+ // bakes into the shell prelude (independent of the snapshot pin below).
1941
+ bakedLoaderMaterial = true;
1942
+ try {
1943
+ // serializeResult (not rscSerialize): null is a valid container and
1944
+ // must round-trip; serializeResult preserves it through Flight.
1945
+ serializeContainer ??= (await import("../cache/segment-codec.js"))
1946
+ .serializeResult;
1947
+ const serialized = await serializeContainer(elided.value);
1948
+ if (serialized !== null) {
1949
+ (snapshot ??= []).push({
1950
+ family: "loader",
1951
+ key: segmentKey,
1952
+ // The hole bit rides with the record so the HIT overlay knows
1953
+ // without rescanning whether the pin can resolve immediately
1954
+ // (holes: 0) or must wait for the fresh run's live promises
1955
+ // (holes: 1). See ShellSnapshotLoaderValue.
1956
+ value: { value: serialized, holes: elided.hasHole ? 1 : 0 },
1957
+ });
1958
+ }
1959
+ } catch {
1960
+ // Non-serializable container: leave it unpinned (it drifts on a HIT,
1961
+ // the pre-snapshot behavior) rather than failing the capture.
1962
+ }
1963
+ }
1964
+ }
1965
+
1966
+ // Snapshot size guard (issue #651): the snapshot duplicates every pinned
1967
+ // cache value inside the shell entry, so a page over a large cache()
1968
+ // segment can push the stored envelope toward store value limits (KV caps
1969
+ // a value at 25 MiB) with no signal — the kv.put rejects deep inside
1970
+ // waitUntil. Measure the serialized snapshot (UTF-8 bytes of the JSON that
1971
+ // rides in the envelope) AFTER the loader family is appended, and over the
1972
+ // cap store the shell WITHOUT it: pinned reads then fall back to the live
1973
+ // store on a HIT (documented drift — hydration repairs a mismatch
1974
+ // client-side, the pre-snapshot behavior), which beats losing the whole
1975
+ // entry to a store-side write rejection. Reported once per key.
1976
+ if (snapshot && snapshot.length > 0) {
1977
+ const snapshotBytes = SNAPSHOT_BYTE_ENCODER.encode(
1978
+ JSON.stringify(snapshot),
1979
+ ).length;
1980
+ if (stats) stats.snapshotBytes = snapshotBytes;
1981
+ const cap = capture.maxSnapshotBytes ?? DEFAULT_PPR_MAX_SNAPSHOT_BYTES;
1982
+ if (snapshotBytes > cap) {
1983
+ warnSnapshotOverCapOnce(capture.key, snapshotBytes, cap);
1984
+ snapshot = undefined;
1985
+ if (stats) stats.snapshotSkipped = true;
1986
+ }
1987
+ }
1988
+
1989
+ // Shell tags snapshot at the WRITE BARRIER, not at stream construction: by
1990
+ // here the capture has quiesced and the deferred cache writes were awaited, so
1991
+ // tags recorded AFTER an await in async shell content (and by async
1992
+ // cache()/"use cache" reads propagating through recordRequestTags) are
1993
+ // included — issue #676. Loaders are masked, so loader cache tags — which
1994
+ // belong to the holes, not the shell — never execute during capture and cannot
1995
+ // contribute. Union with the route's static ppr.tags (capture.tags); the
1996
+ // collected set is authoritative, the option only adds what the render cannot
1997
+ // know.
1998
+ const collected = [...reqCtx._requestTags];
1999
+ const union = new Set<string>([...(capture.tags ?? []), ...collected]);
2000
+ const shellTags = union.size > 0 ? [...union] : undefined;
2001
+
2002
+ // Missing tags are valid: the shell follows TTL/SWR-only invalidation. Expose
2003
+ // that choice only to operators who enabled structured capture diagnostics.
2004
+ if (
2005
+ capture.debugSink &&
2006
+ stats &&
2007
+ bakedLoaderMaterial &&
2008
+ shellTags === undefined
2009
+ ) {
2010
+ stats.untaggedBake = true;
2011
+ }
2012
+
2013
+ const store = capture.store ?? reqCtx._cacheStore;
2014
+ if (store?.putShell) {
2015
+ try {
2016
+ const entry: ShellCacheEntry = {
2017
+ // Document half only for document captures. A navigationOnly entry's
2018
+ // HTML is never served (document reads skip the flag; partial replay
2019
+ // consumes only snapshot/docKey), so storing it would ride every KV
2020
+ // write/read as dead weight — the prerender still ran above as the
2021
+ // completeness arbiter and sanity gate, its output is dropped here.
2022
+ ...(capture.navigationOnly
2023
+ ? {}
2024
+ : {
2025
+ // slice() copies just this view's bytes into a fresh
2026
+ // ArrayBuffer, so a prelude that is a subarray of a larger
2027
+ // backing buffer encodes only its own region — bufferToBase64
2028
+ // reads the whole ArrayBuffer it is handed.
2029
+ prelude: bufferToBase64(
2030
+ result.prelude.slice().buffer as ArrayBuffer,
2031
+ ),
2032
+ postponed: result.postponed,
2033
+ }),
2034
+ reactVersion: React.version,
2035
+ buildVersion: capture.buildVersion,
2036
+ // The theme this capture's payload was built with (buildFullPayload
2037
+ // reads reqCtx.theme off the derived context). The serve tail replays
2038
+ // it so the resume tree matches the frozen prelude — see
2039
+ // ShellCacheEntry.initialTheme.
2040
+ initialTheme: reqCtx.theme,
2041
+ snapshot,
2042
+ // The canonical doc segment record's key, published by the doc
2043
+ // scope's cacheRoute during this capture's match (undefined when no
2044
+ // doc record was recorded — the entry then never claims navigation
2045
+ // replayability). Only meaningful alongside a snapshot.
2046
+ docKey: snapshot ? reqCtx._shellImplicitCache?.docKey : undefined,
2047
+ navigationOnly: capture.navigationOnly,
2048
+ // Handler-layer liveness folded at the barrier: nested thenables in
2049
+ // handler-scoped pushes, handler pushes still pending (liveness
2050
+ // unknowable), or a handler-invoked loader execution — any of them
2051
+ // refuses the FAST PATH, not the capture. See
2052
+ // _shellCaptureHandleLiveness.
2053
+ handlerLiveHoles: handlerLayerIsLive(
2054
+ reqCtx._shellCaptureHandleLiveness,
2055
+ ),
2056
+ transitionWhen: reqCtx._transitionWhen?.length ? true : undefined,
2057
+ createdAt: captureStartedAt,
2058
+ };
2059
+ const storeWrite = await store.putShell(
2060
+ capture.key,
2061
+ entry,
2062
+ capture.ttl,
2063
+ capture.swr,
2064
+ shellTags,
2065
+ );
2066
+ if (stats && storeWrite) stats.storeWrite = storeWrite;
2067
+ if (storeWrite === "invalidated") {
2068
+ warnCaptureRefusedOnce(
2069
+ capture.key,
2070
+ "one of the shell's tags was invalidated after this capture generation started, so the store rejected the write. " +
2071
+ "If capture code deterministically calls updateTag() on its own shell tag, move that mutation out of the render; " +
2072
+ "otherwise every generation is invalidated before it can be served.",
2073
+ );
2074
+ return "refused";
2075
+ }
2076
+ if (storeWrite === "uncacheable") {
2077
+ // The store declared the entry unstorable under its current
2078
+ // configuration — every retry would refuse identically, so back
2079
+ // the key off like any refused capture instead of burning a full
2080
+ // serialized render per MISS. Store-neutral on purpose: the
2081
+ // acknowledging store emits its own diagnostic naming the specific
2082
+ // limit (CFCacheStore warns about the over-limit Cache-Tag set).
2083
+ warnCaptureRefusedOnce(
2084
+ capture.key,
2085
+ "the store cannot cache this shell under its current configuration and acknowledged " +
2086
+ "the write as permanently refusable, so the key is backed off. See the cache store's " +
2087
+ "own warning for the specific limit and remedy.",
2088
+ );
2089
+ return "refused";
2090
+ }
2091
+ } catch (error) {
2092
+ // Best-effort: a failed put must never throw out of the background task.
2093
+ reportCacheError(
2094
+ error,
2095
+ "cache-write",
2096
+ "[ShellCache] capture put",
2097
+ reqCtx,
2098
+ );
2099
+ }
2100
+ }
2101
+ // A shell was captured (ordinary store I/O failure is reported, not retried).
2102
+ // An acknowledged invalidation rejection returned `refused` above so the
2103
+ // scheduler backs the key off instead of recapturing on every request.
2104
+ return "stored";
2105
+ } finally {
2106
+ // Stop the hop loop for the pathological never-quiets path (quiesce never
2107
+ // fired, capture returned via maxWaitMs). On the normal path the loop already
2108
+ // stopped when it fired quiesce; dispose() is then a no-op.
2109
+ gate.dispose();
2110
+ }
2111
+ }
2112
+
2113
+ // Exported for unit tests that drive the capture core directly, and — with the
2114
+ // cold-graph retry pieces — for producer B (prerender/build-shell-capture.ts),
2115
+ // which mirrors the runtime capture's retry-in-place with the same delay.
2116
+ export {
2117
+ runShellCapture,
2118
+ captureAndStoreShell,
2119
+ delay,
2120
+ SHELL_CAPTURE_RETRY_DELAY_MS,
2121
+ };
2122
+
2123
+ // Exported for unit tests that pin the refused-capture backoff policy directly
2124
+ // (dev cap vs production exponential growth, stored-clears, cold-start re-probe).
2125
+ // These are the same module-level functions the schedule path uses; a test that
2126
+ // drove them through a real capture round-trip could not assert the exact window
2127
+ // arithmetic without a full cold render.
2128
+ export {
2129
+ isCaptureBackedOff,
2130
+ markCaptureBackoff,
2131
+ clearCaptureBackoff,
2132
+ REFUSED_CAPTURE_BASE_MS,
2133
+ REFUSED_CAPTURE_MAX_MS,
2134
+ REFUSED_CAPTURE_DEV_MAX_MS,
2135
+ };