@rangojs/router 0.0.0-experimental.eb0645d3 → 0.0.0-experimental.f1468e3c

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 (392) hide show
  1. package/AGENTS.md +8 -0
  2. package/README.md +126 -16
  3. package/dist/bin/rango.js +319 -95
  4. package/dist/testing/vitest.js +82 -0
  5. package/dist/vite/index.js +2724 -1053
  6. package/package.json +68 -14
  7. package/skills/api-client/SKILL.md +211 -0
  8. package/skills/breadcrumbs/SKILL.md +64 -2
  9. package/skills/bundle-analysis/SKILL.md +159 -0
  10. package/skills/cache-guide/SKILL.md +224 -32
  11. package/skills/caching/SKILL.md +279 -17
  12. package/skills/composability/SKILL.md +27 -3
  13. package/skills/css/SKILL.md +76 -0
  14. package/skills/debug-manifest/SKILL.md +4 -2
  15. package/skills/document-cache/SKILL.md +78 -55
  16. package/skills/handler-use/SKILL.md +11 -9
  17. package/skills/hooks/SKILL.md +243 -29
  18. package/skills/host-router/SKILL.md +83 -23
  19. package/skills/i18n/SKILL.md +276 -0
  20. package/skills/intercept/SKILL.md +68 -19
  21. package/skills/layout/SKILL.md +13 -9
  22. package/skills/links/SKILL.md +190 -23
  23. package/skills/loader/SKILL.md +235 -9
  24. package/skills/middleware/SKILL.md +18 -10
  25. package/skills/migrate-nextjs/SKILL.md +43 -19
  26. package/skills/migrate-react-router/SKILL.md +8 -2
  27. package/skills/mime-routes/SKILL.md +28 -1
  28. package/skills/observability/SKILL.md +172 -0
  29. package/skills/parallel/SKILL.md +18 -7
  30. package/skills/prerender/SKILL.md +65 -60
  31. package/skills/rango/SKILL.md +251 -24
  32. package/skills/react-compiler/SKILL.md +168 -0
  33. package/skills/response-routes/SKILL.md +115 -48
  34. package/skills/route/SKILL.md +46 -5
  35. package/skills/router-setup/SKILL.md +30 -8
  36. package/skills/scripts/SKILL.md +179 -0
  37. package/skills/server-actions/SKILL.md +775 -0
  38. package/skills/tailwind/SKILL.md +27 -3
  39. package/skills/testing/SKILL.md +130 -0
  40. package/skills/testing/bindings.md +103 -0
  41. package/skills/testing/cache-prerender.md +127 -0
  42. package/skills/testing/client-components.md +124 -0
  43. package/skills/testing/e2e-parity.md +125 -0
  44. package/skills/testing/flight.md +91 -0
  45. package/skills/testing/handles.md +129 -0
  46. package/skills/testing/loader.md +128 -0
  47. package/skills/testing/middleware.md +99 -0
  48. package/skills/testing/render-handler.md +122 -0
  49. package/skills/testing/response-routes.md +95 -0
  50. package/skills/testing/reverse-and-types.md +84 -0
  51. package/skills/testing/server-actions.md +107 -0
  52. package/skills/testing/server-tree.md +128 -0
  53. package/skills/testing/setup.md +123 -0
  54. package/skills/typesafety/SKILL.md +322 -29
  55. package/skills/use-cache/SKILL.md +57 -14
  56. package/skills/view-transitions/SKILL.md +337 -0
  57. package/src/__augment-tests__/augment.ts +81 -0
  58. package/src/__augment-tests__/augmented.check.ts +116 -0
  59. package/src/__internal.ts +0 -65
  60. package/src/browser/action-coordinator.ts +53 -36
  61. package/src/browser/action-fence.ts +47 -0
  62. package/src/browser/app-shell.ts +39 -0
  63. package/src/browser/connection-warmup.ts +134 -0
  64. package/src/browser/cookie-name.ts +140 -0
  65. package/src/browser/event-controller.ts +192 -150
  66. package/src/browser/history-state.ts +21 -0
  67. package/src/browser/index.ts +3 -3
  68. package/src/browser/invalidate-client-cache.ts +52 -0
  69. package/src/browser/navigation-bridge.ts +94 -25
  70. package/src/browser/navigation-client.ts +121 -84
  71. package/src/browser/navigation-store-handle.ts +38 -0
  72. package/src/browser/navigation-store.ts +115 -67
  73. package/src/browser/navigation-transaction.ts +9 -59
  74. package/src/browser/network-error-handler.ts +34 -7
  75. package/src/browser/partial-update.ts +147 -128
  76. package/src/browser/prefetch/cache.ts +107 -56
  77. package/src/browser/prefetch/fetch.ts +204 -34
  78. package/src/browser/prefetch/queue.ts +6 -3
  79. package/src/browser/rango-state.ts +158 -76
  80. package/src/browser/react/Link.tsx +30 -7
  81. package/src/browser/react/NavigationProvider.tsx +283 -118
  82. package/src/browser/react/ScrollRestoration.tsx +10 -6
  83. package/src/browser/react/deferred-handle-resolution.ts +75 -0
  84. package/src/browser/react/filter-segment-order.ts +66 -7
  85. package/src/browser/react/index.ts +0 -48
  86. package/src/browser/react/location-state-shared.ts +178 -8
  87. package/src/browser/react/location-state.ts +39 -14
  88. package/src/browser/react/use-action.ts +6 -15
  89. package/src/browser/react/use-handle.ts +17 -14
  90. package/src/browser/react/use-href.tsx +8 -1
  91. package/src/browser/react/use-link-status.ts +33 -8
  92. package/src/browser/react/use-navigation.ts +10 -5
  93. package/src/browser/react/use-params.ts +11 -11
  94. package/src/browser/react/use-reverse.ts +106 -0
  95. package/src/browser/react/use-router.ts +25 -3
  96. package/src/browser/react/use-search-params.ts +0 -5
  97. package/src/browser/react/use-segments.ts +11 -21
  98. package/src/browser/response-adapter.ts +99 -8
  99. package/src/browser/rsc-router.tsx +91 -24
  100. package/src/browser/scroll-restoration.ts +30 -17
  101. package/src/browser/segment-structure-assert.ts +2 -2
  102. package/src/browser/server-action-bridge.ts +214 -55
  103. package/src/browser/types.ts +80 -9
  104. package/src/browser/validate-redirect-origin.ts +43 -16
  105. package/src/build/collect-fallback-refs.ts +107 -0
  106. package/src/build/generate-manifest.ts +60 -35
  107. package/src/build/generate-route-types.ts +2 -1
  108. package/src/build/index.ts +8 -2
  109. package/src/build/prefix-tree-utils.ts +123 -0
  110. package/src/build/route-trie.ts +117 -14
  111. package/src/build/route-types/ast-route-extraction.ts +15 -8
  112. package/src/build/route-types/codegen.ts +16 -5
  113. package/src/build/route-types/include-resolution.ts +117 -23
  114. package/src/build/route-types/param-extraction.ts +6 -3
  115. package/src/build/route-types/per-module-writer.ts +22 -6
  116. package/src/build/route-types/router-processing.ts +55 -28
  117. package/src/build/route-types/scan-filter.ts +1 -1
  118. package/src/build/route-types/source-scan.ts +216 -0
  119. package/src/build/runtime-discovery.ts +9 -20
  120. package/src/cache/cache-error.ts +104 -0
  121. package/src/cache/cache-key-utils.ts +29 -13
  122. package/src/cache/cache-policy.ts +108 -34
  123. package/src/cache/cache-runtime.ts +224 -41
  124. package/src/cache/cache-scope.ts +188 -82
  125. package/src/cache/cache-tag.ts +103 -0
  126. package/src/cache/cf/cf-base64.ts +33 -0
  127. package/src/cache/cf/cf-cache-constants.ts +127 -0
  128. package/src/cache/cf/cf-cache-store.ts +1989 -378
  129. package/src/cache/cf/cf-cache-types.ts +349 -0
  130. package/src/cache/cf/cf-kv-utils.ts +46 -0
  131. package/src/cache/cf/cf-tag-marker-memo.ts +105 -0
  132. package/src/cache/cf/index.ts +6 -16
  133. package/src/cache/document-cache.ts +89 -21
  134. package/src/cache/handle-snapshot.ts +70 -0
  135. package/src/cache/index.ts +10 -20
  136. package/src/cache/memory-segment-store.ts +136 -37
  137. package/src/cache/profile-registry.ts +46 -31
  138. package/src/cache/read-through-swr.ts +56 -12
  139. package/src/cache/segment-codec.ts +9 -17
  140. package/src/cache/tag-invalidation.ts +230 -0
  141. package/src/cache/types.ts +37 -100
  142. package/src/client.rsc.tsx +44 -21
  143. package/src/client.tsx +36 -61
  144. package/src/cloudflare/index.ts +11 -0
  145. package/src/cloudflare/tracing.ts +109 -0
  146. package/src/component-utils.ts +19 -0
  147. package/src/components/DefaultDocument.tsx +8 -2
  148. package/src/context-var.ts +18 -6
  149. package/src/decode-loader-results.ts +52 -0
  150. package/src/defer.ts +196 -0
  151. package/src/deps/ssr.ts +0 -1
  152. package/src/encode-kv.ts +49 -0
  153. package/src/errors.ts +30 -4
  154. package/src/escape-script.ts +52 -0
  155. package/src/handle.ts +31 -23
  156. package/src/handles/MetaTags.tsx +62 -19
  157. package/src/handles/Scripts.tsx +183 -0
  158. package/src/handles/breadcrumbs.ts +37 -8
  159. package/src/handles/is-thenable.ts +19 -0
  160. package/src/handles/meta.ts +51 -40
  161. package/src/handles/script.ts +244 -0
  162. package/src/host/cookie-handler.ts +9 -60
  163. package/src/host/errors.ts +0 -24
  164. package/src/host/index.ts +8 -2
  165. package/src/host/pattern-matcher.ts +23 -52
  166. package/src/host/router.ts +107 -99
  167. package/src/host/testing.ts +40 -27
  168. package/src/host/types.ts +37 -4
  169. package/src/host/utils.ts +1 -1
  170. package/src/href-client.ts +137 -22
  171. package/src/index.rsc.ts +96 -12
  172. package/src/index.ts +94 -14
  173. package/src/internal-debug.ts +11 -10
  174. package/src/loader-store.ts +500 -0
  175. package/src/loader.rsc.ts +20 -13
  176. package/src/loader.ts +12 -11
  177. package/src/missing-id-error.ts +68 -0
  178. package/src/outlet-context.ts +1 -1
  179. package/src/outlet-provider.tsx +1 -5
  180. package/src/prerender/param-hash.ts +16 -16
  181. package/src/prerender/store.ts +32 -37
  182. package/src/prerender.ts +61 -6
  183. package/src/redirect-origin.ts +100 -0
  184. package/src/regex-escape.ts +8 -0
  185. package/src/render-error-thrower.tsx +20 -0
  186. package/src/response-utils.ts +34 -0
  187. package/src/reverse.ts +65 -40
  188. package/src/root-error-boundary.tsx +1 -19
  189. package/src/route-content-wrapper.tsx +19 -77
  190. package/src/route-definition/dsl-helpers.ts +304 -309
  191. package/src/route-definition/helper-factories.ts +28 -140
  192. package/src/route-definition/helpers-types.ts +82 -55
  193. package/src/route-definition/index.ts +1 -2
  194. package/src/route-definition/redirect.ts +44 -11
  195. package/src/route-definition/resolve-handler-use.ts +12 -1
  196. package/src/route-definition/use-item-types.ts +29 -0
  197. package/src/route-map-builder.ts +0 -16
  198. package/src/route-types.ts +19 -46
  199. package/src/router/basename.ts +14 -0
  200. package/src/router/content-negotiation.ts +73 -25
  201. package/src/router/error-handling.ts +45 -18
  202. package/src/router/find-match.ts +44 -23
  203. package/src/router/handler-context.ts +27 -43
  204. package/src/router/instrument.ts +350 -0
  205. package/src/router/intercept-resolution.ts +39 -20
  206. package/src/router/lazy-includes.ts +10 -47
  207. package/src/router/loader-resolution.ts +155 -72
  208. package/src/router/logging.ts +0 -6
  209. package/src/router/manifest.ts +18 -29
  210. package/src/router/match-api.ts +9 -24
  211. package/src/router/match-context.ts +0 -22
  212. package/src/router/match-handlers.ts +58 -58
  213. package/src/router/match-middleware/background-revalidation.ts +40 -24
  214. package/src/router/match-middleware/cache-lookup.ts +159 -285
  215. package/src/router/match-middleware/cache-store.ts +64 -52
  216. package/src/router/match-middleware/intercept-resolution.ts +0 -22
  217. package/src/router/match-middleware/segment-resolution.ts +0 -22
  218. package/src/router/match-pipelines.ts +1 -42
  219. package/src/router/match-result.ts +44 -74
  220. package/src/router/metrics.ts +0 -34
  221. package/src/router/middleware-types.ts +7 -134
  222. package/src/router/middleware.ts +247 -166
  223. package/src/router/navigation-snapshot.ts +0 -51
  224. package/src/router/params-util.ts +23 -0
  225. package/src/router/pattern-matching.ts +85 -94
  226. package/src/router/prefetch-cache-ttl.ts +51 -0
  227. package/src/router/prerender-match.ts +104 -65
  228. package/src/router/preview-match.ts +3 -1
  229. package/src/router/request-classification.ts +28 -62
  230. package/src/router/revalidation.ts +123 -73
  231. package/src/router/route-snapshot.ts +0 -1
  232. package/src/router/router-context.ts +3 -28
  233. package/src/router/router-interfaces.ts +83 -35
  234. package/src/router/router-options.ts +136 -5
  235. package/src/router/router-registry.ts +2 -5
  236. package/src/router/segment-resolution/fresh.ts +97 -84
  237. package/src/router/segment-resolution/helpers.ts +86 -6
  238. package/src/router/segment-resolution/loader-cache.ts +76 -39
  239. package/src/router/segment-resolution/revalidation.ts +272 -320
  240. package/src/router/segment-resolution/static-store.ts +19 -5
  241. package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
  242. package/src/router/segment-resolution/view-transition-default.ts +56 -0
  243. package/src/router/segment-resolution.ts +5 -1
  244. package/src/router/segment-wrappers.ts +6 -5
  245. package/src/router/state-cookie-name.ts +33 -0
  246. package/src/router/substitute-pattern-params.ts +56 -0
  247. package/src/router/telemetry-otel.ts +161 -199
  248. package/src/router/telemetry.ts +96 -19
  249. package/src/router/timeout.ts +0 -20
  250. package/src/router/tracing.ts +206 -0
  251. package/src/router/trie-matching.ts +162 -64
  252. package/src/router/types.ts +9 -63
  253. package/src/router/url-params.ts +0 -5
  254. package/src/router.ts +110 -55
  255. package/src/rsc/handler-context.ts +3 -2
  256. package/src/rsc/handler.ts +264 -220
  257. package/src/rsc/helpers.ts +100 -6
  258. package/src/rsc/index.ts +2 -5
  259. package/src/rsc/json-route-result.ts +38 -0
  260. package/src/rsc/loader-fetch.ts +114 -38
  261. package/src/rsc/manifest-init.ts +28 -41
  262. package/src/rsc/origin-guard.ts +39 -25
  263. package/src/rsc/progressive-enhancement.ts +117 -11
  264. package/src/rsc/redirect-guard.ts +99 -0
  265. package/src/rsc/response-cache-serve.ts +238 -0
  266. package/src/rsc/response-error.ts +79 -12
  267. package/src/rsc/response-route-handler.ts +88 -188
  268. package/src/rsc/rsc-rendering.ts +98 -76
  269. package/src/rsc/runtime-warnings.ts +23 -10
  270. package/src/rsc/server-action.ts +281 -117
  271. package/src/rsc/ssr-setup.ts +16 -0
  272. package/src/rsc/transition-gate.ts +89 -0
  273. package/src/rsc/types.ts +23 -5
  274. package/src/runtime-env.ts +18 -0
  275. package/src/search-params.ts +35 -30
  276. package/src/segment-loader-promise.ts +31 -4
  277. package/src/segment-system.tsx +254 -143
  278. package/src/serialize.ts +243 -0
  279. package/src/server/context.ts +163 -51
  280. package/src/server/cookie-parse.ts +32 -0
  281. package/src/server/cookie-store.ts +80 -5
  282. package/src/server/handle-store.ts +21 -38
  283. package/src/server/loader-registry.ts +33 -42
  284. package/src/server/request-context.ts +287 -178
  285. package/src/ssr/index.tsx +21 -16
  286. package/src/static-handler.ts +10 -13
  287. package/src/testing/cache-status.ts +162 -0
  288. package/src/testing/collect-handle.ts +40 -0
  289. package/src/testing/dispatch.ts +701 -0
  290. package/src/testing/dom.entry.ts +22 -0
  291. package/src/testing/e2e/fixture.ts +188 -0
  292. package/src/testing/e2e/index.ts +128 -0
  293. package/src/testing/e2e/matchers.ts +35 -0
  294. package/src/testing/e2e/page-helpers.ts +272 -0
  295. package/src/testing/e2e/parity.ts +387 -0
  296. package/src/testing/e2e/server.ts +195 -0
  297. package/src/testing/flight-matchers.ts +97 -0
  298. package/src/testing/flight-normalize.ts +11 -0
  299. package/src/testing/flight-runtime.d.ts +57 -0
  300. package/src/testing/flight-tree.ts +682 -0
  301. package/src/testing/flight.entry.ts +52 -0
  302. package/src/testing/flight.ts +257 -0
  303. package/src/testing/generated-routes.ts +183 -0
  304. package/src/testing/index.ts +105 -0
  305. package/src/testing/internal/context.ts +371 -0
  306. package/src/testing/internal/flight-client-globals.ts +30 -0
  307. package/src/testing/internal/seed-vars.ts +54 -0
  308. package/src/testing/render-handler.ts +357 -0
  309. package/src/testing/render-route.tsx +581 -0
  310. package/src/testing/run-loader.ts +385 -0
  311. package/src/testing/run-middleware.ts +205 -0
  312. package/src/testing/run-transition-when.ts +164 -0
  313. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  314. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  315. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  316. package/src/testing/vitest-stubs/version.ts +5 -0
  317. package/src/testing/vitest.ts +305 -0
  318. package/src/theme/ThemeProvider.tsx +20 -58
  319. package/src/theme/ThemeScript.tsx +7 -9
  320. package/src/theme/constants.ts +52 -13
  321. package/src/theme/index.ts +0 -7
  322. package/src/theme/theme-context.ts +1 -5
  323. package/src/theme/theme-script.ts +22 -21
  324. package/src/theme/use-theme.ts +0 -3
  325. package/src/types/boundaries.ts +0 -35
  326. package/src/types/cache-types.ts +13 -4
  327. package/src/types/error-types.ts +30 -90
  328. package/src/types/global-namespace.ts +54 -41
  329. package/src/types/handler-context.ts +110 -62
  330. package/src/types/index.ts +3 -10
  331. package/src/types/loader-types.ts +11 -9
  332. package/src/types/request-scope.ts +112 -0
  333. package/src/types/route-config.ts +6 -50
  334. package/src/types/route-entry.ts +0 -6
  335. package/src/types/segments.ts +135 -14
  336. package/src/urls/include-helper.ts +9 -56
  337. package/src/urls/index.ts +1 -11
  338. package/src/urls/path-helper-types.ts +29 -12
  339. package/src/urls/path-helper.ts +17 -106
  340. package/src/urls/pattern-types.ts +36 -19
  341. package/src/urls/response-types.ts +22 -29
  342. package/src/urls/type-extraction.ts +58 -139
  343. package/src/urls/urls-function.ts +1 -19
  344. package/src/use-loader.tsx +292 -107
  345. package/src/vite/debug.ts +185 -0
  346. package/src/vite/discovery/bundle-postprocess.ts +8 -7
  347. package/src/vite/discovery/discover-routers.ts +126 -85
  348. package/src/vite/discovery/discovery-errors.ts +194 -0
  349. package/src/vite/discovery/gate-state.ts +171 -0
  350. package/src/vite/discovery/prerender-collection.ts +96 -68
  351. package/src/vite/discovery/route-types-writer.ts +40 -84
  352. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  353. package/src/vite/discovery/state.ts +44 -0
  354. package/src/vite/discovery/virtual-module-codegen.ts +14 -34
  355. package/src/vite/index.ts +2 -0
  356. package/src/vite/inject-client-debug.ts +36 -0
  357. package/src/vite/plugin-types.ts +126 -8
  358. package/src/vite/plugins/cjs-to-esm.ts +16 -19
  359. package/src/vite/plugins/client-ref-dedup.ts +16 -11
  360. package/src/vite/plugins/client-ref-hashing.ts +28 -15
  361. package/src/vite/plugins/cloudflare-protocol-stub.ts +1 -21
  362. package/src/vite/plugins/expose-action-id.ts +48 -95
  363. package/src/vite/plugins/expose-id-utils.ts +88 -55
  364. package/src/vite/plugins/expose-ids/export-analysis.ts +101 -34
  365. package/src/vite/plugins/expose-ids/handler-transform.ts +11 -90
  366. package/src/vite/plugins/expose-ids/loader-transform.ts +14 -24
  367. package/src/vite/plugins/expose-ids/router-transform.ts +118 -29
  368. package/src/vite/plugins/expose-internal-ids.ts +505 -486
  369. package/src/vite/plugins/performance-tracks.ts +26 -25
  370. package/src/vite/plugins/refresh-cmd.ts +1 -1
  371. package/src/vite/plugins/use-cache-transform.ts +73 -83
  372. package/src/vite/plugins/version-injector.ts +40 -29
  373. package/src/vite/plugins/version-plugin.ts +37 -40
  374. package/src/vite/plugins/virtual-entries.ts +39 -25
  375. package/src/vite/rango.ts +109 -118
  376. package/src/vite/router-discovery.ts +718 -119
  377. package/src/vite/utils/ast-handler-extract.ts +26 -35
  378. package/src/vite/utils/banner.ts +1 -1
  379. package/src/vite/utils/bundle-analysis.ts +10 -15
  380. package/src/vite/utils/client-chunks.ts +184 -0
  381. package/src/vite/utils/directive-prologue.ts +40 -0
  382. package/src/vite/utils/forward-user-plugins.ts +171 -0
  383. package/src/vite/utils/manifest-utils.ts +4 -59
  384. package/src/vite/utils/package-resolution.ts +20 -52
  385. package/src/vite/utils/prerender-utils.ts +54 -39
  386. package/src/vite/utils/shared-utils.ts +90 -41
  387. package/src/browser/action-response-classifier.ts +0 -99
  388. package/src/browser/react/use-client-cache.ts +0 -58
  389. package/src/browser/shallow.ts +0 -40
  390. package/src/handles/index.ts +0 -7
  391. package/src/network-error-thrower.tsx +0 -23
  392. package/src/router/middleware-cookies.ts +0 -55
@@ -78,6 +78,14 @@ export interface CacheOptions<TEnv = unknown> {
78
78
  * - Loader-specific caching strategies
79
79
  * - Hot data in fast cache, cold data in larger/slower cache
80
80
  *
81
+ * Tag invalidation caveat: a per-boundary store becomes reachable by
82
+ * `updateTag()` / `revalidateTag()` once this boundary is resolved in the
83
+ * current process. If the store is *durable* (shared across processes) and the
84
+ * very first request to a fresh worker is an `updateTag`/`revalidateTag` for a
85
+ * tag held only in this store - before this boundary is matched - that
86
+ * invalidation can miss it. For data you invalidate by tag, prefer the
87
+ * app-level store (always reachable), or ensure the boundary is warmed.
88
+ *
81
89
  * @example
82
90
  * ```typescript
83
91
  * const kvStore = new CloudflareKVStore(env.CACHE_KV);
@@ -145,10 +153,11 @@ export interface CacheOptions<TEnv = unknown> {
145
153
  * Tags for cache invalidation.
146
154
  * Can be a static array or a function that returns tags.
147
155
  *
148
- * Note: Tags are passed through to the store but built-in stores
149
- * (MemorySegmentCacheStore, CFCacheStore) do not yet index or
150
- * invalidate by tag. Effective tag-based invalidation requires a
151
- * custom store implementation with secondary indices.
156
+ * The built-in `MemorySegmentCacheStore` and `CFCacheStore` index by tag.
157
+ * Invalidate on demand with `updateTag(...tags)` (awaitable, read-your-own-writes;
158
+ * for server actions) or `revalidateTag(...tags)` (background hard-purge, not
159
+ * awaited; for route handlers / webhooks). For `CFCacheStore`, distributed
160
+ * invalidation requires a `kv` namespace (markers live in that same namespace).
152
161
  *
153
162
  * @example
154
163
  * ```typescript
@@ -14,19 +14,19 @@
14
14
  * - "unknown": Fallback for unclassified errors (not currently invoked)
15
15
  */
16
16
  export type ErrorPhase =
17
- | "routing" // During route matching
18
- | "manifest" // During manifest loading (reserved, not currently invoked)
19
- | "middleware" // During middleware execution (errors propagate to handler phase)
20
- | "loader" // During loader execution
21
- | "handler" // During route/layout handler execution
22
- | "rendering" // During RSC/SSR rendering (SSR handler uses separate callback)
23
- | "action" // During server action execution
24
- | "revalidation" // During revalidation evaluation
25
- | "cache" // During "use cache" background operations (stale revalidation, async cache writes)
26
- | "prerender" // During build-time pre-rendering (Vite closeBundle)
27
- | "static" // During build-time static handler rendering (Vite closeBundle)
28
- | "origin" // During cross-origin request validation (CSRF protection)
29
- | "unknown"; // Fallback for unclassified errors
17
+ | "routing"
18
+ | "manifest"
19
+ | "middleware"
20
+ | "loader"
21
+ | "handler"
22
+ | "rendering"
23
+ | "action"
24
+ | "revalidation"
25
+ | "cache"
26
+ | "prerender"
27
+ | "static"
28
+ | "origin"
29
+ | "unknown";
30
30
 
31
31
  /**
32
32
  * Comprehensive context passed to onError callback
@@ -59,103 +59,43 @@ export type ErrorPhase =
59
59
  * ```
60
60
  */
61
61
  export interface OnErrorContext<TEnv = any> {
62
- /**
63
- * The error that occurred
64
- */
65
62
  error: Error;
66
-
67
- /**
68
- * Phase where the error occurred
69
- */
70
63
  phase: ErrorPhase;
71
-
72
- /**
73
- * The original request
74
- */
75
64
  request: Request;
76
-
77
- /**
78
- * Parsed URL from the request
79
- */
80
65
  url: URL;
81
-
82
- /**
83
- * Request pathname
84
- */
85
66
  pathname: string;
86
-
87
- /**
88
- * HTTP method
89
- */
90
67
  method: string;
91
-
92
- /**
93
- * Matched route key (if available)
94
- * e.g., "shop.products.detail"
95
- */
68
+ /** Matched route key (if available) e.g., "shop.products.detail" */
96
69
  routeKey?: string;
97
-
98
- /**
99
- * Route params (if available)
100
- * e.g., { slug: "headphones" }
101
- */
70
+ /** Route params (if available) e.g., { slug: "headphones" } */
102
71
  params?: Record<string, string>;
103
-
104
- /**
105
- * Segment ID where error occurred (if available)
106
- * e.g., "M1L0" for a layout, "M1R0" for a route
107
- */
72
+ /** Segment ID where error occurred (if available) e.g., "M1L0" for a layout, "M1R0" for a route */
108
73
  segmentId?: string;
109
-
110
- /**
111
- * Segment type where error occurred (if available)
112
- */
74
+ /** Segment type where error occurred (if available) */
113
75
  segmentType?: "layout" | "route" | "parallel" | "loader" | "middleware";
114
-
115
- /**
116
- * Loader name (if error occurred in a loader)
117
- */
76
+ /** Loader name (if error occurred in a loader) */
118
77
  loaderName?: string;
119
-
120
- /**
121
- * Middleware name/id (if error occurred in middleware)
122
- */
78
+ /** Middleware name/id (if error occurred in middleware) */
123
79
  middlewareId?: string;
124
-
125
- /**
126
- * Action ID (if error occurred during server action)
127
- * e.g., "src/actions.ts#addToCart"
128
- */
80
+ /** Action ID (if error occurred during server action) e.g., "src/actions.ts#addToCart" */
129
81
  actionId?: string;
130
-
131
- /**
132
- * Environment/bindings (platform context)
133
- */
82
+ /** Environment/bindings (platform context) */
134
83
  env?: TEnv;
135
-
136
- /**
137
- * Duration from request start to error (milliseconds)
138
- */
84
+ /** Duration from request start to error (milliseconds) */
139
85
  duration?: number;
140
-
141
- /**
142
- * Whether this is a partial/navigation request
143
- */
86
+ /** Whether this is a partial/navigation request */
144
87
  isPartial?: boolean;
145
-
146
- /**
147
- * Whether an error boundary caught the error
148
- * If true, the error was handled and a fallback UI was rendered
149
- */
88
+ /** Whether an error boundary caught the error */
150
89
  handledByBoundary?: boolean;
151
-
152
- /**
153
- * Stack trace (if available)
154
- */
90
+ /** Stack trace (if available) */
155
91
  stack?: string;
156
92
 
157
93
  /**
158
- * Additional metadata specific to the error phase
94
+ * Additional metadata specific to the error phase. For the `cache` phase,
95
+ * `metadata.category` is a `CacheErrorCategory` (exported from
96
+ * `@rangojs/router/cache`) identifying the failure kind, e.g. `cache-read`
97
+ * (transient outage, degraded to a miss) vs `cache-corrupt` (faulty entry
98
+ * self-healed) vs `cache-invalidate` (a failed background revalidateTag).
159
99
  */
160
100
  metadata?: Record<string, unknown>;
161
101
  }
@@ -7,7 +7,7 @@
7
7
  * ```typescript
8
8
  * // In env.ts or env.d.ts
9
9
  * declare global {
10
- * namespace RSCRouter {
10
+ * namespace Rango {
11
11
  * interface Env extends AppBindings {}
12
12
  * interface Vars extends AppVariables {}
13
13
  * }
@@ -18,39 +18,41 @@
18
18
  * ```
19
19
  */
20
20
  declare global {
21
- namespace RSCRouter {
21
+ namespace Rango {
22
22
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
23
- interface Env {
24
- // Empty by default - users augment with their bindings (e.g., { DB: D1Database })
25
- }
23
+ interface Env {}
26
24
 
27
25
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
28
- interface Vars {
29
- // Empty by default - users augment with their variables (e.g., { user?: User })
30
- }
26
+ interface Vars {}
31
27
 
32
28
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
33
- interface RegisteredRoutes {
34
- // Empty by default - users augment with their merged route maps for type-safe href()
35
- // Values are string (pattern) for RSC routes, or { path: string; response: T } for response routes
36
- }
29
+ interface RegisteredRoutes {}
37
30
 
38
31
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
39
- interface GeneratedRouteMap {
40
- // Empty by default - populated by generated named-routes.gen.ts
41
- // Maps route names to URL pattern strings for Handler<"routeName"> support
42
- }
32
+ interface GeneratedRouteMap {}
43
33
  }
44
34
  }
45
35
 
46
36
  /**
47
- * Get registered routes or fallback to generic Record<string, string>
48
- * When RSCRouter.RegisteredRoutes is augmented, provides autocomplete for route names
49
- * When not augmented, allows any string (no autocomplete)
37
+ * Route map for path-validation surfaces (`href`, `ValidPaths`, `PathResponse`).
38
+ *
39
+ * Resolution order:
40
+ * 1. `RegisteredRoutes` — manual `extends typeof router.routeMap`; richest map,
41
+ * the only one carrying response-route payload metadata.
42
+ * 2. `GeneratedRouteMap` — auto-wired by `router.named-routes.gen.ts`; path +
43
+ * search only. Lets `rango generate` alone enable `href()`/`ValidPaths` path
44
+ * checking without a manual `RegisteredRoutes` declaration.
45
+ * 3. `Record<string, string>` — permissive fallback when nothing is registered.
46
+ *
47
+ * Referencing `GeneratedRouteMap` here is cycle-safe: it is declared in the
48
+ * standalone gen file with no imports, unlike `RegisteredRoutes extends typeof
49
+ * router.routeMap`.
50
50
  */
51
- export type GetRegisteredRoutes = keyof RSCRouter.RegisteredRoutes extends never
52
- ? Record<string, string>
53
- : RSCRouter.RegisteredRoutes;
51
+ export type GetRegisteredRoutes = keyof Rango.RegisteredRoutes extends never
52
+ ? keyof Rango.GeneratedRouteMap extends never
53
+ ? Record<string, string>
54
+ : Rango.GeneratedRouteMap
55
+ : Rango.RegisteredRoutes;
54
56
 
55
57
  /**
56
58
  * Default route map for reverse() surfaces.
@@ -58,12 +60,11 @@ export type GetRegisteredRoutes = keyof RSCRouter.RegisteredRoutes extends never
58
60
  * cycles, but falls back to RegisteredRoutes for manual augmentation and then to
59
61
  * a permissive record when no route types are available.
60
62
  */
61
- export type DefaultReverseRouteMap =
62
- keyof RSCRouter.GeneratedRouteMap extends never
63
- ? keyof RSCRouter.RegisteredRoutes extends never
64
- ? Record<string, string>
65
- : RSCRouter.RegisteredRoutes
66
- : RSCRouter.GeneratedRouteMap;
63
+ export type DefaultReverseRouteMap = keyof Rango.GeneratedRouteMap extends never
64
+ ? keyof Rango.RegisteredRoutes extends never
65
+ ? Record<string, string>
66
+ : Rango.RegisteredRoutes
67
+ : Rango.GeneratedRouteMap;
67
68
 
68
69
  /**
69
70
  * Default route map for Handler type.
@@ -71,30 +72,42 @@ export type DefaultReverseRouteMap =
71
72
  * circular dependencies: router.tsx -> urls.tsx -> handler.tsx -> RegisteredRoutes -> router.tsx.
72
73
  * GeneratedRouteMap is declared in a standalone gen file with no imports.
73
74
  */
74
- export type DefaultHandlerRouteMap =
75
- keyof RSCRouter.GeneratedRouteMap extends never
76
- ? {}
77
- : RSCRouter.GeneratedRouteMap;
75
+ export type DefaultHandlerRouteMap = keyof Rango.GeneratedRouteMap extends never
76
+ ? {}
77
+ : Rango.GeneratedRouteMap;
78
78
 
79
79
  /**
80
- * Default environment type - uses global augmentation if available, any otherwise
80
+ * Default environment type - uses global augmentation if available.
81
+ *
82
+ * Falls back to `unknown` (not `any`) when `Rango.Env` is not augmented, so
83
+ * an app that forgets to register its bindings gets a compile error on
84
+ * `ctx.env.SOMETHING` instead of silently losing all env type-checking. Augment
85
+ * `Rango.Env` to type `ctx.env`.
81
86
  */
82
- export type DefaultEnv = keyof RSCRouter.Env extends never
83
- ? any
84
- : RSCRouter.Env;
87
+ export type DefaultEnv = keyof Rango.Env extends never ? unknown : Rango.Env;
85
88
 
86
89
  /**
87
- * Default variables type - uses global augmentation if available, Record<string, any> otherwise
90
+ * Variables type backing the string-key `ctx.get` / `ctx.set` overloads.
91
+ *
92
+ * Uses `Rango.Vars` augmentation when present; otherwise falls back to
93
+ * `Record<string, any>` so an un-augmented app can use string-key vars with
94
+ * zero config -- at the cost of a typo'd key being silently `any`.
95
+ *
96
+ * This `any` fallback is deliberate (see #561) and is an intentional asymmetry
97
+ * with `DefaultEnv` above, which falls back to `unknown`: env bindings are
98
+ * platform-critical and should be registered, so a forgotten binding is made a
99
+ * compile error; vars are ad-hoc and middleware-set, so the zero-config path
100
+ * wins. Augment `Rango.Vars` for type-safe keys.
88
101
  */
89
- export type DefaultVars = keyof RSCRouter.Vars extends never
102
+ export type DefaultVars = keyof Rango.Vars extends never
90
103
  ? Record<string, any>
91
- : RSCRouter.Vars;
104
+ : Rango.Vars;
92
105
 
93
106
  /**
94
107
  * Default route name type for public `routeName` on contexts.
95
108
  * When GeneratedRouteMap is augmented, narrows to the known route names.
96
109
  * Otherwise falls back to `string` for untyped usage.
97
110
  */
98
- export type DefaultRouteName = keyof RSCRouter.GeneratedRouteMap extends never
111
+ export type DefaultRouteName = keyof Rango.GeneratedRouteMap extends never
99
112
  ? string
100
- : keyof RSCRouter.GeneratedRouteMap & string;
113
+ : keyof Rango.GeneratedRouteMap & string;
@@ -1,5 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { Handle } from "../handle.js";
3
+ import type { HandlePush } from "../defer.js";
3
4
  import type { ContextVar } from "../context-var.js";
4
5
  import type { MiddlewareFn } from "../router/middleware.js";
5
6
  import type { Theme } from "../theme/types.js";
@@ -20,6 +21,7 @@ import type {
20
21
  } from "./route-config.js";
21
22
  import type { LoaderDefinition } from "./loader-types.js";
22
23
  import type { UseItems, HandlerUseItem } from "../route-types.js";
24
+ import type { RequestScope } from "./request-scope.js";
23
25
 
24
26
  // Re-export MiddlewareFn for internal/advanced use
25
27
  export type { MiddlewareFn } from "../router/middleware.js";
@@ -42,7 +44,7 @@ export type { MiddlewareFn } from "../router/middleware.js";
42
44
  */
43
45
  export type ScopedRouteMap<
44
46
  TPrefix extends string,
45
- TMap = RSCRouter.GeneratedRouteMap,
47
+ TMap = Rango.GeneratedRouteMap,
46
48
  > = {
47
49
  [K in keyof TMap as K extends `${TPrefix}.${infer Rest}`
48
50
  ? Rest
@@ -106,14 +108,6 @@ type StrictLocalParamsWithExtras<TEntry> =
106
108
  ? Record<string, string>
107
109
  : ExtractParamsFromEntry<TEntry, {}> & Record<string, string>;
108
110
 
109
- // HandlerContext.reverse is the only reverse surface with runtime param autofill
110
- // from the current matched request. Middleware/loaders/request context do not
111
- // have the same local-route guarantees, so they keep plain ScopedReverseFunction.
112
- //
113
- // When a handler has an explicit local route map, enforce that local route
114
- // params declared by that map are present while still allowing extra mount
115
- // params to be passed through. Global names remain autofill-friendly because
116
- // parent include() params are often unknown at the module definition site.
117
111
  type StrictLocalAutofillGlobalReverseFunction<TLocalRoutes, TGlobalRoutes> =
118
112
  ScopedReverseFunction<TLocalRoutes, TGlobalRoutes> & {
119
113
  <TName extends keyof TGlobalRoutes & string>(
@@ -195,7 +189,7 @@ export type HandlerContext<
195
189
  TEnv = DefaultEnv,
196
190
  TSearch extends SearchSchema = {},
197
191
  TRouteMap = never,
198
- > = {
192
+ > = RequestScope<TEnv> & {
199
193
  /**
200
194
  * Route parameters extracted from the URL pattern.
201
195
  * Type-safe when using Handler<"/path/:param"> or Handler<{ param: string }>.
@@ -215,44 +209,11 @@ export type HandlerContext<
215
209
  * changing build semantics (e.g., skip expensive operations in dev).
216
210
  */
217
211
  dev: boolean;
218
- /**
219
- * The original incoming Request object (transport URL intact).
220
- * Use `ctx.url` / `ctx.searchParams` for application logic — those have
221
- * internal `_rsc*` params stripped. `ctx.request` preserves the raw URL
222
- * for cases where you need original headers, method, or body.
223
- */
224
- request: Request;
225
- /**
226
- * Query parameters from the URL (system params like `_rsc*` are filtered).
227
- * Always a standard URLSearchParams instance.
228
- */
229
- searchParams: URLSearchParams;
230
212
  /**
231
213
  * Typed search parameters parsed from URL query string via the route's
232
214
  * search schema. Empty object when no schema is defined.
233
215
  */
234
216
  search: {} extends TSearch ? {} : ResolveSearchSchema<TSearch>;
235
- /**
236
- * The pathname portion of the request URL.
237
- */
238
- pathname: string;
239
- /**
240
- * The full URL object (with internal `_rsc*` params stripped).
241
- * Use this for application logic — routing, link generation, display.
242
- */
243
- url: URL;
244
- /**
245
- * The original request URL with all parameters intact, including
246
- * internal `_rsc*` transport params. Use `ctx.url` for application
247
- * logic — this is only needed for advanced cases like debugging
248
- * or custom cache keying.
249
- */
250
- originalUrl: URL;
251
- /**
252
- * Platform bindings (DB, KV, secrets, etc.).
253
- * Access resources like `ctx.env.DB`, `ctx.env.KV`.
254
- */
255
- env: TEnv;
256
217
  /**
257
218
  * Type-safe getter for middleware variables.
258
219
  * Preferred way to read middleware-injected variables.
@@ -314,6 +275,8 @@ export type HandlerContext<
314
275
  * For handles: Returns a push function to add data for this segment.
315
276
  * Handle data accumulates across all matched route segments.
316
277
  * Push accepts: direct value, Promise, or async callback (executed immediately).
278
+ * Or call `.defer()` to reserve the slot now and resolve it later (e.g. from a
279
+ * deep async component), with a timeout safety net — see {@link HandlePush}.
317
280
  *
318
281
  * @example
319
282
  * ```typescript
@@ -347,6 +310,13 @@ export type HandlerContext<
347
310
  * });
348
311
  * return <ProductPage />;
349
312
  * });
313
+ *
314
+ * // Handle usage - deferred (reserve the slot now, resolve from a deep component)
315
+ * route("product", (ctx) => {
316
+ * const resolve = ctx.use(Breadcrumbs).defer({ timeoutMs: 5000, else: null });
317
+ * loadCrumb(ctx.params.id).then(resolve); // resolver is push-equal
318
+ * return <ProductPage />; // auto-resolves to `else` on timeout
319
+ * });
350
320
  * ```
351
321
  */
352
322
  use: {
@@ -355,7 +325,7 @@ export type HandlerContext<
355
325
  ): Promise<T>;
356
326
  <TData, TAccumulated = TData[]>(
357
327
  handle: Handle<TData, TAccumulated>,
358
- ): (data: TData | Promise<TData> | (() => Promise<TData>)) => void;
328
+ ): HandlePush<TData>;
359
329
  };
360
330
  /**
361
331
  * Current theme (from cookie or default).
@@ -462,6 +432,18 @@ export type InternalHandlerContext<
462
432
  _responseType?: string;
463
433
  /** Route name for cache key scoping (prevents cross-route collisions). */
464
434
  _routeName?: string;
435
+ /**
436
+ * @internal Loader-cache override table: loaderId -> memoized data promise.
437
+ * A single stable ctx.use interceptor consults this instead of chaining one
438
+ * wrapper per cached loader (avoids O(N) dispatch). See loader-cache.ts.
439
+ */
440
+ _loaderCacheOverrides?: Map<string, Promise<any>>;
441
+ /**
442
+ * @internal ctx.use captured before the loader-cache interceptor was installed.
443
+ * The cache-miss execute runs the loader through this, bypassing the override
444
+ * table (so a loader cannot await its own in-flight memoized promise).
445
+ */
446
+ _loaderCacheOriginalUse?: (item: any) => any;
465
447
  };
466
448
 
467
449
  /**
@@ -503,13 +485,16 @@ export type RevalidateParams<TParams = GenericParams, TEnv = any> = Parameters<
503
485
  * **Return Types:**
504
486
  * - `boolean` - Hard decision: immediately returns this value (short-circuits)
505
487
  * - `{ defaultShouldRevalidate: boolean }` - Soft decision: updates suggestion for next revalidator
488
+ * - `void` / `null` / `undefined` - Defer to the current suggestion (no opinion); the
489
+ * loop continues to the next revalidator without changing the running default
506
490
  *
507
491
  * **Execution Flow:**
508
492
  * 1. Start with built-in `defaultShouldRevalidate` (true if params changed)
509
493
  * 2. Execute global revalidators first, then route-specific
510
494
  * 3. Hard decision (boolean): stop immediately and use that value
511
495
  * 4. Soft decision (object): update suggestion and continue to next revalidator
512
- * 5. If all return soft decisions: use the final suggestion
496
+ * 5. Defer (`void` / `null` / `undefined`): leave suggestion unchanged and continue
497
+ * 6. If no hard decision was returned: use the final running suggestion
513
498
  *
514
499
  * @param args.currentParams - Previous route params (generic by default, can be narrowed)
515
500
  * @param args.currentUrl - Previous URL
@@ -519,9 +504,10 @@ export type RevalidateParams<TParams = GenericParams, TEnv = any> = Parameters<
519
504
  * @param args.context - App context (db, user, etc.)
520
505
  * @param args.actionResult - Result from action (future support)
521
506
  * @param args.formData - Form data from action (future support)
522
- * @param args.formMethod - HTTP method from action (future support)
507
+ * @param args.method - HTTP method: "GET" for navigation, "POST" for server actions
523
508
  *
524
- * @returns Hard decision (boolean) or soft suggestion (object)
509
+ * @returns Hard decision (boolean), soft suggestion (object), or defer
510
+ * (`void` / `null` / `undefined`) to keep the running suggestion as-is.
525
511
  *
526
512
  * @example
527
513
  * ```typescript
@@ -541,20 +527,46 @@ export type RevalidateParams<TParams = GenericParams, TEnv = any> = Parameters<
541
527
  * })
542
528
  * ```
543
529
  */
530
+ /**
531
+ * A reference to a server action, used by `isAction()` in a revalidate predicate.
532
+ *
533
+ * Either a directly imported action (`import { addToCart }`) or a namespace
534
+ * import of an action module (`import * as CartActions`). Matching resolves the
535
+ * action's build-injected id (`path#export`) — the same identity the router uses
536
+ * for `actionId` — so a renamed or moved action breaks at compile time instead
537
+ * of silently failing to match.
538
+ */
539
+ export type ActionRef =
540
+ | ((...args: never[]) => unknown)
541
+ | Record<string, unknown>;
542
+
544
543
  /**
545
544
  * Revalidation function called during client-side navigation to decide whether
546
545
  * a segment (layout, route, parallel slot, or loader) should be re-rendered.
547
546
  *
548
547
  * Return `true` to re-render, `false` to skip (keep client's current version),
549
- * or `{ defaultShouldRevalidate: boolean }` to override the default for
550
- * downstream segments.
548
+ * `{ defaultShouldRevalidate: boolean }` to update the running suggestion for
549
+ * downstream revalidators, or nothing (`void` / `null` / `undefined`) to defer
550
+ * to the current suggestion without changing it.
551
+ *
552
+ * Two idioms cover almost every case; they differ only in what an _unrelated_
553
+ * action does. Match actions by reference with `ctx.isAction()` (rename-safe)
554
+ * rather than `actionId?.includes("...")` (a renamed or moved action silently
555
+ * stops matching). Because `isAction` returns a raw boolean, combine it with
556
+ * `|| undefined` to defer or leave it bare to suppress.
551
557
  *
552
558
  * @example
553
559
  * ```ts
554
- * // Re-render only when a cart action happened or browser signals staleness
555
- * revalidate(({ actionId, stale }) =>
556
- * actionId?.includes("cart") || stale || false
557
- * )
560
+ * import * as CartActions from "./actions/cart";
561
+ *
562
+ * // Idiom A — "mine, else defer": re-render on my actions, otherwise return
563
+ * // undefined so the segment's default decision still applies (and downstream
564
+ * // revalidators get a say).
565
+ * revalidate((ctx) => ctx.isAction(CartActions) || undefined)
566
+ *
567
+ * // Idiom B — "mine only": re-render on my actions and suppress everything
568
+ * // else (isAction returns a raw boolean, so an unrelated action yields false).
569
+ * revalidate((ctx) => ctx.isAction(CartActions))
558
570
  *
559
571
  * // Always re-render when params change (default behavior made explicit)
560
572
  * revalidate(({ defaultShouldRevalidate }) => defaultShouldRevalidate)
@@ -580,8 +592,11 @@ export type ShouldRevalidateFn<TParams = GenericParams, TEnv = any> = (args: {
580
592
 
581
593
  // ── Segment metadata (which segment is being evaluated) ──────────────
582
594
 
583
- /** The type of segment being revalidated. */
584
- segmentType: "layout" | "route" | "parallel";
595
+ /**
596
+ * The type of segment being revalidated. `"loader"` is passed to revalidate
597
+ * functions attached to a `loader(Fn, () => [revalidate(...)])` registration.
598
+ */
599
+ segmentType: "layout" | "route" | "parallel" | "loader";
585
600
  /** Layout name (e.g., `"root"`, `"shop"`, `"auth"`). Only set for layout segments. */
586
601
  layoutName?: string;
587
602
  /** Slot name (e.g., `"@sidebar"`, `"@modal"`). Only set for parallel segments. */
@@ -597,21 +612,54 @@ export type ShouldRevalidateFn<TParams = GenericParams, TEnv = any> = (args: {
597
612
  * relative to the project root, followed by `#` and the exported function name.
598
613
  *
599
614
  * This is stable and can be used for path-based matching to revalidate
600
- * when any action in a module or directory fires:
615
+ * when any action in a module or directory fires. Prefer `|| undefined`
616
+ * (defer to the segment default / downstream revalidators) over `?? false`
617
+ * (hard short-circuit that suppresses the default and ends the chain):
601
618
  *
602
619
  * @example
603
620
  * ```ts
604
621
  * // Match a specific action
605
- * revalidate(({ actionId }) => actionId === "src/actions/cart.ts#addToCart")
622
+ * revalidate(({ actionId }) => actionId === "src/actions/cart.ts#addToCart" || undefined)
606
623
  *
607
624
  * // Match any action in the cart module
608
- * revalidate(({ actionId }) => actionId?.includes("cart") ?? false)
625
+ * revalidate(({ actionId }) => actionId?.includes("cart") || undefined)
609
626
  *
610
627
  * // Match any action under src/apps/store/actions/
611
- * revalidate(({ actionId }) => actionId?.startsWith("src/apps/store/actions/") ?? false)
628
+ * revalidate(({ actionId }) => actionId?.startsWith("src/apps/store/actions/") || undefined)
612
629
  * ```
613
630
  */
614
631
  actionId?: string;
632
+ /**
633
+ * Typed, rename-safe action matching. Returns `true` when the action that
634
+ * triggered this revalidation is one of the given references — or, for a
635
+ * namespace import (`import * as CartActions`), any export of that module —
636
+ * and `false` otherwise (including plain navigation with no action).
637
+ *
638
+ * Called with NO arguments it answers "is this request an action at all?":
639
+ * `true` for any action, `false` on plain navigation. Use the bare form when
640
+ * you want to revalidate on every action regardless of which one fired.
641
+ *
642
+ * Prefer this over hand-written `actionId` substring matches: it resolves the
643
+ * action's stable `path#export` id from the imported reference, so a rename is
644
+ * a type error in one place instead of silent drift across consumers. It
645
+ * resolves the reference the same way the action boundary derives `actionId`
646
+ * (`$id ?? $$id`), so it matches in both dev and production.
647
+ *
648
+ * Returns a raw boolean, so for the common "revalidate on match, else defer"
649
+ * intent combine with `|| undefined`:
650
+ *
651
+ * @example
652
+ * ```ts
653
+ * import { addToCart, removeFromCart } from "./actions/cart";
654
+ * import * as CartActions from "./actions/cart";
655
+ *
656
+ * revalidate((ctx) => ctx.isAction() || undefined); // any action
657
+ * revalidate((ctx) => ctx.isAction(addToCart) || undefined); // one action
658
+ * revalidate((ctx) => ctx.isAction(addToCart, removeFromCart) || undefined); // several
659
+ * revalidate((ctx) => ctx.isAction(CartActions) || undefined); // any in the module
660
+ * ```
661
+ */
662
+ isAction: (...actions: ActionRef[]) => boolean;
615
663
  /** URL where the action was executed (the page the user was on when they triggered the action). */
616
664
  actionUrl?: URL;
617
665
  /** Return value from the action execution. Can be used to conditionally revalidate based on the action's outcome. */
@@ -647,7 +695,7 @@ export type ShouldRevalidateFn<TParams = GenericParams, TEnv = any> = (args: {
647
695
  * action that may have mutated backend state.
648
696
  */
649
697
  stale?: boolean;
650
- }) => boolean | { defaultShouldRevalidate: boolean };
698
+ }) => boolean | { defaultShouldRevalidate: boolean } | null | void;
651
699
 
652
700
  // MiddlewareFn is imported from "../router/middleware.js" and re-exported
653
701
 
@@ -752,7 +800,7 @@ export type Revalidate<
752
800
  * Middleware function with typed params and environment
753
801
  *
754
802
  * @template TParams - Params object (defaults to generic)
755
- * @template TEnv - Environment type (defaults to global RSCRouter.Env)
803
+ * @template TEnv - Environment type (defaults to global Rango.Env)
756
804
  *
757
805
  * Note: Middleware cannot directly use route names for params typing because
758
806
  * middleware is defined during router setup, before RegisteredRoutes is populated.
@@ -760,7 +808,7 @@ export type Revalidate<
760
808
  *
761
809
  * @example
762
810
  * ```typescript
763
- * // Basic middleware (uses global RSCRouter.Env via module augmentation)
811
+ * // Basic middleware (uses global Rango.Env via module augmentation)
764
812
  * const middleware: Middleware = async (ctx, next) => {
765
813
  * ctx.set("user", { id: "123" }); // Type-safe!
766
814
  * await next();