@rangojs/router 0.0.0-experimental.0f44aca1
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/AGENTS.md +5 -0
- package/README.md +899 -0
- package/dist/bin/rango.js +1601 -0
- package/dist/vite/index.js +5214 -0
- package/package.json +176 -0
- package/skills/breadcrumbs/SKILL.md +250 -0
- package/skills/cache-guide/SKILL.md +262 -0
- package/skills/caching/SKILL.md +220 -0
- package/skills/composability/SKILL.md +172 -0
- package/skills/debug-manifest/SKILL.md +112 -0
- package/skills/document-cache/SKILL.md +182 -0
- package/skills/fonts/SKILL.md +167 -0
- package/skills/hooks/SKILL.md +704 -0
- package/skills/host-router/SKILL.md +218 -0
- package/skills/intercept/SKILL.md +313 -0
- package/skills/layout/SKILL.md +310 -0
- package/skills/links/SKILL.md +239 -0
- package/skills/loader/SKILL.md +596 -0
- package/skills/middleware/SKILL.md +339 -0
- package/skills/mime-routes/SKILL.md +128 -0
- package/skills/parallel/SKILL.md +305 -0
- package/skills/prerender/SKILL.md +643 -0
- package/skills/rango/SKILL.md +118 -0
- package/skills/response-routes/SKILL.md +411 -0
- package/skills/route/SKILL.md +385 -0
- package/skills/router-setup/SKILL.md +439 -0
- package/skills/tailwind/SKILL.md +129 -0
- package/skills/theme/SKILL.md +79 -0
- package/skills/typesafety/SKILL.md +623 -0
- package/skills/use-cache/SKILL.md +324 -0
- package/src/__internal.ts +273 -0
- package/src/bin/rango.ts +321 -0
- package/src/browser/action-coordinator.ts +97 -0
- package/src/browser/action-response-classifier.ts +99 -0
- package/src/browser/event-controller.ts +899 -0
- package/src/browser/history-state.ts +80 -0
- package/src/browser/index.ts +18 -0
- package/src/browser/intercept-utils.ts +52 -0
- package/src/browser/link-interceptor.ts +141 -0
- package/src/browser/logging.ts +55 -0
- package/src/browser/merge-segment-loaders.ts +134 -0
- package/src/browser/navigation-bridge.ts +645 -0
- package/src/browser/navigation-client.ts +215 -0
- package/src/browser/navigation-store.ts +806 -0
- package/src/browser/navigation-transaction.ts +295 -0
- package/src/browser/network-error-handler.ts +61 -0
- package/src/browser/partial-update.ts +550 -0
- package/src/browser/prefetch/cache.ts +146 -0
- package/src/browser/prefetch/fetch.ts +135 -0
- package/src/browser/prefetch/observer.ts +65 -0
- package/src/browser/prefetch/policy.ts +42 -0
- package/src/browser/prefetch/queue.ts +88 -0
- package/src/browser/rango-state.ts +112 -0
- package/src/browser/react/Link.tsx +360 -0
- package/src/browser/react/NavigationProvider.tsx +386 -0
- package/src/browser/react/ScrollRestoration.tsx +94 -0
- package/src/browser/react/context.ts +59 -0
- package/src/browser/react/filter-segment-order.ts +11 -0
- package/src/browser/react/index.ts +52 -0
- package/src/browser/react/location-state-shared.ts +162 -0
- package/src/browser/react/location-state.ts +107 -0
- package/src/browser/react/mount-context.ts +37 -0
- package/src/browser/react/nonce-context.ts +23 -0
- package/src/browser/react/shallow-equal.ts +27 -0
- package/src/browser/react/use-action.ts +218 -0
- package/src/browser/react/use-client-cache.ts +58 -0
- package/src/browser/react/use-handle.ts +162 -0
- package/src/browser/react/use-href.tsx +40 -0
- package/src/browser/react/use-link-status.ts +135 -0
- package/src/browser/react/use-mount.ts +31 -0
- package/src/browser/react/use-navigation.ts +99 -0
- package/src/browser/react/use-params.ts +65 -0
- package/src/browser/react/use-pathname.ts +47 -0
- package/src/browser/react/use-router.ts +63 -0
- package/src/browser/react/use-search-params.ts +56 -0
- package/src/browser/react/use-segments.ts +171 -0
- package/src/browser/response-adapter.ts +73 -0
- package/src/browser/rsc-router.tsx +431 -0
- package/src/browser/scroll-restoration.ts +400 -0
- package/src/browser/segment-reconciler.ts +216 -0
- package/src/browser/segment-structure-assert.ts +83 -0
- package/src/browser/server-action-bridge.ts +667 -0
- package/src/browser/shallow.ts +40 -0
- package/src/browser/types.ts +538 -0
- package/src/browser/validate-redirect-origin.ts +29 -0
- package/src/build/generate-manifest.ts +438 -0
- package/src/build/generate-route-types.ts +36 -0
- package/src/build/index.ts +35 -0
- package/src/build/route-trie.ts +265 -0
- 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 +102 -0
- package/src/build/route-types/include-resolution.ts +411 -0
- package/src/build/route-types/param-extraction.ts +48 -0
- package/src/build/route-types/per-module-writer.ts +128 -0
- package/src/build/route-types/router-processing.ts +469 -0
- package/src/build/route-types/scan-filter.ts +78 -0
- package/src/build/runtime-discovery.ts +231 -0
- package/src/cache/background-task.ts +34 -0
- package/src/cache/cache-key-utils.ts +44 -0
- package/src/cache/cache-policy.ts +125 -0
- package/src/cache/cache-runtime.ts +338 -0
- package/src/cache/cache-scope.ts +382 -0
- package/src/cache/cf/cf-cache-store.ts +540 -0
- package/src/cache/cf/index.ts +25 -0
- package/src/cache/document-cache.ts +369 -0
- package/src/cache/handle-capture.ts +81 -0
- package/src/cache/handle-snapshot.ts +41 -0
- package/src/cache/index.ts +43 -0
- package/src/cache/memory-segment-store.ts +328 -0
- package/src/cache/profile-registry.ts +73 -0
- package/src/cache/read-through-swr.ts +134 -0
- package/src/cache/segment-codec.ts +256 -0
- package/src/cache/taint.ts +98 -0
- package/src/cache/types.ts +342 -0
- package/src/client.rsc.tsx +85 -0
- package/src/client.tsx +601 -0
- package/src/component-utils.ts +76 -0
- package/src/components/DefaultDocument.tsx +27 -0
- package/src/context-var.ts +86 -0
- package/src/debug.ts +243 -0
- package/src/default-error-boundary.tsx +88 -0
- package/src/deps/browser.ts +8 -0
- package/src/deps/html-stream-client.ts +2 -0
- package/src/deps/html-stream-server.ts +2 -0
- package/src/deps/rsc.ts +10 -0
- package/src/deps/ssr.ts +2 -0
- package/src/errors.ts +365 -0
- package/src/handle.ts +135 -0
- package/src/handles/MetaTags.tsx +246 -0
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +7 -0
- package/src/handles/meta.ts +264 -0
- package/src/host/cookie-handler.ts +165 -0
- package/src/host/errors.ts +97 -0
- package/src/host/index.ts +53 -0
- package/src/host/pattern-matcher.ts +214 -0
- package/src/host/router.ts +352 -0
- package/src/host/testing.ts +79 -0
- package/src/host/types.ts +146 -0
- package/src/host/utils.ts +25 -0
- package/src/href-client.ts +222 -0
- package/src/index.rsc.ts +233 -0
- package/src/index.ts +277 -0
- package/src/internal-debug.ts +11 -0
- package/src/loader.rsc.ts +89 -0
- package/src/loader.ts +64 -0
- package/src/network-error-thrower.tsx +23 -0
- package/src/outlet-context.ts +15 -0
- package/src/outlet-provider.tsx +45 -0
- package/src/prerender/param-hash.ts +37 -0
- package/src/prerender/store.ts +185 -0
- package/src/prerender.ts +463 -0
- package/src/reverse.ts +330 -0
- package/src/root-error-boundary.tsx +289 -0
- package/src/route-content-wrapper.tsx +196 -0
- package/src/route-definition/dsl-helpers.ts +934 -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 +52 -0
- package/src/route-definition/redirect.ts +93 -0
- package/src/route-definition.ts +1 -0
- package/src/route-map-builder.ts +275 -0
- package/src/route-name.ts +53 -0
- package/src/route-types.ts +259 -0
- package/src/router/content-negotiation.ts +116 -0
- package/src/router/debug-manifest.ts +72 -0
- package/src/router/error-handling.ts +287 -0
- package/src/router/find-match.ts +158 -0
- package/src/router/handler-context.ts +451 -0
- package/src/router/intercept-resolution.ts +395 -0
- package/src/router/lazy-includes.ts +234 -0
- package/src/router/loader-resolution.ts +420 -0
- package/src/router/logging.ts +248 -0
- package/src/router/manifest.ts +267 -0
- package/src/router/match-api.ts +620 -0
- package/src/router/match-context.ts +266 -0
- package/src/router/match-handlers.ts +440 -0
- package/src/router/match-middleware/background-revalidation.ts +223 -0
- package/src/router/match-middleware/cache-lookup.ts +634 -0
- package/src/router/match-middleware/cache-store.ts +295 -0
- package/src/router/match-middleware/index.ts +81 -0
- package/src/router/match-middleware/intercept-resolution.ts +306 -0
- package/src/router/match-middleware/segment-resolution.ts +192 -0
- package/src/router/match-pipelines.ts +179 -0
- package/src/router/match-result.ts +219 -0
- package/src/router/metrics.ts +282 -0
- package/src/router/middleware-cookies.ts +55 -0
- package/src/router/middleware-types.ts +222 -0
- package/src/router/middleware.ts +748 -0
- package/src/router/pattern-matching.ts +563 -0
- package/src/router/prerender-match.ts +402 -0
- package/src/router/preview-match.ts +170 -0
- package/src/router/revalidation.ts +289 -0
- package/src/router/router-context.ts +316 -0
- package/src/router/router-interfaces.ts +452 -0
- package/src/router/router-options.ts +592 -0
- package/src/router/router-registry.ts +24 -0
- package/src/router/segment-resolution/fresh.ts +570 -0
- package/src/router/segment-resolution/helpers.ts +263 -0
- package/src/router/segment-resolution/loader-cache.ts +198 -0
- package/src/router/segment-resolution/revalidation.ts +1239 -0
- package/src/router/segment-resolution/static-store.ts +67 -0
- package/src/router/segment-resolution.ts +21 -0
- package/src/router/segment-wrappers.ts +289 -0
- package/src/router/telemetry-otel.ts +299 -0
- package/src/router/telemetry.ts +300 -0
- package/src/router/timeout.ts +148 -0
- package/src/router/trie-matching.ts +239 -0
- package/src/router/types.ts +170 -0
- package/src/router.ts +1002 -0
- package/src/rsc/handler-context.ts +45 -0
- package/src/rsc/handler.ts +1089 -0
- package/src/rsc/helpers.ts +198 -0
- package/src/rsc/index.ts +36 -0
- package/src/rsc/loader-fetch.ts +209 -0
- package/src/rsc/manifest-init.ts +86 -0
- package/src/rsc/nonce.ts +32 -0
- package/src/rsc/origin-guard.ts +141 -0
- package/src/rsc/progressive-enhancement.ts +379 -0
- package/src/rsc/response-error.ts +37 -0
- package/src/rsc/response-route-handler.ts +347 -0
- package/src/rsc/rsc-rendering.ts +235 -0
- package/src/rsc/runtime-warnings.ts +42 -0
- package/src/rsc/server-action.ts +348 -0
- package/src/rsc/ssr-setup.ts +128 -0
- package/src/rsc/types.ts +263 -0
- package/src/search-params.ts +230 -0
- package/src/segment-system.tsx +454 -0
- package/src/server/context.ts +591 -0
- package/src/server/cookie-store.ts +190 -0
- package/src/server/fetchable-loader-store.ts +37 -0
- package/src/server/handle-store.ts +308 -0
- package/src/server/loader-registry.ts +133 -0
- package/src/server/request-context.ts +914 -0
- package/src/server/root-layout.tsx +10 -0
- package/src/server/tsconfig.json +14 -0
- package/src/server.ts +51 -0
- package/src/ssr/index.tsx +365 -0
- package/src/static-handler.ts +114 -0
- package/src/theme/ThemeProvider.tsx +297 -0
- package/src/theme/ThemeScript.tsx +61 -0
- package/src/theme/constants.ts +62 -0
- package/src/theme/index.ts +48 -0
- package/src/theme/theme-context.ts +44 -0
- package/src/theme/theme-script.ts +155 -0
- package/src/theme/types.ts +182 -0
- package/src/theme/use-theme.ts +44 -0
- package/src/types/boundaries.ts +158 -0
- package/src/types/cache-types.ts +198 -0
- package/src/types/error-types.ts +192 -0
- package/src/types/global-namespace.ts +100 -0
- package/src/types/handler-context.ts +687 -0
- package/src/types/index.ts +88 -0
- package/src/types/loader-types.ts +183 -0
- package/src/types/route-config.ts +170 -0
- package/src/types/route-entry.ts +102 -0
- package/src/types/segments.ts +148 -0
- package/src/types.ts +1 -0
- package/src/urls/include-helper.ts +197 -0
- package/src/urls/index.ts +53 -0
- package/src/urls/path-helper-types.ts +339 -0
- package/src/urls/path-helper.ts +329 -0
- package/src/urls/pattern-types.ts +95 -0
- package/src/urls/response-types.ts +106 -0
- package/src/urls/type-extraction.ts +372 -0
- package/src/urls/urls-function.ts +98 -0
- package/src/urls.ts +1 -0
- package/src/use-loader.tsx +354 -0
- package/src/vite/discovery/bundle-postprocess.ts +184 -0
- package/src/vite/discovery/discover-routers.ts +344 -0
- package/src/vite/discovery/prerender-collection.ts +385 -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 +203 -0
- package/src/vite/index.ts +16 -0
- package/src/vite/plugin-types.ts +131 -0
- package/src/vite/plugins/cjs-to-esm.ts +93 -0
- package/src/vite/plugins/client-ref-dedup.ts +115 -0
- package/src/vite/plugins/client-ref-hashing.ts +105 -0
- package/src/vite/plugins/expose-action-id.ts +365 -0
- package/src/vite/plugins/expose-id-utils.ts +287 -0
- 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 +74 -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 +569 -0
- package/src/vite/plugins/refresh-cmd.ts +65 -0
- package/src/vite/plugins/use-cache-transform.ts +323 -0
- package/src/vite/plugins/version-injector.ts +83 -0
- package/src/vite/plugins/version-plugin.ts +254 -0
- package/src/vite/plugins/version.d.ts +12 -0
- package/src/vite/plugins/virtual-entries.ts +123 -0
- package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
- package/src/vite/rango.ts +510 -0
- package/src/vite/router-discovery.ts +785 -0
- package/src/vite/utils/ast-handler-extract.ts +517 -0
- 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/utils/package-resolution.ts +121 -0
- package/src/vite/utils/prerender-utils.ts +189 -0
- package/src/vite/utils/shared-utils.ts +169 -0
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prerender
|
|
3
|
+
description: Pre-render route segments at build time with Prerender and passthrough fallback
|
|
4
|
+
argument-hint: [passthrough]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Pre-rendering with Prerender
|
|
8
|
+
|
|
9
|
+
Pre-rendering is **caching at build time**. Same serialization format, same
|
|
10
|
+
deserialization path, same segment system. The worker handles every request --
|
|
11
|
+
there are NO static .html or .rsc files served from assets. The worker reads
|
|
12
|
+
pre-computed Flight payloads instead of executing handler code.
|
|
13
|
+
|
|
14
|
+
Canonical semantics reference:
|
|
15
|
+
[docs/execution-model.md](../../docs/internal/execution-model.md)
|
|
16
|
+
|
|
17
|
+
## API: Prerender
|
|
18
|
+
|
|
19
|
+
### Static Route (no params)
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Prerender } from "@rangojs/router";
|
|
23
|
+
|
|
24
|
+
export const AboutPage = Prerender(async (ctx) => {
|
|
25
|
+
const content = await fs.readFile("content/about.md", "utf-8");
|
|
26
|
+
return <Page content={markdownToJsx(content)} />;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// urls.tsx
|
|
30
|
+
path("/about", AboutPage, { name: "about" })
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Dynamic Route (with params)
|
|
34
|
+
|
|
35
|
+
Params come first, handler second:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
export const BlogPost = Prerender(
|
|
39
|
+
// 1. Params: which slugs to pre-render
|
|
40
|
+
async () => {
|
|
41
|
+
const files = await glob("content/blog/*.md");
|
|
42
|
+
return files.map(f => ({ slug: basename(f, ".md") }));
|
|
43
|
+
},
|
|
44
|
+
// 2. Handler: runs at build time with BuildContext
|
|
45
|
+
async (ctx) => {
|
|
46
|
+
const md = await fs.readFile(`content/${ctx.params.slug}.md`, "utf-8");
|
|
47
|
+
return <Article content={markdownToJsx(md)} />;
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// urls.tsx
|
|
52
|
+
path("/blog/:slug", BlogPost, { name: "blog.post" })
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With Passthrough (live fallback for unknown params)
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
export const ProductPage = Prerender(
|
|
59
|
+
async () => {
|
|
60
|
+
const top = await db.query("SELECT id FROM products WHERE featured");
|
|
61
|
+
return top.map(p => ({ id: p.id }));
|
|
62
|
+
},
|
|
63
|
+
async (ctx) => {
|
|
64
|
+
const product = await db.query("SELECT * FROM products WHERE id = ?", ctx.params.id);
|
|
65
|
+
return <Product data={product} />;
|
|
66
|
+
},
|
|
67
|
+
{ passthrough: true, concurrency: 4 }
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Passthrough Mode
|
|
72
|
+
|
|
73
|
+
Controls whether the handler stays in the RSC server bundle after build:
|
|
74
|
+
|
|
75
|
+
| | `passthrough: false` (default) | `passthrough: true` |
|
|
76
|
+
| ------------------- | --------------------------------------- | --------------------------------------- |
|
|
77
|
+
| Known params | Served from pre-rendered Flight payload | Served from pre-rendered Flight payload |
|
|
78
|
+
| Unknown params | Handler evicted, no live fallback | Handler runs live at request time |
|
|
79
|
+
| `ctx.passthrough()` | Throws (not allowed) | Skips artifact, defers to live fallback |
|
|
80
|
+
| Bundle size | Handler code + imports removed | Handler code kept in RSC bundle |
|
|
81
|
+
| `revalidate()` | Not allowed (handler gone) | Allowed (handler can re-render) |
|
|
82
|
+
| `loading()` | Ignored (segments fully resolved) | Works for live fallback renders |
|
|
83
|
+
|
|
84
|
+
### When to use passthrough
|
|
85
|
+
|
|
86
|
+
Use `passthrough: true` when:
|
|
87
|
+
|
|
88
|
+
- The route has a large or open-ended param space (e.g., user profiles, product pages)
|
|
89
|
+
- You want to pre-render popular/known params for speed but still serve unknown params live
|
|
90
|
+
- You need `revalidate()` on the route
|
|
91
|
+
|
|
92
|
+
Use `passthrough: false` (default) when:
|
|
93
|
+
|
|
94
|
+
- All possible params are known at build time (e.g., markdown files, config-driven pages)
|
|
95
|
+
- You want maximum bundle size reduction (handler code + node:fs imports removed)
|
|
96
|
+
- The route uses build-only APIs (node:fs, local files) not available at runtime
|
|
97
|
+
|
|
98
|
+
## BuildContext
|
|
99
|
+
|
|
100
|
+
Handlers receive `BuildContext` at build time, a subset of the runtime `HandlerContext`:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
interface BuildContext<TParams> {
|
|
104
|
+
params: TParams; // From getParams
|
|
105
|
+
build: true; // Always true at build time
|
|
106
|
+
use: <T>(handle: Handle<T>) => (data: T) => void; // Push handle data
|
|
107
|
+
url: URL; // Synthetic URL from pattern + params
|
|
108
|
+
pathname: string; // Pathname from synthetic URL
|
|
109
|
+
set(key: string, value: any): void; // Set context variable (string key)
|
|
110
|
+
set<T>(contextVar: ContextVar<T>, value: T): void; // Set typed context variable
|
|
111
|
+
get(key: string): any; // Read context variable (string key)
|
|
112
|
+
get<T>(contextVar: ContextVar<T>): T | undefined; // Read typed context variable
|
|
113
|
+
reverse(
|
|
114
|
+
name: string,
|
|
115
|
+
params?: Record<string, string>,
|
|
116
|
+
search?: Record<string, unknown>,
|
|
117
|
+
): string; // URL generation
|
|
118
|
+
passthrough(): PrerenderPassthroughResult; // Skip local artifact (passthrough routes only)
|
|
119
|
+
// NOT available: req, headers, cookies, env (throws descriptive errors)
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Use `createVar<T>()` to share typed data from a Prerender handler to child layouts:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { Prerender, createVar } from "@rangojs/router";
|
|
127
|
+
|
|
128
|
+
interface PaginationData { current: number; total: number; }
|
|
129
|
+
export const Pagination = createVar<PaginationData>();
|
|
130
|
+
|
|
131
|
+
export const ArticleList = Prerender<{ page: string }>(
|
|
132
|
+
async () => [{ page: "1" }, { page: "2" }],
|
|
133
|
+
async (ctx) => {
|
|
134
|
+
ctx.set(Pagination, { current: Number(ctx.params.page), total: 2 });
|
|
135
|
+
return <Articles />;
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
All items inside the path's use() callback (child layouts, parallels) also receive
|
|
141
|
+
`BuildContext` during pre-rendering. Loaders are the exception -- they run at
|
|
142
|
+
request time with full server context.
|
|
143
|
+
|
|
144
|
+
This is one reason prerender is a good fit for handler-first composition:
|
|
145
|
+
the handler and its child layouts/parallels participate in the same full
|
|
146
|
+
render pass, so data set with `ctx.set()` is available downstream via
|
|
147
|
+
`ctx.get()`.
|
|
148
|
+
|
|
149
|
+
At runtime, partial action revalidation follows a narrower rule: only
|
|
150
|
+
revalidated segments are recomputed. If a child segment depends on data
|
|
151
|
+
established by an outer handler/layout, that outer segment must also be
|
|
152
|
+
revalidated, or the child must load/guard the data independently.
|
|
153
|
+
|
|
154
|
+
## Supported Export Patterns
|
|
155
|
+
|
|
156
|
+
All of the following are equivalent and fully supported by the Vite transform:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Direct export (most common)
|
|
160
|
+
export const BlogPost = Prerender(getParams, handler);
|
|
161
|
+
|
|
162
|
+
// Separate declaration + named export
|
|
163
|
+
const BlogPost = Prerender(getParams, handler);
|
|
164
|
+
export { BlogPost };
|
|
165
|
+
|
|
166
|
+
// Aliased export
|
|
167
|
+
const InternalPage = Prerender(getParams, handler);
|
|
168
|
+
export { InternalPage as BlogPost };
|
|
169
|
+
|
|
170
|
+
// Aliased import
|
|
171
|
+
import { Prerender as cph } from "@rangojs/router";
|
|
172
|
+
export const BlogPost = cph(getParams, handler);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
All patterns support whole-file stubbing, expression stubbing, and build-time
|
|
176
|
+
module tracking. The same applies to `Static`.
|
|
177
|
+
|
|
178
|
+
## Handler Eviction
|
|
179
|
+
|
|
180
|
+
In production builds, `Prerender` exports are replaced with stubs:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// Original
|
|
184
|
+
export const BlogPost = Prerender(getParams, handler);
|
|
185
|
+
|
|
186
|
+
// Stubbed (ships to server bundle when passthrough: false)
|
|
187
|
+
export const BlogPost = {
|
|
188
|
+
__brand: "prerenderHandler",
|
|
189
|
+
$$id: "abc123#BlogPost",
|
|
190
|
+
};
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The original module and its imports (node:fs, markdown libs) are excluded from
|
|
194
|
+
the bundle. With `passthrough: true`, the handler code stays in the RSC bundle.
|
|
195
|
+
|
|
196
|
+
In client and SSR environments, ALL prerender handlers are always stubbed
|
|
197
|
+
(passthrough only affects the RSC server bundle).
|
|
198
|
+
|
|
199
|
+
## Sub-use Semantics
|
|
200
|
+
|
|
201
|
+
Everything inside the path's use() callback is part of the B segment and gets
|
|
202
|
+
pre-rendered:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
path("/blog/:slug", BlogPost, { name: "blog.post" }, () => [
|
|
206
|
+
layout(<PostLayout />, () => [ // inside B -> pre-rendered
|
|
207
|
+
loader(PostMetaLoader), // live at runtime, bundled normally
|
|
208
|
+
]),
|
|
209
|
+
parallel({ "@sidebar": BlogSidebar }), // inside B -> pre-rendered
|
|
210
|
+
])
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
If a parallel or child layout uses node APIs, wrap it in `Prerender`
|
|
214
|
+
(static, no getParams) so the Vite plugin can stub it:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// sidebar.tsx -- uses node:fs, must be a Prerender
|
|
218
|
+
export const BlogSidebar = Prerender(async (ctx) => {
|
|
219
|
+
const files = await fs.readdir("content/blog/");
|
|
220
|
+
return <Sidebar posts={files.map(f => basename(f, ".md"))} />;
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// urls.tsx
|
|
224
|
+
path("/blog/:slug", BlogPost, { name: "blog.post" }, () => [
|
|
225
|
+
parallel({ "@sidebar": BlogSidebar }), // stubbable, node:fs excluded
|
|
226
|
+
])
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Interaction with DSL Items
|
|
230
|
+
|
|
231
|
+
| DSL item | Behavior with Prerender |
|
|
232
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
233
|
+
| `loader()` | Live at runtime, bundled normally. Use `cache()` for caching. |
|
|
234
|
+
| `revalidate()` | Not allowed without passthrough. Allowed with passthrough. |
|
|
235
|
+
| `cache()` | Orthogonal -- use on parent layouts and loaders. |
|
|
236
|
+
| `layout()` | Child layouts inside path are pre-rendered. Parent layouts are live. |
|
|
237
|
+
| `parallel()` | Parallel slots inside path are pre-rendered. |
|
|
238
|
+
| `middleware()` | Skipped during pre-render (no request). Runs at request time for loaders. |
|
|
239
|
+
| `loading()` | Ignored without passthrough. Works for live fallback with passthrough. |
|
|
240
|
+
| `intercept()` | Pre-rendered at build time. Intercept variant stored under `/i` key alongside main segments. At runtime, the correct variant is served based on `ctx.isIntercept`. `when()` conditions are skipped at build time (all intercepts are pre-rendered unconditionally). |
|
|
241
|
+
|
|
242
|
+
When passthrough revalidation is enabled, remember that revalidation is
|
|
243
|
+
still partial: opting a child segment into revalidation does not
|
|
244
|
+
implicitly re-run outer prerender-derived handlers/layouts.
|
|
245
|
+
|
|
246
|
+
## Dev Mode
|
|
247
|
+
|
|
248
|
+
In dev mode there is no production-style prerender build pass and no handler
|
|
249
|
+
stubbing.
|
|
250
|
+
|
|
251
|
+
**Node.js dev server** — `Prerender` acts as a normal handler. Routes render
|
|
252
|
+
live on every request with full runtime context (`ctx.build === false`).
|
|
253
|
+
|
|
254
|
+
**Non-Node runtimes (Cloudflare workerd, Deno workers)** — Handlers that
|
|
255
|
+
depend on Node APIs (e.g. `node:fs`) cannot run in-process. The Vite plugin
|
|
256
|
+
can intercept these requests and resolve them via the `/__rsc_prerender`
|
|
257
|
+
endpoint, which runs `matchForPrerender` in a Node.js temp server. In this
|
|
258
|
+
path the handler receives `BuildContext` (`ctx.build === true`) and segments
|
|
259
|
+
are resolved identically to production prerendering, then served on-demand.
|
|
260
|
+
This only applies when `__PRERENDER_DEV_URL` is set by the plugin.
|
|
261
|
+
|
|
262
|
+
## Storage Layout
|
|
263
|
+
|
|
264
|
+
Pre-rendered Flight payloads are stored in the build output:
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
dist/static/__<hash>/
|
|
268
|
+
prerender/
|
|
269
|
+
blog.post/
|
|
270
|
+
d4e5f6a7.flight # hash of { slug: "hello-world" }
|
|
271
|
+
b8c9d0e1.flight # hash of { slug: "getting-started" }
|
|
272
|
+
about/
|
|
273
|
+
_.flight # static route, no params
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Concurrency
|
|
277
|
+
|
|
278
|
+
Prerender handlers can specify how many param sets render in parallel:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
export const BlogPost = Prerender(
|
|
282
|
+
async () => posts.map(p => ({ slug: p.slug })),
|
|
283
|
+
async (ctx) => <PostPage slug={ctx.params.slug} />,
|
|
284
|
+
{ concurrency: 4 },
|
|
285
|
+
);
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Default is `1` (sequential). Only `Prerender` supports concurrency; `Static` handlers
|
|
289
|
+
always render sequentially.
|
|
290
|
+
|
|
291
|
+
## Skipping Entries with Skip
|
|
292
|
+
|
|
293
|
+
Throw `Skip` inside a Prerender or Static handler to skip an individual entry
|
|
294
|
+
without failing the build:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { Prerender, Skip } from "@rangojs/router";
|
|
298
|
+
|
|
299
|
+
export const BlogPost = Prerender(
|
|
300
|
+
async () => [{ slug: "published" }, { slug: "draft" }],
|
|
301
|
+
async (ctx) => {
|
|
302
|
+
if (ctx.params.slug === "draft") {
|
|
303
|
+
throw new Skip("Draft articles are not pre-rendered");
|
|
304
|
+
}
|
|
305
|
+
return <PostPage slug={ctx.params.slug} />;
|
|
306
|
+
},
|
|
307
|
+
{ passthrough: true },
|
|
308
|
+
);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Skipped entries are excluded from the build output. With `passthrough: true`,
|
|
312
|
+
the handler stays in the bundle and serves skipped params live at request time.
|
|
313
|
+
|
|
314
|
+
`Skip` also works in `Static` handlers:
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
import { Static, Skip } from "@rangojs/router";
|
|
318
|
+
|
|
319
|
+
export const TocSidebar = Static(() => {
|
|
320
|
+
throw new Skip("Not ready for pre-rendering");
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Error behavior at build time
|
|
325
|
+
|
|
326
|
+
| Handler outcome | Effect |
|
|
327
|
+
| --------------------------- | ----------------------------------------------------- |
|
|
328
|
+
| JSX / `null` | Normal prerender entry, log OK |
|
|
329
|
+
| `return ctx.passthrough()` | Skip entry, log PASS, continue (passthrough routes) |
|
|
330
|
+
| `throw new Skip("reason")` | Skip entry, log SKIP, continue with remaining entries |
|
|
331
|
+
| `throw new Error("reason")` | Log FAIL, stop ALL pre-rendering, fail the build |
|
|
332
|
+
|
|
333
|
+
Both error types propagate to the router's `onError` callback with phase
|
|
334
|
+
`"prerender"` or `"static"`.
|
|
335
|
+
|
|
336
|
+
### Build logs
|
|
337
|
+
|
|
338
|
+
The build produces per-URL timing logs:
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
[rsc-router] Pre-rendering 12 URL(s) (concurrency: 4)...
|
|
342
|
+
[rsc-router] OK /articles/hello (42ms)
|
|
343
|
+
[rsc-router] PASS /articles/remote-only (5ms) - live fallback
|
|
344
|
+
[rsc-router] SKIP /articles/draft-post (3ms) - Article is a draft
|
|
345
|
+
[rsc-router] Pre-render complete: 11 done, 1 skipped (1204ms total)
|
|
346
|
+
|
|
347
|
+
[rsc-router] Rendering 3 static handler(s)...
|
|
348
|
+
[rsc-router] OK DocsLayout (28ms)
|
|
349
|
+
[rsc-router] SKIP TocSidebar (1ms) - Not ready
|
|
350
|
+
[rsc-router] Static render complete: 2 done, 1 skipped (120ms total)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
A `FAIL` line is logged per-URL when a handler throws a non-Skip error. The
|
|
354
|
+
error is re-thrown immediately, so no summary line is printed — the build
|
|
355
|
+
stops at the first failure.
|
|
356
|
+
|
|
357
|
+
### Dev mode behavior
|
|
358
|
+
|
|
359
|
+
**Node.js dev server** — `Skip` behaves like a regular runtime error because
|
|
360
|
+
the handler runs live with `ctx.build === false`.
|
|
361
|
+
|
|
362
|
+
**Non-Node runtimes using `/__rsc_prerender`** — `Skip` participates in the
|
|
363
|
+
on-demand prerender path, so build-style skip logic does run for that request.
|
|
364
|
+
The dev prerender endpoint treats it like a prerender miss and the request
|
|
365
|
+
falls back according to normal dev/runtime behavior.
|
|
366
|
+
|
|
367
|
+
## Per-Param Passthrough with ctx.passthrough()
|
|
368
|
+
|
|
369
|
+
On `{ passthrough: true }` routes, a handler can return `ctx.passthrough()`
|
|
370
|
+
to skip writing a local prerender artifact for a specific param set. At
|
|
371
|
+
runtime, the missing entry falls through to the live handler.
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
export const BlogPost = Prerender(
|
|
375
|
+
async () => [{ slug: "a" }, { slug: "b" }, { slug: "c" }],
|
|
376
|
+
async (ctx) => {
|
|
377
|
+
const post = await getPost(ctx.params.slug);
|
|
378
|
+
if (!post) return ctx.passthrough();
|
|
379
|
+
return <article>{post.content}</article>;
|
|
380
|
+
},
|
|
381
|
+
{ passthrough: true },
|
|
382
|
+
);
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Semantics
|
|
386
|
+
|
|
387
|
+
- JSX or `null` from the handler produces a normal prerender entry.
|
|
388
|
+
- `ctx.passthrough()` returns a sentinel that signals "no local artifact".
|
|
389
|
+
The build skips the manifest entry for that param set.
|
|
390
|
+
- `ctx.passthrough()` on a non-passthrough route throws an invariant error.
|
|
391
|
+
- `ctx.passthrough()` at runtime (`ctx.build === false`) also throws.
|
|
392
|
+
It is a build-time-only control flow.
|
|
393
|
+
- `getParams()` still enumerates the param set; the handler decides per-param
|
|
394
|
+
whether to produce an artifact or defer to runtime.
|
|
395
|
+
|
|
396
|
+
### Difference from Skip
|
|
397
|
+
|
|
398
|
+
| Mechanism | Effect on build | Runtime behavior |
|
|
399
|
+
| ------------------- | ---------------------- | ---------------------------------------------------- |
|
|
400
|
+
| `throw new Skip()` | Skips entry, logs SKIP | No artifact, no live fallback unless passthrough |
|
|
401
|
+
| `ctx.passthrough()` | Skips entry, logs PASS | Always defers to live handler (requires passthrough) |
|
|
402
|
+
|
|
403
|
+
Use `ctx.passthrough()` when you want the handler to run live at request time
|
|
404
|
+
for specific params. Use `Skip` when you want to exclude params entirely.
|
|
405
|
+
|
|
406
|
+
### Use case: Remote storage
|
|
407
|
+
|
|
408
|
+
`ctx.passthrough()` enables a pattern where build-time data is stored in a
|
|
409
|
+
remote KV store instead of the local prerender manifest. The handler
|
|
410
|
+
pre-computes data during `getParams`, pushes it to KV, then calls
|
|
411
|
+
`ctx.passthrough()` so the local build skips the artifact. At runtime,
|
|
412
|
+
the live handler reads from KV:
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
export const Product = Prerender(
|
|
416
|
+
async () => {
|
|
417
|
+
const products = await db.getFeaturedProducts();
|
|
418
|
+
// Pre-compute and store in remote KV during build
|
|
419
|
+
for (const p of products) {
|
|
420
|
+
await kv.put(`product:${p.id}`, await renderProduct(p));
|
|
421
|
+
}
|
|
422
|
+
return products.map(p => ({ id: p.id }));
|
|
423
|
+
},
|
|
424
|
+
async (ctx) => {
|
|
425
|
+
// At build time: skip local artifact, data is in KV
|
|
426
|
+
if (ctx.build) return ctx.passthrough();
|
|
427
|
+
// At runtime: read from KV
|
|
428
|
+
const cached = await kv.get(`product:${ctx.params.id}`);
|
|
429
|
+
if (cached) return cached;
|
|
430
|
+
return <Product data={await db.getProduct(ctx.params.id)} />;
|
|
431
|
+
},
|
|
432
|
+
{ passthrough: true },
|
|
433
|
+
);
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Build logs
|
|
437
|
+
|
|
438
|
+
Passthrough entries are logged distinctly:
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
[rsc-router] OK /blog/a (42ms)
|
|
442
|
+
[rsc-router] PASS /blog/b (3ms) - live fallback
|
|
443
|
+
[rsc-router] OK /blog/c (38ms)
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## Edge Cases and Constraints
|
|
447
|
+
|
|
448
|
+
### Loaders are always live
|
|
449
|
+
|
|
450
|
+
Loaders on pre-rendered routes run at request time. They are bundled normally
|
|
451
|
+
and need `cache()` for caching. Do not use build-only APIs in loaders.
|
|
452
|
+
|
|
453
|
+
### Handle data is frozen
|
|
454
|
+
|
|
455
|
+
Handle values pushed via `ctx.use()` during pre-rendering are baked into the
|
|
456
|
+
Flight payload. They do not update at request time.
|
|
457
|
+
|
|
458
|
+
### Server actions work normally
|
|
459
|
+
|
|
460
|
+
Actions do not re-render the B segment. The pre-rendered handler output stays
|
|
461
|
+
frozen. Loaders are live and can be revalidated by actions. With `passthrough: true`
|
|
462
|
+
and `revalidate()`, the handler itself can re-render live.
|
|
463
|
+
|
|
464
|
+
### Empty getParams
|
|
465
|
+
|
|
466
|
+
If `getParams` returns an empty array, no Flight payloads are written. No error.
|
|
467
|
+
|
|
468
|
+
### Route name is required
|
|
469
|
+
|
|
470
|
+
Routes using `Prerender` must have a `name` in path options.
|
|
471
|
+
The name is used as the storage key for Flight payloads.
|
|
472
|
+
|
|
473
|
+
### No revalidate without passthrough
|
|
474
|
+
|
|
475
|
+
Using `revalidate()` with `passthrough: false` produces a build-time warning.
|
|
476
|
+
The handler is evicted -- there is nothing to re-render.
|
|
477
|
+
|
|
478
|
+
### loading() is ignored without passthrough
|
|
479
|
+
|
|
480
|
+
Pre-rendered segments are fully resolved at build time and never suspend.
|
|
481
|
+
With `passthrough: true`, `loading()` works for live fallback renders.
|
|
482
|
+
|
|
483
|
+
## Complete Example
|
|
484
|
+
|
|
485
|
+
```typescript
|
|
486
|
+
// pages/guides-handler.tsx
|
|
487
|
+
import { Prerender } from "@rangojs/router";
|
|
488
|
+
import { Link } from "@rangojs/router/client";
|
|
489
|
+
import { href } from "../router.js";
|
|
490
|
+
|
|
491
|
+
const knownGuides: Record<string, string> = {
|
|
492
|
+
routing: "Routing Guide",
|
|
493
|
+
caching: "Caching Guide",
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
export const GuidesDetail = Prerender<{ slug: string }>(
|
|
497
|
+
async () => Object.keys(knownGuides).map((slug) => ({ slug })),
|
|
498
|
+
async (ctx) => {
|
|
499
|
+
const title = knownGuides[ctx.params.slug] ?? `Guide: ${ctx.params.slug}`;
|
|
500
|
+
return (
|
|
501
|
+
<div>
|
|
502
|
+
<h1>{title}</h1>
|
|
503
|
+
<p>Slug: {ctx.params.slug}</p>
|
|
504
|
+
<nav>
|
|
505
|
+
<Link to={href("guides.detail", { slug: "routing" })}>Routing</Link>
|
|
506
|
+
{" | "}
|
|
507
|
+
<Link to={href("guides.detail", { slug: "dynamic-test" })}>Dynamic</Link>
|
|
508
|
+
</nav>
|
|
509
|
+
</div>
|
|
510
|
+
);
|
|
511
|
+
},
|
|
512
|
+
{ passthrough: true },
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
// pages/guides.tsx
|
|
516
|
+
import { urls } from "@rangojs/router";
|
|
517
|
+
import { GuidesDetail } from "./guides-handler.js";
|
|
518
|
+
|
|
519
|
+
export const guidesPatterns = urls(({ path }) => [
|
|
520
|
+
path("/:slug", GuidesDetail, { name: "detail" }),
|
|
521
|
+
]);
|
|
522
|
+
|
|
523
|
+
// urls.tsx
|
|
524
|
+
import { urls } from "@rangojs/router";
|
|
525
|
+
import { guidesPatterns } from "./pages/guides.js";
|
|
526
|
+
|
|
527
|
+
export const urlpatterns = urls(({ path, include }) => [
|
|
528
|
+
path("/", HomePage, { name: "home" }),
|
|
529
|
+
include("/guides", guidesPatterns, { name: "guides" }),
|
|
530
|
+
]);
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## Interaction with intercept()
|
|
534
|
+
|
|
535
|
+
When a pre-rendered route is also the target of an `intercept()`, the build system
|
|
536
|
+
resolves the intercept handler at build time and stores a combined entry (main
|
|
537
|
+
segments + intercept segments) under an `/i`-suffixed key alongside the main entry:
|
|
538
|
+
|
|
539
|
+
```
|
|
540
|
+
prerender store keys:
|
|
541
|
+
"blog.post/a1b2c3" -> main segments (full page)
|
|
542
|
+
"blog.post/a1b2c3/i" -> main segments + intercept segments (modal variant)
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
At runtime, the cache-lookup middleware checks `ctx.isIntercept`:
|
|
546
|
+
|
|
547
|
+
- **Intercept navigation**: looks up `paramHash/i` first. If found, yields
|
|
548
|
+
the combined entry. `handleCacheHitIntercept()` extracts intercept segments
|
|
549
|
+
(filtered by `namespace?.startsWith("intercept:")`) and sets up slots.
|
|
550
|
+
- **Direct navigation**: looks up `paramHash` (no suffix). Standard prerender path.
|
|
551
|
+
- **Intercept miss (no `/i` entry)**: falls through to the normal pipeline so
|
|
552
|
+
intercept-resolution middleware runs live. This handles `when()` conditions
|
|
553
|
+
that prevented pre-rendering.
|
|
554
|
+
|
|
555
|
+
The `when()` callback receives an `InterceptSelectorContext` with `from.pathname`
|
|
556
|
+
which is unknown at build time. All intercepts are pre-rendered unconditionally;
|
|
557
|
+
`when()` is evaluated at runtime by the intercept-resolution middleware.
|
|
558
|
+
|
|
559
|
+
### Example: Pre-rendered route with intercept
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
// Route handler is pre-rendered at build time
|
|
563
|
+
export const ProductDetail = Prerender(
|
|
564
|
+
async () => [{ slug: "shoes" }, { slug: "jacket" }],
|
|
565
|
+
async (ctx) => <ProductPage slug={ctx.params.slug} />,
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
// urls.tsx
|
|
569
|
+
layout(ShopLayout, () => [
|
|
570
|
+
path("/:slug", ProductDetail, { name: "detail" }, () => [
|
|
571
|
+
loader(ProductLoader),
|
|
572
|
+
]),
|
|
573
|
+
|
|
574
|
+
// Intercept detail from shop index into a modal.
|
|
575
|
+
// At build time, this is resolved and stored under the /i key.
|
|
576
|
+
intercept("@modal", ".detail", <ProductModal />, () => [
|
|
577
|
+
when(({ from }) => from.pathname === "/shop"),
|
|
578
|
+
loader(ProductLoader),
|
|
579
|
+
]),
|
|
580
|
+
])
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Both `ProductPage` (main) and `ProductModal` (intercept) are frozen at build time.
|
|
584
|
+
Loaders run fresh at request time for both variants.
|
|
585
|
+
|
|
586
|
+
## Trie Flags
|
|
587
|
+
|
|
588
|
+
Pre-rendered routes set flags on the route trie leaf at build time:
|
|
589
|
+
|
|
590
|
+
- `pr: true` -- route has pre-rendered B segment data
|
|
591
|
+
- `pt: true` -- passthrough mode (handler available for live fallback)
|
|
592
|
+
|
|
593
|
+
At runtime, the cache-lookup middleware uses these flags:
|
|
594
|
+
|
|
595
|
+
- `pr + hit` -- serve pre-rendered Flight payload
|
|
596
|
+
- `pr + pt + miss` -- fall through to live handler (handler kept in bundle)
|
|
597
|
+
- `pr + miss` (no pt) -- fall through (handler stubbed, no live render)
|
|
598
|
+
|
|
599
|
+
## Contributor Checklist
|
|
600
|
+
|
|
601
|
+
Before changing prerender behavior, read these docs and run these tests.
|
|
602
|
+
|
|
603
|
+
### Docs to re-read
|
|
604
|
+
|
|
605
|
+
- [Prerender API design](../../docs/prerender-api-design.md) -- canonical
|
|
606
|
+
architecture: build-time flow, runtime flow, storage, passthrough, intercept
|
|
607
|
+
- [Execution model](../../docs/internal/execution-model.md) -- handler-first
|
|
608
|
+
ordering, middleware scope, context visibility rules
|
|
609
|
+
- [Semantic change checklist](../../docs/internal/semantic-change-checklist.md)
|
|
610
|
+
-- gate for any change to execution semantics
|
|
611
|
+
|
|
612
|
+
### Tests to run
|
|
613
|
+
|
|
614
|
+
```bash
|
|
615
|
+
# Core prerender e2e (passthrough, eviction, loaders, sub-use, intercept)
|
|
616
|
+
pnpm --filter @rangojs/router exec playwright test prerender
|
|
617
|
+
|
|
618
|
+
# Prerender-specific unit test
|
|
619
|
+
pnpm --filter @rangojs/router run test:unit -- prerender-passthrough
|
|
620
|
+
|
|
621
|
+
# Semantic matrix (prerender rows cover intercept + ctx propagation)
|
|
622
|
+
pnpm --filter @rangojs/router exec playwright test semantic-matrix
|
|
623
|
+
|
|
624
|
+
# Handler-first (ctx.set/get visibility with prerender handlers)
|
|
625
|
+
pnpm --filter @rangojs/router exec playwright test handler-first
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
### Dev-only vs build-parity
|
|
629
|
+
|
|
630
|
+
- Prerender e2e tests run against a real production build by default (the
|
|
631
|
+
fixture builds the test app). Dev-mode prerender behavior is tested via
|
|
632
|
+
`/__rsc_prerender` endpoint tests and node.js dev-server fallback.
|
|
633
|
+
- Log-based assertions (build output lines, debug cache logs) are inherently
|
|
634
|
+
dev/build-only and do not need a production counterpart.
|
|
635
|
+
- Behavioral assertions (rendered content, loader freshness, passthrough
|
|
636
|
+
fallback, intercept variant selection) must work in the production build.
|
|
637
|
+
|
|
638
|
+
## Maintenance References
|
|
639
|
+
|
|
640
|
+
- [Stability next steps plan](../../docs/internal/stability-next-steps-plan.md)
|
|
641
|
+
-- completed parity and cleanup pass (reference for decisions made)
|
|
642
|
+
- [Test quality baseline](../../docs/internal/test-quality-baseline.md) --
|
|
643
|
+
measured test inventory, sleep debt, production coverage gaps
|