@rangojs/router 0.0.0-experimental.19 → 0.0.0-experimental.1fa245e2

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 (160) hide show
  1. package/{CLAUDE.md → AGENTS.md} +4 -0
  2. package/README.md +122 -30
  3. package/dist/bin/rango.js +245 -63
  4. package/dist/vite/index.js +859 -418
  5. package/package.json +3 -3
  6. package/skills/breadcrumbs/SKILL.md +250 -0
  7. package/skills/cache-guide/SKILL.md +32 -0
  8. package/skills/caching/SKILL.md +49 -8
  9. package/skills/document-cache/SKILL.md +2 -2
  10. package/skills/hooks/SKILL.md +33 -31
  11. package/skills/host-router/SKILL.md +218 -0
  12. package/skills/links/SKILL.md +3 -1
  13. package/skills/loader/SKILL.md +72 -22
  14. package/skills/middleware/SKILL.md +2 -0
  15. package/skills/parallel/SKILL.md +126 -0
  16. package/skills/prerender/SKILL.md +112 -70
  17. package/skills/rango/SKILL.md +0 -1
  18. package/skills/route/SKILL.md +34 -4
  19. package/skills/router-setup/SKILL.md +95 -5
  20. package/skills/typesafety/SKILL.md +35 -23
  21. package/src/__internal.ts +92 -0
  22. package/src/bin/rango.ts +18 -0
  23. package/src/browser/app-version.ts +14 -0
  24. package/src/browser/event-controller.ts +5 -0
  25. package/src/browser/link-interceptor.ts +4 -0
  26. package/src/browser/navigation-bridge.ts +114 -18
  27. package/src/browser/navigation-client.ts +126 -44
  28. package/src/browser/navigation-store.ts +43 -8
  29. package/src/browser/navigation-transaction.ts +11 -9
  30. package/src/browser/partial-update.ts +80 -15
  31. package/src/browser/prefetch/cache.ts +166 -27
  32. package/src/browser/prefetch/fetch.ts +52 -39
  33. package/src/browser/prefetch/policy.ts +6 -0
  34. package/src/browser/prefetch/queue.ts +92 -20
  35. package/src/browser/prefetch/resource-ready.ts +77 -0
  36. package/src/browser/react/Link.tsx +70 -14
  37. package/src/browser/react/NavigationProvider.tsx +40 -4
  38. package/src/browser/react/context.ts +7 -2
  39. package/src/browser/react/use-handle.ts +9 -58
  40. package/src/browser/react/use-router.ts +21 -8
  41. package/src/browser/rsc-router.tsx +143 -59
  42. package/src/browser/scroll-restoration.ts +41 -42
  43. package/src/browser/segment-reconciler.ts +6 -1
  44. package/src/browser/server-action-bridge.ts +454 -436
  45. package/src/browser/types.ts +60 -5
  46. package/src/build/generate-manifest.ts +6 -6
  47. package/src/build/generate-route-types.ts +5 -0
  48. package/src/build/route-trie.ts +19 -3
  49. package/src/build/route-types/include-resolution.ts +8 -1
  50. package/src/build/route-types/router-processing.ts +346 -87
  51. package/src/build/route-types/scan-filter.ts +8 -1
  52. package/src/cache/cache-runtime.ts +15 -11
  53. package/src/cache/cache-scope.ts +48 -7
  54. package/src/cache/cf/cf-cache-store.ts +453 -11
  55. package/src/cache/cf/index.ts +5 -1
  56. package/src/cache/document-cache.ts +17 -7
  57. package/src/cache/index.ts +1 -0
  58. package/src/cache/taint.ts +55 -0
  59. package/src/client.rsc.tsx +2 -1
  60. package/src/client.tsx +3 -102
  61. package/src/context-var.ts +72 -2
  62. package/src/debug.ts +2 -2
  63. package/src/handle.ts +40 -0
  64. package/src/handles/breadcrumbs.ts +66 -0
  65. package/src/handles/index.ts +1 -0
  66. package/src/host/index.ts +0 -3
  67. package/src/index.rsc.ts +8 -37
  68. package/src/index.ts +40 -66
  69. package/src/prerender/store.ts +57 -15
  70. package/src/prerender.ts +138 -77
  71. package/src/reverse.ts +22 -1
  72. package/src/route-definition/dsl-helpers.ts +73 -25
  73. package/src/route-definition/helpers-types.ts +10 -6
  74. package/src/route-definition/index.ts +3 -3
  75. package/src/route-definition/redirect.ts +11 -3
  76. package/src/route-definition/resolve-handler-use.ts +149 -0
  77. package/src/route-map-builder.ts +7 -1
  78. package/src/route-types.ts +11 -0
  79. package/src/router/content-negotiation.ts +100 -1
  80. package/src/router/find-match.ts +4 -2
  81. package/src/router/handler-context.ts +108 -25
  82. package/src/router/intercept-resolution.ts +11 -4
  83. package/src/router/lazy-includes.ts +4 -1
  84. package/src/router/loader-resolution.ts +123 -11
  85. package/src/router/logging.ts +5 -2
  86. package/src/router/manifest.ts +9 -3
  87. package/src/router/match-api.ts +125 -190
  88. package/src/router/match-middleware/background-revalidation.ts +30 -2
  89. package/src/router/match-middleware/cache-lookup.ts +88 -16
  90. package/src/router/match-middleware/cache-store.ts +53 -10
  91. package/src/router/match-middleware/intercept-resolution.ts +9 -7
  92. package/src/router/match-middleware/segment-resolution.ts +61 -5
  93. package/src/router/match-result.ts +22 -15
  94. package/src/router/metrics.ts +238 -13
  95. package/src/router/middleware-types.ts +53 -12
  96. package/src/router/middleware.ts +172 -85
  97. package/src/router/navigation-snapshot.ts +182 -0
  98. package/src/router/pattern-matching.ts +20 -5
  99. package/src/router/prerender-match.ts +114 -10
  100. package/src/router/preview-match.ts +30 -102
  101. package/src/router/request-classification.ts +310 -0
  102. package/src/router/revalidation.ts +27 -7
  103. package/src/router/route-snapshot.ts +245 -0
  104. package/src/router/router-context.ts +6 -1
  105. package/src/router/router-interfaces.ts +50 -5
  106. package/src/router/router-options.ts +50 -19
  107. package/src/router/segment-resolution/fresh.ts +200 -19
  108. package/src/router/segment-resolution/helpers.ts +30 -25
  109. package/src/router/segment-resolution/loader-cache.ts +1 -0
  110. package/src/router/segment-resolution/revalidation.ts +429 -301
  111. package/src/router/segment-wrappers.ts +2 -0
  112. package/src/router/trie-matching.ts +20 -2
  113. package/src/router/types.ts +1 -0
  114. package/src/router.ts +88 -15
  115. package/src/rsc/handler.ts +546 -359
  116. package/src/rsc/index.ts +0 -20
  117. package/src/rsc/manifest-init.ts +5 -1
  118. package/src/rsc/progressive-enhancement.ts +25 -8
  119. package/src/rsc/rsc-rendering.ts +35 -43
  120. package/src/rsc/server-action.ts +16 -10
  121. package/src/rsc/ssr-setup.ts +128 -0
  122. package/src/rsc/types.ts +10 -1
  123. package/src/search-params.ts +16 -13
  124. package/src/segment-system.tsx +140 -4
  125. package/src/server/context.ts +148 -16
  126. package/src/server/loader-registry.ts +9 -8
  127. package/src/server/request-context.ts +182 -34
  128. package/src/server.ts +6 -0
  129. package/src/ssr/index.tsx +4 -0
  130. package/src/static-handler.ts +18 -6
  131. package/src/theme/index.ts +4 -13
  132. package/src/types/cache-types.ts +4 -4
  133. package/src/types/handler-context.ts +149 -49
  134. package/src/types/loader-types.ts +36 -9
  135. package/src/types/route-config.ts +17 -8
  136. package/src/types/route-entry.ts +8 -1
  137. package/src/types/segments.ts +2 -5
  138. package/src/urls/path-helper-types.ts +9 -2
  139. package/src/urls/path-helper.ts +48 -13
  140. package/src/urls/pattern-types.ts +12 -0
  141. package/src/urls/response-types.ts +16 -6
  142. package/src/use-loader.tsx +73 -4
  143. package/src/vite/discovery/bundle-postprocess.ts +61 -89
  144. package/src/vite/discovery/discover-routers.ts +23 -5
  145. package/src/vite/discovery/prerender-collection.ts +48 -15
  146. package/src/vite/discovery/state.ts +17 -13
  147. package/src/vite/index.ts +8 -3
  148. package/src/vite/plugin-types.ts +51 -79
  149. package/src/vite/plugins/client-ref-dedup.ts +115 -0
  150. package/src/vite/plugins/expose-action-id.ts +1 -3
  151. package/src/vite/plugins/performance-tracks.ts +88 -0
  152. package/src/vite/plugins/refresh-cmd.ts +127 -0
  153. package/src/vite/plugins/version-plugin.ts +13 -1
  154. package/src/vite/rango.ts +174 -211
  155. package/src/vite/router-discovery.ts +169 -42
  156. package/src/vite/utils/banner.ts +3 -3
  157. package/src/vite/utils/prerender-utils.ts +78 -0
  158. package/src/vite/utils/shared-utils.ts +3 -2
  159. package/skills/testing/SKILL.md +0 -226
  160. package/src/route-definition/route-function.ts +0 -119
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rangojs/router",
3
- "version": "0.0.0-experimental.19",
3
+ "version": "0.0.0-experimental.1fa245e2",
4
4
  "description": "Django-inspired RSC router with composable URL patterns",
5
5
  "keywords": [
6
6
  "react",
@@ -31,7 +31,7 @@
31
31
  "!src/**/*.test.tsx",
32
32
  "dist",
33
33
  "skills",
34
- "CLAUDE.md",
34
+ "AGENTS.md",
35
35
  "README.md"
36
36
  ],
37
37
  "type": "module",
@@ -142,7 +142,7 @@
142
142
  "test:unit:watch": "vitest"
143
143
  },
144
144
  "dependencies": {
145
- "@vitejs/plugin-rsc": "^0.5.14",
145
+ "@vitejs/plugin-rsc": "^0.5.19",
146
146
  "magic-string": "^0.30.17",
147
147
  "picomatch": "^4.0.3",
148
148
  "rsc-html-stream": "^0.0.7"
@@ -0,0 +1,250 @@
1
+ ---
2
+ name: breadcrumbs
3
+ description: Built-in Breadcrumbs handle for accumulating breadcrumb navigation across route segments
4
+ argument-hint: [setup]
5
+ ---
6
+
7
+ # Breadcrumbs
8
+
9
+ Built-in handle for accumulating breadcrumb items across route segments.
10
+ Each layout/route pushes items via `ctx.use(Breadcrumbs)`, and they are
11
+ collected in parent-to-child order with automatic deduplication by `href`.
12
+
13
+ ## BreadcrumbItem Type
14
+
15
+ ```typescript
16
+ interface BreadcrumbItem {
17
+ label: string; // Display text
18
+ href: string; // URL the breadcrumb links to
19
+ content?: ReactNode | Promise<ReactNode>; // Optional extra content (sync or async)
20
+ }
21
+ ```
22
+
23
+ ## Pushing Breadcrumbs (Server)
24
+
25
+ Import `Breadcrumbs` from `@rangojs/router` in RSC/server context:
26
+
27
+ ```typescript
28
+ import { urls, Breadcrumbs } from "@rangojs/router";
29
+ import { Outlet } from "@rangojs/router/client";
30
+
31
+ export const urlpatterns = urls(({ path, layout }) => [
32
+ // Root layout pushes "Home"
33
+ layout((ctx) => {
34
+ const breadcrumb = ctx.use(Breadcrumbs);
35
+ breadcrumb({ label: "Home", href: "/" });
36
+ return <RootLayout />;
37
+ }, () => [
38
+ path("/", HomePage, { name: "home" }),
39
+
40
+ // Nested layout pushes "Blog"
41
+ layout((ctx) => {
42
+ const breadcrumb = ctx.use(Breadcrumbs);
43
+ breadcrumb({ label: "Blog", href: "/blog" });
44
+ return <BlogLayout />;
45
+ }, () => [
46
+ path("/blog", BlogIndex, { name: "blog.index" }),
47
+
48
+ // Route handler pushes post title
49
+ path("/blog/:slug", (ctx) => {
50
+ const breadcrumb = ctx.use(Breadcrumbs);
51
+ breadcrumb({ label: ctx.params.slug, href: `/blog/${ctx.params.slug}` });
52
+ return <BlogPost slug={ctx.params.slug} />;
53
+ }, { name: "blog.post" }),
54
+ ]),
55
+ ]),
56
+ ]);
57
+ ```
58
+
59
+ On `/blog/my-post`, breadcrumbs accumulate: `Home > Blog > my-post`.
60
+
61
+ ## Async Content
62
+
63
+ The `content` field supports `Promise<ReactNode>` for streaming:
64
+
65
+ ```typescript
66
+ path("/product/:id", async (ctx) => {
67
+ const breadcrumb = ctx.use(Breadcrumbs);
68
+ const productPromise = fetchProduct(ctx.params.id);
69
+
70
+ breadcrumb({
71
+ label: "Product",
72
+ href: `/product/${ctx.params.id}`,
73
+ content: productPromise.then((p) => <span>({p.category})</span>),
74
+ });
75
+
76
+ const product = await productPromise;
77
+ return <ProductPage product={product} />;
78
+ }, { name: "product" })
79
+ ```
80
+
81
+ Async content is a `Promise<ReactNode>`. Resolve it in your component
82
+ with React's `use()` hook wrapped in `<Suspense>`.
83
+
84
+ ## Consuming Breadcrumbs (Client)
85
+
86
+ Use `useHandle(Breadcrumbs)` in a client component to read the accumulated items:
87
+
88
+ ```tsx
89
+ "use client";
90
+ import { useHandle, Breadcrumbs, Link } from "@rangojs/router/client";
91
+
92
+ function BreadcrumbNav() {
93
+ const breadcrumbs = useHandle(Breadcrumbs);
94
+
95
+ if (!breadcrumbs.length) return null;
96
+
97
+ return (
98
+ <nav aria-label="Breadcrumb">
99
+ <ol>
100
+ {breadcrumbs.map((crumb, i) => (
101
+ <li key={crumb.href}>
102
+ {i === breadcrumbs.length - 1 ? (
103
+ <span aria-current="page">{crumb.label}</span>
104
+ ) : (
105
+ <Link to={crumb.href}>{crumb.label}</Link>
106
+ )}
107
+ </li>
108
+ ))}
109
+ </ol>
110
+ </nav>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ### With Selector
116
+
117
+ Re-render only when the selected value changes:
118
+
119
+ ```tsx
120
+ // Only the last breadcrumb
121
+ const current = useHandle(Breadcrumbs, (data) => data.at(-1));
122
+
123
+ // Breadcrumb count
124
+ const count = useHandle(Breadcrumbs, (data) => data.length);
125
+ ```
126
+
127
+ ## Deduplication
128
+
129
+ The built-in collect function deduplicates by `href`. If multiple segments
130
+ push the same `href`, the last one wins. This prevents duplicates when
131
+ navigating between sibling routes that share a common breadcrumb.
132
+
133
+ ## Passing as Props
134
+
135
+ Breadcrumbs handle can be passed from server to client components:
136
+
137
+ ```tsx
138
+ // Server component
139
+ path("/dashboard", (ctx) => {
140
+ const breadcrumb = ctx.use(Breadcrumbs);
141
+ breadcrumb({ label: "Dashboard", href: "/dashboard" });
142
+ return <DashboardNav handle={Breadcrumbs} />;
143
+ });
144
+
145
+ // Client component
146
+ ("use client");
147
+ import { useHandle, type Breadcrumbs } from "@rangojs/router/client";
148
+
149
+ function DashboardNav({ handle }: { handle: typeof Breadcrumbs }) {
150
+ const crumbs = useHandle(handle);
151
+ return (
152
+ <nav>
153
+ {crumbs.map((c) => (
154
+ <a href={c.href}>{c.label}</a>
155
+ ))}
156
+ </nav>
157
+ );
158
+ }
159
+ ```
160
+
161
+ ## Complete Example
162
+
163
+ ```typescript
164
+ // urls.tsx
165
+ import { urls, Breadcrumbs, Meta } from "@rangojs/router";
166
+ import { Outlet, MetaTags } from "@rangojs/router/client";
167
+ import { BreadcrumbNav } from "./components/BreadcrumbNav";
168
+
169
+ function RootLayout() {
170
+ return (
171
+ <html lang="en">
172
+ <head><MetaTags /></head>
173
+ <body>
174
+ <BreadcrumbNav />
175
+ <main><Outlet /></main>
176
+ </body>
177
+ </html>
178
+ );
179
+ }
180
+
181
+ export const urlpatterns = urls(({ path, layout }) => [
182
+ layout((ctx) => {
183
+ ctx.use(Breadcrumbs)({ label: "Home", href: "/" });
184
+ ctx.use(Meta)({ title: "My App" });
185
+ return <RootLayout />;
186
+ }, () => [
187
+ path("/", () => <h1>Welcome</h1>, { name: "home" }),
188
+
189
+ layout((ctx) => {
190
+ ctx.use(Breadcrumbs)({ label: "Shop", href: "/shop" });
191
+ return <Outlet />;
192
+ }, () => [
193
+ path("/shop", () => <h1>Shop</h1>, { name: "shop" }),
194
+ path("/shop/:slug", (ctx) => {
195
+ ctx.use(Breadcrumbs)({
196
+ label: ctx.params.slug,
197
+ href: `/shop/${ctx.params.slug}`,
198
+ });
199
+ return <h1>Product: {ctx.params.slug}</h1>;
200
+ }, { name: "shop.product" }),
201
+ ]),
202
+ ]),
203
+ ]);
204
+ ```
205
+
206
+ Navigating to `/shop/widget` produces: `Home / Shop / widget`
207
+
208
+ ## Custom Handles
209
+
210
+ Create your own handle with `createHandle()`:
211
+
212
+ ```typescript
213
+ import { createHandle } from "@rangojs/router";
214
+
215
+ // Default: flatten into array
216
+ export const PageTitle = createHandle<string, string>(
217
+ (segments) => segments.flat().at(-1) ?? "Default Title",
218
+ );
219
+
220
+ // No collect function: default flattens into T[]
221
+ export const Warnings = createHandle<string>();
222
+ ```
223
+
224
+ The Vite `exposeInternalIds` plugin auto-injects a stable `$$id` based on
225
+ file path and export name. No manual naming required for project-local code.
226
+
227
+ ### Handles in 3rd-party packages
228
+
229
+ The `exposeInternalIds` plugin skips `node_modules/`, so handles defined in
230
+ published packages won't get auto-injected IDs. Pass a manual tag as the
231
+ second argument to `createHandle()`:
232
+
233
+ ```typescript
234
+ import { createHandle } from "@rangojs/router";
235
+
236
+ // With a collect function (reducer): collect is first arg, tag is second
237
+ export const Breadcrumbs = createHandle<BreadcrumbItem, BreadcrumbItem[]>(
238
+ collectBreadcrumbs,
239
+ "__my_package_breadcrumbs__",
240
+ );
241
+
242
+ // Without a collect function: pass undefined, then the tag
243
+ export const Warnings = createHandle<string>(
244
+ undefined,
245
+ "__my_package_warnings__",
246
+ );
247
+ ```
248
+
249
+ The tag must be globally unique and stable across builds. Without it,
250
+ `createHandle` throws in development mode.
@@ -162,6 +162,38 @@ middleware(async (ctx, next) => {
162
162
  });
163
163
  ```
164
164
 
165
+ ## Context Variable Cache Safety
166
+
167
+ Context variables created with `createVar()` are cacheable by default and can
168
+ be read freely inside `cache()` and `"use cache"` scopes. Non-cacheable vars
169
+ throw at read time to prevent request-specific data from being captured.
170
+
171
+ There are two ways to mark a value as non-cacheable:
172
+
173
+ ```typescript
174
+ // Var-level policy — inherently request-specific data
175
+ const Session = createVar<SessionData>({ cache: false });
176
+
177
+ // Write-level escalation — this specific write is non-cacheable
178
+ ctx.set(Theme, derivedTheme, { cache: false });
179
+ ```
180
+
181
+ "Least cacheable wins": if either the var definition or the `ctx.set()` call
182
+ specifies `cache: false`, the value is non-cacheable.
183
+
184
+ **Behavior inside cache scopes:**
185
+
186
+ | Operation | Inside `cache()` / `"use cache"` |
187
+ | ----------------------------------- | -------------------------------- |
188
+ | `ctx.get(cacheableVar)` | Allowed |
189
+ | `ctx.get(nonCacheableVar)` | Throws |
190
+ | `ctx.set(var, value)` (cacheable) | Allowed |
191
+ | `ctx.header()`, `ctx.cookie()`, etc | Throws (response side effects) |
192
+
193
+ Write is dumb — `ctx.set()` stores the cache metadata but does not enforce.
194
+ Enforcement happens at read time (`ctx.get()`), where ALS detects the cache
195
+ scope and rejects non-cacheable reads.
196
+
165
197
  ## Loaders Are Always Fresh
166
198
 
167
199
  Loaders are **never cached** by route-level `cache()`. Even on a full cache hit
@@ -89,7 +89,7 @@ Configure a cache store in the router:
89
89
 
90
90
  ```typescript
91
91
  import { createRouter } from "@rangojs/router";
92
- import { MemorySegmentCacheStore } from "@rangojs/router/rsc";
92
+ import { MemorySegmentCacheStore } from "@rangojs/router/cache";
93
93
 
94
94
  const store = new MemorySegmentCacheStore({
95
95
  defaults: { ttl: 60, swr: 300 },
@@ -112,7 +112,7 @@ const router = createRouter({
112
112
  For single-instance deployments:
113
113
 
114
114
  ```typescript
115
- import { MemorySegmentCacheStore } from "@rangojs/router/rsc";
115
+ import { MemorySegmentCacheStore } from "@rangojs/router/cache";
116
116
 
117
117
  const store = new MemorySegmentCacheStore({
118
118
  defaults: { ttl: 60, swr: 300 },
@@ -120,26 +120,67 @@ const store = new MemorySegmentCacheStore({
120
120
  });
121
121
  ```
122
122
 
123
- ### Cloudflare KV Store
123
+ ### Cloudflare Edge Cache Store
124
124
 
125
- For distributed caching on Cloudflare Workers:
125
+ For distributed caching on Cloudflare Workers using the Cache API:
126
126
 
127
127
  ```typescript
128
- import { CFCacheStore } from "@rangojs/router/cache/cf";
128
+ import { CFCacheStore } from "@rangojs/router/cache";
129
129
 
130
130
  const router = createRouter<AppBindings>({
131
131
  document: Document,
132
132
  urls: urlpatterns,
133
133
  cache: (env, ctx) => ({
134
134
  store: new CFCacheStore({
135
- kv: env.CACHE_KV,
136
- waitUntil: (fn) => ctx!.waitUntil(fn),
135
+ ctx,
136
+ defaults: { ttl: 60, swr: 300 },
137
137
  }),
138
138
  enabled: true,
139
139
  }),
140
140
  });
141
141
  ```
142
142
 
143
+ ### With KV L2 Persistence
144
+
145
+ Add a KV namespace for global cross-colo persistence. On Cache API miss, KV is
146
+ checked and hits are promoted back to L1. Writes go to both layers.
147
+
148
+ ```typescript
149
+ import { CFCacheStore } from "@rangojs/router/cache";
150
+
151
+ const router = createRouter<AppBindings>({
152
+ document: Document,
153
+ urls: urlpatterns,
154
+ cache: (env, ctx) => ({
155
+ store: new CFCacheStore({
156
+ ctx,
157
+ kv: env.CACHE_KV, // optional KV namespace binding
158
+ defaults: { ttl: 60, swr: 300 },
159
+ }),
160
+ enabled: true,
161
+ }),
162
+ });
163
+ ```
164
+
165
+ **How the two layers work:**
166
+
167
+ | Scenario | L1 (Cache API) | L2 (KV) | Result |
168
+ | ------------ | -------------- | ------- | ----------------------------- |
169
+ | Hot request | HIT | — | Serve from L1 (fast) |
170
+ | Cold colo | MISS | HIT | Serve from KV, promote to L1 |
171
+ | First render | MISS | MISS | Render, write to both L1 + KV |
172
+
173
+ KV entries require `expirationTtl >= 60s`. Short-lived entries (< 60s total TTL)
174
+ are only cached in L1.
175
+
176
+ ## Context Variables Inside Cache Boundaries
177
+
178
+ Context variables (`createVar`) are cacheable by default and can be read and
179
+ written inside `cache()` scopes. Variables marked with `{ cache: false }` (at
180
+ the var level or write level) throw when read inside a cache scope. Response
181
+ side effects (`ctx.header()`, `ctx.cookie()`) always throw inside cache
182
+ boundaries. See `/cache-guide` for the full cache safety table.
183
+
143
184
  ## Nested Cache Boundaries
144
185
 
145
186
  Override cache settings for specific sections:
@@ -175,7 +216,7 @@ cache({ store: checkoutCache }, () => [
175
216
 
176
217
  ```typescript
177
218
  import { urls } from "@rangojs/router";
178
- import { MemorySegmentCacheStore } from "@rangojs/router/rsc";
219
+ import { MemorySegmentCacheStore } from "@rangojs/router/cache";
179
220
 
180
221
  // Custom store for checkout (short TTL)
181
222
  const checkoutCache = new MemorySegmentCacheStore({
@@ -14,7 +14,7 @@ Configure document cache in router:
14
14
 
15
15
  ```typescript
16
16
  import { createRouter } from "@rangojs/router";
17
- import { CFCacheStore } from "@rangojs/router/cache/cf";
17
+ import { CFCacheStore } from "@rangojs/router/cache";
18
18
  import { urlpatterns } from "./urls";
19
19
 
20
20
  const router = createRouter<AppBindings>({
@@ -134,7 +134,7 @@ Segment hash ensures different cached responses for navigations from different s
134
134
  ```typescript
135
135
  // router.tsx
136
136
  import { createRouter } from "@rangojs/router";
137
- import { CFCacheStore } from "@rangojs/router/cache/cf";
137
+ import { CFCacheStore } from "@rangojs/router/cache";
138
138
  import { urlpatterns } from "./urls";
139
139
 
140
140
  const router = createRouter<AppBindings>({
@@ -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);
@@ -297,8 +301,7 @@ path("/dashboard", (ctx) => {
297
301
 
298
302
  // Client component — typeof infers the full Handle<T> type
299
303
  ("use client");
300
- import { useHandle } from "@rangojs/router/client";
301
- import type { Breadcrumbs } from "../handles";
304
+ import { useHandle, type Breadcrumbs } from "@rangojs/router/client";
302
305
 
303
306
  function DashboardNav({ handle }: { handle: typeof Breadcrumbs }) {
304
307
  const crumbs = useHandle(handle);
@@ -324,7 +327,7 @@ Track state of server action invocations:
324
327
 
325
328
  ```tsx
326
329
  "use client";
327
- import { useAction } from "@rangojs/router";
330
+ import { useAction } from "@rangojs/router/client";
328
331
  import { addToCart } from "../actions/cart";
329
332
 
330
333
  function AddToCartButton({ productId }: { productId: string }) {
@@ -359,7 +362,7 @@ Read type-safe state from history:
359
362
 
360
363
  ```tsx
361
364
  "use client";
362
- import { useLocationState, createLocationState } from "@rangojs/router";
365
+ import { useLocationState, createLocationState } from "@rangojs/router/client";
363
366
 
364
367
  // Define typed state (all export patterns supported)
365
368
  // Keys are auto-injected by the Vite plugin -- no manual key needed.
@@ -509,7 +512,7 @@ Manually control client-side navigation cache:
509
512
 
510
513
  ```tsx
511
514
  "use client";
512
- import { useClientCache } from "@rangojs/router";
515
+ import { useClientCache } from "@rangojs/router/client";
513
516
 
514
517
  function SaveButton() {
515
518
  const { clear } = useClientCache();
@@ -537,7 +540,7 @@ function SaveButton() {
537
540
  Render child content in layouts:
538
541
 
539
542
  ```tsx
540
- import { Outlet, ParallelOutlet } from "@rangojs/router";
543
+ import { Outlet, ParallelOutlet } from "@rangojs/router/client";
541
544
 
542
545
  function DashboardLayout({ children }: { children?: React.ReactNode }) {
543
546
  return (
@@ -558,7 +561,7 @@ Access outlet content programmatically:
558
561
 
559
562
  ```tsx
560
563
  "use client";
561
- import { useOutlet } from "@rangojs/router";
564
+ import { useOutlet } from "@rangojs/router/client";
562
565
 
563
566
  function ConditionalLayout() {
564
567
  const outlet = useOutlet();
@@ -695,7 +698,6 @@ See `/links` for full URL generation guide including server-side `ctx.reverse`.
695
698
  | `useLinkStatus()` | Link pending state | { pending } |
696
699
  | `useLoader()` | Loader data (strict) | data, isLoading, error |
697
700
  | `useFetchLoader()` | Loader with on-demand fetch | data, load, isLoading |
698
- | `useLoaderData()` | All loader data | Record<string, any> |
699
701
  | `useHandle()` | Accumulated handle data | T (handle type) |
700
702
  | `useAction()` | Server action state | state, error, result |
701
703
  | `useLocationState()` | History state (persists or flash) | T \| undefined |