@rangojs/router 0.0.0-experimental.124 → 0.0.0-experimental.126
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 +6 -4
- package/dist/bin/rango.js +3 -4
- package/dist/vite/index.js +315 -68
- package/package.json +19 -18
- package/skills/breadcrumbs/SKILL.md +60 -0
- package/skills/hooks/SKILL.md +2 -2
- package/skills/route/SKILL.md +6 -0
- package/skills/server-actions/SKILL.md +25 -1
- package/skills/testing/SKILL.md +17 -17
- package/skills/testing/cache-prerender.md +29 -3
- package/skills/testing/flight.md +13 -10
- package/skills/testing/render-handler.md +3 -0
- package/skills/testing/server-tree.md +1 -1
- package/skills/testing/setup.md +1 -1
- package/src/__internal.ts +0 -65
- package/src/browser/action-coordinator.ts +1 -1
- package/src/browser/action-fence.ts +10 -0
- package/src/browser/event-controller.ts +1 -83
- package/src/browser/navigation-store-handle.ts +3 -4
- package/src/browser/navigation-store.ts +0 -39
- package/src/browser/navigation-transaction.ts +0 -32
- package/src/browser/partial-update.ts +23 -84
- package/src/browser/prefetch/cache.ts +6 -45
- package/src/browser/prefetch/queue.ts +6 -3
- package/src/browser/rango-state.ts +2 -23
- package/src/browser/react/Link.tsx +0 -2
- package/src/browser/react/NavigationProvider.tsx +2 -1
- package/src/browser/react/ScrollRestoration.tsx +10 -6
- package/src/browser/react/filter-segment-order.ts +0 -2
- package/src/browser/react/index.ts +0 -45
- package/src/browser/react/location-state-shared.ts +0 -13
- package/src/browser/react/location-state.ts +0 -1
- package/src/browser/react/use-action.ts +6 -15
- package/src/browser/react/use-handle.ts +0 -5
- package/src/browser/react/use-link-status.ts +0 -4
- package/src/browser/react/use-navigation.ts +0 -3
- package/src/browser/react/use-params.ts +0 -2
- package/src/browser/react/use-router.ts +2 -1
- package/src/browser/react/use-search-params.ts +0 -5
- package/src/browser/react/use-segments.ts +0 -13
- package/src/browser/rsc-router.tsx +10 -3
- package/src/browser/server-action-bridge.ts +51 -3
- package/src/browser/types.ts +23 -5
- package/src/browser/validate-redirect-origin.ts +43 -16
- package/src/build/index.ts +8 -9
- package/src/build/route-trie.ts +46 -11
- package/src/build/route-types/param-extraction.ts +6 -3
- package/src/build/route-types/router-processing.ts +0 -8
- package/src/cache/cache-policy.ts +0 -54
- package/src/cache/cache-runtime.ts +48 -24
- package/src/cache/cache-scope.ts +0 -27
- package/src/cache/cache-tag.ts +0 -37
- package/src/cache/cf/cf-cache-store.ts +72 -45
- package/src/cache/cf/index.ts +0 -24
- package/src/cache/document-cache.ts +10 -36
- package/src/cache/handle-snapshot.ts +0 -40
- package/src/cache/index.ts +0 -27
- package/src/cache/memory-segment-store.ts +0 -52
- package/src/cache/profile-registry.ts +6 -30
- package/src/cache/read-through-swr.ts +41 -11
- package/src/cache/segment-codec.ts +0 -16
- package/src/cache/types.ts +0 -98
- package/src/client.rsc.tsx +4 -22
- package/src/client.tsx +19 -32
- package/src/context-var.ts +12 -0
- package/src/defer.ts +196 -0
- package/src/deps/ssr.ts +0 -1
- package/src/handle.ts +2 -12
- package/src/handles/MetaTags.tsx +0 -14
- package/src/handles/breadcrumbs.ts +16 -5
- package/src/handles/meta.ts +0 -39
- package/src/host/cookie-handler.ts +0 -36
- package/src/host/errors.ts +0 -24
- package/src/host/index.ts +6 -0
- package/src/host/pattern-matcher.ts +7 -50
- package/src/host/router.ts +1 -65
- package/src/host/testing.ts +0 -16
- package/src/host/types.ts +6 -2
- package/src/href-client.ts +0 -4
- package/src/index.rsc.ts +27 -2
- package/src/index.ts +7 -0
- package/src/internal-debug.ts +2 -4
- package/src/loader.rsc.ts +4 -15
- package/src/loader.ts +3 -9
- package/src/network-error-thrower.tsx +1 -6
- package/src/outlet-provider.tsx +1 -5
- package/src/prerender/param-hash.ts +10 -11
- package/src/prerender/store.ts +23 -30
- package/src/prerender.ts +34 -0
- package/src/redirect-origin.ts +100 -0
- package/src/root-error-boundary.tsx +1 -19
- package/src/route-content-wrapper.tsx +1 -44
- package/src/route-definition/dsl-helpers.ts +7 -19
- package/src/route-definition/helpers-types.ts +3 -3
- package/src/route-definition/redirect.ts +43 -9
- package/src/route-definition/resolve-handler-use.ts +6 -0
- package/src/route-map-builder.ts +0 -16
- package/src/router/content-negotiation.ts +0 -13
- package/src/router/error-handling.ts +12 -16
- package/src/router/find-match.ts +4 -31
- package/src/router/intercept-resolution.ts +10 -1
- package/src/router/lazy-includes.ts +1 -57
- package/src/router/loader-resolution.ts +25 -23
- package/src/router/logging.ts +0 -6
- package/src/router/manifest.ts +1 -25
- package/src/router/match-api.ts +0 -20
- package/src/router/match-context.ts +0 -22
- package/src/router/match-handlers.ts +0 -43
- package/src/router/match-middleware/background-revalidation.ts +0 -7
- package/src/router/match-middleware/cache-lookup.ts +96 -179
- package/src/router/match-middleware/cache-store.ts +0 -31
- package/src/router/match-middleware/intercept-resolution.ts +0 -22
- package/src/router/match-middleware/segment-resolution.ts +0 -22
- package/src/router/match-pipelines.ts +1 -42
- package/src/router/match-result.ts +1 -52
- package/src/router/metrics.ts +0 -34
- package/src/router/middleware-types.ts +0 -116
- package/src/router/middleware.ts +77 -60
- package/src/router/navigation-snapshot.ts +0 -51
- package/src/router/params-util.ts +23 -0
- package/src/router/pattern-matching.ts +5 -56
- package/src/router/prerender-match.ts +56 -51
- package/src/router/request-classification.ts +1 -38
- package/src/router/revalidation.ts +14 -62
- package/src/router/route-snapshot.ts +0 -1
- package/src/router/router-context.ts +0 -27
- package/src/router/router-interfaces.ts +10 -0
- package/src/router/segment-resolution/fresh.ts +25 -57
- package/src/router/segment-resolution/helpers.ts +34 -0
- package/src/router/segment-resolution/loader-cache.ts +35 -23
- package/src/router/segment-resolution/revalidation.ts +188 -283
- package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
- package/src/router/segment-resolution.ts +4 -1
- package/src/router/segment-wrappers.ts +0 -3
- package/src/router/telemetry-otel.ts +0 -20
- package/src/router/telemetry.ts +0 -22
- package/src/router/timeout.ts +0 -20
- package/src/router/trie-matching.ts +66 -45
- package/src/router/types.ts +1 -63
- package/src/router/url-params.ts +0 -5
- package/src/router.ts +8 -11
- package/src/rsc/handler-context.ts +1 -0
- package/src/rsc/handler.ts +20 -4
- package/src/rsc/helpers.ts +71 -3
- package/src/rsc/json-route-result.ts +38 -0
- package/src/rsc/origin-guard.ts +9 -15
- package/src/rsc/progressive-enhancement.ts +10 -1
- package/src/rsc/redirect-guard.ts +99 -0
- package/src/rsc/response-route-handler.ts +23 -18
- package/src/rsc/rsc-rendering.ts +2 -7
- package/src/rsc/runtime-warnings.ts +14 -0
- package/src/rsc/server-action.ts +34 -29
- package/src/rsc/types.ts +6 -3
- package/src/search-params.ts +0 -16
- package/src/segment-loader-promise.ts +14 -2
- package/src/segment-system.tsx +79 -88
- package/src/server/handle-store.ts +7 -24
- package/src/server/loader-registry.ts +5 -24
- package/src/server/request-context.ts +29 -92
- package/src/ssr/index.tsx +14 -14
- package/src/static-handler.ts +2 -27
- package/src/testing/cache-status.ts +44 -48
- package/src/testing/collect-handle.ts +1 -24
- package/src/testing/dispatch.ts +43 -6
- package/src/testing/e2e/index.ts +1 -22
- package/src/testing/e2e/matchers.ts +0 -16
- package/src/testing/flight-matchers.ts +0 -13
- package/src/testing/flight-normalize.ts +3 -30
- package/src/testing/flight.ts +46 -48
- package/src/testing/generated-routes.ts +1 -41
- package/src/testing/index.ts +1 -21
- package/src/testing/internal/context.ts +3 -45
- package/src/testing/internal/seed-vars.ts +0 -26
- package/src/testing/render-handler.ts +31 -61
- package/src/testing/render-route.tsx +75 -103
- package/src/testing/run-loader.ts +0 -96
- package/src/testing/run-middleware.ts +0 -26
- package/src/theme/ThemeProvider.tsx +0 -52
- package/src/theme/ThemeScript.tsx +0 -6
- package/src/theme/constants.ts +0 -12
- package/src/theme/index.ts +0 -7
- package/src/theme/theme-context.ts +1 -5
- package/src/theme/theme-script.ts +0 -14
- package/src/theme/use-theme.ts +0 -3
- package/src/types/boundaries.ts +0 -35
- package/src/types/error-types.ts +25 -89
- package/src/types/global-namespace.ts +4 -14
- package/src/types/handler-context.ts +28 -9
- package/src/types/index.ts +0 -10
- package/src/types/request-scope.ts +0 -19
- package/src/types/route-config.ts +6 -50
- package/src/types/route-entry.ts +0 -6
- package/src/types/segments.ts +0 -13
- package/src/urls/include-helper.ts +0 -4
- package/src/urls/index.ts +0 -6
- package/src/urls/path-helper-types.ts +2 -2
- package/src/urls/path-helper.ts +0 -54
- package/src/urls/urls-function.ts +0 -13
- package/src/use-loader.tsx +0 -186
- package/src/vite/discovery/bundle-postprocess.ts +2 -1
- package/src/vite/discovery/discover-routers.ts +28 -18
- package/src/vite/discovery/prerender-collection.ts +2 -4
- package/src/vite/discovery/state.ts +5 -0
- package/src/vite/discovery/virtual-module-codegen.ts +1 -11
- package/src/vite/plugin-types.ts +35 -9
- package/src/vite/plugins/cjs-to-esm.ts +0 -11
- package/src/vite/plugins/client-ref-dedup.ts +0 -11
- package/src/vite/plugins/client-ref-hashing.ts +0 -10
- package/src/vite/plugins/cloudflare-protocol-stub.ts +0 -20
- package/src/vite/plugins/expose-action-id.ts +2 -73
- package/src/vite/plugins/expose-id-utils.ts +0 -55
- package/src/vite/plugins/expose-ids/export-analysis.ts +0 -38
- package/src/vite/plugins/expose-ids/handler-transform.ts +0 -15
- package/src/vite/plugins/expose-ids/loader-transform.ts +0 -15
- package/src/vite/plugins/expose-ids/router-transform.ts +0 -13
- package/src/vite/plugins/expose-internal-ids.ts +10 -0
- package/src/vite/plugins/performance-tracks.ts +0 -3
- package/src/vite/plugins/refresh-cmd.ts +1 -1
- package/src/vite/plugins/use-cache-transform.ts +21 -46
- package/src/vite/plugins/version-injector.ts +0 -20
- package/src/vite/plugins/version-plugin.ts +1 -49
- package/src/vite/plugins/virtual-entries.ts +0 -15
- package/src/vite/rango.ts +2 -108
- package/src/vite/router-discovery.ts +9 -1
- package/src/vite/utils/ast-handler-extract.ts +0 -16
- package/src/vite/utils/bundle-analysis.ts +6 -13
- package/src/vite/utils/client-chunks.ts +0 -6
- package/src/vite/utils/forward-user-plugins.ts +0 -22
- package/src/vite/utils/manifest-utils.ts +0 -4
- package/src/vite/utils/package-resolution.ts +1 -73
- package/src/vite/utils/prerender-utils.ts +0 -35
- package/src/vite/utils/shared-utils.ts +3 -35
- package/src/browser/shallow.ts +0 -40
- package/src/handles/index.ts +0 -7
- package/src/router/middleware-cookies.ts +0 -55
package/src/use-loader.tsx
CHANGED
|
@@ -15,14 +15,6 @@ import { OutletContext, type OutletContextValue } from "./outlet-context.js";
|
|
|
15
15
|
import { loaderStore, type LoaderEntry } from "./loader-store.js";
|
|
16
16
|
import type { LoaderDefinition, LoadOptions } from "./types.js";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* A shareable GET — a `load()` call that reads data (GET or defaulted method)
|
|
20
|
-
* with no request body. Params are allowed. This is the gate for keyed sharing:
|
|
21
|
-
* when a hook is given an explicit `key`, every shareable GET writes to the
|
|
22
|
-
* keyed bucket so co-keyed readers (including parameterized views) refresh
|
|
23
|
-
* together. Non-GET methods and body-bearing calls are mutations and stay local
|
|
24
|
-
* to the call site.
|
|
25
|
-
*/
|
|
26
18
|
function isShareableGet(options: LoadOptions | undefined): boolean {
|
|
27
19
|
if (!options) return true;
|
|
28
20
|
if (options.method && options.method !== "GET") return false;
|
|
@@ -32,44 +24,14 @@ function isShareableGet(options: LoadOptions | undefined): boolean {
|
|
|
32
24
|
return true;
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
/**
|
|
36
|
-
* Plain route-context refetch — a `load()` call with no options or a
|
|
37
|
-
* trivially-defaulted GET (no params, no body). Results from these are
|
|
38
|
-
* broadcast to every component reading the same loader id via the shared
|
|
39
|
-
* store, so a layout's refetch button updates page + parallel-slot reads
|
|
40
|
-
* automatically.
|
|
41
|
-
*
|
|
42
|
-
* Calls with explicit `params`, an explicit non-GET method, or a `body`
|
|
43
|
-
* stay local to the call site — that preserves the today-semantics of
|
|
44
|
-
* `useFetchLoader(SearchLoader).load({ params: { q } })` style code where
|
|
45
|
-
* each component owns its own fetched view. (An explicit `key` opts a
|
|
46
|
-
* parameterized GET back into sharing; see `isShareableGet`.)
|
|
47
|
-
*/
|
|
48
27
|
function isPlainRefetch(options: LoadOptions | undefined): boolean {
|
|
49
28
|
if (!isShareableGet(options)) return false;
|
|
50
29
|
if (options?.params && Object.keys(options.params).length > 0) return false;
|
|
51
30
|
return true;
|
|
52
31
|
}
|
|
53
32
|
|
|
54
|
-
// Per-hook unique suffix for grouped reads that have no explicit `key`. Such a
|
|
55
|
-
// read must NOT share the bare `loader.$$id` bucket, or a cross-loader group
|
|
56
|
-
// refresh would leak into unrelated unkeyed readers of the same loader (which
|
|
57
|
-
// the contract keeps local). Sharing within a group is opt-in via an explicit
|
|
58
|
-
// `key`; without one, each grouped read gets its own private bucket. The value
|
|
59
|
-
// is only ever used as a client-side store bucket key (never rendered), so the
|
|
60
|
-
// counter has no SSR/hydration consistency requirement.
|
|
61
33
|
let privateGroupBucketSeq = 0;
|
|
62
34
|
|
|
63
|
-
/**
|
|
64
|
-
* Extract a specific loader's data from a content ReactNode.
|
|
65
|
-
*
|
|
66
|
-
* When a route registers loaders via loader(), the resolved data lives in
|
|
67
|
-
* the route's OutletProvider (rendered as <Outlet /> content). Parallel
|
|
68
|
-
* slots are siblings of <Outlet />, so they can't find it by walking
|
|
69
|
-
* the parent context chain. This helper traverses wrapper elements
|
|
70
|
-
* (MountContextProvider, ViewTransition, etc.) to reach the OutletProvider
|
|
71
|
-
* and extract the loader data directly.
|
|
72
|
-
*/
|
|
73
35
|
const NOT_FOUND = Symbol("not-found");
|
|
74
36
|
|
|
75
37
|
function extractContentLoaderData(
|
|
@@ -85,10 +47,6 @@ function extractContentLoaderData(
|
|
|
85
47
|
return props.loaderData[loaderId];
|
|
86
48
|
}
|
|
87
49
|
|
|
88
|
-
// LoaderBoundary: loaderIds + loaderDataPromise (already resolved array).
|
|
89
|
-
// When the segment has loading(), loaderData is resolved inside
|
|
90
|
-
// LoaderBoundary via use(). If the promise was pre-awaited (forceAwait
|
|
91
|
-
// or isAction), the prop is a raw array we can index into.
|
|
92
50
|
if (
|
|
93
51
|
props.loaderIds &&
|
|
94
52
|
Array.isArray(props.loaderIds) &&
|
|
@@ -98,7 +56,6 @@ function extractContentLoaderData(
|
|
|
98
56
|
const idx = (props.loaderIds as string[]).indexOf(loaderId);
|
|
99
57
|
if (idx !== -1) {
|
|
100
58
|
const data = (props.loaderDataPromise as any[])[idx];
|
|
101
|
-
// loaderDataPromise entries may be { ok, data } result objects
|
|
102
59
|
if (data && typeof data === "object" && "ok" in data) {
|
|
103
60
|
return data.ok ? data.data : NOT_FOUND;
|
|
104
61
|
}
|
|
@@ -106,118 +63,45 @@ function extractContentLoaderData(
|
|
|
106
63
|
}
|
|
107
64
|
}
|
|
108
65
|
|
|
109
|
-
// Traverse into wrapper elements (MountContextProvider, ViewTransition,
|
|
110
|
-
// Suspense wrappers, etc.)
|
|
111
66
|
if (props.children) return extractContentLoaderData(props.children, loaderId);
|
|
112
67
|
return NOT_FOUND;
|
|
113
68
|
}
|
|
114
69
|
|
|
115
|
-
/**
|
|
116
|
-
* Payload returned by loader RSC requests
|
|
117
|
-
*/
|
|
118
70
|
interface LoaderRscPayload<T = unknown> {
|
|
119
71
|
loaderResult: T;
|
|
120
72
|
loaderError?: { message: string; name: string };
|
|
121
73
|
}
|
|
122
74
|
|
|
123
|
-
/**
|
|
124
|
-
* Load function type for fetching loader data from the client
|
|
125
|
-
*/
|
|
126
75
|
export type LoadFunction<T> = (options?: LoadOptions) => Promise<T>;
|
|
127
76
|
|
|
128
|
-
/**
|
|
129
|
-
* Result type for useLoader hook (strict - data is required)
|
|
130
|
-
*/
|
|
131
77
|
export interface UseLoaderResult<T> {
|
|
132
|
-
/** The loaded data - guaranteed to exist when loader is registered on route */
|
|
133
78
|
data: T;
|
|
134
|
-
/** True while a load() is in progress */
|
|
135
79
|
isLoading: boolean;
|
|
136
|
-
/** Error from the most recent load attempt, null if successful */
|
|
137
80
|
error: Error | null;
|
|
138
|
-
/** Function to trigger a fetch (only works if loader is fetchable) */
|
|
139
81
|
load: LoadFunction<T>;
|
|
140
|
-
/** Alias for load */
|
|
141
82
|
refetch: LoadFunction<T>;
|
|
142
83
|
}
|
|
143
84
|
|
|
144
|
-
/**
|
|
145
|
-
* Result type for useFetchLoader hook (flexible - data is optional)
|
|
146
|
-
*/
|
|
147
85
|
export interface UseFetchLoaderResult<T> {
|
|
148
|
-
/** The loaded data - may be undefined if not yet fetched or not in context */
|
|
149
86
|
data: T | undefined;
|
|
150
|
-
/** True while a load() is in progress */
|
|
151
87
|
isLoading: boolean;
|
|
152
|
-
/** Error from the most recent load attempt, null if successful */
|
|
153
88
|
error: Error | null;
|
|
154
|
-
/** Function to trigger a fetch (only works if loader is fetchable) */
|
|
155
89
|
load: LoadFunction<T>;
|
|
156
|
-
/** Alias for load */
|
|
157
90
|
refetch: LoadFunction<T>;
|
|
158
91
|
}
|
|
159
92
|
|
|
160
|
-
/**
|
|
161
|
-
* Options for useLoader hook
|
|
162
|
-
*/
|
|
163
93
|
export interface UseLoaderOptions {
|
|
164
|
-
/**
|
|
165
|
-
* If true (default), errors from load() will be thrown to the nearest error boundary.
|
|
166
|
-
* If false, errors are only captured in the `error` state.
|
|
167
|
-
* @default true
|
|
168
|
-
*/
|
|
169
94
|
throwOnError?: boolean;
|
|
170
|
-
/**
|
|
171
|
-
* Client refresh key. Partitions the shared refresh store so that only hooks
|
|
172
|
-
* using the same `key` refresh together when one of them calls `load()`.
|
|
173
|
-
*
|
|
174
|
-
* Without a `key` (default), a plain `load()` on a route-registered loader
|
|
175
|
-
* broadcasts to every reader of that loader, and any parameterized / unregistered
|
|
176
|
-
* load stays local to the calling hook. With a `key`:
|
|
177
|
-
* - readers of the same loader that share a `key` form one refresh group —
|
|
178
|
-
* a `load()` from any of them updates the whole group, including
|
|
179
|
-
* parameterized GETs;
|
|
180
|
-
* - readers with different keys are independent;
|
|
181
|
-
* - it works even when the loader is NOT registered on the route (keyed
|
|
182
|
-
* `useFetchLoader`), letting unrelated components opt into sharing.
|
|
183
|
-
*
|
|
184
|
-
* This is a client-side refresh identity only. It is unrelated to the server
|
|
185
|
-
* `cache({ key })` option and to `revalidate()`; it never changes the request
|
|
186
|
-
* sent to the server.
|
|
187
|
-
*/
|
|
188
95
|
key?: string;
|
|
189
|
-
/**
|
|
190
|
-
* Cross-loader refresh group tag(s). Tag reads of DIFFERENT loaders with a
|
|
191
|
-
* shared name, then call `useRefreshLoaders()(name)` to refresh the whole group
|
|
192
|
-
* at once. Pass an array to tag one read into several groups — it is refreshed
|
|
193
|
-
* when ANY of its groups is refreshed, so a coarse tag can cover the whole set
|
|
194
|
-
* while a finer tag targets a subset. Each member is refreshed with a plain GET
|
|
195
|
-
* against the current route URL — no params, no body, no mutation methods —
|
|
196
|
-
* because a group spans heterogeneous loaders with different param/return
|
|
197
|
-
* shapes.
|
|
198
|
-
*
|
|
199
|
-
* For parameterized sharing of a SINGLE loader, use `key` instead; group
|
|
200
|
-
* members should be registered or non-parameterized-keyed reads (a plain-GET
|
|
201
|
-
* group refresh would drop any per-call params).
|
|
202
|
-
*/
|
|
203
96
|
refreshGroup?: string | string[];
|
|
204
97
|
}
|
|
205
98
|
|
|
206
|
-
/**
|
|
207
|
-
* Internal hook implementation shared by useLoader and useFetchLoader
|
|
208
|
-
*/
|
|
209
99
|
function useLoaderInternal<T>(
|
|
210
100
|
loader: LoaderDefinition<T>,
|
|
211
101
|
options?: UseLoaderOptions,
|
|
212
102
|
): UseFetchLoaderResult<T> {
|
|
213
103
|
const context = useContext(OutletContext);
|
|
214
104
|
|
|
215
|
-
// Get data from context (SSR/navigation). `hasContextData` distinguishes
|
|
216
|
-
// "loader registered on the route, value happens to be undefined" from
|
|
217
|
-
// "loader is not in any parent's context at all". The shared store is
|
|
218
|
-
// only consulted when the loader really is in route context — that
|
|
219
|
-
// preserves per-component isolation for ad-hoc useFetchLoader callers
|
|
220
|
-
// who use the same fetchable loader without registering it.
|
|
221
105
|
const { contextData, hasContextData } = useMemo((): {
|
|
222
106
|
contextData: T | undefined;
|
|
223
107
|
hasContextData: boolean;
|
|
@@ -230,9 +114,6 @@ function useLoaderInternal<T>(
|
|
|
230
114
|
hasContextData: true,
|
|
231
115
|
};
|
|
232
116
|
}
|
|
233
|
-
// Check content element — the route's OutletProvider is rendered as
|
|
234
|
-
// <Outlet /> content (a child), so its loaderData isn't in the parent
|
|
235
|
-
// chain. Parallel slots need to reach into it to find route-level loaders.
|
|
236
117
|
const contentData = extractContentLoaderData(
|
|
237
118
|
current.content,
|
|
238
119
|
loader.$$id,
|
|
@@ -245,23 +126,8 @@ function useLoaderInternal<T>(
|
|
|
245
126
|
return { contextData: undefined, hasContextData: false };
|
|
246
127
|
}, [context, loader.$$id]);
|
|
247
128
|
|
|
248
|
-
// Shared subscription: every component reading the same loader id sees
|
|
249
|
-
// the same snapshot, so a plain refetch from one component propagates to
|
|
250
|
-
// the others. Mirrors the convention used by useParams / useLinkStatus —
|
|
251
|
-
// useState seeded from the store, useEffect subscribes for updates and
|
|
252
|
-
// calls setState inside startTransition so subscriber re-renders don't
|
|
253
|
-
// trip Suspense fallbacks during a refetch (matches the per-hook
|
|
254
|
-
// startTransition the old code wrapped setFetchedData in).
|
|
255
129
|
const loaderId = loader.$$id;
|
|
256
|
-
// Client refresh key. The shared store is partitioned by bucket key so that
|
|
257
|
-
// only hooks with the same `key` refresh together. Default (no key) keeps the
|
|
258
|
-
// historical behavior: one bucket per loader id.
|
|
259
130
|
const key = options?.key;
|
|
260
|
-
// Normalize the refresh-group tag(s) to a stable, deduped, sorted list. The
|
|
261
|
-
// joined `groupKey` string is the subscribe effect's dependency, so passing an
|
|
262
|
-
// inline array literal (`refreshGroup={["a", "b"]}`) does not force a
|
|
263
|
-
// resubscribe on every render. An empty list means "no groups" — identical to
|
|
264
|
-
// omitting the option (`hasGroups` stays false, no private bucket is created).
|
|
265
131
|
const refreshGroupOption = options?.refreshGroup;
|
|
266
132
|
const groupKey =
|
|
267
133
|
refreshGroupOption === undefined
|
|
@@ -276,10 +142,6 @@ function useLoaderInternal<T>(
|
|
|
276
142
|
[groupKey],
|
|
277
143
|
);
|
|
278
144
|
const hasGroups = groupList.length > 0;
|
|
279
|
-
// A grouped reader with no explicit key gets a private per-hook bucket so a
|
|
280
|
-
// cross-loader group refresh cannot leak into the bare `loader.$$id` bucket
|
|
281
|
-
// shared by unrelated unkeyed readers. Sharing within a group is opt-in via
|
|
282
|
-
// an explicit `key`.
|
|
283
145
|
const privateBucketIdRef = useRef<string | null>(null);
|
|
284
146
|
if (hasGroups && key === undefined && privateBucketIdRef.current === null) {
|
|
285
147
|
privateBucketIdRef.current = `__rg${privateGroupBucketSeq++}`;
|
|
@@ -289,12 +151,6 @@ function useLoaderInternal<T>(
|
|
|
289
151
|
const bucketKey =
|
|
290
152
|
effectiveKey === undefined ? loaderId : `${loaderId}::${effectiveKey}`;
|
|
291
153
|
|
|
292
|
-
// Plain-GET refresh thunk registered with the store for cross-loader group
|
|
293
|
-
// refresh (useRefreshLoaders). Always shares into this hook's bucket, never
|
|
294
|
-
// touches lastSharedRequestIdRef (so a group refresh never render-throws —
|
|
295
|
-
// errors surface via `error` and reject the refreshGroups() promise instead),
|
|
296
|
-
// and sends no params/body. Stable across navigations (depends only on
|
|
297
|
-
// loaderId + bucketKey), so the store keeps one current thunk per bucket.
|
|
298
154
|
const groupRefetch = useCallback(async (): Promise<void> => {
|
|
299
155
|
if (!loaderId) return;
|
|
300
156
|
const requestId = loaderStore.reserveRequestId(bucketKey);
|
|
@@ -333,9 +189,6 @@ function useLoaderInternal<T>(
|
|
|
333
189
|
? sharedState.snapshot
|
|
334
190
|
: loaderStore.getSnapshot(bucketKey);
|
|
335
191
|
useEffect(() => {
|
|
336
|
-
// Sync any value the store committed between this hook's lazy
|
|
337
|
-
// initializer and effect-time (e.g. a sibling that mounted earlier
|
|
338
|
-
// already triggered a load()).
|
|
339
192
|
const initial = loaderStore.getSnapshot(bucketKey);
|
|
340
193
|
if (initial !== sharedSnapshot) {
|
|
341
194
|
startTransition(() => {
|
|
@@ -430,10 +283,6 @@ function useLoaderInternal<T>(
|
|
|
430
283
|
|
|
431
284
|
const throwOnError = options?.throwOnError ?? true;
|
|
432
285
|
|
|
433
|
-
// Refs for values used inside load() that should NOT cause callback identity
|
|
434
|
-
// churn. loader.$$id can change if a reusable component receives a different
|
|
435
|
-
// loader without remounting; data changes on every navigation. Refs keep the
|
|
436
|
-
// callback stable while always reading the latest values.
|
|
437
286
|
const loaderIdRef = useRef(loaderId);
|
|
438
287
|
loaderIdRef.current = loaderId;
|
|
439
288
|
const bucketKeyRef = useRef(bucketKey);
|
|
@@ -443,8 +292,6 @@ function useLoaderInternal<T>(
|
|
|
443
292
|
const hasContextDataRef = useRef(hasContextData);
|
|
444
293
|
hasContextDataRef.current = hasContextData;
|
|
445
294
|
|
|
446
|
-
// Load function for fetching data via the ?_rsc_loader endpoint.
|
|
447
|
-
// Supports GET (data fetching) and POST/PUT/PATCH/DELETE (mutations).
|
|
448
295
|
const load = useCallback(
|
|
449
296
|
async (loadOptions?: LoadOptions): Promise<T> => {
|
|
450
297
|
const id = loaderIdRef.current;
|
|
@@ -455,20 +302,8 @@ function useLoaderInternal<T>(
|
|
|
455
302
|
}
|
|
456
303
|
|
|
457
304
|
const bucket = bucketKeyRef.current;
|
|
458
|
-
// A dedicated bucket means this read owns a bucket distinct from the bare
|
|
459
|
-
// loader id — either an explicit `key` (`$$id::key`) or a refreshGroup's
|
|
460
|
-
// private bucket (`$$id::<private>`).
|
|
461
305
|
const hasDedicatedBucket = bucket !== id;
|
|
462
306
|
|
|
463
|
-
// Deciding shared vs local:
|
|
464
|
-
// - With a dedicated bucket, every shareable GET (params allowed) writes
|
|
465
|
-
// to that bucket — the key/group is an explicit opt-in to sharing, and
|
|
466
|
-
// a direct load() must land in the same bucket a group refresh uses.
|
|
467
|
-
// - On the bare loader-id bucket, sharing is only correct when the
|
|
468
|
-
// loader is registered on the route and the call is a plain refetch —
|
|
469
|
-
// otherwise two unrelated components calling load() on the same
|
|
470
|
-
// fetchable loader would overwrite each other's local view.
|
|
471
|
-
// Mutations (non-GET / body) stay local in both cases.
|
|
472
307
|
const shared = hasDedicatedBucket
|
|
473
308
|
? isShareableGet(loadOptions)
|
|
474
309
|
: isPlainRefetch(loadOptions) && hasContextDataRef.current;
|
|
@@ -477,9 +312,6 @@ function useLoaderInternal<T>(
|
|
|
477
312
|
if (shared) {
|
|
478
313
|
sharedRequestId = loaderStore.reserveRequestId(bucket);
|
|
479
314
|
lastSharedRequestIdRef.current = sharedRequestId;
|
|
480
|
-
// beginRequest flips loading on AND clears any prior error so a
|
|
481
|
-
// throwOnError: false consumer doesn't keep showing the stale
|
|
482
|
-
// error during the retry. Gated on requestId === latest.
|
|
483
315
|
loaderStore.beginRequest(bucket, sharedRequestId);
|
|
484
316
|
} else {
|
|
485
317
|
localRequestId = ++localRequestIdRef.current;
|
|
@@ -505,8 +337,6 @@ function useLoaderInternal<T>(
|
|
|
505
337
|
loadOptions?.params && Object.keys(loadOptions.params).length > 0;
|
|
506
338
|
|
|
507
339
|
if (bodyValue instanceof FormData) {
|
|
508
|
-
// FormData body — send as multipart/form-data (preserves File objects).
|
|
509
|
-
// Params are appended as a JSON string in a special field.
|
|
510
340
|
if (hasParams) {
|
|
511
341
|
bodyValue.set(
|
|
512
342
|
"_rsc_loader_params",
|
|
@@ -519,7 +349,6 @@ function useLoaderInternal<T>(
|
|
|
519
349
|
body: bodyValue,
|
|
520
350
|
};
|
|
521
351
|
} else {
|
|
522
|
-
// JSON body — send params and body as JSON
|
|
523
352
|
const bodyPayload: {
|
|
524
353
|
params?: Record<string, string>;
|
|
525
354
|
body?: unknown;
|
|
@@ -541,7 +370,6 @@ function useLoaderInternal<T>(
|
|
|
541
370
|
};
|
|
542
371
|
}
|
|
543
372
|
} else {
|
|
544
|
-
// GET - send params in query string
|
|
545
373
|
if (
|
|
546
374
|
loadOptions?.params &&
|
|
547
375
|
Object.keys(loadOptions.params).length > 0
|
|
@@ -571,12 +399,8 @@ function useLoaderInternal<T>(
|
|
|
571
399
|
|
|
572
400
|
const result = payload.loaderResult;
|
|
573
401
|
if (shared) {
|
|
574
|
-
// finishData is gated on requestId; a stale response is dropped.
|
|
575
402
|
loaderStore.finishData(bucket, sharedRequestId, result);
|
|
576
403
|
} else if (localRequestId === localRequestIdRef.current) {
|
|
577
|
-
// Local-branch gate, mirrors the shared-branch requestId check:
|
|
578
|
-
// if a newer load() was issued from this hook before this one
|
|
579
|
-
// resolved, drop the stale result.
|
|
580
404
|
startTransition(() => {
|
|
581
405
|
setLocalFetchedData({ has: true, value: result });
|
|
582
406
|
setLocalIsLoading(false);
|
|
@@ -594,12 +418,9 @@ function useLoaderInternal<T>(
|
|
|
594
418
|
if (throwOnError) {
|
|
595
419
|
throw err;
|
|
596
420
|
}
|
|
597
|
-
// When throwOnError is false, return the latest data snapshot (previous
|
|
598
|
-
// successful value or undefined). Caller should check error state.
|
|
599
421
|
return dataRef.current as T;
|
|
600
422
|
} finally {
|
|
601
423
|
if (shared) {
|
|
602
|
-
// setLoading is gated; only the latest request flips the flag off.
|
|
603
424
|
loaderStore.setLoading(bucket, sharedRequestId, false);
|
|
604
425
|
}
|
|
605
426
|
}
|
|
@@ -607,13 +428,6 @@ function useLoaderInternal<T>(
|
|
|
607
428
|
[throwOnError],
|
|
608
429
|
);
|
|
609
430
|
|
|
610
|
-
// Throw during render if there's an error and throwOnError is true.
|
|
611
|
-
// - Local errors always belong to this hook, so always throw on opt-in.
|
|
612
|
-
// - Shared errors throw only when this hook initiated the failing
|
|
613
|
-
// request (entry.requestId matches lastSharedRequestIdRef). Sibling
|
|
614
|
-
// readers expose the error via `error` but do not throw, so a
|
|
615
|
-
// throwOnError: true reader never explodes because of someone else's
|
|
616
|
-
// throwOnError: false load() failure.
|
|
617
431
|
if (throwOnError) {
|
|
618
432
|
if (localError) throw localError;
|
|
619
433
|
if (
|
|
@@ -9,6 +9,7 @@ import { resolve } from "node:path";
|
|
|
9
9
|
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
10
10
|
import { evictHandlerCode } from "../utils/bundle-analysis.js";
|
|
11
11
|
import { copyStagedBuildAssets } from "../utils/prerender-utils.js";
|
|
12
|
+
import { jsonParseExpression } from "../utils/manifest-utils.js";
|
|
12
13
|
import type { DiscoveryState } from "./state.js";
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -104,7 +105,7 @@ export function postprocessBundle(state: DiscoveryState): void {
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
const manifestCode = [
|
|
107
|
-
`const m
|
|
108
|
+
`const m=${jsonParseExpression(manifestMap)};`,
|
|
108
109
|
`export function loadPrerenderAsset(s){return import(s)}`,
|
|
109
110
|
`export default m;`,
|
|
110
111
|
"",
|
|
@@ -11,6 +11,16 @@ import {
|
|
|
11
11
|
formatNestedRouterConflictError,
|
|
12
12
|
findNestedRouterConflict,
|
|
13
13
|
} from "../../build/generate-route-types.js";
|
|
14
|
+
// Pure data transforms over generateManifestFull's output. Imported directly
|
|
15
|
+
// from source (not the public ./build barrel, and not the runner) because they
|
|
16
|
+
// are realm-independent: buildRouteTrie/buildPerRouterTrie operate on plain
|
|
17
|
+
// manifest data, and collectFallbackClientRefs keys on the global-registry
|
|
18
|
+
// Symbol.for("react.client.reference"), so it detects client references in a
|
|
19
|
+
// boundary tree regardless of which realm imported the walker. Only
|
|
20
|
+
// generateManifestFull must stay on the runner (it invokes user handlers via
|
|
21
|
+
// RangoContext from the runner realm) — see the runner.import below.
|
|
22
|
+
import { buildRouteTrie, buildPerRouterTrie } from "../../build/route-trie.js";
|
|
23
|
+
import { collectFallbackClientRefs } from "../../build/collect-fallback-refs.js";
|
|
14
24
|
import {
|
|
15
25
|
flattenLeafEntries,
|
|
16
26
|
buildRouteToStaticPrefix,
|
|
@@ -107,7 +117,10 @@ export async function discoverRouters(
|
|
|
107
117
|
}
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
//
|
|
120
|
+
// generateManifestFull must run in the RSC runner realm: it invokes the
|
|
121
|
+
// user's urlpatterns.handler() via RangoContext, consuming router instances
|
|
122
|
+
// from the runner. The trie/fallback-ref builders are pure transforms over
|
|
123
|
+
// its output and are imported directly from source above.
|
|
111
124
|
const buildMod = await timed(
|
|
112
125
|
debug,
|
|
113
126
|
"inner: import @rangojs/router/build",
|
|
@@ -158,11 +171,12 @@ export async function discoverRouters(
|
|
|
158
171
|
// are NOT in EntryData, so generateManifestFull's walk misses them. Collect any
|
|
159
172
|
// "use client" default boundary directly off the router instance. The value is
|
|
160
173
|
// commonly a handler function wrapping the client boundary in server providers,
|
|
161
|
-
// so collectFallbackClientRefs invokes + walks the tree.
|
|
162
|
-
// so it
|
|
174
|
+
// so collectFallbackClientRefs invokes + walks the tree. The walker keys on the
|
|
175
|
+
// global-registry Symbol.for("react.client.reference"), so it detects client
|
|
176
|
+
// references in a runner-realm boundary tree even when imported here directly.
|
|
163
177
|
const collectFromBoundaryNode = (node: unknown): void => {
|
|
164
|
-
if (collectClientFallbackRef
|
|
165
|
-
|
|
178
|
+
if (collectClientFallbackRef) {
|
|
179
|
+
collectFallbackClientRefs(node, collectClientFallbackRef);
|
|
166
180
|
}
|
|
167
181
|
};
|
|
168
182
|
|
|
@@ -243,20 +257,19 @@ export async function discoverRouters(
|
|
|
243
257
|
// Flatten prefix tree leaf nodes into precomputed entries.
|
|
244
258
|
// Leaf nodes (no children) can have their routes used directly by
|
|
245
259
|
// evaluateLazyEntry() without running the handler at runtime.
|
|
260
|
+
// Walk once into a per-router array, then fold it into the merged array;
|
|
261
|
+
// the merged and per-router entries are identical, so a second walk is
|
|
262
|
+
// redundant. Append order is preserved within and across routers.
|
|
263
|
+
const routerPrecomputed: PrecomputedEntry[] = [];
|
|
246
264
|
flattenLeafEntries(
|
|
247
265
|
manifest.prefixTree,
|
|
248
266
|
manifest.routeManifest,
|
|
249
|
-
|
|
267
|
+
routerPrecomputed,
|
|
250
268
|
);
|
|
269
|
+
newMergedPrecomputedEntries.push(...routerPrecomputed);
|
|
251
270
|
|
|
252
271
|
// Store per-router manifest and precomputed entries for isolated virtual modules.
|
|
253
272
|
newPerRouterManifestDataMap.set(id, manifest.routeManifest);
|
|
254
|
-
const routerPrecomputed: PrecomputedEntry[] = [];
|
|
255
|
-
flattenLeafEntries(
|
|
256
|
-
manifest.prefixTree,
|
|
257
|
-
manifest.routeManifest,
|
|
258
|
-
routerPrecomputed,
|
|
259
|
-
);
|
|
260
273
|
newPerRouterPrecomputedMap.set(id, routerPrecomputed);
|
|
261
274
|
|
|
262
275
|
console.log(
|
|
@@ -294,8 +307,7 @@ export async function discoverRouters(
|
|
|
294
307
|
let newMergedRouteTrie: any = null;
|
|
295
308
|
const trieStart = debug ? performance.now() : 0;
|
|
296
309
|
if (Object.keys(newMergedRouteManifest).length > 0) {
|
|
297
|
-
|
|
298
|
-
if (buildRouteTrie && mergedRouteAncestry) {
|
|
310
|
+
if (mergedRouteAncestry) {
|
|
299
311
|
// Build routeToStaticPrefix from saved manifests
|
|
300
312
|
const routeToStaticPrefix: Record<string, string> = {};
|
|
301
313
|
for (const { manifest } of allManifests) {
|
|
@@ -343,11 +355,9 @@ export async function discoverRouters(
|
|
|
343
355
|
// Build per-router tries for multi-router isolation. Uses the single
|
|
344
356
|
// shared buildPerRouterTrie so the production serialized trie is built by
|
|
345
357
|
// exactly the same code as the dev/HMR runtime rebuild (manifest-init.ts).
|
|
346
|
-
|
|
358
|
+
// Returns null for route-less manifests (route-trie.ts).
|
|
347
359
|
for (const { id, manifest } of allManifests) {
|
|
348
|
-
const perRouterTrie = buildPerRouterTrie
|
|
349
|
-
? buildPerRouterTrie(manifest)
|
|
350
|
-
: null;
|
|
360
|
+
const perRouterTrie = buildPerRouterTrie(manifest);
|
|
351
361
|
if (perRouterTrie) {
|
|
352
362
|
newPerRouterTrieMap.set(id, perRouterTrie);
|
|
353
363
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* generation.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { contextSet } from "../../context-var.js";
|
|
9
|
+
import { contextSet, hasContextVars } from "../../context-var.js";
|
|
10
10
|
import {
|
|
11
11
|
encodePathParam,
|
|
12
12
|
substituteRouteParams,
|
|
@@ -135,9 +135,7 @@ export async function expandPrerenderRoutes(
|
|
|
135
135
|
(performance.now() - getParamsStart).toFixed(1),
|
|
136
136
|
);
|
|
137
137
|
const concurrency = def.options?.concurrency ?? 1;
|
|
138
|
-
const hasBuildVars =
|
|
139
|
-
Object.keys(buildVars).length > 0 ||
|
|
140
|
-
Object.getOwnPropertySymbols(buildVars).length > 0;
|
|
138
|
+
const hasBuildVars = hasContextVars(buildVars);
|
|
141
139
|
for (const params of paramsList) {
|
|
142
140
|
let url = substituteRouteParams(
|
|
143
141
|
pattern,
|
|
@@ -20,6 +20,11 @@ export interface PluginOptions {
|
|
|
20
20
|
buildEnv?: import("../plugin-types.js").BuildEnvOption;
|
|
21
21
|
/** Deployment preset (needed for buildEnv "auto" resolution). */
|
|
22
22
|
preset?: "node" | "cloudflare";
|
|
23
|
+
/**
|
|
24
|
+
* Route-discovery scan filter (glob include/exclude) from rango() config.
|
|
25
|
+
* Compiled into `DiscoveryState.scanFilter` once `projectRoot` is known.
|
|
26
|
+
*/
|
|
27
|
+
discovery?: { include?: string[]; exclude?: string[] };
|
|
23
28
|
/**
|
|
24
29
|
* Shared context the built-in clientChunks strategy reads. Discovery populates
|
|
25
30
|
* it (registered fallback hashes + single-router name) before the client build
|
|
@@ -49,7 +49,6 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
49
49
|
);
|
|
50
50
|
genFileVars.push(varName);
|
|
51
51
|
} else {
|
|
52
|
-
// Routers without sourceFile: inline their manifest data directly
|
|
53
52
|
routersWithoutGenFile.push({
|
|
54
53
|
id: entry.id,
|
|
55
54
|
manifest: entry.routeManifest,
|
|
@@ -68,14 +67,12 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
68
67
|
`clearAllRouterData();`,
|
|
69
68
|
];
|
|
70
69
|
|
|
71
|
-
// Flatten NamedRoutes entries: search schema objects -> plain string paths
|
|
72
70
|
if (genFileVars.length > 0) {
|
|
73
71
|
lines.push(
|
|
74
72
|
`function __flat(r) { const o = {}; for (const [k, v] of Object.entries(r)) o[k] = typeof v === "string" ? v : v.path; return o; }`,
|
|
75
73
|
);
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
// Build the merged manifest from gen file imports + inlined data
|
|
79
76
|
if (genFileVars.length === 1 && routersWithoutGenFile.length === 0) {
|
|
80
77
|
lines.push(`setCachedManifest(__flat(${genFileVars[0]}));`);
|
|
81
78
|
} else {
|
|
@@ -86,7 +83,6 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
86
83
|
lines.push(`setCachedManifest({ ${parts.join(", ")} });`);
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
// Set per-router manifests
|
|
90
86
|
let genVarIdx = 0;
|
|
91
87
|
for (const entry of state.perRouterManifests) {
|
|
92
88
|
if (entry.sourceFile) {
|
|
@@ -114,8 +110,6 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
114
110
|
// against live router.urlpatterns, which is always correct after a
|
|
115
111
|
// program reload.
|
|
116
112
|
|
|
117
|
-
// Register lazy loaders for per-router manifest modules.
|
|
118
|
-
// Each import() uses a static string literal so Rollup creates separate chunks.
|
|
119
113
|
for (const routerId of state.perRouterManifestDataMap.keys()) {
|
|
120
114
|
lines.push(
|
|
121
115
|
`registerRouterManifestLoader(${JSON.stringify(routerId)}, () => import(${JSON.stringify(VIRTUAL_ROUTES_MANIFEST_ID + "/" + routerId)}));`,
|
|
@@ -129,9 +123,6 @@ export function generateRoutesManifestModule(state: DiscoveryState): string {
|
|
|
129
123
|
return lines.join("\n");
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
// No manifest: either discovery hasn't completed or no runner (Cloudflare dev).
|
|
133
|
-
// Still inject __PRERENDER_DEV_URL so the prerender store can fetch on-demand.
|
|
134
|
-
// Re-resolve origin now since the server is listening by module load time.
|
|
135
126
|
if (!state.isBuildMode) {
|
|
136
127
|
const origin =
|
|
137
128
|
state.devServerOrigin ||
|
|
@@ -160,7 +151,6 @@ export function generatePerRouterModule(
|
|
|
160
151
|
const lines: string[] = [];
|
|
161
152
|
|
|
162
153
|
if (routerEntry?.sourceFile) {
|
|
163
|
-
// Import manifest from the gen file so HMR auto-propagates
|
|
164
154
|
const routerDir = dirname(routerEntry.sourceFile);
|
|
165
155
|
const routerBasename = basename(routerEntry.sourceFile).replace(
|
|
166
156
|
/\.(tsx?|jsx?)$/,
|
|
@@ -189,5 +179,5 @@ export function generatePerRouterModule(
|
|
|
189
179
|
`export const precomputedEntries = ${jsonParseExpression(entries)};`,
|
|
190
180
|
);
|
|
191
181
|
}
|
|
192
|
-
return lines.join("\n") || "
|
|
182
|
+
return lines.join("\n") || "";
|
|
193
183
|
}
|
package/src/vite/plugin-types.ts
CHANGED
|
@@ -127,16 +127,18 @@ interface RangoBaseOptions {
|
|
|
127
127
|
clientChunks?: ClientChunks;
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* This is the build-time env supplied by the Vite plugin, not the live
|
|
135
|
-
* request env. It is shared across all prerender invocations for the build.
|
|
130
|
+
* Filter which files route discovery scans, by glob. Paths are matched
|
|
131
|
+
* root-relative (e.g. `src/routes/**`). `include` restricts discovery to
|
|
132
|
+
* matching files; `exclude` removes matches (the defaults cover tests, dist,
|
|
133
|
+
* coverage, etc.). Mirrors the CLI's `--include`/`--exclude`.
|
|
136
134
|
*
|
|
137
|
-
* @
|
|
135
|
+
* @example
|
|
136
|
+
* rango({ discovery: { include: ["src/routes/**"] } })
|
|
138
137
|
*/
|
|
139
|
-
|
|
138
|
+
discovery?: {
|
|
139
|
+
include?: string[];
|
|
140
|
+
exclude?: string[];
|
|
141
|
+
};
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
@@ -147,6 +149,17 @@ export interface RangoNodeOptions extends RangoBaseOptions {
|
|
|
147
149
|
* Deployment preset. Defaults to 'node' when not specified.
|
|
148
150
|
*/
|
|
149
151
|
preset?: "node";
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Environment bindings available to Prerender and Static handlers at build
|
|
155
|
+
* time via `ctx.env`. Shared across all prerender invocations for the build.
|
|
156
|
+
*
|
|
157
|
+
* `"auto"` is Cloudflare-only (it resolves the wrangler platform proxy), so it
|
|
158
|
+
* is not accepted on the Node preset — pass an object or a factory instead.
|
|
159
|
+
*
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
buildEnv?: Exclude<BuildEnvOption, "auto">;
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
/**
|
|
@@ -156,12 +169,25 @@ export interface RangoCloudflareOptions extends RangoBaseOptions {
|
|
|
156
169
|
/**
|
|
157
170
|
* Deployment preset for Cloudflare Workers.
|
|
158
171
|
* When using cloudflare preset:
|
|
159
|
-
* - @vitejs/plugin-rsc
|
|
172
|
+
* - @vitejs/plugin-rsc IS still added by rango(), but with `serverHandler: false`
|
|
173
|
+
* (the cloudflare plugin owns the RSC worker/server entry); only `client` and
|
|
174
|
+
* `ssr` virtual entries are configured, no rsc entry
|
|
160
175
|
* - Your worker entry (e.g., worker.rsc.tsx) imports the router directly
|
|
161
176
|
* - Browser and SSR use virtual entries
|
|
162
177
|
* - Build-time manifest generation is auto-detected from the resolved RSC environment config
|
|
163
178
|
*/
|
|
164
179
|
preset: "cloudflare";
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Environment bindings available to Prerender and Static handlers at build
|
|
183
|
+
* time via `ctx.env`. Shared across all prerender invocations for the build.
|
|
184
|
+
*
|
|
185
|
+
* `"auto"` resolves the Cloudflare platform proxy via wrangler
|
|
186
|
+
* `getPlatformProxy()`.
|
|
187
|
+
*
|
|
188
|
+
* @default false
|
|
189
|
+
*/
|
|
190
|
+
buildEnv?: BuildEnvOption;
|
|
165
191
|
}
|
|
166
192
|
|
|
167
193
|
/**
|