@rangojs/router 0.0.0-experimental.15 → 0.0.0-experimental.151

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