@rangojs/router 0.0.0-experimental.20 → 0.0.0-experimental.20dbba0c

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 (189) hide show
  1. package/AGENTS.md +4 -0
  2. package/README.md +172 -50
  3. package/dist/bin/rango.js +138 -50
  4. package/dist/vite/index.js +1160 -508
  5. package/dist/vite/index.js.bak +5448 -0
  6. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  7. package/package.json +17 -16
  8. package/skills/breadcrumbs/SKILL.md +252 -0
  9. package/skills/cache-guide/SKILL.md +32 -0
  10. package/skills/caching/SKILL.md +49 -8
  11. package/skills/document-cache/SKILL.md +2 -2
  12. package/skills/handler-use/SKILL.md +362 -0
  13. package/skills/hooks/SKILL.md +61 -51
  14. package/skills/host-router/SKILL.md +218 -0
  15. package/skills/intercept/SKILL.md +20 -0
  16. package/skills/layout/SKILL.md +22 -0
  17. package/skills/links/SKILL.md +91 -17
  18. package/skills/loader/SKILL.md +107 -24
  19. package/skills/middleware/SKILL.md +34 -3
  20. package/skills/migrate-nextjs/SKILL.md +560 -0
  21. package/skills/migrate-react-router/SKILL.md +765 -0
  22. package/skills/parallel/SKILL.md +185 -0
  23. package/skills/prerender/SKILL.md +112 -70
  24. package/skills/rango/SKILL.md +24 -23
  25. package/skills/response-routes/SKILL.md +8 -0
  26. package/skills/route/SKILL.md +58 -4
  27. package/skills/router-setup/SKILL.md +95 -5
  28. package/skills/streams-and-websockets/SKILL.md +283 -0
  29. package/skills/typesafety/SKILL.md +38 -24
  30. package/src/__internal.ts +92 -0
  31. package/src/browser/app-shell.ts +52 -0
  32. package/src/browser/app-version.ts +14 -0
  33. package/src/browser/event-controller.ts +5 -0
  34. package/src/browser/link-interceptor.ts +4 -0
  35. package/src/browser/navigation-bridge.ts +175 -17
  36. package/src/browser/navigation-client.ts +177 -44
  37. package/src/browser/navigation-store.ts +68 -9
  38. package/src/browser/navigation-transaction.ts +11 -9
  39. package/src/browser/partial-update.ts +113 -17
  40. package/src/browser/prefetch/cache.ts +275 -28
  41. package/src/browser/prefetch/fetch.ts +191 -46
  42. package/src/browser/prefetch/policy.ts +6 -0
  43. package/src/browser/prefetch/queue.ts +123 -20
  44. package/src/browser/prefetch/resource-ready.ts +77 -0
  45. package/src/browser/rango-state.ts +53 -13
  46. package/src/browser/react/Link.tsx +98 -14
  47. package/src/browser/react/NavigationProvider.tsx +89 -14
  48. package/src/browser/react/context.ts +7 -2
  49. package/src/browser/react/use-handle.ts +9 -58
  50. package/src/browser/react/use-navigation.ts +22 -2
  51. package/src/browser/react/use-params.ts +11 -1
  52. package/src/browser/react/use-router.ts +29 -9
  53. package/src/browser/rsc-router.tsx +177 -66
  54. package/src/browser/scroll-restoration.ts +41 -42
  55. package/src/browser/segment-reconciler.ts +36 -9
  56. package/src/browser/server-action-bridge.ts +8 -6
  57. package/src/browser/types.ts +73 -5
  58. package/src/build/generate-manifest.ts +6 -6
  59. package/src/build/generate-route-types.ts +3 -0
  60. package/src/build/route-trie.ts +67 -25
  61. package/src/build/route-types/include-resolution.ts +8 -1
  62. package/src/build/route-types/router-processing.ts +223 -74
  63. package/src/build/route-types/scan-filter.ts +8 -1
  64. package/src/cache/cache-runtime.ts +15 -11
  65. package/src/cache/cache-scope.ts +48 -7
  66. package/src/cache/cf/cf-cache-store.ts +455 -15
  67. package/src/cache/cf/index.ts +5 -1
  68. package/src/cache/document-cache.ts +17 -7
  69. package/src/cache/index.ts +1 -0
  70. package/src/cache/taint.ts +55 -0
  71. package/src/client.rsc.tsx +2 -1
  72. package/src/client.tsx +85 -276
  73. package/src/context-var.ts +72 -2
  74. package/src/debug.ts +2 -2
  75. package/src/handle.ts +40 -0
  76. package/src/handles/breadcrumbs.ts +66 -0
  77. package/src/handles/index.ts +1 -0
  78. package/src/host/index.ts +0 -3
  79. package/src/index.rsc.ts +9 -36
  80. package/src/index.ts +79 -70
  81. package/src/outlet-context.ts +1 -1
  82. package/src/prerender/store.ts +57 -15
  83. package/src/prerender.ts +138 -77
  84. package/src/response-utils.ts +28 -0
  85. package/src/reverse.ts +27 -2
  86. package/src/route-definition/dsl-helpers.ts +240 -40
  87. package/src/route-definition/helpers-types.ts +67 -19
  88. package/src/route-definition/index.ts +3 -3
  89. package/src/route-definition/redirect.ts +11 -3
  90. package/src/route-definition/resolve-handler-use.ts +155 -0
  91. package/src/route-map-builder.ts +7 -1
  92. package/src/route-types.ts +18 -0
  93. package/src/router/content-negotiation.ts +100 -1
  94. package/src/router/find-match.ts +4 -2
  95. package/src/router/handler-context.ts +129 -26
  96. package/src/router/intercept-resolution.ts +11 -4
  97. package/src/router/lazy-includes.ts +10 -7
  98. package/src/router/loader-resolution.ts +160 -22
  99. package/src/router/logging.ts +5 -2
  100. package/src/router/manifest.ts +31 -16
  101. package/src/router/match-api.ts +128 -193
  102. package/src/router/match-middleware/background-revalidation.ts +30 -2
  103. package/src/router/match-middleware/cache-lookup.ts +94 -17
  104. package/src/router/match-middleware/cache-store.ts +53 -10
  105. package/src/router/match-middleware/intercept-resolution.ts +9 -7
  106. package/src/router/match-middleware/segment-resolution.ts +61 -5
  107. package/src/router/match-result.ts +103 -18
  108. package/src/router/metrics.ts +238 -13
  109. package/src/router/middleware-types.ts +48 -27
  110. package/src/router/middleware.ts +201 -86
  111. package/src/router/navigation-snapshot.ts +182 -0
  112. package/src/router/pattern-matching.ts +77 -11
  113. package/src/router/prerender-match.ts +114 -10
  114. package/src/router/preview-match.ts +30 -102
  115. package/src/router/request-classification.ts +310 -0
  116. package/src/router/revalidation.ts +27 -7
  117. package/src/router/route-snapshot.ts +245 -0
  118. package/src/router/router-context.ts +6 -1
  119. package/src/router/router-interfaces.ts +50 -5
  120. package/src/router/router-options.ts +50 -19
  121. package/src/router/segment-resolution/fresh.ts +215 -19
  122. package/src/router/segment-resolution/helpers.ts +30 -25
  123. package/src/router/segment-resolution/loader-cache.ts +1 -0
  124. package/src/router/segment-resolution/revalidation.ts +454 -301
  125. package/src/router/segment-wrappers.ts +2 -0
  126. package/src/router/trie-matching.ts +30 -6
  127. package/src/router/types.ts +1 -0
  128. package/src/router/url-params.ts +49 -0
  129. package/src/router.ts +89 -17
  130. package/src/rsc/handler.ts +563 -364
  131. package/src/rsc/helpers.ts +69 -41
  132. package/src/rsc/index.ts +0 -20
  133. package/src/rsc/loader-fetch.ts +23 -3
  134. package/src/rsc/manifest-init.ts +5 -1
  135. package/src/rsc/progressive-enhancement.ts +37 -10
  136. package/src/rsc/response-route-handler.ts +14 -1
  137. package/src/rsc/rsc-rendering.ts +47 -44
  138. package/src/rsc/server-action.ts +24 -10
  139. package/src/rsc/ssr-setup.ts +128 -0
  140. package/src/rsc/types.ts +11 -1
  141. package/src/search-params.ts +16 -13
  142. package/src/segment-content-promise.ts +67 -0
  143. package/src/segment-loader-promise.ts +122 -0
  144. package/src/segment-system.tsx +109 -23
  145. package/src/server/context.ts +174 -19
  146. package/src/server/handle-store.ts +19 -0
  147. package/src/server/loader-registry.ts +9 -8
  148. package/src/server/request-context.ts +218 -65
  149. package/src/server.ts +6 -0
  150. package/src/ssr/index.tsx +4 -0
  151. package/src/static-handler.ts +18 -6
  152. package/src/theme/index.ts +4 -13
  153. package/src/types/cache-types.ts +4 -4
  154. package/src/types/handler-context.ts +140 -72
  155. package/src/types/loader-types.ts +41 -15
  156. package/src/types/request-scope.ts +126 -0
  157. package/src/types/route-config.ts +17 -8
  158. package/src/types/route-entry.ts +19 -1
  159. package/src/types/segments.ts +2 -5
  160. package/src/urls/include-helper.ts +24 -14
  161. package/src/urls/path-helper-types.ts +39 -6
  162. package/src/urls/path-helper.ts +48 -13
  163. package/src/urls/pattern-types.ts +12 -0
  164. package/src/urls/response-types.ts +18 -16
  165. package/src/use-loader.tsx +77 -5
  166. package/src/vite/discovery/bundle-postprocess.ts +61 -89
  167. package/src/vite/discovery/discover-routers.ts +7 -4
  168. package/src/vite/discovery/prerender-collection.ts +162 -88
  169. package/src/vite/discovery/state.ts +17 -13
  170. package/src/vite/index.ts +8 -3
  171. package/src/vite/plugin-types.ts +51 -79
  172. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  173. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  174. package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
  175. package/src/vite/plugins/expose-action-id.ts +1 -3
  176. package/src/vite/plugins/expose-id-utils.ts +12 -0
  177. package/src/vite/plugins/expose-ids/handler-transform.ts +30 -0
  178. package/src/vite/plugins/expose-internal-ids.ts +257 -40
  179. package/src/vite/plugins/performance-tracks.ts +88 -0
  180. package/src/vite/plugins/refresh-cmd.ts +127 -0
  181. package/src/vite/plugins/version-plugin.ts +13 -1
  182. package/src/vite/rango.ts +190 -217
  183. package/src/vite/router-discovery.ts +241 -45
  184. package/src/vite/utils/banner.ts +4 -4
  185. package/src/vite/utils/package-resolution.ts +34 -1
  186. package/src/vite/utils/prerender-utils.ts +97 -5
  187. package/src/vite/utils/shared-utils.ts +3 -2
  188. package/skills/testing/SKILL.md +0 -226
  189. package/src/route-definition/route-function.ts +0 -119
@@ -0,0 +1,362 @@
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
+ If `handler.use()` returns a disallowed item for a mount site, registration throws:
63
+
64
+ ```
65
+ handler.use() returned middleware() which is not valid inside parallel().
66
+ Allowed types: revalidate, loader, loading, errorBoundary, notFoundBoundary, transition.
67
+ ```
68
+
69
+ The narrowest contract is `parallel()` — slots cannot bring their own middleware or layout; only data, loading, error/notFound boundaries, revalidation, and transitions.
70
+
71
+ ## Composition with explicit `use()`
72
+
73
+ Every mount site that takes a `use` callback merges in this order:
74
+
75
+ 1. **`handler.use()` items first** — the handler's defaults.
76
+ 2. **Explicit `use()` items second** — overrides specified at the mount site.
77
+
78
+ Items of the same kind from the explicit `use()` follow the existing override rules of that item type. The most important ones for composition:
79
+
80
+ - **`loading()`** — last definition wins, so explicit `loading()` replaces the handler's default.
81
+ - **`parallel({ "@slot": … })`** — the last `parallel()` call wins per slot name. Other slots from earlier calls are preserved (see `skills/parallel`).
82
+ - **`loader()`, `middleware()`, etc.** — accumulate; both the handler's and the explicit ones run.
83
+
84
+ Skip the boilerplate: if neither `handler.use` nor explicit `use()` is provided, no merge happens.
85
+
86
+ ```typescript
87
+ // Handler brings a loader + a (placeholder) loading; explicit use replaces loading.
88
+ const SidebarSlot: Handler = async (ctx) => {
89
+ const data = await ctx.use(SidebarLoader);
90
+ return <Sidebar data={data} />;
91
+ };
92
+ SidebarSlot.use = () => [
93
+ loader(SidebarLoader),
94
+ loading(<DefaultSidebarSkeleton />),
95
+ ];
96
+
97
+ parallel({ "@sidebar": SidebarSlot }, () => [
98
+ // Replaces the default skeleton; SidebarLoader from handler.use still runs.
99
+ loading(<SiteSpecificSidebarSkeleton />),
100
+ ]);
101
+ ```
102
+
103
+ ## Composable parallel slots (the main pay-off)
104
+
105
+ 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.
106
+
107
+ ### Without `handler.use` (every caller wires it up)
108
+
109
+ ```typescript
110
+ layout(<DashboardLayout />, () => [
111
+ parallel({ "@cart": CartSummary }, () => [
112
+ loader(CartLoader),
113
+ loading(<CartSkeleton />),
114
+ revalidate(revalidateCartData),
115
+ ]),
116
+ parallel({ "@notifs": NotificationPanel }, () => [
117
+ loader(NotificationsLoader),
118
+ loading(<NotifsSkeleton />),
119
+ revalidate(revalidateNotifs),
120
+ ]),
121
+ path("/dashboard", DashboardIndex, { name: "dashboard.index" }),
122
+ ]);
123
+ ```
124
+
125
+ Every layout that wants `@cart` must repeat the same loader/loading/revalidate triplet.
126
+
127
+ ### With `handler.use` (slot owns its dependencies)
128
+
129
+ ```typescript
130
+ const CartSummary: Handler = async (ctx) => {
131
+ const cart = await ctx.use(CartLoader);
132
+ return <CartSummaryView cart={cart} />;
133
+ };
134
+ CartSummary.use = () => [
135
+ loader(CartLoader),
136
+ loading(<CartSkeleton />),
137
+ revalidate(revalidateCartData),
138
+ ];
139
+
140
+ const NotificationPanel: Handler = async (ctx) => {
141
+ const items = await ctx.use(NotificationsLoader);
142
+ return <NotificationsView items={items} />;
143
+ };
144
+ NotificationPanel.use = () => [
145
+ loader(NotificationsLoader),
146
+ loading(<NotifsSkeleton />),
147
+ revalidate(revalidateNotifs),
148
+ ];
149
+
150
+ // Mount sites become declarative — no per-call data wiring.
151
+ layout(<DashboardLayout />, () => [
152
+ parallel({ "@cart": CartSummary, "@notifs": NotificationPanel }),
153
+ path("/dashboard", DashboardIndex, { name: "dashboard.index" }),
154
+ ]);
155
+
156
+ layout(<AccountLayout />, () => [
157
+ // Same slot, same defaults, zero re-wiring.
158
+ parallel({ "@cart": CartSummary }),
159
+ path("/account", AccountIndex, { name: "account.index" }),
160
+ ]);
161
+ ```
162
+
163
+ Each slot handler is now a portable, self-contained unit. Different layouts can use the same slot without copying data plumbing.
164
+
165
+ ### Streaming behavior is per-slot
166
+
167
+ 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.
168
+
169
+ ```typescript
170
+ parallel({
171
+ "@cart": CartSummary, // handler.use loading() → streams independently
172
+ "@cartBadge": CartBadge, // no loading() anywhere → awaited before paint
173
+ });
174
+ ```
175
+
176
+ ### Two scopes for explicit `use` at the mount site: shared (broadcast) and slot-local
177
+
178
+ `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.)
179
+
180
+ 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.
181
+
182
+ ```typescript
183
+ parallel({
184
+ "@meta": MetaSlot,
185
+ "@sidebar": {
186
+ handler: SidebarSlot,
187
+ use: () => [loading(<SidebarSkeleton />)], // ← only @sidebar
188
+ },
189
+ });
190
+ ```
191
+
192
+ Per-slot merge order is **handler.use → shared use → slot-local use** (narrowest scope wins for last-write-wins items like `loading()`):
193
+
194
+ ```typescript
195
+ parallel(
196
+ {
197
+ "@cart": {
198
+ handler: Cart,
199
+ use: () => [loading(<CartSkeleton />)], // wins for @cart
200
+ },
201
+ "@notifs": Notifs, // gets <BroadcastSkeleton />
202
+ },
203
+ () => [
204
+ loader(SharedAnalyticsLoader), // accumulates on every slot
205
+ loading(<BroadcastSkeleton />), // applies to slots without slot-local
206
+ ],
207
+ );
208
+ ```
209
+
210
+ Use the descriptor's `use` for `loading(false)` too — opting one slot out of streaming without affecting siblings:
211
+
212
+ ```typescript
213
+ parallel(
214
+ {
215
+ "@cart": { handler: Cart, use: () => [loading(false)] }, // @cart awaits
216
+ "@notifs": Notifs, // @notifs still streams with broadcast skeleton
217
+ },
218
+ () => [loading(<BroadcastSkeleton />)],
219
+ );
220
+ ```
221
+
222
+ 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)`.
223
+
224
+ ### Replacing a whole slot from a parent's `handler.use`
225
+
226
+ 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).
227
+
228
+ ```typescript
229
+ const ProductPage: Handler<"/product/:slug"> = (ctx) => (
230
+ <article>
231
+ <ProductHero slug={ctx.params.slug} />
232
+ <ParallelOutlet name="@related" />
233
+ <ParallelOutlet name="@reviews" />
234
+ </article>
235
+ );
236
+ ProductPage.use = () => [
237
+ parallel({
238
+ "@related": DefaultRelatedProducts,
239
+ "@reviews": DefaultReviews,
240
+ }),
241
+ ];
242
+
243
+ path("/product/:slug", ProductPage, { name: "product" }, () => [
244
+ // Override @related only; @reviews keeps the default from handler.use.
245
+ parallel({ "@related": SiteSpecificRelated }),
246
+ ]);
247
+ ```
248
+
249
+ ## Other mount sites
250
+
251
+ ### Pages (`path()`)
252
+
253
+ Page handlers can carry middleware, loaders, error boundaries, parallel slots, etc. — anything from the `path` row of the table above.
254
+
255
+ ```typescript
256
+ const CheckoutPage: Handler<"/checkout"> = async (ctx) => { /* … */ };
257
+ CheckoutPage.use = () => [
258
+ middleware(requireAuth),
259
+ loader(CartLoader),
260
+ errorBoundary(<CheckoutError />),
261
+ notFoundBoundary(<CheckoutNotFound />),
262
+ ];
263
+ ```
264
+
265
+ ### Layouts (`layout()`)
266
+
267
+ Layout handlers can carry middleware that runs for every child route, plus default parallels, includes, etc.
268
+
269
+ ```typescript
270
+ const AdminLayout: Handler = (ctx) => {
271
+ const user = ctx.get(CurrentUser);
272
+ return <Admin user={user} />;
273
+ };
274
+ AdminLayout.use = () => [
275
+ middleware(requireAdmin),
276
+ parallel({ "@adminNotifs": AdminNotifsSlot }),
277
+ ];
278
+ ```
279
+
280
+ ### Intercepts (`intercept()`)
281
+
282
+ Intercept handlers can carry their own middleware chain, loaders, and even nested layouts/routes for the modal shell.
283
+
284
+ ```typescript
285
+ const QuickViewModal: Handler = async (ctx) => {
286
+ const product = await ctx.use(ProductLoader);
287
+ return <QuickView product={product} />;
288
+ };
289
+ QuickViewModal.use = () => [
290
+ loader(ProductLoader),
291
+ loading(<QuickViewSkeleton />),
292
+ layout(<ModalChrome />),
293
+ ];
294
+ ```
295
+
296
+ ## `loading()` is a single-assignment item — scope it correctly
297
+
298
+ 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 `loadingFn`](../../src/route-definition/dsl-helpers.ts)).
299
+
300
+ 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.
301
+
302
+ 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:
303
+
304
+ ```typescript
305
+ const Cart: Handler = async (ctx) => { /* … */ };
306
+ Cart.use = () => [loader(CartLoader), loading(<CartSkeleton />)];
307
+
308
+ const Notifs: Handler = async (ctx) => { /* … */ };
309
+ Notifs.use = () => [loader(NotifsLoader), loading(<NotifsSkeleton />)];
310
+
311
+ // ✅ @cart gets a custom skeleton; @notifs keeps its handler.use default.
312
+ parallel({
313
+ "@cart": {
314
+ handler: Cart,
315
+ use: () => [loading(<CustomCartSkeleton />)],
316
+ },
317
+ "@notifs": Notifs,
318
+ });
319
+
320
+ // ✅ Opt one slot out of streaming while siblings still stream the broadcast.
321
+ parallel(
322
+ {
323
+ "@cart": { handler: Cart, use: () => [loading(false)] },
324
+ "@notifs": Notifs,
325
+ },
326
+ () => [loading(<BroadcastSkeleton />)],
327
+ );
328
+ ```
329
+
330
+ 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.
331
+
332
+ Other things to keep in mind about `loading()`:
333
+
334
+ - 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.
335
+
336
+ 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.
337
+
338
+ ## Edge cases & gotchas
339
+
340
+ - **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.
341
+ - **Branded handlers** — `Static()`, `Prerender()`, and `Passthrough()` are positional constructors (not object-arg). Construct first, then attach `.use` to the returned definition:
342
+
343
+ ```typescript
344
+ const ProductPage = Prerender(async (ctx) => {
345
+ const product = await fetchProduct(ctx.params.slug);
346
+ return <ProductView product={product} />;
347
+ });
348
+ ProductPage.use = () => [loader(ProductLoader)];
349
+ ```
350
+
351
+ - **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.
352
+ - **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.
353
+ - **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.
354
+
355
+ ## Cross-references
356
+
357
+ - `skills/route` — `path()` mount site basics
358
+ - `skills/layout` — `layout()` mount site basics
359
+ - `skills/parallel` — parallel slot semantics, slot override rules, streaming behavior
360
+ - `skills/intercept` — intercept mount site basics
361
+ - `skills/loader` — defining `createLoader` and reading via `ctx.use()`
362
+ - `skills/middleware` — middleware semantics and ordering
@@ -6,7 +6,8 @@ argument-hint: [hook-name]
6
6
 
7
7
  # Client-Side React Hooks
8
8
 
9
- All hooks are imported from `@rangojs/router` or `@rangojs/router/client`.
9
+ Import the hooks and components in this skill from `@rangojs/router/client`.
10
+ The root `@rangojs/router` entrypoint is for server/RSC APIs and shared types.
10
11
 
11
12
  ## Navigation Hooks
12
13
 
@@ -57,13 +58,33 @@ function NavigationControls() {
57
58
  }
58
59
  ```
59
60
 
61
+ #### Skipping revalidation
62
+
63
+ Pass `revalidate: false` to skip the RSC server fetch for same-pathname navigations (search param or hash changes). The URL updates and all hooks re-render, but server components stay as-is.
64
+
65
+ ```tsx
66
+ // Update search params without server round-trip
67
+ router.push("/products?color=blue", { revalidate: false });
68
+ router.replace("/products?page=3", { revalidate: false });
69
+ ```
70
+
71
+ If the pathname changes, `revalidate: false` is silently ignored and a full navigation occurs. This also works on `<Link>`:
72
+
73
+ ```tsx
74
+ <Link to="/products?color=blue" revalidate={false}>
75
+ Blue
76
+ </Link>
77
+ ```
78
+
79
+ Plain `<a>` tags can opt in via `data-revalidate="false"`.
80
+
60
81
  ### useSegments()
61
82
 
62
83
  Access current URL path and matched route segments:
63
84
 
64
85
  ```tsx
65
86
  "use client";
66
- import { useSegments } from "@rangojs/router";
87
+ import { useSegments } from "@rangojs/router/client";
67
88
 
68
89
  function Breadcrumbs() {
69
90
  const { path, segmentIds, location } = useSegments();
@@ -107,7 +128,7 @@ Access loader data (strict - data guaranteed):
107
128
 
108
129
  ```tsx
109
130
  "use client";
110
- import { useLoader } from "@rangojs/router";
131
+ import { useLoader } from "@rangojs/router/client";
111
132
  import { ProductLoader } from "../loaders/product";
112
133
 
113
134
  function ProductPrice() {
@@ -143,7 +164,7 @@ Access loader with on-demand fetching (flexible):
143
164
 
144
165
  ```tsx
145
166
  "use client";
146
- import { useFetchLoader } from "@rangojs/router";
167
+ import { useFetchLoader } from "@rangojs/router/client";
147
168
  import { SearchLoader } from "../loaders/search";
148
169
 
149
170
  function SearchResults() {
@@ -197,7 +218,7 @@ server, JSON bodies are available via `ctx.body` and FormData bodies via `ctx.fo
197
218
 
198
219
  ```tsx
199
220
  "use client";
200
- import { useFetchLoader } from "@rangojs/router";
221
+ import { useFetchLoader } from "@rangojs/router/client";
201
222
  import { FileUploadLoader } from "../loaders/upload";
202
223
 
203
224
  function FileUploader() {
@@ -238,22 +259,6 @@ export const FileUploadLoader = createLoader(async (ctx) => {
238
259
  }, true); // true = fetchable (can be called from the client via load())
239
260
  ```
240
261
 
241
- ### useLoaderData()
242
-
243
- Get all loader data in current context:
244
-
245
- ```tsx
246
- "use client";
247
- import { useLoaderData } from "@rangojs/router";
248
-
249
- function DebugPanel() {
250
- const allData = useLoaderData();
251
- // Record<string, any> - Map of loader ID to data
252
-
253
- return <pre>{JSON.stringify(allData, null, 2)}</pre>;
254
- }
255
- ```
256
-
257
262
  ## Handle Hooks
258
263
 
259
264
  ### useHandle()
@@ -262,8 +267,7 @@ Access accumulated handle data from route segments:
262
267
 
263
268
  ```tsx
264
269
  "use client";
265
- import { useHandle } from "@rangojs/router";
266
- import { Breadcrumbs } from "../handles/breadcrumbs";
270
+ import { useHandle, Breadcrumbs } from "@rangojs/router/client";
267
271
 
268
272
  function BreadcrumbNav() {
269
273
  const crumbs = useHandle(Breadcrumbs);
@@ -294,11 +298,12 @@ path("/dashboard", (ctx) => {
294
298
  push({ label: "Dashboard", href: "/dashboard" });
295
299
  return <DashboardNav handle={Breadcrumbs} />;
296
300
  });
301
+ ```
297
302
 
303
+ ```tsx
298
304
  // Client component — typeof infers the full Handle<T> type
299
- ("use client");
300
- import { useHandle } from "@rangojs/router/client";
301
- import type { Breadcrumbs } from "../handles";
305
+ "use client";
306
+ import { useHandle, type Breadcrumbs } from "@rangojs/router/client";
302
307
 
303
308
  function DashboardNav({ handle }: { handle: typeof Breadcrumbs }) {
304
309
  const crumbs = useHandle(handle);
@@ -324,7 +329,7 @@ Track state of server action invocations:
324
329
 
325
330
  ```tsx
326
331
  "use client";
327
- import { useAction } from "@rangojs/router";
332
+ import { useAction } from "@rangojs/router/client";
328
333
  import { addToCart } from "../actions/cart";
329
334
 
330
335
  function AddToCartButton({ productId }: { productId: string }) {
@@ -359,7 +364,7 @@ Read type-safe state from history:
359
364
 
360
365
  ```tsx
361
366
  "use client";
362
- import { useLocationState, createLocationState } from "@rangojs/router";
367
+ import { useLocationState, createLocationState } from "@rangojs/router/client";
363
368
 
364
369
  // Define typed state (all export patterns supported)
365
370
  // Keys are auto-injected by the Vite plugin -- no manual key needed.
@@ -509,7 +514,7 @@ Manually control client-side navigation cache:
509
514
 
510
515
  ```tsx
511
516
  "use client";
512
- import { useClientCache } from "@rangojs/router";
517
+ import { useClientCache } from "@rangojs/router/client";
513
518
 
514
519
  function SaveButton() {
515
520
  const { clear } = useClientCache();
@@ -537,7 +542,7 @@ function SaveButton() {
537
542
  Render child content in layouts:
538
543
 
539
544
  ```tsx
540
- import { Outlet, ParallelOutlet } from "@rangojs/router";
545
+ import { Outlet, ParallelOutlet } from "@rangojs/router/client";
541
546
 
542
547
  function DashboardLayout({ children }: { children?: React.ReactNode }) {
543
548
  return (
@@ -558,7 +563,7 @@ Access outlet content programmatically:
558
563
 
559
564
  ```tsx
560
565
  "use client";
561
- import { useOutlet } from "@rangojs/router";
566
+ import { useOutlet } from "@rangojs/router/client";
562
567
 
563
568
  function ConditionalLayout() {
564
569
  const outlet = useOutlet();
@@ -590,6 +595,12 @@ function ProductPage() {
590
595
  return <h1>Product {params.productId}</h1>;
591
596
  }
592
597
 
598
+ // Annotate the expected shape via a generic
599
+ function ProductPageTyped() {
600
+ const { productId } = useParams<{ productId: string }>();
601
+ return <h1>Product {productId}</h1>;
602
+ }
603
+
593
604
  // With selector for performance (re-renders only when selected value changes)
594
605
  function ProductId() {
595
606
  const productId = useParams((p) => p.productId);
@@ -597,7 +608,7 @@ function ProductId() {
597
608
  }
598
609
  ```
599
610
 
600
- Returns merged params from all matched route segments. Updates on navigation commit (not during pending navigation).
611
+ Returns merged params from all matched route segments as a `Readonly<T>` map. Updates on navigation commit (not during pending navigation).
601
612
 
602
613
  ### usePathname()
603
614
 
@@ -678,25 +689,24 @@ function MountInfo() {
678
689
  }
679
690
  ```
680
691
 
681
- See `/links` for full URL generation guide including server-side `ctx.reverse`.
692
+ See `/links` for full URL generation guide. The default server API is `ctx.reverse()`; in client components, receive URLs as props, loader data, or server-action return values — `reverse()` is not available in the browser.
682
693
 
683
694
  ## Hook Summary
684
695
 
685
- | Hook | Purpose | Returns |
686
- | -------------------- | --------------------------------- | ----------------------------------------------- |
687
- | `useParams()` | Route params | `Record<string, string>` or selected value |
688
- | `usePathname()` | Current pathname | `string` |
689
- | `useSearchParams()` | URL search params | `ReadonlyURLSearchParams` |
690
- | `useHref()` | Mount-aware href | `(path) => string` |
691
- | `useMount()` | Current include() mount path | `string` |
692
- | `useNavigation()` | Reactive navigation state | state, location, isStreaming |
693
- | `useRouter()` | Stable router actions | push, replace, refresh, prefetch, back, forward |
694
- | `useSegments()` | URL path & segment IDs | path, segmentIds, location |
695
- | `useLinkStatus()` | Link pending state | { pending } |
696
- | `useLoader()` | Loader data (strict) | data, isLoading, error |
697
- | `useFetchLoader()` | Loader with on-demand fetch | data, load, isLoading |
698
- | `useLoaderData()` | All loader data | Record<string, any> |
699
- | `useHandle()` | Accumulated handle data | T (handle type) |
700
- | `useAction()` | Server action state | state, error, result |
701
- | `useLocationState()` | History state (persists or flash) | T \| undefined |
702
- | `useClientCache()` | Cache control | { clear } |
696
+ | Hook | Purpose | Returns |
697
+ | -------------------- | --------------------------------- | ------------------------------------------------------------------ |
698
+ | `useParams()` | Route params | `Readonly<T>` (default `Record<string, string>`) or selected value |
699
+ | `usePathname()` | Current pathname | `string` |
700
+ | `useSearchParams()` | URL search params | `ReadonlyURLSearchParams` |
701
+ | `useHref()` | Mount-aware href | `(path) => string` |
702
+ | `useMount()` | Current include() mount path | `string` |
703
+ | `useNavigation()` | Reactive navigation state | state, location, isStreaming |
704
+ | `useRouter()` | Stable router actions | push, replace, refresh, prefetch, back, forward |
705
+ | `useSegments()` | URL path & segment IDs | path, segmentIds, location |
706
+ | `useLinkStatus()` | Link pending state | { pending } |
707
+ | `useLoader()` | Loader data (strict) | data, isLoading, error |
708
+ | `useFetchLoader()` | Loader with on-demand fetch | data, load, isLoading |
709
+ | `useHandle()` | Accumulated handle data | T (handle type) |
710
+ | `useAction()` | Server action state | state, error, result |
711
+ | `useLocationState()` | History state (persists or flash) | T \| undefined |
712
+ | `useClientCache()` | Cache control | { clear } |