@rangojs/router 0.0.0-experimental.f3c21dba → 0.0.0-experimental.f4a8e8de

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