@rangojs/router 0.0.0-experimental.dfdb0387 → 0.0.0-experimental.e16b7c00

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 (237) hide show
  1. package/README.md +120 -25
  2. package/dist/bin/rango.js +147 -57
  3. package/dist/vite/index.js +2106 -842
  4. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  5. package/package.json +13 -8
  6. package/skills/breadcrumbs/SKILL.md +3 -1
  7. package/skills/bundle-analysis/SKILL.md +159 -0
  8. package/skills/cache-guide/SKILL.md +222 -30
  9. package/skills/caching/SKILL.md +188 -8
  10. package/skills/composability/SKILL.md +27 -2
  11. package/skills/document-cache/SKILL.md +78 -55
  12. package/skills/handler-use/SKILL.md +364 -0
  13. package/skills/hooks/SKILL.md +229 -20
  14. package/skills/host-router/SKILL.md +45 -20
  15. package/skills/i18n/SKILL.md +276 -0
  16. package/skills/intercept/SKILL.md +46 -4
  17. package/skills/layout/SKILL.md +28 -7
  18. package/skills/links/SKILL.md +247 -17
  19. package/skills/loader/SKILL.md +219 -9
  20. package/skills/middleware/SKILL.md +47 -12
  21. package/skills/migrate-nextjs/SKILL.md +582 -0
  22. package/skills/migrate-react-router/SKILL.md +769 -0
  23. package/skills/mime-routes/SKILL.md +27 -0
  24. package/skills/observability/SKILL.md +137 -0
  25. package/skills/parallel/SKILL.md +71 -6
  26. package/skills/prerender/SKILL.md +14 -33
  27. package/skills/rango/SKILL.md +236 -22
  28. package/skills/react-compiler/SKILL.md +168 -0
  29. package/skills/response-routes/SKILL.md +66 -9
  30. package/skills/route/SKILL.md +57 -4
  31. package/skills/router-setup/SKILL.md +3 -3
  32. package/skills/server-actions/SKILL.md +751 -0
  33. package/skills/streams-and-websockets/SKILL.md +283 -0
  34. package/skills/typesafety/SKILL.md +319 -27
  35. package/skills/use-cache/SKILL.md +36 -5
  36. package/skills/view-transitions/SKILL.md +294 -0
  37. package/src/__augment-tests__/augment.ts +81 -0
  38. package/src/__augment-tests__/augmented.check.ts +117 -0
  39. package/src/browser/action-coordinator.ts +53 -36
  40. package/src/browser/app-shell.ts +52 -0
  41. package/src/browser/event-controller.ts +86 -70
  42. package/src/browser/history-state.ts +21 -0
  43. package/src/browser/index.ts +3 -3
  44. package/src/browser/navigation-bridge.ts +86 -11
  45. package/src/browser/navigation-client.ts +45 -25
  46. package/src/browser/navigation-store.ts +32 -9
  47. package/src/browser/navigation-transaction.ts +10 -28
  48. package/src/browser/partial-update.ts +61 -28
  49. package/src/browser/prefetch/cache.ts +124 -26
  50. package/src/browser/prefetch/fetch.ts +129 -37
  51. package/src/browser/prefetch/queue.ts +36 -5
  52. package/src/browser/rango-state.ts +53 -13
  53. package/src/browser/react/Link.tsx +18 -13
  54. package/src/browser/react/NavigationProvider.tsx +72 -31
  55. package/src/browser/react/filter-segment-order.ts +51 -7
  56. package/src/browser/react/index.ts +3 -0
  57. package/src/browser/react/location-state-shared.ts +175 -4
  58. package/src/browser/react/location-state.ts +39 -13
  59. package/src/browser/react/use-handle.ts +17 -9
  60. package/src/browser/react/use-navigation.ts +22 -2
  61. package/src/browser/react/use-params.ts +20 -8
  62. package/src/browser/react/use-reverse.ts +106 -0
  63. package/src/browser/react/use-router.ts +22 -2
  64. package/src/browser/react/use-segments.ts +11 -8
  65. package/src/browser/response-adapter.ts +25 -0
  66. package/src/browser/rsc-router.tsx +64 -22
  67. package/src/browser/scroll-restoration.ts +22 -14
  68. package/src/browser/segment-reconciler.ts +10 -14
  69. package/src/browser/segment-structure-assert.ts +2 -2
  70. package/src/browser/server-action-bridge.ts +23 -30
  71. package/src/browser/types.ts +21 -0
  72. package/src/build/collect-fallback-refs.ts +107 -0
  73. package/src/build/generate-manifest.ts +60 -35
  74. package/src/build/generate-route-types.ts +2 -0
  75. package/src/build/index.ts +2 -0
  76. package/src/build/route-trie.ts +52 -25
  77. package/src/build/route-types/codegen.ts +4 -4
  78. package/src/build/route-types/include-resolution.ts +1 -1
  79. package/src/build/route-types/per-module-writer.ts +7 -4
  80. package/src/build/route-types/router-processing.ts +55 -14
  81. package/src/build/route-types/scan-filter.ts +1 -1
  82. package/src/build/route-types/source-scan.ts +118 -0
  83. package/src/build/runtime-discovery.ts +9 -20
  84. package/src/cache/cache-error.ts +104 -0
  85. package/src/cache/cache-policy.ts +95 -1
  86. package/src/cache/cache-runtime.ts +79 -13
  87. package/src/cache/cache-scope.ts +77 -46
  88. package/src/cache/cache-tag.ts +135 -0
  89. package/src/cache/cf/cf-cache-store.ts +1067 -176
  90. package/src/cache/cf/index.ts +4 -1
  91. package/src/cache/document-cache.ts +59 -7
  92. package/src/cache/index.ts +6 -0
  93. package/src/cache/memory-segment-store.ts +158 -14
  94. package/src/cache/tag-invalidation.ts +206 -0
  95. package/src/cache/types.ts +27 -0
  96. package/src/client.rsc.tsx +3 -0
  97. package/src/client.tsx +92 -182
  98. package/src/context-var.ts +5 -5
  99. package/src/decode-loader-results.ts +36 -0
  100. package/src/errors.ts +30 -1
  101. package/src/handle.ts +4 -6
  102. package/src/host/index.ts +2 -2
  103. package/src/host/router.ts +129 -57
  104. package/src/host/types.ts +31 -2
  105. package/src/host/utils.ts +1 -1
  106. package/src/href-client.ts +140 -20
  107. package/src/index.rsc.ts +16 -4
  108. package/src/index.ts +65 -15
  109. package/src/loader-store.ts +500 -0
  110. package/src/loader.rsc.ts +2 -5
  111. package/src/loader.ts +3 -10
  112. package/src/missing-id-error.ts +68 -0
  113. package/src/outlet-context.ts +1 -1
  114. package/src/prerender.ts +4 -4
  115. package/src/response-utils.ts +37 -0
  116. package/src/reverse.ts +65 -36
  117. package/src/route-content-wrapper.tsx +6 -28
  118. package/src/route-definition/dsl-helpers.ts +384 -257
  119. package/src/route-definition/helper-factories.ts +29 -139
  120. package/src/route-definition/helpers-types.ts +100 -28
  121. package/src/route-definition/resolve-handler-use.ts +6 -0
  122. package/src/route-definition/use-item-types.ts +32 -0
  123. package/src/route-types.ts +26 -41
  124. package/src/router/content-negotiation.ts +15 -2
  125. package/src/router/error-handling.ts +1 -1
  126. package/src/router/handler-context.ts +21 -38
  127. package/src/router/intercept-resolution.ts +4 -18
  128. package/src/router/lazy-includes.ts +8 -8
  129. package/src/router/loader-resolution.ts +19 -2
  130. package/src/router/manifest.ts +22 -13
  131. package/src/router/match-api.ts +4 -3
  132. package/src/router/match-handlers.ts +1 -0
  133. package/src/router/match-middleware/cache-lookup.ts +46 -92
  134. package/src/router/match-middleware/cache-store.ts +3 -2
  135. package/src/router/match-result.ts +53 -32
  136. package/src/router/metrics.ts +1 -1
  137. package/src/router/middleware-types.ts +15 -26
  138. package/src/router/middleware.ts +99 -84
  139. package/src/router/pattern-matching.ts +101 -17
  140. package/src/router/prerender-match.ts +3 -1
  141. package/src/router/preview-match.ts +3 -1
  142. package/src/router/request-classification.ts +4 -28
  143. package/src/router/revalidation.ts +58 -2
  144. package/src/router/router-interfaces.ts +45 -28
  145. package/src/router/router-options.ts +25 -1
  146. package/src/router/router-registry.ts +2 -5
  147. package/src/router/segment-resolution/fresh.ts +27 -6
  148. package/src/router/segment-resolution/loader-cache.ts +8 -17
  149. package/src/router/segment-resolution/revalidation.ts +147 -106
  150. package/src/router/segment-resolution/view-transition-default.ts +36 -0
  151. package/src/router/substitute-pattern-params.ts +56 -0
  152. package/src/router/trie-matching.ts +18 -13
  153. package/src/router/types.ts +8 -0
  154. package/src/router/url-params.ts +49 -0
  155. package/src/router.ts +23 -18
  156. package/src/rsc/handler-context.ts +2 -2
  157. package/src/rsc/handler.ts +38 -70
  158. package/src/rsc/helpers.ts +72 -43
  159. package/src/rsc/index.ts +1 -1
  160. package/src/rsc/origin-guard.ts +28 -10
  161. package/src/rsc/progressive-enhancement.ts +4 -0
  162. package/src/rsc/response-route-handler.ts +54 -54
  163. package/src/rsc/rsc-rendering.ts +35 -51
  164. package/src/rsc/runtime-warnings.ts +9 -10
  165. package/src/rsc/server-action.ts +17 -37
  166. package/src/rsc/ssr-setup.ts +16 -0
  167. package/src/rsc/types.ts +8 -2
  168. package/src/search-params.ts +4 -4
  169. package/src/segment-content-promise.ts +67 -0
  170. package/src/segment-loader-promise.ts +122 -0
  171. package/src/segment-system.tsx +132 -116
  172. package/src/serialize.ts +243 -0
  173. package/src/server/context.ts +143 -53
  174. package/src/server/cookie-store.ts +28 -4
  175. package/src/server/request-context.ts +46 -44
  176. package/src/ssr/index.tsx +5 -1
  177. package/src/static-handler.ts +1 -1
  178. package/src/types/cache-types.ts +13 -4
  179. package/src/types/error-types.ts +5 -1
  180. package/src/types/global-namespace.ts +39 -26
  181. package/src/types/handler-context.ts +68 -50
  182. package/src/types/index.ts +1 -0
  183. package/src/types/loader-types.ts +5 -6
  184. package/src/types/request-scope.ts +126 -0
  185. package/src/types/route-entry.ts +11 -0
  186. package/src/types/segments.ts +35 -2
  187. package/src/urls/include-helper.ts +34 -67
  188. package/src/urls/index.ts +0 -3
  189. package/src/urls/path-helper-types.ts +41 -7
  190. package/src/urls/path-helper.ts +17 -52
  191. package/src/urls/pattern-types.ts +36 -19
  192. package/src/urls/response-types.ts +22 -29
  193. package/src/urls/type-extraction.ts +26 -116
  194. package/src/urls/urls-function.ts +1 -5
  195. package/src/use-loader.tsx +413 -42
  196. package/src/vite/debug.ts +185 -0
  197. package/src/vite/discovery/bundle-postprocess.ts +6 -6
  198. package/src/vite/discovery/discover-routers.ts +101 -51
  199. package/src/vite/discovery/discovery-errors.ts +194 -0
  200. package/src/vite/discovery/gate-state.ts +171 -0
  201. package/src/vite/discovery/prerender-collection.ts +67 -26
  202. package/src/vite/discovery/route-types-writer.ts +40 -84
  203. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  204. package/src/vite/discovery/state.ts +33 -0
  205. package/src/vite/discovery/virtual-module-codegen.ts +13 -23
  206. package/src/vite/index.ts +2 -0
  207. package/src/vite/plugin-types.ts +67 -0
  208. package/src/vite/plugins/cjs-to-esm.ts +8 -7
  209. package/src/vite/plugins/client-ref-dedup.ts +16 -0
  210. package/src/vite/plugins/client-ref-hashing.ts +28 -5
  211. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  212. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  213. package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
  214. package/src/vite/plugins/expose-action-id.ts +54 -30
  215. package/src/vite/plugins/expose-id-utils.ts +12 -8
  216. package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
  217. package/src/vite/plugins/expose-ids/handler-transform.ts +8 -61
  218. package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
  219. package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
  220. package/src/vite/plugins/expose-internal-ids.ts +496 -486
  221. package/src/vite/plugins/performance-tracks.ts +29 -25
  222. package/src/vite/plugins/use-cache-transform.ts +65 -50
  223. package/src/vite/plugins/version-injector.ts +39 -23
  224. package/src/vite/plugins/version-plugin.ts +59 -2
  225. package/src/vite/plugins/virtual-entries.ts +2 -2
  226. package/src/vite/rango.ts +116 -29
  227. package/src/vite/router-discovery.ts +750 -100
  228. package/src/vite/utils/ast-handler-extract.ts +15 -15
  229. package/src/vite/utils/banner.ts +1 -1
  230. package/src/vite/utils/bundle-analysis.ts +4 -2
  231. package/src/vite/utils/client-chunks.ts +190 -0
  232. package/src/vite/utils/forward-user-plugins.ts +193 -0
  233. package/src/vite/utils/manifest-utils.ts +21 -5
  234. package/src/vite/utils/package-resolution.ts +41 -1
  235. package/src/vite/utils/prerender-utils.ts +21 -6
  236. package/src/vite/utils/shared-utils.ts +107 -26
  237. package/src/browser/action-response-classifier.ts +0 -99
@@ -0,0 +1,364 @@
1
+ ---
2
+ name: handler-use
3
+ description: Attach default loaders, middleware, parallels, and other use items directly to handlers via handler.use, and compose them with explicit use() at mount sites
4
+ argument-hint: "[handler]"
5
+ ---
6
+
7
+ # Handler-Attached `.use`
8
+
9
+ A handler function (or branded `Static`/`Prerender`/`Passthrough` definition) can carry its own defaults via a `.use` callback that returns an array of `use` items (loader, middleware, parallel, intercept, layout, loading, etc.). The mount-site DSL (`path()`, `layout()`, `parallel()`, `intercept()`) merges those defaults with any explicit `use()` callback supplied at the registration site.
10
+
11
+ This lets handlers be **self-contained, reusable units** — a page brings its own loader, a layout brings its own middleware, a parallel slot brings its own data + skeleton — without forcing every caller to wire the same items at every mount site.
12
+
13
+ Canonical implementation reference:
14
+ [src/route-definition/resolve-handler-use.ts](../../src/route-definition/resolve-handler-use.ts)
15
+
16
+ ## Defining a handler with `.use`
17
+
18
+ Attach `.use` to the function (or to the branded definition for `Static()`/`Prerender()`/`Passthrough()`):
19
+
20
+ ```typescript
21
+ import {
22
+ loader,
23
+ middleware,
24
+ loading,
25
+ createLoader,
26
+ type Handler,
27
+ } from "@rangojs/router";
28
+
29
+ export const ProductLoader = createLoader(async (ctx) =>
30
+ fetchProduct(ctx.params.slug),
31
+ );
32
+
33
+ const ProductPage: Handler<"/product/:slug"> = async (ctx) => {
34
+ const product = await ctx.use(ProductLoader);
35
+ return <ProductView product={product} />;
36
+ };
37
+
38
+ ProductPage.use = () => [
39
+ loader(ProductLoader),
40
+ loading(<ProductSkeleton />),
41
+ middleware(async (ctx, next) => {
42
+ await next();
43
+ ctx.header("Cache-Control", "private, max-age=60");
44
+ }),
45
+ ];
46
+ ```
47
+
48
+ Now `ProductPage` carries its loader, loading state, and response-header middleware regardless of where it is mounted.
49
+
50
+ ## Allowed items per mount site
51
+
52
+ `handler.use()` is the same callback shape regardless of where the handler runs, but the runtime validates that the items it returns are valid for the mount site. Driven by `MOUNT_SITE_ALLOWED_TYPES` in [resolve-handler-use.ts](../../src/route-definition/resolve-handler-use.ts):
53
+
54
+ | Mount site | Allowed item types |
55
+ | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
56
+ | `path()` / `route()` | `layout`, `parallel`, `intercept`, `middleware`, `revalidate`, `loader`, `loading`, `errorBoundary`, `notFoundBoundary`, `cache`, `transition` |
57
+ | `layout()` | All of the above, plus `route`, `include` |
58
+ | `parallel()` (per slot) | `revalidate`, `loader`, `loading`, `errorBoundary`, `notFoundBoundary`, `transition` |
59
+ | `intercept()` | `middleware`, `revalidate`, `loader`, `loading`, `errorBoundary`, `notFoundBoundary`, `layout`, `route`, `when`, `transition` |
60
+ | Response routes (`path.json()`, `path.text()`, …) | `middleware`, `cache` |
61
+
62
+ For per-item semantics see the dedicated skills: [middleware](../middleware/SKILL.md), [loader](../loader/SKILL.md), [parallel](../parallel/SKILL.md), [intercept](../intercept/SKILL.md), [layout](../layout/SKILL.md), [view-transitions](../view-transitions/SKILL.md).
63
+
64
+ If `handler.use()` returns a disallowed item for a mount site, registration throws:
65
+
66
+ ```
67
+ handler.use() returned middleware() which is not valid inside parallel().
68
+ Allowed types: revalidate, loader, loading, errorBoundary, notFoundBoundary, transition.
69
+ ```
70
+
71
+ The narrowest contract is `parallel()` — slots cannot bring their own middleware or layout; only data, loading, error/notFound boundaries, revalidation, and transitions.
72
+
73
+ ## Composition with explicit `use()`
74
+
75
+ Every mount site that takes a `use` callback merges in this order:
76
+
77
+ 1. **`handler.use()` items first** — the handler's defaults.
78
+ 2. **Explicit `use()` items second** — overrides specified at the mount site.
79
+
80
+ Items of the same kind from the explicit `use()` follow the existing override rules of that item type. The most important ones for composition:
81
+
82
+ - **`loading()`** — last definition wins, so explicit `loading()` replaces the handler's default.
83
+ - **`parallel({ "@slot": … })`** — the last `parallel()` call wins per slot name. Other slots from earlier calls are preserved (see `skills/parallel`).
84
+ - **`loader()`, `middleware()`, etc.** — accumulate; both the handler's and the explicit ones run.
85
+
86
+ Skip the boilerplate: if neither `handler.use` nor explicit `use()` is provided, no merge happens.
87
+
88
+ ```typescript
89
+ // Handler brings a loader + a (placeholder) loading; explicit use replaces loading.
90
+ const SidebarSlot: Handler = async (ctx) => {
91
+ const data = await ctx.use(SidebarLoader);
92
+ return <Sidebar data={data} />;
93
+ };
94
+ SidebarSlot.use = () => [
95
+ loader(SidebarLoader),
96
+ loading(<DefaultSidebarSkeleton />),
97
+ ];
98
+
99
+ parallel({ "@sidebar": SidebarSlot }, () => [
100
+ // Replaces the default skeleton; SidebarLoader from handler.use still runs.
101
+ loading(<SiteSpecificSidebarSkeleton />),
102
+ ]);
103
+ ```
104
+
105
+ ## Composable parallel slots (the main pay-off)
106
+
107
+ The parallel slot site is where `handler.use` shines. A slot handler that owns its data/loading lets a layout declare **just** the slot names — every loader, skeleton, and revalidation contract travels with the slot itself.
108
+
109
+ ### Without `handler.use` (every caller wires it up)
110
+
111
+ ```typescript
112
+ layout(<DashboardLayout />, () => [
113
+ parallel({ "@cart": CartSummary }, () => [
114
+ loader(CartLoader),
115
+ loading(<CartSkeleton />),
116
+ revalidate(revalidateCartData),
117
+ ]),
118
+ parallel({ "@notifs": NotificationPanel }, () => [
119
+ loader(NotificationsLoader),
120
+ loading(<NotifsSkeleton />),
121
+ revalidate(revalidateNotifs),
122
+ ]),
123
+ path("/dashboard", DashboardIndex, { name: "dashboard.index" }),
124
+ ]);
125
+ ```
126
+
127
+ Every layout that wants `@cart` must repeat the same loader/loading/revalidate triplet.
128
+
129
+ ### With `handler.use` (slot owns its dependencies)
130
+
131
+ ```typescript
132
+ const CartSummary: Handler = async (ctx) => {
133
+ const cart = await ctx.use(CartLoader);
134
+ return <CartSummaryView cart={cart} />;
135
+ };
136
+ CartSummary.use = () => [
137
+ loader(CartLoader),
138
+ loading(<CartSkeleton />),
139
+ revalidate(revalidateCartData),
140
+ ];
141
+
142
+ const NotificationPanel: Handler = async (ctx) => {
143
+ const items = await ctx.use(NotificationsLoader);
144
+ return <NotificationsView items={items} />;
145
+ };
146
+ NotificationPanel.use = () => [
147
+ loader(NotificationsLoader),
148
+ loading(<NotifsSkeleton />),
149
+ revalidate(revalidateNotifs),
150
+ ];
151
+
152
+ // Mount sites become declarative — no per-call data wiring.
153
+ layout(<DashboardLayout />, () => [
154
+ parallel({ "@cart": CartSummary, "@notifs": NotificationPanel }),
155
+ path("/dashboard", DashboardIndex, { name: "dashboard.index" }),
156
+ ]);
157
+
158
+ layout(<AccountLayout />, () => [
159
+ // Same slot, same defaults, zero re-wiring.
160
+ parallel({ "@cart": CartSummary }),
161
+ path("/account", AccountIndex, { name: "account.index" }),
162
+ ]);
163
+ ```
164
+
165
+ Each slot handler is now a portable, self-contained unit. Different layouts can use the same slot without copying data plumbing.
166
+
167
+ ### Streaming behavior is per-slot
168
+
169
+ A slot's `loading()` (whether from `handler.use` or explicit) makes that slot an independent streaming unit — its loader does not block the parent layout. Two slot handlers with their own loading skeletons stream independently.
170
+
171
+ ```typescript
172
+ parallel({
173
+ "@cart": CartSummary, // handler.use loading() → streams independently
174
+ "@cartBadge": CartBadge, // no loading() anywhere → awaited before paint
175
+ });
176
+ ```
177
+
178
+ ### Two scopes for explicit `use` at the mount site: shared (broadcast) and slot-local
179
+
180
+ `parallel()` accepts an explicit `use()` callback that **broadcasts** to every slot in the call ([dsl-helpers.ts](../../src/route-definition/dsl-helpers.ts)). That's the right behavior for the items the parallel allow-list permits and that accumulate (`loader`, `revalidate`, `errorBoundary`, `notFoundBoundary`, `transition`) — every slot gets them. (Note: `middleware` is not allowed inside `parallel()`; see the allowed-types table above.)
181
+
182
+ For single-assignment items like `loading()`, broadcasting overwrites every slot's `handler.use` default. Pass a **slot descriptor** `{ handler, use }` instead: items in the descriptor's `use` apply only to that slot.
183
+
184
+ ```typescript
185
+ parallel({
186
+ "@meta": MetaSlot,
187
+ "@sidebar": {
188
+ handler: SidebarSlot,
189
+ use: () => [loading(<SidebarSkeleton />)], // ← only @sidebar
190
+ },
191
+ });
192
+ ```
193
+
194
+ Per-slot merge order is **handler.use → shared use → slot-local use** (narrowest scope wins for last-write-wins items like `loading()`):
195
+
196
+ ```typescript
197
+ parallel(
198
+ {
199
+ "@cart": {
200
+ handler: Cart,
201
+ use: () => [loading(<CartSkeleton />)], // wins for @cart
202
+ },
203
+ "@notifs": Notifs, // gets <BroadcastSkeleton />
204
+ },
205
+ () => [
206
+ loader(SharedAnalyticsLoader), // accumulates on every slot
207
+ loading(<BroadcastSkeleton />), // applies to slots without slot-local
208
+ ],
209
+ );
210
+ ```
211
+
212
+ Use the descriptor's `use` for `loading(false)` too — opting one slot out of streaming without affecting siblings:
213
+
214
+ ```typescript
215
+ parallel(
216
+ {
217
+ "@cart": { handler: Cart, use: () => [loading(false)] }, // @cart awaits
218
+ "@notifs": Notifs, // @notifs still streams with broadcast skeleton
219
+ },
220
+ () => [loading(<BroadcastSkeleton />)],
221
+ );
222
+ ```
223
+
224
+ Rule of thumb: shared `use` is for items that legitimately apply to every slot. Slot-local `use` is for per-slot precision — especially `loading()` and `loading(false)`.
225
+
226
+ ### Replacing a whole slot from a parent's `handler.use`
227
+
228
+ A handler can publish a default `parallel({...})` set via its `.use`, and the mount site can replace any individual slot by re-declaring it. Last `parallel()` per slot name wins (see `skills/parallel` § Slot Override Semantics).
229
+
230
+ ```typescript
231
+ const ProductPage: Handler<"/product/:slug"> = (ctx) => (
232
+ <article>
233
+ <ProductHero slug={ctx.params.slug} />
234
+ <ParallelOutlet name="@related" />
235
+ <ParallelOutlet name="@reviews" />
236
+ </article>
237
+ );
238
+ ProductPage.use = () => [
239
+ parallel({
240
+ "@related": DefaultRelatedProducts,
241
+ "@reviews": DefaultReviews,
242
+ }),
243
+ ];
244
+
245
+ path("/product/:slug", ProductPage, { name: "product" }, () => [
246
+ // Override @related only; @reviews keeps the default from handler.use.
247
+ parallel({ "@related": SiteSpecificRelated }),
248
+ ]);
249
+ ```
250
+
251
+ ## Other mount sites
252
+
253
+ ### Pages (`path()`)
254
+
255
+ Page handlers can carry middleware, loaders, error boundaries, parallel slots, etc. — anything from the `path` row of the table above.
256
+
257
+ ```typescript
258
+ const CheckoutPage: Handler<"/checkout"> = async (ctx) => { /* … */ };
259
+ CheckoutPage.use = () => [
260
+ middleware(requireAuth),
261
+ loader(CartLoader),
262
+ errorBoundary(<CheckoutError />),
263
+ notFoundBoundary(<CheckoutNotFound />),
264
+ ];
265
+ ```
266
+
267
+ ### Layouts (`layout()`)
268
+
269
+ Layout handlers can carry middleware that runs for every child route, plus default parallels, includes, etc.
270
+
271
+ ```typescript
272
+ const AdminLayout: Handler = (ctx) => {
273
+ const user = ctx.get(CurrentUser);
274
+ return <Admin user={user} />;
275
+ };
276
+ AdminLayout.use = () => [
277
+ middleware(requireAdmin),
278
+ parallel({ "@adminNotifs": AdminNotifsSlot }),
279
+ ];
280
+ ```
281
+
282
+ ### Intercepts (`intercept()`)
283
+
284
+ Intercept handlers can carry their own middleware chain, loaders, and even nested layouts/routes for the modal shell.
285
+
286
+ ```typescript
287
+ const QuickViewModal: Handler = async (ctx) => {
288
+ const product = await ctx.use(ProductLoader);
289
+ return <QuickView product={product} />;
290
+ };
291
+ QuickViewModal.use = () => [
292
+ loader(ProductLoader),
293
+ loading(<QuickViewSkeleton />),
294
+ layout(<ModalChrome />),
295
+ ];
296
+ ```
297
+
298
+ ## `loading()` is a single-assignment item — scope it correctly
299
+
300
+ Most `use` items accumulate when merged: `handler.use` `middleware()` runs _and_ explicit `middleware()` runs; both `loader()` registrations apply. `loading()` is different — it mutates `entry.loading` directly, last call wins ([dsl-helpers.ts `loading`](../../src/route-definition/dsl-helpers.ts)).
301
+
302
+ For pages, layouts, and intercepts that's straightforward: explicit `loading()` at the mount site replaces any `loading()` from `handler.use`. The merge order is `handler.use → explicit`, so the explicit one is the last writer and wins.
303
+
304
+ For parallel slots, the shared `parallel(..., () => [...])` callback is **broadcast** to every slot in the call. A single `loading()` placed there lands on every slot, overwriting each slot's `handler.use` default. To scope `loading()` to one slot, use the **slot descriptor** form:
305
+
306
+ ```typescript
307
+ const Cart: Handler = async (ctx) => { /* … */ };
308
+ Cart.use = () => [loader(CartLoader), loading(<CartSkeleton />)];
309
+
310
+ const Notifs: Handler = async (ctx) => { /* … */ };
311
+ Notifs.use = () => [loader(NotifsLoader), loading(<NotifsSkeleton />)];
312
+
313
+ // ✅ @cart gets a custom skeleton; @notifs keeps its handler.use default.
314
+ parallel({
315
+ "@cart": {
316
+ handler: Cart,
317
+ use: () => [loading(<CustomCartSkeleton />)],
318
+ },
319
+ "@notifs": Notifs,
320
+ });
321
+
322
+ // ✅ Opt one slot out of streaming while siblings still stream the broadcast.
323
+ parallel(
324
+ {
325
+ "@cart": { handler: Cart, use: () => [loading(false)] },
326
+ "@notifs": Notifs,
327
+ },
328
+ () => [loading(<BroadcastSkeleton />)],
329
+ );
330
+ ```
331
+
332
+ Per-slot merge order is **handler.use → shared use → slot-local use**. Slot-local is the narrowest scope, so it wins for last-write-wins items like `loading()`. Items that accumulate within the parallel allow-list (`loader`, `revalidate`, `errorBoundary`, `notFoundBoundary`, `transition`) compose across all three layers regardless.
333
+
334
+ Other things to keep in mind about `loading()`:
335
+
336
+ - Any `loading()` (regardless of source) makes the segment a streaming unit. A handler that includes `loading()` in its `.use` opts every mount site into streaming by default. To opt back out, pass `loading(false)` at the mount site (`loading: false` handling in [match-middleware/segment-resolution.ts](../../src/router/match-middleware/segment-resolution.ts)) — use the slot descriptor form for parallel slots so the opt-out doesn't broadcast.
337
+
338
+ Rule of thumb: only put `loading()` in `handler.use` if you genuinely want every mount site to stream by default. Use the slot descriptor's `use` for any per-slot intent at a `parallel()` call.
339
+
340
+ ## Edge cases & gotchas
341
+
342
+ - **ReactNode handlers cannot have `.use`.** A bare JSX element passed as a handler (e.g., `path("/about", <About />)`) has no function to attach properties to. Pass a function or branded definition instead.
343
+ - **Branded handlers** — `Static()`, `Prerender()`, and `Passthrough()` are positional constructors (not object-arg). Construct first, then attach `.use` to the returned definition:
344
+
345
+ ```typescript
346
+ const ProductPage = Prerender(async (ctx) => {
347
+ const product = await fetchProduct(ctx.params.slug);
348
+ return <ProductView product={product} />;
349
+ });
350
+ ProductPage.use = () => [loader(ProductLoader)];
351
+ ```
352
+
353
+ - **Items can be flat or nested arrays.** `handler.use()` results are flattened with `.flat(3)` before validation, so factory helpers that return arrays inline work the same as in regular `use()` callbacks.
354
+ - **Validation runs at registration / first match**, not at handler definition. A handler doesn't know its mount site at definition time — the same handler used in a `path()` and an `intercept()` is validated against each mount's allowed-types set when registered.
355
+ - **No silent shadowing.** If a disallowed item slips through (e.g., a layout factory returning `cache()` from a slot's `handler.use`), the runtime throws with the offending type and mount site named.
356
+
357
+ ## Cross-references
358
+
359
+ - `skills/route` — `path()` mount site basics
360
+ - `skills/layout` — `layout()` mount site basics
361
+ - `skills/parallel` — parallel slot semantics, slot override rules, streaming behavior
362
+ - `skills/intercept` — intercept mount site basics
363
+ - `skills/loader` — defining `createLoader` and reading via `ctx.use()`
364
+ - `skills/middleware` — middleware semantics and ordering
@@ -190,6 +190,141 @@ function SearchResults() {
190
190
  }
191
191
  ```
192
192
 
193
+ **Shared refetch behavior**:
194
+
195
+ When the loader is registered on the route via `loader()`, a plain
196
+ `load()` call (no options, or a trivially-defaulted GET with no
197
+ `params` and no `body`) broadcasts its result to every component
198
+ reading the same loader id. Layout, page, and parallel-slot reads
199
+ all converge on the new value:
200
+
201
+ ```tsx
202
+ // Layout button calls load() — the page read below sees the update too.
203
+ function Layout() {
204
+ const { data, load } = useLoader(CartLoader);
205
+ return <button onClick={() => load()}>Refresh ({data.count})</button>;
206
+ }
207
+ function Page() {
208
+ const { data } = useLoader(CartLoader); // updates with the layout's load()
209
+ return <span>{data.count} items</span>;
210
+ }
211
+ ```
212
+
213
+ `isLoading` and `error` follow the same scope. `throwOnError: true`
214
+ render-throws are scoped to the **originating** hook — sibling readers
215
+ see the error in their `error` state but their boundaries are not
216
+ triggered by someone else's failure. A successful follow-up `load()`
217
+ clears the shared error.
218
+
219
+ **`load()` calls that stay local** (no broadcast, per-hook state, same
220
+ semantics as the old per-component `useState`):
221
+
222
+ - `load({ params: { ... } })` — explicit params.
223
+ - `load({ method: "POST", body })` — mutations.
224
+ - Any `load()` on a `useFetchLoader(loader)` whose loader is **not**
225
+ registered on the current route. Two unrelated components calling
226
+ `load()` on the same fetchable-but-unregistered loader keep
227
+ independent results.
228
+
229
+ So the search/list pattern still works — two components calling
230
+ `load({ params: { q } })` with different `q` values each keep their
231
+ own result; they do not collapse to last-write-wins through a shared
232
+ store.
233
+
234
+ **Scoping refetch with a `key`**:
235
+
236
+ Pass a `key` to partition the shared refresh store. Only hooks using the
237
+ **same** `key` refresh together when one of them calls `load()`. This is a
238
+ client-side refresh identity only — it never changes the request sent to the
239
+ server, and is unrelated to the server `cache({ key })` option and to
240
+ `revalidate()`.
241
+
242
+ ```tsx
243
+ // Two independent dashboards using the same loader. Without a key, one
244
+ // dashboard's load() would flip the other's spinner and value. With a key,
245
+ // they refresh independently.
246
+ function Dashboard({ id }: { id: string }) {
247
+ const { data, load } = useLoader(StatsLoader, { key: `dashboard:${id}` });
248
+ return <button onClick={() => load()}>Refresh {data.total}</button>;
249
+ }
250
+ ```
251
+
252
+ The `key` widens sharing in two ways the default cannot:
253
+
254
+ - **Parameterized GETs share.** `useFetchLoader(SearchLoader, { key: q })`
255
+ with the same `q` in two components share one result and refresh together —
256
+ a keyed `load({ params: { q } })` broadcasts to the group instead of staying
257
+ local. (Mutations — non-GET or `body` — stay local even with a key.)
258
+ - **Unregistered loaders share.** A `key` makes `useFetchLoader` of a loader
259
+ that is **not** registered on the route share too, letting unrelated
260
+ components opt into a common refresh group.
261
+
262
+ Lifecycle: a keyed read of an unregistered loader is reference-counted — its
263
+ shared value lives as long as at least one component using that key is mounted.
264
+ A persistent component (e.g. a header) keeps the value across navigations; a
265
+ route-scoped component's value is reclaimed when it unmounts. Registered-loader
266
+ reads (keyed or not) reset on navigation from fresh route data, as before.
267
+
268
+ **Refreshing multiple loaders together (`refreshGroup` + `useRefreshLoaders`)**:
269
+
270
+ `key` groups readers of one loader. To refresh **different** loaders together,
271
+ tag them with a shared `refreshGroup` name and trigger them with
272
+ `useRefreshLoaders()`. The hook takes no argument; you pass the group(s) to the
273
+ function it returns, so one `useRefreshLoaders()` can refresh different groups
274
+ depending on context. A read may carry **several** tags — pass an array — and is
275
+ refreshed when **any** of its groups is refreshed:
276
+
277
+ ```tsx
278
+ function Profile() {
279
+ const { data } = useLoader(ProfileLoader, {
280
+ key: userId,
281
+ refreshGroup: "account",
282
+ });
283
+ return <span>{data.name}</span>;
284
+ }
285
+ function Orders() {
286
+ // Tagged into two groups: refreshed by "account" (the whole set) or the
287
+ // finer "orders" tag.
288
+ const { data } = useLoader(OrdersLoader, {
289
+ key: userId,
290
+ refreshGroup: ["account", "orders"],
291
+ });
292
+ return <span>{data.count} orders</span>;
293
+ }
294
+ function RefreshButtons() {
295
+ const refresh = useRefreshLoaders();
296
+ return (
297
+ <>
298
+ <button onClick={() => refresh("account")}>Refresh account</button>
299
+ <button onClick={() => refresh("orders")}>Refresh orders only</button>
300
+ <button onClick={() => refresh(["account", "orders"])}>
301
+ Refresh both
302
+ </button>
303
+ </>
304
+ );
305
+ }
306
+ ```
307
+
308
+ `refresh(groups)` accepts one name or an array and re-runs every currently-mounted
309
+ member tagged with **any** of them, with a **plain GET** against the current route
310
+ URL — no params, no body, no mutation methods, because a group spans loaders with
311
+ different shapes. A member that sits in two of the requested groups is fetched
312
+ once (members are unioned and deduped by read). It returns a promise that resolves
313
+ when all members settle and **rejects with an `AggregateError`** if any fail;
314
+ group refresh never render-throws, so handle failures at the await site
315
+ (`await refresh("account").catch(...)`). Each failing member also exposes its
316
+ error via its own read's `error`.
317
+
318
+ Multiple tags give you granular vs. whole-set refresh from one place: a coarse
319
+ tag (`"account"`) covers everything, while a finer tag (`"orders"`) targets a
320
+ subset. Sharing within a group is opt-in via `key`: members that share a `key`
321
+ share one value (and one fetch); a grouped reader **without** a `key` gets its own
322
+ private bucket, so a group refresh updates only that read and never leaks into
323
+ unrelated unkeyed reads of the same loader. A bucket may belong to several groups
324
+ at once (one read tagged with multiple names, or different reads tagging the same
325
+ keyed bucket with different names). Keep parameterized loaders on the single-loader
326
+ `key` — a plain-GET group refresh sends no params.
327
+
193
328
  **Load options**:
194
329
 
195
330
  ```tsx
@@ -298,9 +433,11 @@ path("/dashboard", (ctx) => {
298
433
  push({ label: "Dashboard", href: "/dashboard" });
299
434
  return <DashboardNav handle={Breadcrumbs} />;
300
435
  });
436
+ ```
301
437
 
438
+ ```tsx
302
439
  // Client component — typeof infers the full Handle<T> type
303
- ("use client");
440
+ "use client";
304
441
  import { useHandle, type Breadcrumbs } from "@rangojs/router/client";
305
442
 
306
443
  function DashboardNav({ handle }: { handle: typeof Breadcrumbs }) {
@@ -321,6 +458,11 @@ RSC serialization strips the `collect` function via `toJSON()`. On the client,
321
458
 
322
459
  ## Action Hooks
323
460
 
461
+ For the full server-action guide (defining actions, `useActionState`,
462
+ `useOptimistic`, validation, revalidation, error handling, file uploads),
463
+ see `/server-actions`. `useAction()` below is a Rango-specific hook for
464
+ tracking actions called outside a `<form action={...}>` flow.
465
+
324
466
  ### useAction()
325
467
 
326
468
  Track state of server action invocations:
@@ -504,6 +646,43 @@ const flash = FlashMessage.read();
504
646
  const product = ProductState.read();
505
647
  ```
506
648
 
649
+ > **Hydration:** `.read()` returns `undefined` on the server but may return
650
+ > a real value on the first client render (history state survives reload).
651
+ > Do not call `.read()` directly during the initial render of a component;
652
+ > call it from an event handler or inside a `useEffect` post-mount. For
653
+ > reactive hydration-safe access, use `useLocationState()` instead.
654
+
655
+ ### .write() / .delete() (static, non-reactive)
656
+
657
+ Static counterparts to `.read()`. Both mutate the current history entry's
658
+ `history.state` via `replaceState`, preserving any other keys (router
659
+ bookkeeping, other location state slots). Both are client-only; they throw
660
+ when called on the server.
661
+
662
+ Neither dispatches an event, so components reading via `useLocationState`
663
+ will NOT re-render until the next navigation/popstate. Pair with `.read()`
664
+ (or a fresh mount via back/forward/reload) instead.
665
+
666
+ ```tsx
667
+ "use client";
668
+ import { ProductState } from "./state";
669
+
670
+ // Persisted across hard refresh and back/forward of this entry.
671
+ ProductState.write({ name: "Widget", price: 9.99 });
672
+
673
+ // Read later (or on next mount).
674
+ const current = ProductState.read();
675
+
676
+ // Manually clear the slot. Idempotent if it isn't set.
677
+ ProductState.delete();
678
+ ```
679
+
680
+ | Method | Updates `history.state` | Fires `useLocationState` rerender | SSR behavior |
681
+ | ----------- | ----------------------- | --------------------------------- | ------------------- |
682
+ | `.read()` | no | n/a (returns snapshot) | returns `undefined` |
683
+ | `.write()` | yes (replace this slot) | no | throws |
684
+ | `.delete()` | yes (remove this slot) | no | throws |
685
+
507
686
  ## Cache Hooks
508
687
 
509
688
  ### useClientCache()
@@ -593,6 +772,12 @@ function ProductPage() {
593
772
  return <h1>Product {params.productId}</h1>;
594
773
  }
595
774
 
775
+ // Annotate the expected shape via a generic
776
+ function ProductPageTyped() {
777
+ const { productId } = useParams<{ productId: string }>();
778
+ return <h1>Product {productId}</h1>;
779
+ }
780
+
596
781
  // With selector for performance (re-renders only when selected value changes)
597
782
  function ProductId() {
598
783
  const productId = useParams((p) => p.productId);
@@ -600,7 +785,7 @@ function ProductId() {
600
785
  }
601
786
  ```
602
787
 
603
- Returns merged params from all matched route segments. Updates on navigation commit (not during pending navigation).
788
+ Returns merged params from all matched route segments as a `Readonly<T>` map. Updates on navigation commit (not during pending navigation).
604
789
 
605
790
  ### usePathname()
606
791
 
@@ -681,24 +866,48 @@ function MountInfo() {
681
866
  }
682
867
  ```
683
868
 
684
- See `/links` for full URL generation guide including server-side `ctx.reverse`.
869
+ ### useReverse(routes)
870
+
871
+ Mount-aware local reverse for client components. Import the generated `routes` map from a `urls()` module's `.gen.ts` and call `reverse("name", params?)` — the leading dot is optional. Auto-fills params from `useParams()`; explicit params override.
872
+
873
+ > Per-module `*.gen.ts` files are **CLI opt-in and not Vite-watched** — run `rango generate <urls-file>` (or wire it into `predev`) and re-run it whenever the module's routes change. See `/links` for the full generated-file setup and exposure-boundary rules.
874
+
875
+ ```tsx
876
+ "use client";
877
+ import { Link, useReverse } from "@rangojs/router/client";
878
+ import { routes as blogRoutes } from "../urls/blog.gen.js";
879
+
880
+ function BlogNav() {
881
+ const reverse = useReverse(blogRoutes);
882
+ return (
883
+ <nav>
884
+ <Link to={reverse("index")}>Blog</Link>
885
+ <Link to={reverse("post", { postId: "hello" })}>Post</Link>
886
+ </nav>
887
+ );
888
+ }
889
+ ```
890
+
891
+ See `/links` for the full URL generation guide. `ctx.reverse()` is server-only; on the client, prefer `useReverse(routes)` for in-module names and pass URLs as props for cross-module ones.
685
892
 
686
893
  ## Hook Summary
687
894
 
688
- | Hook | Purpose | Returns |
689
- | -------------------- | --------------------------------- | ----------------------------------------------- |
690
- | `useParams()` | Route params | `Record<string, string>` or selected value |
691
- | `usePathname()` | Current pathname | `string` |
692
- | `useSearchParams()` | URL search params | `ReadonlyURLSearchParams` |
693
- | `useHref()` | Mount-aware href | `(path) => string` |
694
- | `useMount()` | Current include() mount path | `string` |
695
- | `useNavigation()` | Reactive navigation state | state, location, isStreaming |
696
- | `useRouter()` | Stable router actions | push, replace, refresh, prefetch, back, forward |
697
- | `useSegments()` | URL path & segment IDs | path, segmentIds, location |
698
- | `useLinkStatus()` | Link pending state | { pending } |
699
- | `useLoader()` | Loader data (strict) | data, isLoading, error |
700
- | `useFetchLoader()` | Loader with on-demand fetch | data, load, isLoading |
701
- | `useHandle()` | Accumulated handle data | T (handle type) |
702
- | `useAction()` | Server action state | state, error, result |
703
- | `useLocationState()` | History state (persists or flash) | T \| undefined |
704
- | `useClientCache()` | Cache control | { clear } |
895
+ | Hook | Purpose | Returns |
896
+ | --------------------- | --------------------------------- | ------------------------------------------------------------------ |
897
+ | `useParams()` | Route params | `Readonly<T>` (default `Record<string, string>`) or selected value |
898
+ | `usePathname()` | Current pathname | `string` |
899
+ | `useSearchParams()` | URL search params | `ReadonlyURLSearchParams` |
900
+ | `useHref()` | Mount-aware href | `(path) => string` |
901
+ | `useMount()` | Current include() mount path | `string` |
902
+ | `useReverse()` | Local reverse for imported routes | `(name, params?, search?) => string` |
903
+ | `useNavigation()` | Reactive navigation state | state, location, isStreaming |
904
+ | `useRouter()` | Stable router actions | push, replace, refresh, prefetch, back, forward |
905
+ | `useSegments()` | URL path & segment IDs | path, segmentIds, location |
906
+ | `useLinkStatus()` | Link pending state | { pending } |
907
+ | `useLoader()` | Loader data (strict) | data, isLoading, error |
908
+ | `useFetchLoader()` | Loader with on-demand fetch | data, load, isLoading |
909
+ | `useRefreshLoaders()` | Refresh cross-loader group(s) | `() => (groups: string \| string[]) => Promise<void>` |
910
+ | `useHandle()` | Accumulated handle data | T (handle type) |
911
+ | `useAction()` | Server action state | state, error, result |
912
+ | `useLocationState()` | History state (persists or flash) | T \| undefined |
913
+ | `useClientCache()` | Cache control | { clear } |