@rangojs/router 0.0.0-experimental.f2d1a2f1 → 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 (1301) hide show
  1. package/AGENTS.md +8 -4
  2. package/README.md +318 -821
  3. package/dist/bin/rango.js +925 -271
  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 +9695 -3592
  821. package/package.json +119 -39
  822. package/skills/api-client/SKILL.md +211 -0
  823. package/skills/breadcrumbs/SKILL.md +82 -5
  824. package/skills/bundle-analysis/SKILL.md +159 -0
  825. package/skills/cache-guide/SKILL.md +232 -34
  826. package/skills/caching/SKILL.md +375 -19
  827. package/skills/catalog.json +283 -0
  828. package/skills/cloudflare/SKILL.md +151 -0
  829. package/skills/cloudflare/agents/openai.yaml +4 -0
  830. package/skills/cloudflare/references/d1-and-local-dev.md +131 -0
  831. package/skills/cloudflare/references/streaming-and-deploy.md +107 -0
  832. package/skills/cloudflare/references/webhooks-and-crypto.md +147 -0
  833. package/skills/comparison/SKILL.md +50 -0
  834. package/skills/comparison/agents/openai.yaml +4 -0
  835. package/skills/comparison/references/framework-comparison.md +844 -0
  836. package/skills/composability/SKILL.md +124 -4
  837. package/skills/css/SKILL.md +76 -0
  838. package/skills/debug-manifest/SKILL.md +5 -11
  839. package/skills/defer-hydration/SKILL.md +235 -0
  840. package/skills/deployment-caching/SKILL.md +176 -0
  841. package/skills/document-cache/SKILL.md +116 -58
  842. package/skills/fonts/SKILL.md +1 -1
  843. package/skills/handler-use/SKILL.md +12 -10
  844. package/skills/hooks/SKILL.md +73 -699
  845. package/skills/hooks/data.md +273 -0
  846. package/skills/hooks/handle-and-actions.md +103 -0
  847. package/skills/hooks/navigation.md +110 -0
  848. package/skills/hooks/outlets.md +62 -0
  849. package/skills/hooks/state.md +228 -0
  850. package/skills/hooks/urls.md +135 -0
  851. package/skills/host-router/SKILL.md +129 -27
  852. package/skills/i18n/SKILL.md +276 -0
  853. package/skills/intercept/SKILL.md +75 -19
  854. package/skills/layout/SKILL.md +40 -19
  855. package/skills/links/SKILL.md +211 -17
  856. package/skills/loader/SKILL.md +230 -25
  857. package/skills/middleware/SKILL.md +58 -13
  858. package/skills/migrate-nextjs/SKILL.md +267 -33
  859. package/skills/migrate-nextjs/backend-host-swap.md +120 -0
  860. package/skills/migrate-react-router/SKILL.md +59 -671
  861. package/skills/migrate-react-router/component-migration.md +196 -0
  862. package/skills/migrate-react-router/data-and-actions.md +225 -0
  863. package/skills/migrate-react-router/route-mapping.md +271 -0
  864. package/skills/mime-routes/SKILL.md +55 -18
  865. package/skills/observability/SKILL.md +231 -0
  866. package/skills/parallel/SKILL.md +50 -10
  867. package/skills/ppr/SKILL.md +904 -0
  868. package/skills/prerender/SKILL.md +130 -68
  869. package/skills/rango/SKILL.md +321 -26
  870. package/skills/react-compiler/SKILL.md +168 -0
  871. package/skills/response-routes/SKILL.md +172 -52
  872. package/skills/route/SKILL.md +123 -9
  873. package/skills/router-setup/SKILL.md +53 -9
  874. package/skills/scripts/SKILL.md +179 -0
  875. package/skills/server-actions/SKILL.md +776 -0
  876. package/skills/shell-manifest/SKILL.md +185 -0
  877. package/skills/streams-and-websockets/SKILL.md +1 -1
  878. package/skills/tailwind/SKILL.md +28 -4
  879. package/skills/testing/SKILL.md +131 -0
  880. package/skills/testing/bindings.md +103 -0
  881. package/skills/testing/cache-prerender.md +172 -0
  882. package/skills/testing/client-components.md +131 -0
  883. package/skills/testing/e2e-parity.md +125 -0
  884. package/skills/testing/flight.md +91 -0
  885. package/skills/testing/handles.md +131 -0
  886. package/skills/testing/loader.md +128 -0
  887. package/skills/testing/middleware.md +99 -0
  888. package/skills/testing/render-handler.md +122 -0
  889. package/skills/testing/response-routes.md +95 -0
  890. package/skills/testing/reverse-and-types.md +85 -0
  891. package/skills/testing/server-actions.md +107 -0
  892. package/skills/testing/server-tree.md +128 -0
  893. package/skills/testing/setup.md +123 -0
  894. package/skills/theme/SKILL.md +1 -1
  895. package/skills/typesafety/SKILL.md +45 -628
  896. package/skills/typesafety/env-and-bindings.md +254 -0
  897. package/skills/typesafety/generated-files-and-cli.md +342 -0
  898. package/skills/typesafety/params-and-search.md +153 -0
  899. package/skills/typesafety/route-types.md +213 -0
  900. package/skills/use-cache/SKILL.md +121 -15
  901. package/skills/vercel/SKILL.md +149 -0
  902. package/skills/view-transitions/SKILL.md +341 -0
  903. package/src/__augment-tests__/augment.ts +81 -0
  904. package/src/__augment-tests__/augmented.check.ts +116 -0
  905. package/src/__internal.ts +0 -65
  906. package/src/browser/action-coordinator.ts +53 -36
  907. package/src/browser/action-fence.ts +47 -0
  908. package/src/browser/app-shell.ts +14 -27
  909. package/src/browser/connection-warmup.ts +134 -0
  910. package/src/browser/cookie-name.ts +140 -0
  911. package/src/browser/dev-discovery.ts +66 -0
  912. package/src/browser/event-controller.ts +400 -168
  913. package/src/browser/history-state.ts +21 -0
  914. package/src/browser/index.ts +3 -3
  915. package/src/browser/invalidate-client-cache.ts +52 -0
  916. package/src/browser/link-interceptor.ts +469 -20
  917. package/src/browser/logging.ts +28 -0
  918. package/src/browser/merge-segment-loaders.ts +6 -4
  919. package/src/browser/navigation-bridge.ts +164 -69
  920. package/src/browser/navigation-client.ts +199 -96
  921. package/src/browser/navigation-store-handle.ts +38 -0
  922. package/src/browser/navigation-store.ts +165 -345
  923. package/src/browser/navigation-transaction.ts +9 -59
  924. package/src/browser/network-error-handler.ts +34 -7
  925. package/src/browser/notify-listeners.ts +22 -0
  926. package/src/browser/partial-update.ts +219 -163
  927. package/src/browser/prefetch/cache.ts +240 -97
  928. package/src/browser/prefetch/default-strategy.ts +74 -0
  929. package/src/browser/prefetch/fetch.ts +317 -51
  930. package/src/browser/prefetch/invalidation.ts +30 -0
  931. package/src/browser/prefetch/loader.ts +111 -0
  932. package/src/browser/prefetch/observer.ts +50 -22
  933. package/src/browser/prefetch/queue.ts +25 -7
  934. package/src/browser/prefetch/runtime.ts +6 -0
  935. package/src/browser/rango-state.ts +177 -114
  936. package/src/browser/react/Link.tsx +115 -75
  937. package/src/browser/react/NavigationProvider.tsx +194 -143
  938. package/src/browser/react/ScrollRestoration.tsx +10 -6
  939. package/src/browser/react/context.ts +4 -0
  940. package/src/browser/react/filter-segment-order.ts +66 -7
  941. package/src/browser/react/index.ts +0 -48
  942. package/src/browser/react/location-state-shared.ts +178 -8
  943. package/src/browser/react/location-state.ts +39 -14
  944. package/src/browser/react/use-action.ts +6 -15
  945. package/src/browser/react/use-handle.ts +17 -14
  946. package/src/browser/react/use-href.tsx +8 -1
  947. package/src/browser/react/use-link-status.ts +33 -8
  948. package/src/browser/react/use-navigation.ts +10 -5
  949. package/src/browser/react/use-params.ts +11 -11
  950. package/src/browser/react/use-reverse.ts +106 -0
  951. package/src/browser/react/use-router.ts +21 -6
  952. package/src/browser/react/use-search-params.ts +0 -5
  953. package/src/browser/react/use-segments.ts +11 -21
  954. package/src/browser/response-adapter.ts +99 -8
  955. package/src/browser/rsc-router.tsx +230 -42
  956. package/src/browser/scroll-restoration.ts +37 -22
  957. package/src/browser/segment-reconciler.ts +31 -21
  958. package/src/browser/segment-structure-assert.ts +2 -2
  959. package/src/browser/server-action-bridge.ts +262 -65
  960. package/src/browser/types.ts +132 -47
  961. package/src/browser/validate-redirect-origin.ts +43 -16
  962. package/src/build/collect-fallback-refs.ts +107 -0
  963. package/src/build/generate-manifest.ts +213 -184
  964. package/src/build/generate-route-types.ts +3 -1
  965. package/src/build/index.ts +11 -3
  966. package/src/build/merge-full-manifests.ts +161 -0
  967. package/src/build/prefix-tree-utils.ts +123 -0
  968. package/src/build/route-trie.ts +43 -280
  969. package/src/build/route-types/ast-route-extraction.ts +15 -8
  970. package/src/build/route-types/codegen.ts +16 -5
  971. package/src/build/route-types/include-resolution.ts +513 -64
  972. package/src/build/route-types/param-extraction.ts +6 -3
  973. package/src/build/route-types/per-module-writer.ts +33 -12
  974. package/src/build/route-types/router-processing.ts +312 -204
  975. package/src/build/route-types/scan-filter.ts +1 -1
  976. package/src/build/route-types/source-scan.ts +216 -0
  977. package/src/build/runtime-discovery.ts +32 -29
  978. package/src/cache/cache-error.ts +104 -0
  979. package/src/cache/cache-exec-scope.ts +47 -0
  980. package/src/cache/cache-key-utils.ts +73 -15
  981. package/src/cache/cache-policy.ts +108 -34
  982. package/src/cache/cache-runtime.ts +566 -121
  983. package/src/cache/cache-scope.ts +383 -105
  984. package/src/cache/cache-tag.ts +149 -0
  985. package/src/cache/cf/cf-base64.ts +33 -0
  986. package/src/cache/cf/cf-cache-constants.ts +134 -0
  987. package/src/cache/cf/cf-cache-store.ts +3028 -391
  988. package/src/cache/cf/cf-cache-types.ts +417 -0
  989. package/src/cache/cf/cf-kv-utils.ts +84 -0
  990. package/src/cache/cf/cf-tag-marker-memo.ts +108 -0
  991. package/src/cache/cf/cf-zone-purge.ts +101 -0
  992. package/src/cache/cf/index.ts +11 -16
  993. package/src/cache/document-cache.ts +184 -53
  994. package/src/cache/handle-snapshot.ts +92 -1
  995. package/src/cache/index.ts +32 -20
  996. package/src/cache/memory-segment-store.ts +286 -37
  997. package/src/cache/profile-registry.ts +46 -31
  998. package/src/cache/read-through-swr.ts +66 -16
  999. package/src/cache/search-params-filter.ts +118 -0
  1000. package/src/cache/segment-codec.ts +80 -25
  1001. package/src/cache/shell-snapshot.ts +516 -0
  1002. package/src/cache/tag-invalidation.ts +230 -0
  1003. package/src/cache/taint.ts +28 -9
  1004. package/src/cache/types.ts +323 -100
  1005. package/src/cache/vercel/index.ts +11 -0
  1006. package/src/cache/vercel/vercel-cache-store.ts +1264 -0
  1007. package/src/client-urls/client-root.tsx +161 -0
  1008. package/src/client-urls/client-urls.ts +665 -0
  1009. package/src/client-urls/navigation.ts +237 -0
  1010. package/src/client-urls/revalidation-protocol.ts +56 -0
  1011. package/src/client-urls/server-projection.ts +563 -0
  1012. package/src/client-urls/types.ts +178 -0
  1013. package/src/client.rsc.tsx +48 -21
  1014. package/src/client.tsx +77 -67
  1015. package/src/cloudflare/index.ts +11 -0
  1016. package/src/cloudflare/tracing.ts +112 -0
  1017. package/src/component-utils.ts +19 -0
  1018. package/src/components/DefaultDocument.tsx +8 -2
  1019. package/src/context-var.ts +18 -6
  1020. package/src/decode-loader-results.ts +160 -0
  1021. package/src/defer.ts +185 -0
  1022. package/src/deps/ssr.ts +4 -2
  1023. package/src/dev-discovery-protocol.ts +11 -0
  1024. package/src/encode-kv.ts +49 -0
  1025. package/src/errors.ts +44 -4
  1026. package/src/escape-script.ts +52 -0
  1027. package/src/handle.ts +67 -37
  1028. package/src/handles/MetaTags.tsx +24 -53
  1029. package/src/handles/Scripts.tsx +183 -0
  1030. package/src/handles/breadcrumbs.ts +35 -8
  1031. package/src/handles/deferred-resolution.ts +134 -0
  1032. package/src/handles/is-thenable.ts +16 -0
  1033. package/src/handles/meta.ts +14 -40
  1034. package/src/handles/script.ts +244 -0
  1035. package/src/host/cookie-handler.ts +9 -60
  1036. package/src/host/errors.ts +13 -22
  1037. package/src/host/index.ts +9 -2
  1038. package/src/host/pattern-matcher.ts +23 -52
  1039. package/src/host/router.ts +107 -99
  1040. package/src/host/testing.ts +40 -27
  1041. package/src/host/types.ts +37 -4
  1042. package/src/host/utils.ts +1 -1
  1043. package/src/href-client.ts +137 -22
  1044. package/src/index.rsc.ts +105 -12
  1045. package/src/index.ts +102 -14
  1046. package/src/internal-debug.ts +11 -10
  1047. package/src/loader-redirect.tsx +47 -0
  1048. package/src/loader-store.ts +500 -0
  1049. package/src/loader.rsc.ts +20 -13
  1050. package/src/loader.ts +12 -11
  1051. package/src/missing-id-error.ts +68 -0
  1052. package/src/outlet-context.ts +12 -0
  1053. package/src/outlet-provider.tsx +16 -6
  1054. package/src/prerender/build-shell-capture.ts +453 -0
  1055. package/src/prerender/param-hash.ts +16 -16
  1056. package/src/prerender/shell-manifest-key.ts +20 -0
  1057. package/src/prerender/store.ts +47 -38
  1058. package/src/prerender.ts +81 -13
  1059. package/src/redirect-origin.ts +143 -0
  1060. package/src/regex-escape.ts +8 -0
  1061. package/src/render-error-thrower.tsx +20 -0
  1062. package/src/response-utils.ts +34 -0
  1063. package/src/reverse.ts +65 -40
  1064. package/src/root-error-boundary.tsx +1 -19
  1065. package/src/route-content-wrapper.tsx +112 -78
  1066. package/src/route-definition/dsl-helpers.ts +300 -313
  1067. package/src/route-definition/helper-factories.ts +28 -140
  1068. package/src/route-definition/helpers-types.ts +92 -62
  1069. package/src/route-definition/index.ts +1 -2
  1070. package/src/route-definition/redirect.ts +44 -11
  1071. package/src/route-definition/resolve-handler-use.ts +6 -1
  1072. package/src/route-definition/use-item-types.ts +29 -0
  1073. package/src/route-map-builder.ts +102 -74
  1074. package/src/route-types.ts +19 -46
  1075. package/src/router/basename.ts +14 -0
  1076. package/src/router/content-negotiation.ts +120 -30
  1077. package/src/router/error-handling.ts +110 -29
  1078. package/src/router/find-match.ts +129 -30
  1079. package/src/router/handler-context.ts +41 -57
  1080. package/src/router/instrument.ts +401 -0
  1081. package/src/router/intercept-resolution.ts +98 -21
  1082. package/src/router/lazy-includes.ts +82 -58
  1083. package/src/router/loader-resolution.ts +401 -85
  1084. package/src/router/logging.ts +0 -6
  1085. package/src/router/manifest.ts +74 -40
  1086. package/src/router/match-api.ts +91 -55
  1087. package/src/router/match-context.ts +0 -22
  1088. package/src/router/match-handlers.ts +268 -171
  1089. package/src/router/match-middleware/background-revalidation.ts +40 -24
  1090. package/src/router/match-middleware/cache-lookup.ts +316 -302
  1091. package/src/router/match-middleware/cache-store.ts +134 -52
  1092. package/src/router/match-middleware/intercept-resolution.ts +0 -22
  1093. package/src/router/match-middleware/segment-resolution.ts +0 -22
  1094. package/src/router/match-pipelines.ts +1 -42
  1095. package/src/router/match-result.ts +76 -79
  1096. package/src/router/metrics.ts +17 -36
  1097. package/src/router/middleware-types.ts +20 -110
  1098. package/src/router/middleware.ts +275 -173
  1099. package/src/router/navigation-snapshot.ts +51 -60
  1100. package/src/router/params-util.ts +23 -0
  1101. package/src/router/parse-pattern.ts +115 -0
  1102. package/src/router/pattern-matching.ts +134 -154
  1103. package/src/router/prefetch-cache-ttl.ts +51 -0
  1104. package/src/router/prefetch-default.ts +59 -0
  1105. package/src/router/prefetch-limits.ts +37 -0
  1106. package/src/router/prerender-match.ts +159 -69
  1107. package/src/router/preview-match.ts +6 -2
  1108. package/src/router/request-classification.ts +50 -69
  1109. package/src/router/revalidation.ts +146 -83
  1110. package/src/router/route-snapshot.ts +14 -3
  1111. package/src/router/route-trie-builder.ts +334 -0
  1112. package/src/router/router-context.ts +6 -29
  1113. package/src/router/router-interfaces.ts +168 -38
  1114. package/src/router/router-options.ts +235 -11
  1115. package/src/router/router-registry.ts +2 -5
  1116. package/src/router/segment-resolution/fresh.ts +163 -88
  1117. package/src/router/segment-resolution/helpers.ts +96 -18
  1118. package/src/router/segment-resolution/loader-cache.ts +187 -39
  1119. package/src/router/segment-resolution/loader-mask.ts +60 -0
  1120. package/src/router/segment-resolution/loader-snapshot.ts +259 -0
  1121. package/src/router/segment-resolution/mask-nested.ts +99 -0
  1122. package/src/router/segment-resolution/revalidation.ts +316 -321
  1123. package/src/router/segment-resolution/static-store.ts +55 -15
  1124. package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
  1125. package/src/router/segment-resolution/view-transition-default.ts +60 -0
  1126. package/src/router/segment-resolution.ts +5 -1
  1127. package/src/router/segment-wrappers.ts +6 -5
  1128. package/src/router/state-cookie-name.ts +33 -0
  1129. package/src/router/substitute-pattern-params.ts +75 -0
  1130. package/src/router/telemetry-otel.ts +171 -200
  1131. package/src/router/telemetry.ts +106 -20
  1132. package/src/router/timeout.ts +53 -22
  1133. package/src/router/tracing.ts +235 -0
  1134. package/src/router/transition-when.ts +76 -0
  1135. package/src/router/trie-matching.ts +170 -64
  1136. package/src/router/types.ts +9 -63
  1137. package/src/router/url-params.ts +13 -5
  1138. package/src/router.ts +248 -77
  1139. package/src/rsc/capture-queue.ts +218 -0
  1140. package/src/rsc/full-payload.ts +77 -0
  1141. package/src/rsc/handler-context.ts +4 -2
  1142. package/src/rsc/handler.ts +562 -284
  1143. package/src/rsc/helpers.ts +179 -9
  1144. package/src/rsc/index.ts +2 -5
  1145. package/src/rsc/json-route-result.ts +38 -0
  1146. package/src/rsc/loader-fetch.ts +116 -40
  1147. package/src/rsc/manifest-init.ts +55 -56
  1148. package/src/rsc/nonce.ts +10 -1
  1149. package/src/rsc/origin-guard.ts +39 -25
  1150. package/src/rsc/progressive-enhancement.ts +377 -84
  1151. package/src/rsc/redirect-guard.ts +102 -0
  1152. package/src/rsc/render-pipeline.ts +611 -0
  1153. package/src/rsc/response-cache-serve.ts +259 -0
  1154. package/src/rsc/response-error.ts +79 -12
  1155. package/src/rsc/response-route-handler.ts +73 -212
  1156. package/src/rsc/routine-plan.ts +359 -0
  1157. package/src/rsc/rsc-rendering.ts +1624 -171
  1158. package/src/rsc/runtime-warnings.ts +23 -10
  1159. package/src/rsc/server-action.ts +420 -139
  1160. package/src/rsc/shell-build-manifest.ts +336 -0
  1161. package/src/rsc/shell-capture-constants.ts +45 -0
  1162. package/src/rsc/shell-capture.ts +2063 -0
  1163. package/src/rsc/shell-serve.ts +337 -0
  1164. package/src/rsc/ssr-setup.ts +111 -16
  1165. package/src/rsc/stream-idle.ts +137 -0
  1166. package/src/rsc/transition-gate.ts +86 -0
  1167. package/src/rsc/types.ts +91 -5
  1168. package/src/runtime-env.ts +18 -0
  1169. package/src/search-params.ts +35 -30
  1170. package/src/segment-fragments.ts +165 -0
  1171. package/src/segment-loader-promise.ts +49 -4
  1172. package/src/segment-system.tsx +441 -153
  1173. package/src/serialize.ts +243 -0
  1174. package/src/server/context.ts +416 -55
  1175. package/src/server/cookie-parse.ts +32 -0
  1176. package/src/server/cookie-store.ts +162 -15
  1177. package/src/server/handle-store.ts +190 -70
  1178. package/src/server/loader-registry.ts +33 -42
  1179. package/src/server/request-context.ts +805 -177
  1180. package/src/server.ts +7 -2
  1181. package/src/ssr/index.tsx +631 -183
  1182. package/src/ssr/inject-rsc-eager.ts +167 -0
  1183. package/src/ssr/preinit-client-references.ts +106 -0
  1184. package/src/ssr/ssr-root.tsx +262 -0
  1185. package/src/static-handler.ts +28 -15
  1186. package/src/testing/cache-status.ts +162 -0
  1187. package/src/testing/collect-handle.ts +46 -0
  1188. package/src/testing/dispatch.ts +951 -0
  1189. package/src/testing/dom.entry.ts +22 -0
  1190. package/src/testing/e2e/fixture.ts +188 -0
  1191. package/src/testing/e2e/index.ts +147 -0
  1192. package/src/testing/e2e/matchers.ts +35 -0
  1193. package/src/testing/e2e/page-helpers.ts +319 -0
  1194. package/src/testing/e2e/parity.ts +400 -0
  1195. package/src/testing/e2e/server.ts +195 -0
  1196. package/src/testing/flight-matchers.ts +97 -0
  1197. package/src/testing/flight-normalize.ts +11 -0
  1198. package/src/testing/flight-runtime.d.ts +57 -0
  1199. package/src/testing/flight-tree.ts +682 -0
  1200. package/src/testing/flight.entry.ts +52 -0
  1201. package/src/testing/flight.ts +257 -0
  1202. package/src/testing/generated-routes.ts +199 -0
  1203. package/src/testing/index.ts +121 -0
  1204. package/src/testing/internal/context.ts +380 -0
  1205. package/src/testing/internal/flight-client-globals.ts +30 -0
  1206. package/src/testing/internal/seed-vars.ts +54 -0
  1207. package/src/testing/render-handler.ts +371 -0
  1208. package/src/testing/render-route.tsx +667 -0
  1209. package/src/testing/run-loader.ts +423 -0
  1210. package/src/testing/run-middleware.ts +219 -0
  1211. package/src/testing/run-transition-when.ts +197 -0
  1212. package/src/testing/shell-status.ts +206 -0
  1213. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  1214. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  1215. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  1216. package/src/testing/vitest-stubs/version.ts +5 -0
  1217. package/src/testing/vitest.ts +305 -0
  1218. package/src/theme/ThemeProvider.tsx +56 -84
  1219. package/src/theme/ThemeScript.tsx +7 -9
  1220. package/src/theme/constants.ts +52 -13
  1221. package/src/theme/index.ts +0 -7
  1222. package/src/theme/theme-context.ts +1 -5
  1223. package/src/theme/theme-script.ts +22 -21
  1224. package/src/theme/use-theme.ts +0 -3
  1225. package/src/types/boundaries.ts +15 -35
  1226. package/src/types/cache-types.ts +13 -4
  1227. package/src/types/error-types.ts +30 -90
  1228. package/src/types/global-namespace.ts +54 -41
  1229. package/src/types/handler-context.ts +121 -30
  1230. package/src/types/index.ts +3 -10
  1231. package/src/types/loader-types.ts +38 -7
  1232. package/src/types/request-scope.ts +8 -22
  1233. package/src/types/route-config.ts +20 -52
  1234. package/src/types/route-entry.ts +3 -6
  1235. package/src/types/segments.ts +147 -14
  1236. package/src/urls/include-helper.ts +38 -64
  1237. package/src/urls/include-provider.ts +71 -0
  1238. package/src/urls/index.ts +2 -11
  1239. package/src/urls/path-helper-types.ts +76 -24
  1240. package/src/urls/path-helper.ts +30 -110
  1241. package/src/urls/pattern-types.ts +101 -19
  1242. package/src/urls/response-types.ts +20 -19
  1243. package/src/urls/type-extraction.ts +98 -154
  1244. package/src/urls/urls-function.ts +1 -19
  1245. package/src/use-loader.tsx +355 -109
  1246. package/src/vercel/index.ts +11 -0
  1247. package/src/vercel/tracing.ts +89 -0
  1248. package/src/vite/debug.ts +102 -3
  1249. package/src/vite/discovery/bundle-postprocess.ts +18 -14
  1250. package/src/vite/discovery/client-urls-projection.ts +322 -0
  1251. package/src/vite/discovery/dev-prerender-cache.ts +117 -0
  1252. package/src/vite/discovery/discover-routers.ts +178 -151
  1253. package/src/vite/discovery/discovery-errors.ts +255 -0
  1254. package/src/vite/discovery/gate-state.ts +171 -0
  1255. package/src/vite/discovery/prerender-collection.ts +125 -70
  1256. package/src/vite/discovery/route-types-writer.ts +40 -84
  1257. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  1258. package/src/vite/discovery/shell-prerender-phase.ts +397 -0
  1259. package/src/vite/discovery/state.ts +104 -6
  1260. package/src/vite/discovery/virtual-module-codegen.ts +226 -87
  1261. package/src/vite/encryption-key.ts +29 -0
  1262. package/src/vite/index.ts +12 -0
  1263. package/src/vite/inject-client-debug.ts +88 -0
  1264. package/src/vite/plugin-types.ts +243 -10
  1265. package/src/vite/plugins/cjs-to-esm.ts +16 -19
  1266. package/src/vite/plugins/client-ref-dedup.ts +16 -11
  1267. package/src/vite/plugins/client-ref-hashing.ts +28 -15
  1268. package/src/vite/plugins/cloudflare-protocol-stub.ts +1 -21
  1269. package/src/vite/plugins/expose-action-id.ts +50 -97
  1270. package/src/vite/plugins/expose-id-utils.ts +88 -55
  1271. package/src/vite/plugins/expose-ids/export-analysis.ts +101 -34
  1272. package/src/vite/plugins/expose-ids/handler-transform.ts +11 -90
  1273. package/src/vite/plugins/expose-ids/loader-transform.ts +14 -24
  1274. package/src/vite/plugins/expose-ids/router-transform.ts +118 -29
  1275. package/src/vite/plugins/expose-internal-ids.ts +551 -486
  1276. package/src/vite/plugins/performance-tracks.ts +25 -22
  1277. package/src/vite/plugins/refresh-cmd.ts +1 -1
  1278. package/src/vite/plugins/server-ref-hashing.ts +74 -0
  1279. package/src/vite/plugins/server-reference-pattern.ts +10 -0
  1280. package/src/vite/plugins/use-cache-transform.ts +73 -83
  1281. package/src/vite/plugins/vercel-output.ts +384 -0
  1282. package/src/vite/plugins/version-injector.ts +39 -29
  1283. package/src/vite/plugins/version-plugin.ts +45 -40
  1284. package/src/vite/plugins/virtual-entries.ts +193 -30
  1285. package/src/vite/rango.ts +240 -128
  1286. package/src/vite/router-discovery.ts +1518 -174
  1287. package/src/vite/utils/ast-handler-extract.ts +26 -35
  1288. package/src/vite/utils/bundle-analysis.ts +10 -15
  1289. package/src/vite/utils/client-chunks.ts +184 -0
  1290. package/src/vite/utils/directive-prologue.ts +40 -0
  1291. package/src/vite/utils/forward-user-plugins.ts +171 -0
  1292. package/src/vite/utils/manifest-utils.ts +1 -59
  1293. package/src/vite/utils/package-resolution.ts +2 -73
  1294. package/src/vite/utils/prerender-utils.ts +96 -49
  1295. package/src/vite/utils/shared-utils.ts +156 -43
  1296. package/src/browser/action-response-classifier.ts +0 -99
  1297. package/src/browser/react/use-client-cache.ts +0 -58
  1298. package/src/browser/shallow.ts +0 -40
  1299. package/src/handles/index.ts +0 -7
  1300. package/src/network-error-thrower.tsx +0 -23
  1301. package/src/router/middleware-cookies.ts +0 -55
@@ -0,0 +1,1264 @@
1
+ /**
2
+ * Vercel Runtime Cache Store
3
+ *
4
+ * A SegmentCacheStore backed by Vercel's Runtime Cache (`getCache()` from
5
+ * `@vercel/functions`). It is the production store analogue to CFCacheStore, but
6
+ * far smaller: Vercel's Runtime Cache already IS a distributed, tag-aware cache
7
+ * (regional storage, global tag-expire within ~300ms), so none of CFCacheStore's
8
+ * L1/L2 tiering, KV tag-marker comparison, marker memoization, or per-tier
9
+ * timeout budgets are needed here - the platform does that work. What this store
10
+ * adds on top of the raw primitive is the parts Vercel does NOT give us:
11
+ *
12
+ * 1. Stale-while-revalidate. `getCache` has no stale-but-serve: a TTL'd entry
13
+ * simply becomes a miss. We store our own {staleAt, expiresAt} envelope and
14
+ * set the Vercel ttl to (ttl + swr) so the entry survives its SWR window,
15
+ * computing staleness ourselves via the shared cache-policy helpers.
16
+ * 2. A single-keyspace family split. `getCache` is one flat keyspace, whereas
17
+ * the interface has three value families (segments, "use cache" items, full
18
+ * responses). The memory store keeps three separate Maps; here they must be
19
+ * namespaced by a prefix or a set() of a response would clobber a segment
20
+ * cached under the same router key.
21
+ * 3. The platform guardrails: the 2 MB per-item ceiling (oversized writes
22
+ * silently no-op on Vercel, so we skip + report), the per-item tag cap, and
23
+ * cross-deploy non-reconciliation (TTL/tag updates are not reconciled across
24
+ * deployments - bake a build id into `version` or the getCache namespace).
25
+ *
26
+ * Dependency stance: this module imports NOTHING from `@vercel/functions`. The
27
+ * runtime cache handle (and `waitUntil`) are injected through the constructor and
28
+ * typed against the local VercelRuntimeCache shape below, exactly as CFCacheStore
29
+ * takes its `kv`/`ctx` bindings by injection. The consumer passes the real
30
+ * `getCache(...)` result, which satisfies the shape structurally. That keeps the
31
+ * router free of a hard Vercel dependency.
32
+ */
33
+
34
+ import type {
35
+ SegmentCacheStore,
36
+ CachedEntryData,
37
+ CacheDefaults,
38
+ CacheGetResult,
39
+ CacheItemResult,
40
+ CacheItemOptions,
41
+ ShellCacheEntry,
42
+ ShellSnapshotRecord,
43
+ CacheReadError,
44
+ } from "../types.js";
45
+ import { CACHE_READ_ERROR } from "../types.js";
46
+ import type { RequestContext } from "../../server/request-context.js";
47
+ import { isPerClientSignalHeader } from "../../browser/cookie-name.js";
48
+ import {
49
+ resolveTtl,
50
+ resolveSwrWindow,
51
+ computeExpiration,
52
+ DEFAULT_FUNCTION_TTL,
53
+ } from "../cache-policy.js";
54
+ import { reportCacheError, reportingAsync } from "../cache-error.js";
55
+ import type { CacheErrorCategory } from "../cache-error.js";
56
+ // Reuse the CF store's binary-safe base64 helpers. bufferToBase64 caps each
57
+ // String.fromCharCode batch at 8192 and uses .apply (never a spread), so a large
58
+ // Response/PPR-shell body cannot blow the JS argument-count ceiling (~65k) and
59
+ // throw RangeError inside putResponse/putShell - which the outer try/catch would
60
+ // swallow as a cache-write degrade, silently never caching the entry. Output is
61
+ // byte-identical to a per-byte encoder (chunk size does not affect base64), so
62
+ // this is a robustness fix, not a format change. Do NOT reintroduce a local
63
+ // spread-based encoder or raise the chunk here; cf-base64.ts is import-pure.
64
+ import { bufferToBase64, base64ToBuffer } from "../cf/cf-base64.js";
65
+
66
+ /**
67
+ * Minimal structural shape of the Vercel Runtime Cache returned by `getCache()`
68
+ * from `@vercel/functions`. Declared locally so @rangojs/router carries no hard
69
+ * dependency on `@vercel/functions`; the real handle satisfies it structurally.
70
+ *
71
+ * @see https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#getcache
72
+ */
73
+ export interface VercelRuntimeCache {
74
+ /** Returns the stored value, or a nullish value on miss. Never throws on miss. */
75
+ get(key: string): Promise<unknown>;
76
+ /** Stores a value with optional TTL (seconds), tags, and observability name. */
77
+ set(
78
+ key: string,
79
+ value: unknown,
80
+ options?: { ttl?: number; tags?: string[]; name?: string },
81
+ ): Promise<void>;
82
+ /** Removes a value by key. */
83
+ delete(key: string): Promise<void>;
84
+ /** Expires every entry tagged with any of `tag`. Global, ~300ms propagation. */
85
+ expireTag(tag: string | string[]): Promise<void>;
86
+ }
87
+
88
+ /**
89
+ * Vercel Runtime Cache hard per-item ceiling: 2 MB. Writes above this silently
90
+ * no-op on the platform, so the store measures the serialized envelope and skips
91
+ * (fail-open) entries at or above this size.
92
+ */
93
+ export const VERCEL_MAX_ITEM_BYTES: number = 2 * 1024 * 1024;
94
+
95
+ /**
96
+ * Per-item tag ceiling. Vercel's getCache API reference lists 128 tags per item
97
+ * (https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#getcache).
98
+ * Tags beyond this are dropped with a warning at write time. Does NOT cap
99
+ * invalidateTags() - an invalidation must reach every requested tag.
100
+ */
101
+ export const VERCEL_MAX_TAGS_PER_ITEM: number = 128;
102
+
103
+ /** Max tag length in UTF-8 bytes accepted by Vercel; longer tags are skipped. */
104
+ export const VERCEL_MAX_TAG_BYTES: number = 256;
105
+
106
+ /**
107
+ * URL metacharacters a tag must not contain. The official `@vercel/functions`
108
+ * client interpolates the tag straight into `revalidate?tags=${tag}` with NO
109
+ * URL-encoding (and also sends it in a request header), so a tag carrying one of
110
+ * these is stored intact on write but silently mangled server-side on
111
+ * invalidate: `&` starts a new query param, `?` a query, `#` truncates as a
112
+ * fragment, `%` is read as a (bad) percent-escape, `,` splits the tag list. The
113
+ * entry then never clears while `updateTag()`/`expireTag()` report success -
114
+ * the exact false-success the store's one deliberate throw exists to prevent.
115
+ * Such tags are dropped symmetrically on both the write and invalidate paths.
116
+ */
117
+ const VERCEL_UNSAFE_TAG_CHARS = /[,&#%?]/;
118
+
119
+ /**
120
+ * Herd-dampening window (ms). On a stale read the store pushes the entry's
121
+ * staleAt forward by this much and re-writes it, so other readers in the same
122
+ * region briefly see it as fresh while one revalidates. Best-effort and
123
+ * non-atomic: `getCache` has no compare-and-set, and storage is regional, so a
124
+ * race can still let two readers both trigger revalidation. Matches the intent of
125
+ * CFCacheStore's MAX_REVALIDATION_INTERVAL without its Cache-API atomicity.
126
+ */
127
+ const REVALIDATION_LOCK_MS = 30_000;
128
+
129
+ /** Family prefixes that keep the value tiers from colliding in the single Vercel
130
+ * keyspace. The router's own semantic prefixes (doc:/partial:/use-cache:) become
131
+ * the suffix; `rg:` namespaces every Rango entry. `h` is the PPR shell tier. */
132
+ type CacheFamily = "s" | "i" | "r" | "h" | "tm";
133
+
134
+ /**
135
+ * TTL for tag-invalidation marker entries ("tm" family), written by
136
+ * invalidateTags for the build-shell read-through's isTagsInvalidatedSince
137
+ * gate. The platform's expireTag() DELETES tagged entries (no queryable
138
+ * history), so the markers are rango's own record of "tag X was invalidated
139
+ * at T". One year: runtime tagged-shell retention is capped to this lifetime,
140
+ * while buildVersion retires build shells on the next deploy. An expired marker
141
+ * therefore cannot resurrect a runtime shell that outlived its invalidation.
142
+ */
143
+ const TAG_MARKER_TTL_SECONDS = 365 * 24 * 60 * 60;
144
+
145
+ /** Stored envelope for a segment-tree entry (get/set). */
146
+ interface VercelSegmentEnvelope {
147
+ /** The cached entry data. */
148
+ d: CachedEntryData;
149
+ /** staleAt (ms since epoch). */
150
+ s: number;
151
+ /** expiresAt (ms since epoch). */
152
+ e: number;
153
+ }
154
+
155
+ /** Stored envelope for a "use cache" function result (getItem/setItem). */
156
+ interface VercelItemEnvelope {
157
+ /** RSC-serialized value. */
158
+ v: string;
159
+ /** RSC-encoded handle blob. */
160
+ h?: string;
161
+ /** staleAt (ms since epoch). */
162
+ s: number;
163
+ /** expiresAt (ms since epoch). */
164
+ e: number;
165
+ /** Tags, surfaced on read so a hit still contributes to the document tag set. */
166
+ t?: string[];
167
+ }
168
+
169
+ /** Stored envelope for a full Response (getResponse/putResponse). */
170
+ interface VercelResponseEnvelope {
171
+ /** base64-encoded body bytes. */
172
+ b: string;
173
+ /** HTTP status. */
174
+ st: number;
175
+ /** Header entries (per-client signal headers already stripped). */
176
+ hd: [string, string][];
177
+ /** staleAt (ms since epoch). */
178
+ s: number;
179
+ /** expiresAt (ms since epoch). */
180
+ e: number;
181
+ /** Tags, preserved so a background revalidation re-write keeps them. */
182
+ t?: string[];
183
+ }
184
+
185
+ /** Stored envelope for a PPR shell entry (getShell/putShell). */
186
+ interface VercelShellEnvelope {
187
+ /**
188
+ * base64-encoded prelude bytes. Absent iff `no` (navigationOnly entries
189
+ * store no document half — ShellCacheEntry.prelude).
190
+ */
191
+ p?: string;
192
+ /** postponed state JSON, or null (DATA variant). Absent iff `no`. */
193
+ po?: string | null;
194
+ /** React.version at capture. */
195
+ rv: string;
196
+ /** Build version at capture (ShellCacheEntry.buildVersion). */
197
+ bv?: string;
198
+ /** Capture-generation start time, used by tag marker checks. */
199
+ c: number;
200
+ /** staleAt (ms since epoch). */
201
+ s: number;
202
+ /** expiresAt (ms since epoch). */
203
+ e: number;
204
+ /** Tags, preserved so a background revalidation re-write keeps them. */
205
+ t?: string[];
206
+ /** initialTheme the capture render was built with (resume theme fidelity). */
207
+ i?: string;
208
+ /** Capture data snapshot: recorded cache-store hits/writes for HIT parity. */
209
+ sn?: ShellSnapshotRecord[];
210
+ /**
211
+ * ShellCacheEntry.docKey. Must round-trip: navigation-replay eligibility
212
+ * requires the exact canonical doc segment record named here — dropping the
213
+ * field reads back as "no consumable record" and every partial navigation
214
+ * reports `no-segment-snapshot` after a store round trip.
215
+ */
216
+ dk?: string;
217
+ /**
218
+ * ShellCacheEntry.handlerLiveHoles. Must round-trip: the serve side arms the
219
+ * handler-free fast path on `!entry.handlerLiveHoles`, so dropping the flag
220
+ * here silently fast-pathed handler-live entries after a store round trip —
221
+ * their holes only a handler re-run can fill.
222
+ */
223
+ lh?: boolean;
224
+ /** ShellCacheEntry.transitionWhen; conditional transitions must re-run. */
225
+ tw?: true;
226
+ /** ShellCacheEntry.navigationOnly; its partial-context prelude is not document-safe. */
227
+ no?: true;
228
+ }
229
+
230
+ /** Read-path outcome for the debug sink. */
231
+ export type VercelCacheReadOutcome =
232
+ | "miss"
233
+ | "fresh"
234
+ | "stale-revalidate"
235
+ | "expired"
236
+ | "corrupt"
237
+ | "error";
238
+
239
+ /** Diagnostic event emitted on every read when `debug` is set. */
240
+ export interface VercelCacheReadDebugEvent {
241
+ op: "get" | "getItem" | "getResponse" | "getShell";
242
+ key: string;
243
+ outcome: VercelCacheReadOutcome;
244
+ staleAt?: number;
245
+ expiresAt?: number;
246
+ shouldRevalidate?: boolean;
247
+ /** Wall-clock ms spent in the backing cache.get(). */
248
+ readMs?: number;
249
+ }
250
+
251
+ /** `true` logs each read outcome; a function receives the structured event. */
252
+ export type VercelCacheDebug =
253
+ | boolean
254
+ | ((event: VercelCacheReadDebugEvent) => void);
255
+
256
+ /**
257
+ * Options for VercelCacheStore.
258
+ */
259
+ export interface VercelCacheStoreOptions<TEnv = unknown> {
260
+ /**
261
+ * The Vercel Runtime Cache handle - `getCache()` from `@vercel/functions`.
262
+ * Required. Construct it with a build-hash namespace to bust stale-shaped
263
+ * entries across deployments, since Vercel does not reconcile TTL/tags between
264
+ * deploys:
265
+ *
266
+ * ```ts
267
+ * import { getCache } from "@vercel/functions";
268
+ * new VercelCacheStore({ cache: getCache({ namespace: BUILD_ID }) });
269
+ * ```
270
+ */
271
+ cache: VercelRuntimeCache;
272
+
273
+ /**
274
+ * `waitUntil` from `@vercel/functions`. Used only to run the stale-read lock
275
+ * write (herd dampening) off the response path - the router already
276
+ * backgrounds the actual writes. When omitted, the lock write runs detached
277
+ * (fire-and-forget) instead.
278
+ */
279
+ waitUntil?: (promise: Promise<unknown>) => void;
280
+
281
+ /**
282
+ * Default ttl/swr for cache() boundaries when not explicitly specified.
283
+ */
284
+ defaults?: CacheDefaults;
285
+
286
+ /**
287
+ * Custom key generator applied to all cache operations (region/locale/user
288
+ * segmentation). Receives the request context and the default key.
289
+ */
290
+ keyGenerator?: (
291
+ ctx: RequestContext<TEnv>,
292
+ defaultKey: string,
293
+ ) => string | Promise<string>;
294
+
295
+ /**
296
+ * Build/version id folded into every stored key as `v/{version}/...`. A second
297
+ * cross-deploy busting layer in addition to (or instead of) the getCache
298
+ * namespace. Changing it invalidates everything this store wrote previously.
299
+ */
300
+ version?: string;
301
+
302
+ /**
303
+ * Max serialized entry size in bytes before a write is skipped. Defaults to
304
+ * VERCEL_MAX_ITEM_BYTES (2 MB - the platform's hard cap).
305
+ */
306
+ maxItemBytes?: number;
307
+
308
+ /**
309
+ * Human-readable label passed as the Vercel `set({ name })` option for
310
+ * observability in the Vercel dashboard.
311
+ */
312
+ name?: string;
313
+
314
+ /**
315
+ * Read diagnostics. `true` logs each read outcome to the console; a function
316
+ * receives the structured VercelCacheReadDebugEvent.
317
+ */
318
+ debug?: VercelCacheDebug;
319
+ }
320
+
321
+ function isRecord(value: unknown): value is Record<string, unknown> {
322
+ return typeof value === "object" && value !== null;
323
+ }
324
+
325
+ /**
326
+ * Vercel Runtime Cache-backed segment cache store.
327
+ *
328
+ * Suitable for production deployments on Vercel Functions (Node runtime). The
329
+ * store is best-effort: every read failure degrades to a miss and every write
330
+ * failure to a no-op (reported, never thrown) - the sole exception is
331
+ * invalidateTags(), which rejects when the injected cache's expireTag() rejects
332
+ * so an awaited updateTag() can surface the failure.
333
+ *
334
+ * Read-your-own-writes caveat: this honesty is only as strong as the cache
335
+ * handle. The official `@vercel/functions` cache (`BuildCache.expireTag`)
336
+ * CATCHES backend failures and resolves, so with the official client a failed
337
+ * expireTag is invisible here and an awaited updateTag() can report success that
338
+ * did not happen. Treat tag invalidation on the official Vercel client as
339
+ * best-effort, not a hard read-your-own-writes guarantee. (A custom cache handle
340
+ * that propagates expireTag rejections does get the strict guarantee, which is
341
+ * what the unit suite exercises.)
342
+ *
343
+ * Key hashing / family isolation. The store namespaces its three value tiers as
344
+ * `rg:{s|i|r}:{key}` so segment, `"use cache"`, and response entries occupy
345
+ * disjoint keyspaces. That separation is only as strong as the cache's
346
+ * `keyHashFunction`: `getCache`'s default is djb2, which folds every key to 32
347
+ * bits (8 hex chars), so at a large live-key count a collision can let one
348
+ * entry's body be served for another key (same-family) or be misread as corrupt
349
+ * (cross-family). For deployments with many cached keys, pass a wider hash so
350
+ * the family split is real isolation, e.g. `getCache({ keyHashFunction })` with
351
+ * a sha256-based function.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * import { getCache, waitUntil } from "@vercel/functions";
356
+ * import { VercelCacheStore } from "@rangojs/router/cache";
357
+ *
358
+ * export const router = createRouter({
359
+ * cache: () => ({
360
+ * store: new VercelCacheStore({
361
+ * // `process.env` (not `import.meta.env`, which needs a VITE_ prefix and
362
+ * // would be undefined here) so cross-deploy busting via `version` works.
363
+ * cache: getCache({ namespace: process.env.VERCEL_DEPLOYMENT_ID }),
364
+ * waitUntil,
365
+ * defaults: { ttl: 60, swr: 300 },
366
+ * }),
367
+ * }),
368
+ * });
369
+ * ```
370
+ */
371
+ export class VercelCacheStore<
372
+ TEnv = unknown,
373
+ > implements SegmentCacheStore<TEnv> {
374
+ readonly supportsPassiveShellReads: true = true;
375
+ readonly defaults?: CacheDefaults;
376
+ readonly keyGenerator?: (
377
+ ctx: RequestContext<TEnv>,
378
+ defaultKey: string,
379
+ ) => string | Promise<string>;
380
+
381
+ private readonly cache: VercelRuntimeCache;
382
+ private readonly waitUntil?: (promise: Promise<unknown>) => void;
383
+ private readonly version?: string;
384
+ private readonly maxItemBytes: number;
385
+ private readonly name?: string;
386
+ private readonly debug?: VercelCacheDebug;
387
+
388
+ constructor(options: VercelCacheStoreOptions<TEnv>) {
389
+ if (!options || !options.cache) {
390
+ throw new Error(
391
+ "[VercelCacheStore] requires `cache` (the getCache() handle from @vercel/functions)",
392
+ );
393
+ }
394
+ this.cache = options.cache;
395
+ this.waitUntil = options.waitUntil;
396
+ this.defaults = options.defaults;
397
+ this.keyGenerator = options.keyGenerator;
398
+ this.version = options.version;
399
+ this.maxItemBytes = options.maxItemBytes ?? VERCEL_MAX_ITEM_BYTES;
400
+ this.name = options.name;
401
+ this.debug = options.debug;
402
+ }
403
+
404
+ // --- Segment family (get/set/delete) ---
405
+
406
+ async get(key: string): Promise<CacheGetResult | null | CacheReadError> {
407
+ const storeKey = this.toStoreKey(key, "s");
408
+ const started = Date.now();
409
+ let raw: unknown;
410
+ try {
411
+ raw = await this.cache.get(storeKey);
412
+ } catch (error) {
413
+ reportCacheError(error, "cache-read", "[VercelCacheStore] get");
414
+ this.emitDebug({ op: "get", key, outcome: "error" });
415
+ // Distinct from a miss so the PPR replay composition renders uncached
416
+ // instead of substituting the seeded doc record (CACHE_READ_ERROR).
417
+ return CACHE_READ_ERROR;
418
+ }
419
+ const readMs = Date.now() - started;
420
+
421
+ if (raw == null) {
422
+ this.emitDebug({ op: "get", key, outcome: "miss", readMs });
423
+ return null;
424
+ }
425
+ const env = this.asSegmentEnvelope(this.decodeRaw(raw));
426
+ if (!env) {
427
+ reportCacheError(
428
+ new Error("malformed segment envelope"),
429
+ "cache-corrupt",
430
+ "[VercelCacheStore] get",
431
+ );
432
+ void this.safeDelete(storeKey);
433
+ this.emitDebug({ op: "get", key, outcome: "corrupt", readMs });
434
+ return null;
435
+ }
436
+
437
+ const now = Date.now();
438
+ if (now > env.e) {
439
+ void this.safeDelete(storeKey);
440
+ this.emitDebug({
441
+ op: "get",
442
+ key,
443
+ outcome: "expired",
444
+ staleAt: env.s,
445
+ expiresAt: env.e,
446
+ readMs,
447
+ });
448
+ return null;
449
+ }
450
+
451
+ const isStale = env.s > 0 && now > env.s;
452
+ const shouldRevalidate = isStale
453
+ ? await this.claimRevalidation(storeKey, env.e, "[VercelCacheStore] get")
454
+ : false;
455
+ this.emitDebug({
456
+ op: "get",
457
+ key,
458
+ outcome: shouldRevalidate ? "stale-revalidate" : "fresh",
459
+ shouldRevalidate,
460
+ staleAt: env.s,
461
+ expiresAt: env.e,
462
+ readMs,
463
+ });
464
+ return { data: env.d, shouldRevalidate };
465
+ }
466
+
467
+ async set(
468
+ key: string,
469
+ data: CachedEntryData,
470
+ ttl: number,
471
+ swr?: number,
472
+ ): Promise<void> {
473
+ try {
474
+ const swrWindow = resolveSwrWindow(swr, this.defaults);
475
+ const { staleAt, expiresAt } = computeExpiration(ttl, swrWindow);
476
+ // Embed the CLAMPED tags, like putResponse/setItem: the segment family
477
+ // carries its tags inside `d`, and a raw list would resurface dropped
478
+ // tags into recordRequestTags on every hit.
479
+ const safeTags = this.clampTagsForWrite(
480
+ data.tags,
481
+ "[VercelCacheStore] set",
482
+ );
483
+ const d: CachedEntryData = data.tags
484
+ ? { ...data, tags: safeTags.length > 0 ? safeTags : undefined }
485
+ : data;
486
+ const env: VercelSegmentEnvelope = { d, s: staleAt, e: expiresAt };
487
+ await this.write(
488
+ this.toStoreKey(key, "s"),
489
+ env,
490
+ ttl + swrWindow,
491
+ safeTags,
492
+ "[VercelCacheStore] set",
493
+ );
494
+ } catch (error) {
495
+ reportCacheError(error, "cache-write", "[VercelCacheStore] set");
496
+ }
497
+ }
498
+
499
+ async delete(key: string): Promise<boolean> {
500
+ try {
501
+ await this.cache.delete(this.toStoreKey(key, "s"));
502
+ // Vercel's delete returns void; we cannot know whether the key existed.
503
+ // The router uses the boolean only for self-heal eviction, so report success.
504
+ return true;
505
+ } catch (error) {
506
+ reportCacheError(error, "cache-delete", "[VercelCacheStore] delete");
507
+ return false;
508
+ }
509
+ }
510
+
511
+ // --- Response family (getResponse/putResponse) ---
512
+
513
+ async getResponse(
514
+ key: string,
515
+ ): Promise<{ response: Response; shouldRevalidate: boolean } | null> {
516
+ const storeKey = this.toStoreKey(key, "r");
517
+ const started = Date.now();
518
+ let raw: unknown;
519
+ try {
520
+ raw = await this.cache.get(storeKey);
521
+ } catch (error) {
522
+ reportCacheError(error, "cache-read", "[VercelCacheStore] getResponse");
523
+ this.emitDebug({ op: "getResponse", key, outcome: "error" });
524
+ return null;
525
+ }
526
+ const readMs = Date.now() - started;
527
+
528
+ if (raw == null) {
529
+ this.emitDebug({ op: "getResponse", key, outcome: "miss", readMs });
530
+ return null;
531
+ }
532
+ const env = this.asResponseEnvelope(this.decodeRaw(raw));
533
+ if (!env) {
534
+ reportCacheError(
535
+ new Error("malformed response envelope"),
536
+ "cache-corrupt",
537
+ "[VercelCacheStore] getResponse",
538
+ );
539
+ void this.safeDelete(storeKey);
540
+ this.emitDebug({ op: "getResponse", key, outcome: "corrupt", readMs });
541
+ return null;
542
+ }
543
+
544
+ const now = Date.now();
545
+ if (now > env.e) {
546
+ void this.safeDelete(storeKey);
547
+ this.emitDebug({
548
+ op: "getResponse",
549
+ key,
550
+ outcome: "expired",
551
+ staleAt: env.s,
552
+ expiresAt: env.e,
553
+ readMs,
554
+ });
555
+ return null;
556
+ }
557
+
558
+ // Reconstruct the Response BEFORE claiming revalidation. A corrupt body
559
+ // (e.g. invalid base64 from base64ToBuffer, or bad header entries) would
560
+ // otherwise throw out of getResponse — breaking the fail-open contract — and
561
+ // a stale read would have written a lock for an entry it then evicts. Treat a
562
+ // reconstruction failure as a corrupt entry: report, evict, and miss.
563
+ let response: Response;
564
+ try {
565
+ response = new Response(base64ToBuffer(env.b), {
566
+ status: env.st,
567
+ headers: new Headers(env.hd),
568
+ });
569
+ } catch (error) {
570
+ reportCacheError(
571
+ error,
572
+ "cache-corrupt",
573
+ "[VercelCacheStore] getResponse",
574
+ );
575
+ void this.safeDelete(storeKey);
576
+ this.emitDebug({ op: "getResponse", key, outcome: "corrupt", readMs });
577
+ return null;
578
+ }
579
+
580
+ const isStale = env.s > 0 && now > env.s;
581
+ const shouldRevalidate = isStale
582
+ ? await this.claimRevalidation(
583
+ storeKey,
584
+ env.e,
585
+ "[VercelCacheStore] getResponse",
586
+ )
587
+ : false;
588
+ this.emitDebug({
589
+ op: "getResponse",
590
+ key,
591
+ outcome: shouldRevalidate ? "stale-revalidate" : "fresh",
592
+ shouldRevalidate,
593
+ staleAt: env.s,
594
+ expiresAt: env.e,
595
+ readMs,
596
+ });
597
+ return { response, shouldRevalidate };
598
+ }
599
+
600
+ async putResponse(
601
+ key: string,
602
+ response: Response,
603
+ ttl: number,
604
+ swr?: number,
605
+ tags?: string[],
606
+ ): Promise<void> {
607
+ try {
608
+ const body = await response.clone().arrayBuffer();
609
+ const headers: [string, string][] = [];
610
+ response.headers.forEach((value, name) => {
611
+ if (isPerClientSignalHeader(name)) return;
612
+ headers.push([name, value]);
613
+ });
614
+ const swrWindow = resolveSwrWindow(swr, this.defaults);
615
+ const { staleAt, expiresAt } = computeExpiration(ttl, swrWindow);
616
+ // Embed the CLAMPED tags in the envelope, not the raw list: tags dropped
617
+ // on write (unsafe/over-cap) would otherwise resurface on a hit and be
618
+ // merged into an upstream document's tag set, letting it claim a tag this
619
+ // entry can't actually be invalidated by. write() re-clamps (idempotent
620
+ // and silent on an already-clean list).
621
+ const safeTags = this.clampTagsForWrite(
622
+ tags,
623
+ "[VercelCacheStore] putResponse",
624
+ );
625
+ const env: VercelResponseEnvelope = {
626
+ b: bufferToBase64(body),
627
+ st: response.status,
628
+ hd: headers,
629
+ s: staleAt,
630
+ e: expiresAt,
631
+ t: safeTags.length > 0 ? safeTags : undefined,
632
+ };
633
+ await this.write(
634
+ this.toStoreKey(key, "r"),
635
+ env,
636
+ ttl + swrWindow,
637
+ safeTags,
638
+ "[VercelCacheStore] putResponse",
639
+ );
640
+ } catch (error) {
641
+ reportCacheError(error, "cache-write", "[VercelCacheStore] putResponse");
642
+ }
643
+ }
644
+
645
+ // --- Item family ("use cache" - getItem/setItem) ---
646
+
647
+ async getItem(key: string): Promise<CacheItemResult | null> {
648
+ const storeKey = this.toStoreKey(key, "i");
649
+ const started = Date.now();
650
+ let raw: unknown;
651
+ try {
652
+ raw = await this.cache.get(storeKey);
653
+ } catch (error) {
654
+ reportCacheError(error, "cache-read", "[VercelCacheStore] getItem");
655
+ this.emitDebug({ op: "getItem", key, outcome: "error" });
656
+ return null;
657
+ }
658
+ const readMs = Date.now() - started;
659
+
660
+ if (raw == null) {
661
+ this.emitDebug({ op: "getItem", key, outcome: "miss", readMs });
662
+ return null;
663
+ }
664
+ const env = this.asItemEnvelope(this.decodeRaw(raw));
665
+ if (!env) {
666
+ reportCacheError(
667
+ new Error("malformed item envelope"),
668
+ "cache-corrupt",
669
+ "[VercelCacheStore] getItem",
670
+ );
671
+ void this.safeDelete(storeKey);
672
+ this.emitDebug({ op: "getItem", key, outcome: "corrupt", readMs });
673
+ return null;
674
+ }
675
+
676
+ const now = Date.now();
677
+ if (now > env.e) {
678
+ void this.safeDelete(storeKey);
679
+ this.emitDebug({
680
+ op: "getItem",
681
+ key,
682
+ outcome: "expired",
683
+ staleAt: env.s,
684
+ expiresAt: env.e,
685
+ readMs,
686
+ });
687
+ return null;
688
+ }
689
+
690
+ const isStale = env.s > 0 && now > env.s;
691
+ const shouldRevalidate = isStale
692
+ ? await this.claimRevalidation(
693
+ storeKey,
694
+ env.e,
695
+ "[VercelCacheStore] getItem",
696
+ )
697
+ : false;
698
+ this.emitDebug({
699
+ op: "getItem",
700
+ key,
701
+ outcome: shouldRevalidate ? "stale-revalidate" : "fresh",
702
+ shouldRevalidate,
703
+ staleAt: env.s,
704
+ expiresAt: env.e,
705
+ readMs,
706
+ });
707
+ return {
708
+ value: env.v,
709
+ handles: env.h,
710
+ shouldRevalidate,
711
+ tags: env.t,
712
+ };
713
+ }
714
+
715
+ async setItem(
716
+ key: string,
717
+ value: string,
718
+ options?: CacheItemOptions,
719
+ ): Promise<void> {
720
+ try {
721
+ const ttl = resolveTtl(options?.ttl, this.defaults, DEFAULT_FUNCTION_TTL);
722
+ const swrWindow = resolveSwrWindow(options?.swr, this.defaults);
723
+ const { staleAt, expiresAt } = computeExpiration(ttl, swrWindow);
724
+ // Store the clamped tags (see putResponse) so dropped tags don't resurface
725
+ // on a hit; write() re-clamps idempotently.
726
+ const safeTags = this.clampTagsForWrite(
727
+ options?.tags,
728
+ "[VercelCacheStore] setItem",
729
+ );
730
+ const env: VercelItemEnvelope = {
731
+ v: value,
732
+ h: options?.handles,
733
+ s: staleAt,
734
+ e: expiresAt,
735
+ t: safeTags.length > 0 ? safeTags : undefined,
736
+ };
737
+ await this.write(
738
+ this.toStoreKey(key, "i"),
739
+ env,
740
+ ttl + swrWindow,
741
+ safeTags,
742
+ "[VercelCacheStore] setItem",
743
+ );
744
+ } catch (error) {
745
+ reportCacheError(error, "cache-write", "[VercelCacheStore] setItem");
746
+ }
747
+ }
748
+
749
+ // --- Shell family (PPR shell resume - getShell/putShell) ---
750
+
751
+ async getShell(
752
+ key: string,
753
+ options?: { claimRevalidation?: boolean },
754
+ ): Promise<{ entry: ShellCacheEntry; shouldRevalidate?: boolean } | null> {
755
+ const storeKey = this.toStoreKey(key, "h");
756
+ const started = Date.now();
757
+ let raw: unknown;
758
+ try {
759
+ raw = await this.cache.get(storeKey);
760
+ } catch (error) {
761
+ reportCacheError(error, "cache-read", "[VercelCacheStore] getShell");
762
+ this.emitDebug({ op: "getShell", key, outcome: "error" });
763
+ return null;
764
+ }
765
+ const readMs = Date.now() - started;
766
+
767
+ if (raw == null) {
768
+ this.emitDebug({ op: "getShell", key, outcome: "miss", readMs });
769
+ return null;
770
+ }
771
+ const env = this.asShellEnvelope(this.decodeRaw(raw));
772
+ if (!env) {
773
+ reportCacheError(
774
+ new Error("malformed shell envelope"),
775
+ "cache-corrupt",
776
+ "[VercelCacheStore] getShell",
777
+ );
778
+ void this.safeDelete(storeKey);
779
+ this.emitDebug({ op: "getShell", key, outcome: "corrupt", readMs });
780
+ return null;
781
+ }
782
+
783
+ const now = Date.now();
784
+ if (now > env.e) {
785
+ void this.safeDelete(storeKey);
786
+ this.emitDebug({
787
+ op: "getShell",
788
+ key,
789
+ outcome: "expired",
790
+ staleAt: env.s,
791
+ expiresAt: env.e,
792
+ readMs,
793
+ });
794
+ return null;
795
+ }
796
+
797
+ if (
798
+ env.t &&
799
+ env.t.length > 0 &&
800
+ (await this.isTagsInvalidatedSince(env.t, env.c))
801
+ ) {
802
+ void this.safeDelete(storeKey);
803
+ this.emitDebug({ op: "getShell", key, outcome: "miss", readMs });
804
+ return null;
805
+ }
806
+
807
+ const isStale = env.s > 0 && now > env.s;
808
+ let shouldRevalidate = isStale;
809
+ if (isStale && options?.claimRevalidation !== false) {
810
+ shouldRevalidate = await this.claimRevalidation(
811
+ storeKey,
812
+ env.e,
813
+ "[VercelCacheStore] getShell",
814
+ );
815
+ }
816
+ this.emitDebug({
817
+ op: "getShell",
818
+ key,
819
+ outcome: shouldRevalidate ? "stale-revalidate" : "fresh",
820
+ shouldRevalidate,
821
+ staleAt: env.s,
822
+ expiresAt: env.e,
823
+ readMs,
824
+ });
825
+ return {
826
+ entry: {
827
+ prelude: env.p,
828
+ postponed: env.po,
829
+ reactVersion: env.rv,
830
+ buildVersion: env.bv,
831
+ initialTheme: env.i,
832
+ snapshot: env.sn,
833
+ docKey: env.dk,
834
+ handlerLiveHoles: env.lh,
835
+ transitionWhen: env.tw,
836
+ navigationOnly: env.no,
837
+ createdAt: env.c,
838
+ },
839
+ shouldRevalidate,
840
+ };
841
+ }
842
+
843
+ async putShell(
844
+ key: string,
845
+ entry: ShellCacheEntry,
846
+ ttlSeconds?: number,
847
+ swrSeconds?: number,
848
+ tags?: string[],
849
+ ): Promise<"stored" | "invalidated" | void> {
850
+ try {
851
+ const ttl = resolveTtl(ttlSeconds, this.defaults, DEFAULT_FUNCTION_TTL);
852
+ const swrWindow = resolveSwrWindow(swrSeconds, this.defaults);
853
+ const totalTtl = ttl + swrWindow;
854
+ const now = Date.now();
855
+ const { staleAt, expiresAt } = computeExpiration(ttl, swrWindow);
856
+ // Store the CLAMPED tags (see putResponse/setItem) so dropped tags don't
857
+ // resurface on a hit; write() re-clamps idempotently.
858
+ const safeTags = this.clampTagsForWrite(
859
+ tags,
860
+ "[VercelCacheStore] putShell",
861
+ );
862
+ const storeKey = this.toStoreKey(key, "h");
863
+ if (
864
+ safeTags.length > 0 &&
865
+ (await this.isTagsInvalidatedSince(safeTags, entry.createdAt))
866
+ ) {
867
+ return "invalidated";
868
+ }
869
+ const retentionTtl =
870
+ safeTags.length > 0
871
+ ? Math.min(totalTtl, TAG_MARKER_TTL_SECONDS)
872
+ : totalTtl;
873
+ const env: VercelShellEnvelope = {
874
+ // Presence-keyed: a navigationOnly entry has no document half, and an
875
+ // omitted key (vs an explicit undefined) also keeps it out of the
876
+ // serialized JSON.
877
+ ...(entry.prelude !== undefined ? { p: entry.prelude } : {}),
878
+ ...(entry.postponed !== undefined ? { po: entry.postponed } : {}),
879
+ rv: entry.reactVersion,
880
+ bv: entry.buildVersion,
881
+ c: entry.createdAt,
882
+ s: staleAt,
883
+ e: Math.min(expiresAt, now + retentionTtl * 1000),
884
+ t: safeTags.length > 0 ? safeTags : undefined,
885
+ i: entry.initialTheme,
886
+ sn: entry.snapshot,
887
+ dk: entry.docKey,
888
+ lh: entry.handlerLiveHoles,
889
+ tw: entry.transitionWhen,
890
+ no: entry.navigationOnly,
891
+ };
892
+ // write() enforces the 2 MB per-item ceiling (withinSizeLimit): an
893
+ // oversized shell prelude is reported and skipped (fail-open to a full
894
+ // render), never silently no-op'd on the platform.
895
+ await this.write(
896
+ storeKey,
897
+ env,
898
+ retentionTtl,
899
+ safeTags,
900
+ "[VercelCacheStore] putShell",
901
+ );
902
+ return "stored";
903
+ } catch (error) {
904
+ reportCacheError(error, "cache-write", "[VercelCacheStore] putShell");
905
+ }
906
+ }
907
+
908
+ // --- Tags ---
909
+
910
+ /**
911
+ * Shell tag-generation gate (SegmentCacheStore.isTagsInvalidatedSince).
912
+ * expireTag() keeps no queryable history, so invalidateTags() writes "tm"
913
+ * markers for runtime capture races and immutable build shells. Marker >=
914
+ * generation start wins; read errors fail open like the CF marker check.
915
+ */
916
+ async isTagsInvalidatedSince(
917
+ tags: string[],
918
+ sinceMs: number,
919
+ ): Promise<boolean> {
920
+ try {
921
+ const markers = await Promise.all(
922
+ tags.map((tag) => this.cache.get(this.toStoreKey(tag, "tm"))),
923
+ );
924
+ for (const raw of markers) {
925
+ if (raw == null) continue;
926
+ const decoded = this.decodeRaw(raw) as { at?: unknown } | null;
927
+ const at =
928
+ decoded && typeof decoded.at === "number" ? decoded.at : null;
929
+ if (at !== null && at >= sinceMs) return true;
930
+ }
931
+ return false;
932
+ } catch (error) {
933
+ reportCacheError(
934
+ error,
935
+ "cache-read",
936
+ "[VercelCacheStore] tag invalidation check",
937
+ );
938
+ return false;
939
+ }
940
+ }
941
+
942
+ async invalidateTags(tags: string[]): Promise<void> {
943
+ if (!tags || tags.length === 0) return;
944
+ // No per-item cap here: an invalidation must reach every requested tag.
945
+ const safe = this.validateTags(
946
+ tags,
947
+ "[VercelCacheStore] invalidateTags",
948
+ "cache-invalidate",
949
+ );
950
+ if (safe.length === 0) return;
951
+ // Marker writes FIRST, and strict: isTagsInvalidatedSince() is how an
952
+ // updateTag() reaches a build-time shell entry (expireTag cannot delete
953
+ // what lives in the build manifest), so a failed marker write must reject
954
+ // like a failed expireTag — silently resolving would report success while
955
+ // the baked shell keeps serving.
956
+ await Promise.all(
957
+ safe.map((tag) =>
958
+ this.cache.set(
959
+ this.toStoreKey(tag, "tm"),
960
+ JSON.stringify({ at: Date.now() }),
961
+ { ttl: TAG_MARKER_TTL_SECONDS },
962
+ ),
963
+ ),
964
+ );
965
+ try {
966
+ await this.cache.expireTag(safe);
967
+ } catch (error) {
968
+ // The one deliberate throw: a failed durable invalidation must reject so an
969
+ // awaited updateTag() surfaces it instead of reporting false success.
970
+ // NOTE: this only fires if the injected cache's expireTag() actually
971
+ // rejects. The official @vercel/functions cache catches backend failures
972
+ // and resolves, so on that client a failure is invisible and this throw
973
+ // never fires (tag invalidation is best-effort there). See the class doc.
974
+ reportCacheError(
975
+ error,
976
+ "cache-invalidate",
977
+ "[VercelCacheStore] invalidateTags",
978
+ );
979
+ throw error instanceof Error ? error : new Error(String(error));
980
+ }
981
+ }
982
+
983
+ // --- Internals ---
984
+
985
+ // The `rg:{family}:` prefix keeps the three value tiers in disjoint
986
+ // keyspaces, but the isolation is only as strong as the cache's
987
+ // keyHashFunction: djb2 (getCache's default) folds this to 32 bits, so at a
988
+ // large live-key count a same-family collision can serve the wrong body and a
989
+ // cross-family one reads as corrupt. See the class doc for passing a wider
990
+ // hash (sha256) when many keys are live.
991
+ private toStoreKey(key: string, family: CacheFamily): string {
992
+ const versionPrefix = this.version ? `v/${this.version}/` : "";
993
+ return `${versionPrefix}rg:${family}:${key}`;
994
+ }
995
+
996
+ private async write(
997
+ storeKey: string,
998
+ value: unknown,
999
+ totalTtlSeconds: number,
1000
+ tags: string[] | undefined,
1001
+ label: string,
1002
+ ): Promise<void> {
1003
+ // Serialize the envelope exactly ONCE: the same string measures the entry
1004
+ // against the size cap AND is what we hand the platform. The Vercel client
1005
+ // JSON-serializes whatever value it is given, so passing the raw object here
1006
+ // would walk and stringify the (potentially large) envelope a SECOND time.
1007
+ // Entries written this way are JSON strings; the read path (decodeRaw)
1008
+ // parses them back, and still accepts the legacy object shape written before
1009
+ // this change.
1010
+ let serialized: string | undefined;
1011
+ try {
1012
+ serialized = JSON.stringify(value);
1013
+ } catch {
1014
+ // Unserializable value: fall back to letting the platform serialize it
1015
+ // (best-effort — matches the prior "cannot measure -> allow the write").
1016
+ serialized = undefined;
1017
+ }
1018
+ if (serialized !== undefined && !this.withinSizeLimit(serialized, label)) {
1019
+ return;
1020
+ }
1021
+ const safeTags = this.clampTagsForWrite(tags, label);
1022
+ const options: { ttl: number; tags?: string[]; name?: string } = {
1023
+ ttl: Math.max(1, Math.ceil(totalTtlSeconds)),
1024
+ };
1025
+ if (safeTags.length > 0) options.tags = safeTags;
1026
+ if (this.name) options.name = this.name;
1027
+ await this.cache.set(storeKey, serialized ?? value, options);
1028
+ }
1029
+
1030
+ /**
1031
+ * Normalize a value read back from the cache. Entries written by this store
1032
+ * are pre-serialized JSON strings (see write()); legacy entries (written
1033
+ * before that change, or by a client that deserializes for us) come back as
1034
+ * objects. Parse strings, pass objects through, and treat a non-JSON string
1035
+ * as corrupt (returns undefined, so the caller reports + evicts).
1036
+ */
1037
+ private decodeRaw(raw: unknown): unknown {
1038
+ if (typeof raw !== "string") return raw;
1039
+ try {
1040
+ return JSON.parse(raw);
1041
+ } catch {
1042
+ return undefined;
1043
+ }
1044
+ }
1045
+
1046
+ /**
1047
+ * Stale-read herd dampening via a tiny companion lock key. On a stale read,
1048
+ * check `{storeKey}:lock`; if absent, claim it (write a short-TTL marker) and
1049
+ * return true so THIS reader triggers revalidation. If present, another
1050
+ * same-region reader already claimed it, so return false and serve the stale
1051
+ * entry as fresh without piling on. Best-effort and non-blocking; never throws.
1052
+ *
1053
+ * Only the STALE path pays the extra lock read; the fresh-hit path takes no
1054
+ * lock round trip. Unlike the prior whole-envelope re-stamp, a stale read now
1055
+ * writes only the tiny lock, never the (potentially large) payload.
1056
+ *
1057
+ * Non-atomic (getCache has no compare-and-set): two readers can both find no
1058
+ * lock and both revalidate. The window is REVALIDATION_LOCK_MS wide, after
1059
+ * which the lock expires and the entry is re-claimed (or a fresh write has
1060
+ * superseded it). A read-compare would not close the race without CAS.
1061
+ */
1062
+ private async claimRevalidation(
1063
+ storeKey: string,
1064
+ expiresAt: number,
1065
+ label: string,
1066
+ ): Promise<boolean> {
1067
+ const lockKey = `${storeKey}:lock`;
1068
+ let lock: unknown;
1069
+ try {
1070
+ lock = await this.cache.get(lockKey);
1071
+ } catch {
1072
+ // A lock-read failure must not break the read path: treat as unlocked.
1073
+ lock = null;
1074
+ }
1075
+ if (lock != null) return false;
1076
+
1077
+ const remainingSeconds = Math.ceil((expiresAt - Date.now()) / 1000);
1078
+ const lockTtl = Math.max(
1079
+ 1,
1080
+ Math.min(Math.ceil(REVALIDATION_LOCK_MS / 1000), remainingSeconds),
1081
+ );
1082
+ const task = (): Promise<void> =>
1083
+ this.cache.set(lockKey, 1, { ttl: lockTtl });
1084
+ if (this.waitUntil) {
1085
+ this.waitUntil(reportingAsync(task, "cache-write", label));
1086
+ } else {
1087
+ void reportingAsync(task, "cache-write", label);
1088
+ }
1089
+ return true;
1090
+ }
1091
+
1092
+ /** Measure a pre-serialized entry against the per-item size cap (see write). */
1093
+ private withinSizeLimit(serialized: string, label: string): boolean {
1094
+ const bytes = new TextEncoder().encode(serialized).length;
1095
+ if (bytes >= this.maxItemBytes) {
1096
+ reportCacheError(
1097
+ new Error(
1098
+ `entry is ${bytes}B, at/above the ${this.maxItemBytes}B cap; not cached`,
1099
+ ),
1100
+ "cache-write",
1101
+ label,
1102
+ );
1103
+ return false;
1104
+ }
1105
+ return true;
1106
+ }
1107
+
1108
+ /**
1109
+ * Drop tags Vercel cannot round-trip: over-length tags, and tags carrying a
1110
+ * URL metacharacter the `@vercel/functions` client does not encode (see
1111
+ * VERCEL_UNSAFE_TAG_CHARS). Runs on BOTH paths - the write path
1112
+ * (clampTagsForWrite) and invalidateTags - so a tag that would silently fail
1113
+ * invalidation is never stored in the first place. `category` reports the
1114
+ * drop under the caller's real operation (write vs invalidate).
1115
+ */
1116
+ private validateTags(
1117
+ tags: string[],
1118
+ label: string,
1119
+ category: CacheErrorCategory,
1120
+ ): string[] {
1121
+ const encoder = new TextEncoder();
1122
+ const out: string[] = [];
1123
+ for (const tag of tags) {
1124
+ const unsafe = VERCEL_UNSAFE_TAG_CHARS.exec(tag);
1125
+ if (unsafe) {
1126
+ reportCacheError(
1127
+ new Error(
1128
+ `tag "${tag}" contains an unencodable URL character "${unsafe[0]}"; ` +
1129
+ `skipped (it would not round-trip through Vercel tag invalidation)`,
1130
+ ),
1131
+ category,
1132
+ label,
1133
+ );
1134
+ continue;
1135
+ }
1136
+ if (encoder.encode(tag).length > VERCEL_MAX_TAG_BYTES) {
1137
+ reportCacheError(
1138
+ new Error(`tag exceeds ${VERCEL_MAX_TAG_BYTES} bytes; skipped`),
1139
+ category,
1140
+ label,
1141
+ );
1142
+ continue;
1143
+ }
1144
+ out.push(tag);
1145
+ }
1146
+ return out;
1147
+ }
1148
+
1149
+ /** validateTags + the per-item tag cap. Used on the write path. */
1150
+ private clampTagsForWrite(
1151
+ tags: string[] | undefined,
1152
+ label: string,
1153
+ ): string[] {
1154
+ if (!tags || tags.length === 0) return [];
1155
+ const valid = this.validateTags(tags, label, "cache-write");
1156
+ if (valid.length > VERCEL_MAX_TAGS_PER_ITEM) {
1157
+ reportCacheError(
1158
+ new Error(
1159
+ `entry has ${valid.length} tags, over the ${VERCEL_MAX_TAGS_PER_ITEM}-tag cap; ` +
1160
+ `keeping the first ${VERCEL_MAX_TAGS_PER_ITEM}`,
1161
+ ),
1162
+ "cache-write",
1163
+ label,
1164
+ );
1165
+ return valid.slice(0, VERCEL_MAX_TAGS_PER_ITEM);
1166
+ }
1167
+ return valid;
1168
+ }
1169
+
1170
+ private async safeDelete(storeKey: string): Promise<void> {
1171
+ try {
1172
+ await this.cache.delete(storeKey);
1173
+ } catch (error) {
1174
+ reportCacheError(error, "cache-delete", "[VercelCacheStore] evict");
1175
+ }
1176
+ }
1177
+
1178
+ private emitDebug(event: VercelCacheReadDebugEvent): void {
1179
+ const sink = this.debug;
1180
+ if (!sink) return;
1181
+ try {
1182
+ if (typeof sink === "function") sink(event);
1183
+ else console.log("[VercelCacheStore]", event);
1184
+ } catch {
1185
+ // The debug sink must never break the cache path.
1186
+ }
1187
+ }
1188
+
1189
+ private asSegmentEnvelope(raw: unknown): VercelSegmentEnvelope | null {
1190
+ if (!isRecord(raw)) return null;
1191
+ const { d, s, e } = raw;
1192
+ if (
1193
+ !isRecord(d) ||
1194
+ !Array.isArray((d as Record<string, unknown>).segments)
1195
+ ) {
1196
+ return null;
1197
+ }
1198
+ if (typeof s !== "number" || typeof e !== "number") return null;
1199
+ return { d: d as unknown as CachedEntryData, s, e };
1200
+ }
1201
+
1202
+ private asItemEnvelope(raw: unknown): VercelItemEnvelope | null {
1203
+ if (!isRecord(raw)) return null;
1204
+ const { v, h, s, e, t } = raw;
1205
+ if (typeof v !== "string") return null;
1206
+ if (typeof s !== "number" || typeof e !== "number") return null;
1207
+ return {
1208
+ v,
1209
+ h: typeof h === "string" ? h : undefined,
1210
+ s,
1211
+ e,
1212
+ t: Array.isArray(t) ? (t as string[]) : undefined,
1213
+ };
1214
+ }
1215
+
1216
+ private asShellEnvelope(raw: unknown): VercelShellEnvelope | null {
1217
+ if (!isRecord(raw)) return null;
1218
+ const { p, po, rv, bv, c, s, e, t, i, sn, dk, lh, tw, no } = raw;
1219
+ if (typeof rv !== "string") return null;
1220
+ // Document half: required unless navigationOnly (`no`), which stores
1221
+ // neither field. Tolerate a legacy navigationOnly envelope that still
1222
+ // carries them.
1223
+ if (p === undefined ? no !== true : typeof p !== "string") return null;
1224
+ if (
1225
+ po === undefined ? no !== true : po !== null && typeof po !== "string"
1226
+ ) {
1227
+ return null;
1228
+ }
1229
+ if (typeof c !== "number") return null;
1230
+ if (typeof s !== "number" || typeof e !== "number") return null;
1231
+ return {
1232
+ ...(typeof p === "string" ? { p } : {}),
1233
+ ...(po !== undefined ? { po: po as string | null } : {}),
1234
+ rv,
1235
+ bv: typeof bv === "string" ? bv : undefined,
1236
+ c,
1237
+ s,
1238
+ e,
1239
+ t: Array.isArray(t) ? (t as string[]) : undefined,
1240
+ i: typeof i === "string" ? i : undefined,
1241
+ sn: Array.isArray(sn) ? (sn as ShellSnapshotRecord[]) : undefined,
1242
+ dk: typeof dk === "string" ? dk : undefined,
1243
+ lh: lh === true ? true : undefined,
1244
+ tw: tw === true ? true : undefined,
1245
+ no: no === true ? true : undefined,
1246
+ };
1247
+ }
1248
+
1249
+ private asResponseEnvelope(raw: unknown): VercelResponseEnvelope | null {
1250
+ if (!isRecord(raw)) return null;
1251
+ const { b, st, hd, s, e, t } = raw;
1252
+ if (typeof b !== "string" || typeof st !== "number") return null;
1253
+ if (!Array.isArray(hd)) return null;
1254
+ if (typeof s !== "number" || typeof e !== "number") return null;
1255
+ return {
1256
+ b,
1257
+ st,
1258
+ hd: hd as [string, string][],
1259
+ s,
1260
+ e,
1261
+ t: Array.isArray(t) ? (t as string[]) : undefined,
1262
+ };
1263
+ }
1264
+ }