@rangojs/router 0.0.0-experimental.16 → 0.0.0-experimental.18.d80c2f4.20260228
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.
- package/README.md +63 -35
- package/dist/bin/rango.js +945 -160
- package/dist/vite/index.js +3132 -1812
- package/package.json +60 -52
- package/skills/cache-guide/SKILL.md +258 -0
- package/skills/caching/SKILL.md +42 -13
- package/skills/composability/SKILL.md +172 -0
- package/skills/debug-manifest/SKILL.md +12 -8
- package/skills/document-cache/SKILL.md +8 -6
- package/skills/fonts/SKILL.md +6 -4
- package/skills/hooks/SKILL.md +132 -47
- package/skills/intercept/SKILL.md +48 -4
- package/skills/layout/SKILL.md +40 -3
- package/skills/links/SKILL.md +62 -15
- package/skills/loader/SKILL.md +7 -8
- package/skills/middleware/SKILL.md +62 -5
- package/skills/mime-routes/SKILL.md +14 -10
- package/skills/parallel/SKILL.md +22 -0
- package/skills/prerender/SKILL.md +191 -23
- package/skills/rango/SKILL.md +28 -26
- package/skills/response-routes/SKILL.md +129 -77
- package/skills/route/SKILL.md +149 -15
- package/skills/router-setup/SKILL.md +20 -15
- package/skills/testing/SKILL.md +37 -37
- package/skills/theme/SKILL.md +4 -4
- package/skills/typesafety/SKILL.md +92 -31
- package/skills/use-cache/SKILL.md +310 -0
- package/src/__internal.ts +9 -3
- package/src/bin/rango.ts +228 -19
- package/src/browser/action-response-classifier.ts +2 -7
- package/src/browser/event-controller.ts +25 -16
- package/src/browser/intercept-utils.ts +5 -9
- package/src/browser/link-interceptor.ts +1 -1
- package/src/browser/merge-segment-loaders.ts +5 -5
- package/src/browser/navigation-bridge.ts +137 -43
- package/src/browser/navigation-client.ts +12 -1
- package/src/browser/navigation-store.ts +35 -23
- package/src/browser/partial-update.ts +110 -23
- package/src/browser/react/Link.tsx +26 -11
- package/src/browser/react/NavigationProvider.tsx +16 -11
- package/src/browser/react/index.ts +6 -6
- package/src/browser/react/location-state-shared.ts +75 -51
- package/src/browser/react/location-state.ts +54 -11
- package/src/browser/react/mount-context.ts +6 -1
- package/src/browser/react/use-action.ts +6 -6
- package/src/browser/react/use-handle.ts +8 -6
- package/src/browser/react/use-link-status.ts +6 -5
- package/src/browser/react/use-navigation.ts +1 -2
- package/src/browser/react/use-segments.ts +6 -5
- package/src/browser/rsc-router.tsx +58 -15
- package/src/browser/scroll-restoration.ts +15 -8
- package/src/browser/server-action-bridge.ts +77 -10
- package/src/browser/shallow.ts +6 -1
- package/src/browser/types.ts +26 -12
- package/src/build/generate-manifest.ts +29 -12
- package/src/build/generate-route-types.ts +32 -848
- package/src/build/index.ts +1 -5
- package/src/build/route-trie.ts +5 -2
- package/src/build/route-types/ast-helpers.ts +25 -0
- package/src/build/route-types/ast-route-extraction.ts +98 -0
- package/src/build/route-types/codegen.ts +93 -0
- package/src/build/route-types/include-resolution.ts +398 -0
- package/src/build/route-types/param-extraction.ts +48 -0
- package/src/build/route-types/per-module-writer.ts +116 -0
- package/src/build/route-types/router-processing.ts +317 -0
- package/src/build/route-types/scan-filter.ts +78 -0
- package/src/build/runtime-discovery.ts +219 -0
- package/src/cache/cache-runtime.ts +325 -0
- package/src/cache/cache-scope.ts +62 -247
- package/src/cache/cf/cf-cache-store.ts +109 -2
- package/src/cache/cf/index.ts +8 -2
- package/src/cache/document-cache.ts +12 -7
- package/src/cache/handle-snapshot.ts +41 -0
- package/src/cache/memory-segment-store.ts +167 -5
- package/src/cache/memory-store.ts +2 -2
- package/src/cache/profile-registry.ts +38 -0
- package/src/cache/segment-codec.ts +233 -0
- package/src/cache/taint.ts +71 -0
- package/src/cache/types.ts +72 -8
- package/src/client.rsc.tsx +1 -0
- package/src/client.tsx +20 -45
- package/src/component-utils.ts +4 -4
- package/src/components/DefaultDocument.tsx +5 -1
- package/src/context-var.ts +86 -0
- package/src/debug.ts +17 -7
- package/src/errors.ts +63 -6
- package/src/fetchable-loader-action.ts +30 -0
- package/src/handle.ts +11 -6
- package/src/handles/MetaTags.tsx +68 -18
- package/src/handles/meta.ts +30 -13
- package/src/host/cookie-handler.ts +12 -12
- package/src/host/errors.ts +8 -8
- package/src/host/index.ts +5 -5
- package/src/host/pattern-matcher.ts +27 -27
- package/src/host/router.ts +31 -26
- package/src/host/testing.ts +8 -8
- package/src/host/types.ts +2 -2
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +62 -44
- package/src/index.rsc.ts +46 -6
- package/src/index.ts +82 -31
- package/src/internal-debug.ts +9 -3
- package/src/loader-action-shared.ts +104 -0
- package/src/loader.rsc.ts +23 -77
- package/src/loader.ts +18 -9
- package/src/network-error-thrower.tsx +3 -1
- package/src/outlet-provider.tsx +45 -0
- package/src/prerender/store.ts +69 -7
- package/src/prerender.ts +264 -15
- package/src/reverse.ts +133 -117
- package/src/root-error-boundary.tsx +11 -3
- package/src/route-content-wrapper.tsx +7 -4
- package/src/route-definition/dsl-helpers.ts +931 -0
- package/src/route-definition/helper-factories.ts +200 -0
- package/src/route-definition/helpers-types.ts +430 -0
- package/src/route-definition/index.ts +55 -0
- package/src/route-definition/redirect.ts +81 -0
- package/src/route-definition/route-function.ts +119 -0
- package/src/route-definition.ts +1 -1481
- package/src/route-map-builder.ts +44 -132
- package/src/route-types.ts +34 -6
- package/src/router/content-negotiation.ts +116 -0
- package/src/router/debug-manifest.ts +59 -0
- package/src/router/error-handling.ts +7 -7
- package/src/router/find-match.ts +158 -0
- package/src/router/handler-context.ts +193 -92
- package/src/router/intercept-resolution.ts +3 -0
- package/src/router/lazy-includes.ts +230 -0
- package/src/router/loader-resolution.ts +46 -37
- package/src/router/logging.ts +8 -2
- package/src/router/manifest.ts +20 -16
- package/src/router/match-api.ts +8 -6
- package/src/router/match-handlers.ts +266 -0
- package/src/router/match-middleware/background-revalidation.ts +6 -6
- package/src/router/match-middleware/cache-lookup.ts +176 -48
- package/src/router/match-middleware/cache-store.ts +25 -10
- package/src/router/match-middleware/intercept-resolution.ts +42 -21
- package/src/router/match-middleware/segment-resolution.ts +16 -8
- package/src/router/match-pipelines.ts +4 -4
- package/src/router/match-result.ts +7 -5
- package/src/router/metrics.ts +3 -3
- package/src/router/middleware-cookies.ts +55 -0
- package/src/router/middleware-types.ts +210 -0
- package/src/router/middleware.ts +86 -255
- package/src/router/pattern-matching.ts +66 -16
- package/src/router/prerender-match.ts +360 -0
- package/src/router/preview-match.ts +161 -0
- package/src/router/revalidation.ts +18 -6
- package/src/router/router-context.ts +21 -21
- package/src/router/router-interfaces.ts +315 -0
- package/src/router/router-options.ts +361 -0
- package/src/router/router-registry.ts +21 -0
- package/src/router/segment-resolution/fresh.ts +645 -0
- package/src/router/segment-resolution/loader-cache.ts +194 -0
- package/src/router/segment-resolution/revalidation.ts +1118 -0
- package/src/router/segment-resolution/static-store.ts +67 -0
- package/src/router/segment-resolution.ts +23 -1384
- package/src/router/segment-wrappers.ts +286 -0
- package/src/router/trie-matching.ts +56 -23
- package/src/router/types.ts +8 -8
- package/src/router.ts +314 -2269
- package/src/rsc/handler-context.ts +34 -0
- package/src/rsc/handler.ts +367 -840
- package/src/rsc/helpers.ts +1 -1
- package/src/rsc/loader-fetch.ts +160 -0
- package/src/rsc/manifest-init.ts +85 -0
- package/src/rsc/progressive-enhancement.ts +153 -0
- package/src/rsc/response-error.ts +37 -0
- package/src/rsc/rsc-rendering.ts +224 -0
- package/src/rsc/server-action.ts +237 -0
- package/src/rsc/types.ts +12 -8
- package/src/search-params.ts +29 -32
- package/src/segment-system.tsx +24 -12
- package/src/server/context.ts +83 -38
- package/src/server/handle-store.ts +10 -3
- package/src/server/loader-registry.ts +3 -3
- package/src/server/request-context.ts +114 -32
- package/src/server.ts +10 -9
- package/src/ssr/index.tsx +39 -13
- package/src/static-handler.ts +15 -4
- package/src/theme/ThemeProvider.tsx +15 -14
- package/src/theme/ThemeScript.tsx +5 -5
- package/src/theme/constants.ts +5 -2
- package/src/theme/index.ts +5 -1
- package/src/theme/theme-context.ts +3 -2
- package/src/theme/theme-script.ts +19 -17
- package/src/types/boundaries.ts +158 -0
- package/src/types/cache-types.ts +193 -0
- package/src/types/error-types.ts +189 -0
- package/src/types/global-namespace.ts +71 -0
- package/src/types/handler-context.ts +608 -0
- package/src/types/index.ts +91 -0
- package/src/types/loader-types.ts +200 -0
- package/src/types/route-config.ts +189 -0
- package/src/types/route-entry.ts +74 -0
- package/src/types/segments.ts +153 -0
- package/src/types.ts +1 -1795
- package/src/urls/include-helper.ts +156 -0
- package/src/urls/index.ts +52 -0
- package/src/urls/path-helper-types.ts +321 -0
- package/src/urls/path-helper.ts +314 -0
- package/src/urls/pattern-types.ts +75 -0
- package/src/urls/response-types.ts +85 -0
- package/src/urls/type-extraction.ts +364 -0
- package/src/urls/urls-function.ts +98 -0
- package/src/urls.ts +1 -1352
- package/src/use-loader.tsx +55 -19
- package/src/vite/discovery/bundle-postprocess.ts +204 -0
- package/src/vite/discovery/discover-routers.ts +318 -0
- package/src/vite/discovery/prerender-collection.ts +368 -0
- package/src/vite/discovery/route-types-writer.ts +258 -0
- package/src/vite/discovery/self-gen-tracking.ts +47 -0
- package/src/vite/discovery/state.ts +110 -0
- package/src/vite/discovery/virtual-module-codegen.ts +200 -0
- package/src/vite/index.ts +57 -2368
- package/src/vite/plugin-types.ts +131 -0
- package/src/vite/plugins/cjs-to-esm.ts +93 -0
- package/src/vite/plugins/client-ref-hashing.ts +105 -0
- package/src/vite/{expose-action-id.ts → plugins/expose-action-id.ts} +72 -45
- package/src/vite/{expose-id-utils.ts → plugins/expose-id-utils.ts} +8 -43
- package/src/vite/plugins/expose-ids/export-analysis.ts +296 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +179 -0
- package/src/vite/plugins/expose-ids/loader-transform.ts +92 -0
- package/src/vite/plugins/expose-ids/router-transform.ts +110 -0
- package/src/vite/plugins/expose-ids/types.ts +45 -0
- package/src/vite/plugins/expose-internal-ids.ts +568 -0
- package/src/vite/plugins/use-cache-transform.ts +235 -0
- package/src/vite/plugins/version-injector.ts +83 -0
- package/src/vite/plugins/version-plugin.ts +84 -0
- package/src/vite/{virtual-entries.ts → plugins/virtual-entries.ts} +23 -14
- package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
- package/src/vite/rango.ts +485 -0
- package/src/vite/router-discovery.ts +712 -0
- package/src/vite/{ast-handler-extract.ts → utils/ast-handler-extract.ts} +181 -9
- package/src/vite/utils/banner.ts +36 -0
- package/src/vite/utils/bundle-analysis.ts +137 -0
- package/src/vite/utils/manifest-utils.ts +70 -0
- package/src/vite/{package-resolution.ts → utils/package-resolution.ts} +1 -1
- package/src/vite/utils/prerender-utils.ts +108 -0
- package/src/vite/utils/shared-utils.ts +159 -0
- package/src/vite/expose-internal-ids.ts +0 -1167
- /package/src/vite/{version.d.ts → plugins/version.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -47,10 +47,7 @@ import { defineConfig } from "vite";
|
|
|
47
47
|
import { rango } from "@rangojs/router/vite";
|
|
48
48
|
|
|
49
49
|
export default defineConfig({
|
|
50
|
-
plugins: [
|
|
51
|
-
react(),
|
|
52
|
-
rango({ preset: "cloudflare" }),
|
|
53
|
-
],
|
|
50
|
+
plugins: [react(), rango({ preset: "cloudflare" })],
|
|
54
51
|
});
|
|
55
52
|
```
|
|
56
53
|
|
|
@@ -69,8 +66,7 @@ const urlpatterns = urls(({ path, layout }) => [
|
|
|
69
66
|
]),
|
|
70
67
|
]);
|
|
71
68
|
|
|
72
|
-
export const router = createRouter({ document: Document })
|
|
73
|
-
.routes(urlpatterns);
|
|
69
|
+
export const router = createRouter({ document: Document }).routes(urlpatterns);
|
|
74
70
|
|
|
75
71
|
// Export typed reverse function for URL generation by route name
|
|
76
72
|
export const reverse = router.reverse;
|
|
@@ -138,9 +134,9 @@ const urlpatterns = urls(({ path }) => [
|
|
|
138
134
|
}),
|
|
139
135
|
]);
|
|
140
136
|
|
|
141
|
-
// Handler receives typed
|
|
137
|
+
// Handler receives typed search params via ctx.search
|
|
142
138
|
const SearchPage: Handler<"search"> = (ctx) => {
|
|
143
|
-
const { q, page, sort } = ctx.
|
|
139
|
+
const { q, page, sort } = ctx.search;
|
|
144
140
|
// q: string, page: number | undefined, sort: string | undefined
|
|
145
141
|
};
|
|
146
142
|
```
|
|
@@ -234,7 +230,13 @@ import { BlogSidebarLoader } from "./loaders/blog";
|
|
|
234
230
|
|
|
235
231
|
async function BlogSidebarHandler(ctx: HandlerContext) {
|
|
236
232
|
const { posts } = await ctx.use(BlogSidebarLoader);
|
|
237
|
-
return
|
|
233
|
+
return (
|
|
234
|
+
<ul>
|
|
235
|
+
{posts.map((p) => (
|
|
236
|
+
<li key={p.slug}>{p.title}</li>
|
|
237
|
+
))}
|
|
238
|
+
</ul>
|
|
239
|
+
);
|
|
238
240
|
}
|
|
239
241
|
```
|
|
240
242
|
|
|
@@ -247,7 +249,13 @@ import { BlogSidebarLoader } from "./loaders/blog";
|
|
|
247
249
|
|
|
248
250
|
function BlogSidebar() {
|
|
249
251
|
const { posts } = useLoader(BlogSidebarLoader);
|
|
250
|
-
return
|
|
252
|
+
return (
|
|
253
|
+
<ul>
|
|
254
|
+
{posts.map((p) => (
|
|
255
|
+
<li key={p.slug}>{p.title}</li>
|
|
256
|
+
))}
|
|
257
|
+
</ul>
|
|
258
|
+
);
|
|
251
259
|
}
|
|
252
260
|
```
|
|
253
261
|
|
|
@@ -305,7 +313,9 @@ function Nav() {
|
|
|
305
313
|
return (
|
|
306
314
|
<nav>
|
|
307
315
|
<Link to={href("/")}>Home</Link>
|
|
308
|
-
<Link to={href("/blog")} prefetch="intent">
|
|
316
|
+
<Link to={href("/blog")} prefetch="intent">
|
|
317
|
+
Blog
|
|
318
|
+
</Link>
|
|
309
319
|
<Link to={href("/about")}>About</Link>
|
|
310
320
|
</nav>
|
|
311
321
|
);
|
|
@@ -379,14 +389,17 @@ Included route names are prefixed with the include name: `reverse("api.health")`
|
|
|
379
389
|
|
|
380
390
|
```tsx
|
|
381
391
|
const urlpatterns = urls(({ path, middleware }) => [
|
|
382
|
-
middleware(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
392
|
+
middleware(
|
|
393
|
+
async (ctx, next) => {
|
|
394
|
+
const start = Date.now();
|
|
395
|
+
const response = await next();
|
|
396
|
+
console.log(
|
|
397
|
+
`${ctx.request.method} ${ctx.url.pathname} ${Date.now() - start}ms`,
|
|
398
|
+
);
|
|
399
|
+
return response;
|
|
400
|
+
},
|
|
401
|
+
() => [path("/dashboard", DashboardPage, { name: "dashboard" })],
|
|
402
|
+
),
|
|
390
403
|
]);
|
|
391
404
|
```
|
|
392
405
|
|
|
@@ -407,7 +420,10 @@ const urlpatterns = urls(({ path, cache }) => [
|
|
|
407
420
|
|
|
408
421
|
```tsx
|
|
409
422
|
import { createRouter } from "@rangojs/router";
|
|
410
|
-
import {
|
|
423
|
+
import {
|
|
424
|
+
CFCacheStore,
|
|
425
|
+
createDocumentCacheMiddleware,
|
|
426
|
+
} from "@rangojs/router/cache";
|
|
411
427
|
|
|
412
428
|
export const router = createRouter({
|
|
413
429
|
document: Document,
|
|
@@ -423,6 +439,7 @@ export const router = createRouter({
|
|
|
423
439
|
```
|
|
424
440
|
|
|
425
441
|
Available cache stores:
|
|
442
|
+
|
|
426
443
|
- `CFCacheStore` — Cloudflare edge cache (production)
|
|
427
444
|
- `MemorySegmentCacheStore` — In-memory cache (development/testing)
|
|
428
445
|
|
|
@@ -443,7 +460,15 @@ export const AboutPage = Static(async () => {
|
|
|
443
460
|
|
|
444
461
|
export const DocsNav = Static(async () => {
|
|
445
462
|
const items = await readDocsNavItems();
|
|
446
|
-
return
|
|
463
|
+
return (
|
|
464
|
+
<nav>
|
|
465
|
+
{items.map((i) => (
|
|
466
|
+
<a key={i.slug} href={i.slug}>
|
|
467
|
+
{i.title}
|
|
468
|
+
</a>
|
|
469
|
+
))}
|
|
470
|
+
</nav>
|
|
471
|
+
);
|
|
447
472
|
});
|
|
448
473
|
```
|
|
449
474
|
|
|
@@ -457,7 +482,7 @@ import { Prerender } from "@rangojs/router";
|
|
|
457
482
|
export const BlogPost = Prerender(
|
|
458
483
|
async () => {
|
|
459
484
|
const slugs = await getAllBlogSlugs();
|
|
460
|
-
return slugs.map(slug => ({ slug }));
|
|
485
|
+
return slugs.map((slug) => ({ slug }));
|
|
461
486
|
},
|
|
462
487
|
async (ctx) => {
|
|
463
488
|
const post = await getPost(ctx.params.slug);
|
|
@@ -474,7 +499,7 @@ import { Prerender } from "@rangojs/router";
|
|
|
474
499
|
export const ProductPage = Prerender(
|
|
475
500
|
async () => {
|
|
476
501
|
const featured = await db.getFeaturedProducts();
|
|
477
|
-
return featured.map(p => ({ id: p.id }));
|
|
502
|
+
return featured.map((p) => ({ id: p.id }));
|
|
478
503
|
},
|
|
479
504
|
async (ctx) => {
|
|
480
505
|
const product = await db.getProduct(ctx.params.id);
|
|
@@ -511,8 +536,10 @@ import { useTheme } from "@rangojs/router/theme";
|
|
|
511
536
|
function ThemeToggle() {
|
|
512
537
|
const { theme, setTheme, themes } = useTheme();
|
|
513
538
|
return (
|
|
514
|
-
<select value={theme} onChange={e => setTheme(e.target.value)}>
|
|
515
|
-
{themes.map(t =>
|
|
539
|
+
<select value={theme} onChange={(e) => setTheme(e.target.value)}>
|
|
540
|
+
{themes.map((t) => (
|
|
541
|
+
<option key={t}>{t}</option>
|
|
542
|
+
))}
|
|
516
543
|
</select>
|
|
517
544
|
);
|
|
518
545
|
}
|
|
@@ -572,6 +599,7 @@ npx rango generate src/urls.tsx src/api/ # mix files and directories
|
|
|
572
599
|
```
|
|
573
600
|
|
|
574
601
|
Auto-detects file type:
|
|
602
|
+
|
|
575
603
|
- Files with `createRouter` → `*.named-routes.gen.ts` with global route map
|
|
576
604
|
- Files with `urls()` → `*.gen.ts` with per-module route names, params, and search types
|
|
577
605
|
|
|
@@ -581,16 +609,16 @@ The Vite plugin automatically generates a `router.named-routes.gen.ts` file that
|
|
|
581
609
|
|
|
582
610
|
## Subpath Exports
|
|
583
611
|
|
|
584
|
-
| Export
|
|
585
|
-
|
|
586
|
-
| `@rangojs/router`
|
|
587
|
-
| `@rangojs/router/client` | Client: `Link`, `Outlet`, `href`, `useNavigation`, `useLoader`, `MetaTags`
|
|
588
|
-
| `@rangojs/router/cache`
|
|
589
|
-
| `@rangojs/router/theme`
|
|
590
|
-
| `@rangojs/router/host`
|
|
591
|
-
| `@rangojs/router/vite`
|
|
592
|
-
| `@rangojs/router/server` | Server utilities
|
|
593
|
-
| `@rangojs/router/build`
|
|
612
|
+
| Export | Description |
|
|
613
|
+
| ------------------------ | --------------------------------------------------------------------------------- |
|
|
614
|
+
| `@rangojs/router` | Core: `createRouter`, `urls`, `createLoader`, `Handler`, `Prerender`, `Meta` |
|
|
615
|
+
| `@rangojs/router/client` | Client: `Link`, `Outlet`, `href`, `useNavigation`, `useLoader`, `MetaTags` |
|
|
616
|
+
| `@rangojs/router/cache` | Cache: `CFCacheStore`, `MemorySegmentCacheStore`, `createDocumentCacheMiddleware` |
|
|
617
|
+
| `@rangojs/router/theme` | Theme: `useTheme`, `ThemeProvider`, `ThemeScript` |
|
|
618
|
+
| `@rangojs/router/host` | Host routing: `createHostRouter`, `defineHosts` |
|
|
619
|
+
| `@rangojs/router/vite` | Vite plugin: `rango()` |
|
|
620
|
+
| `@rangojs/router/server` | Server utilities |
|
|
621
|
+
| `@rangojs/router/build` | Build utilities |
|
|
594
622
|
|
|
595
623
|
## Examples
|
|
596
624
|
|