@rangojs/router 0.0.0-experimental.79 → 0.0.0-experimental.7d061845
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 +120 -25
- package/dist/bin/rango.js +147 -57
- package/dist/testing/vitest.js +82 -0
- package/dist/vite/index.js +2138 -841
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +68 -21
- package/skills/breadcrumbs/SKILL.md +3 -1
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +220 -30
- package/skills/caching/SKILL.md +116 -8
- package/skills/composability/SKILL.md +27 -2
- package/skills/document-cache/SKILL.md +78 -55
- package/skills/handler-use/SKILL.md +3 -1
- package/skills/hooks/SKILL.md +229 -20
- package/skills/host-router/SKILL.md +45 -20
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +26 -4
- package/skills/layout/SKILL.md +6 -7
- package/skills/links/SKILL.md +247 -17
- package/skills/loader/SKILL.md +219 -9
- package/skills/middleware/SKILL.md +15 -9
- package/skills/migrate-nextjs/SKILL.md +4 -2
- package/skills/migrate-react-router/SKILL.md +5 -0
- package/skills/mime-routes/SKILL.md +27 -0
- package/skills/observability/SKILL.md +137 -0
- package/skills/parallel/SKILL.md +12 -6
- package/skills/prerender/SKILL.md +14 -33
- package/skills/rango/SKILL.md +242 -24
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +66 -9
- package/skills/route/SKILL.md +33 -4
- package/skills/router-setup/SKILL.md +3 -3
- package/skills/server-actions/SKILL.md +751 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/testing/SKILL.md +816 -0
- package/skills/typesafety/SKILL.md +319 -27
- package/skills/use-cache/SKILL.md +34 -5
- package/skills/view-transitions/SKILL.md +294 -0
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +117 -0
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/event-controller.ts +86 -70
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/navigation-bridge.ts +65 -9
- package/src/browser/navigation-client.ts +45 -25
- package/src/browser/navigation-store.ts +32 -9
- package/src/browser/navigation-transaction.ts +10 -28
- package/src/browser/partial-update.ts +52 -26
- package/src/browser/prefetch/cache.ts +124 -26
- package/src/browser/prefetch/fetch.ts +114 -38
- package/src/browser/prefetch/queue.ts +36 -5
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +18 -13
- package/src/browser/react/NavigationProvider.tsx +72 -31
- package/src/browser/react/filter-segment-order.ts +51 -7
- package/src/browser/react/index.ts +3 -0
- package/src/browser/react/location-state-shared.ts +175 -4
- package/src/browser/react/location-state.ts +39 -13
- package/src/browser/react/use-handle.ts +17 -9
- package/src/browser/react/use-navigation.ts +22 -2
- package/src/browser/react/use-params.ts +20 -8
- package/src/browser/react/use-reverse.ts +106 -0
- package/src/browser/react/use-router.ts +22 -2
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/response-adapter.ts +25 -0
- package/src/browser/rsc-router.tsx +64 -22
- package/src/browser/scroll-restoration.ts +22 -14
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +23 -30
- package/src/browser/types.ts +21 -0
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +60 -35
- package/src/build/generate-route-types.ts +2 -0
- package/src/build/index.ts +2 -0
- package/src/build/route-trie.ts +2 -1
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +1 -1
- package/src/build/route-types/per-module-writer.ts +7 -4
- package/src/build/route-types/router-processing.ts +55 -14
- package/src/build/route-types/scan-filter.ts +1 -1
- package/src/build/route-types/source-scan.ts +118 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-scope.ts +28 -42
- package/src/cache/cf/cf-cache-store.ts +54 -13
- package/src/client.rsc.tsx +3 -0
- package/src/client.tsx +10 -8
- package/src/context-var.ts +5 -5
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +30 -1
- package/src/handle.ts +26 -13
- package/src/host/index.ts +2 -2
- package/src/host/router.ts +129 -57
- package/src/host/types.ts +31 -2
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +140 -20
- package/src/index.rsc.ts +9 -4
- package/src/index.ts +16 -6
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +21 -6
- package/src/loader.ts +3 -10
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/prerender.ts +4 -4
- package/src/response-utils.ts +37 -0
- package/src/reverse.ts +65 -39
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +253 -265
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/helpers-types.ts +43 -15
- package/src/route-definition/resolve-handler-use.ts +6 -0
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-types.ts +19 -41
- package/src/router/basename.ts +14 -0
- package/src/router/content-negotiation.ts +15 -2
- package/src/router/error-handling.ts +1 -1
- package/src/router/handler-context.ts +21 -41
- package/src/router/intercept-resolution.ts +4 -18
- package/src/router/lazy-includes.ts +3 -3
- package/src/router/loader-resolution.ts +19 -2
- package/src/router/match-api.ts +4 -3
- package/src/router/match-handlers.ts +63 -20
- package/src/router/match-middleware/cache-lookup.ts +44 -91
- package/src/router/match-middleware/cache-store.ts +3 -2
- package/src/router/match-result.ts +53 -32
- package/src/router/metrics.ts +1 -1
- package/src/router/middleware-types.ts +15 -26
- package/src/router/middleware.ts +99 -84
- package/src/router/pattern-matching.ts +101 -17
- package/src/router/prerender-match.ts +1 -1
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +4 -28
- package/src/router/revalidation.ts +58 -2
- package/src/router/router-interfaces.ts +45 -28
- package/src/router/router-options.ts +40 -1
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +27 -6
- package/src/router/segment-resolution/revalidation.ts +147 -106
- package/src/router/segment-resolution/view-transition-default.ts +36 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry.ts +99 -0
- package/src/router/trie-matching.ts +18 -13
- package/src/router/types.ts +8 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +38 -23
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/handler.ts +28 -69
- package/src/rsc/helpers.ts +91 -43
- package/src/rsc/index.ts +1 -1
- package/src/rsc/origin-guard.ts +28 -10
- package/src/rsc/progressive-enhancement.ts +4 -0
- package/src/rsc/response-route-handler.ts +46 -53
- package/src/rsc/rsc-rendering.ts +35 -51
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +17 -37
- package/src/rsc/ssr-setup.ts +16 -0
- package/src/rsc/types.ts +8 -2
- package/src/search-params.ts +4 -4
- package/src/segment-system.tsx +122 -56
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +118 -51
- package/src/server/cookie-store.ts +28 -4
- package/src/server/request-context.ts +20 -42
- package/src/ssr/index.tsx +5 -1
- package/src/static-handler.ts +1 -1
- package/src/testing/cache-status.ts +166 -0
- package/src/testing/collect-handle.ts +63 -0
- package/src/testing/dispatch.ts +440 -0
- package/src/testing/dom.entry.ts +22 -0
- package/src/testing/e2e/fixture.ts +154 -0
- package/src/testing/e2e/index.ts +149 -0
- package/src/testing/e2e/matchers.ts +51 -0
- package/src/testing/e2e/page-helpers.ts +272 -0
- package/src/testing/e2e/parity.ts +306 -0
- package/src/testing/e2e/server.ts +183 -0
- package/src/testing/flight-matchers.ts +104 -0
- package/src/testing/flight-runtime.d.ts +57 -0
- package/src/testing/flight-tree.ts +332 -0
- package/src/testing/flight.entry.ts +46 -0
- package/src/testing/flight.ts +224 -0
- package/src/testing/generated-routes.ts +223 -0
- package/src/testing/index.ts +106 -0
- package/src/testing/internal/context.ts +304 -0
- package/src/testing/internal/flight-client-globals.ts +30 -0
- package/src/testing/internal/seed-vars.ts +42 -0
- package/src/testing/render-handler.ts +267 -0
- package/src/testing/render-route.tsx +565 -0
- package/src/testing/run-loader.ts +341 -0
- package/src/testing/run-middleware.ts +188 -0
- package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
- package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
- package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
- package/src/testing/vitest-stubs/version.ts +5 -0
- package/src/testing/vitest.ts +270 -0
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +68 -50
- package/src/types/index.ts +1 -0
- package/src/types/loader-types.ts +5 -6
- package/src/types/request-scope.ts +126 -0
- package/src/types/segments.ts +35 -1
- package/src/urls/include-helper.ts +10 -53
- package/src/urls/index.ts +0 -3
- package/src/urls/path-helper-types.ts +11 -3
- package/src/urls/path-helper.ts +17 -52
- package/src/urls/pattern-types.ts +36 -19
- package/src/urls/response-types.ts +22 -29
- package/src/urls/type-extraction.ts +26 -116
- package/src/urls/urls-function.ts +1 -5
- package/src/use-loader.tsx +413 -42
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +6 -6
- package/src/vite/discovery/discover-routers.ts +101 -51
- package/src/vite/discovery/discovery-errors.ts +194 -0
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +67 -26
- package/src/vite/discovery/route-types-writer.ts +40 -84
- package/src/vite/discovery/self-gen-tracking.ts +27 -1
- package/src/vite/discovery/state.ts +33 -0
- package/src/vite/discovery/virtual-module-codegen.ts +13 -23
- package/src/vite/index.ts +2 -0
- package/src/vite/plugin-types.ts +67 -0
- package/src/vite/plugins/cjs-to-esm.ts +8 -7
- package/src/vite/plugins/client-ref-dedup.ts +16 -0
- package/src/vite/plugins/client-ref-hashing.ts +28 -5
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/plugins/expose-action-id.ts +54 -30
- package/src/vite/plugins/expose-id-utils.ts +12 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
- package/src/vite/plugins/expose-ids/handler-transform.ts +8 -61
- package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
- package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
- package/src/vite/plugins/expose-internal-ids.ts +496 -486
- package/src/vite/plugins/performance-tracks.ts +29 -25
- package/src/vite/plugins/use-cache-transform.ts +65 -50
- package/src/vite/plugins/version-injector.ts +39 -23
- package/src/vite/plugins/version-plugin.ts +59 -2
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +116 -29
- package/src/vite/router-discovery.ts +750 -100
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/banner.ts +1 -1
- package/src/vite/utils/bundle-analysis.ts +4 -2
- package/src/vite/utils/client-chunks.ts +190 -0
- package/src/vite/utils/forward-user-plugins.ts +193 -0
- package/src/vite/utils/manifest-utils.ts +21 -5
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +5 -4
- package/src/vite/utils/shared-utils.ts +107 -26
- package/src/browser/action-response-classifier.ts +0 -99
|
@@ -13,6 +13,10 @@ import type { RouterInstance, RouterNavigateOptions } from "../types.js";
|
|
|
13
13
|
* useRouter() do not re-render on navigation state changes.
|
|
14
14
|
* For reactive navigation state, use useNavigation() instead.
|
|
15
15
|
*
|
|
16
|
+
* Methods read `basename` from the live context on each call so that
|
|
17
|
+
* cross-app navigation (app-switch) sees the current app's basename
|
|
18
|
+
* rather than the one captured at mount time.
|
|
19
|
+
*
|
|
16
20
|
* @example
|
|
17
21
|
* ```tsx
|
|
18
22
|
* const router = useRouter();
|
|
@@ -29,7 +33,10 @@ export function useRouter(): RouterInstance {
|
|
|
29
33
|
throw new Error("useRouter must be used within NavigationProvider");
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
// Stable reference: ctx is
|
|
36
|
+
// Stable reference: ctx itself is stable, and reads on each method call
|
|
37
|
+
// pick up live basename values from the context (backed by a live ref
|
|
38
|
+
// in NavigationProvider), so app-switch transitions are reflected without
|
|
39
|
+
// recreating this object.
|
|
33
40
|
return useMemo<RouterInstance>(() => {
|
|
34
41
|
/** Prefix a root-relative path with basename if not already prefixed. */
|
|
35
42
|
function withBasename(url: string): string {
|
|
@@ -65,7 +72,20 @@ export function useRouter(): RouterInstance {
|
|
|
65
72
|
},
|
|
66
73
|
|
|
67
74
|
back(): void {
|
|
68
|
-
|
|
75
|
+
// Avoid escaping the host on the first entry of this session.
|
|
76
|
+
// Prefer the Navigation API; fall back to the router-stamped
|
|
77
|
+
// history.state.idx (set by pushHistoryWithIdx) for older browsers.
|
|
78
|
+
const nav = (window as { navigation?: { canGoBack: boolean } })
|
|
79
|
+
.navigation;
|
|
80
|
+
const canGoBack =
|
|
81
|
+
nav && typeof nav.canGoBack === "boolean"
|
|
82
|
+
? nav.canGoBack
|
|
83
|
+
: ((window.history.state as { idx?: number } | null)?.idx ?? 0) > 0;
|
|
84
|
+
if (canGoBack) {
|
|
85
|
+
window.history.back();
|
|
86
|
+
} else {
|
|
87
|
+
ctx.navigate(withBasename("/"), { replace: true });
|
|
88
|
+
}
|
|
69
89
|
},
|
|
70
90
|
|
|
71
91
|
forward(): void {
|
|
@@ -25,15 +25,18 @@ function parsePathname(pathname: string): string[] {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Build segments state from event controller
|
|
28
|
+
* Build segments state from event controller. `segmentIds` is the
|
|
29
|
+
* route-only list (parallels and loaders stripped) — distinct from the
|
|
30
|
+
* controller's `segmentOrder` which drives handle collection and includes
|
|
31
|
+
* parallel slot ids.
|
|
29
32
|
*/
|
|
30
33
|
function buildSegmentsState(
|
|
31
34
|
location: URL,
|
|
32
|
-
|
|
35
|
+
routeSegmentIds: string[],
|
|
33
36
|
): SegmentsState {
|
|
34
37
|
return {
|
|
35
38
|
path: parsePathname(location.pathname),
|
|
36
|
-
segmentIds:
|
|
39
|
+
segmentIds: routeSegmentIds,
|
|
37
40
|
location,
|
|
38
41
|
};
|
|
39
42
|
}
|
|
@@ -74,7 +77,7 @@ export function useSegments<T>(
|
|
|
74
77
|
const handleState = ctx.eventController.getHandleState();
|
|
75
78
|
const segmentsState = buildSegmentsState(
|
|
76
79
|
location as URL,
|
|
77
|
-
handleState.
|
|
80
|
+
handleState.routeSegmentIds,
|
|
78
81
|
);
|
|
79
82
|
return selector ? selector(segmentsState) : segmentsState;
|
|
80
83
|
});
|
|
@@ -94,7 +97,7 @@ export function useSegments<T>(
|
|
|
94
97
|
// render-time setState calls.
|
|
95
98
|
const segmentsCache = useRef<{
|
|
96
99
|
location: URL;
|
|
97
|
-
|
|
100
|
+
routeSegmentIds: string[];
|
|
98
101
|
state: SegmentsState;
|
|
99
102
|
} | null>(null);
|
|
100
103
|
|
|
@@ -113,17 +116,17 @@ export function useSegments<T>(
|
|
|
113
116
|
if (
|
|
114
117
|
cache &&
|
|
115
118
|
cache.location === location &&
|
|
116
|
-
cache.
|
|
119
|
+
cache.routeSegmentIds === handleState.routeSegmentIds
|
|
117
120
|
) {
|
|
118
121
|
segmentsState = cache.state;
|
|
119
122
|
} else {
|
|
120
123
|
segmentsState = buildSegmentsState(
|
|
121
124
|
location as URL,
|
|
122
|
-
handleState.
|
|
125
|
+
handleState.routeSegmentIds,
|
|
123
126
|
);
|
|
124
127
|
segmentsCache.current = {
|
|
125
128
|
location: location as URL,
|
|
126
|
-
|
|
129
|
+
routeSegmentIds: handleState.routeSegmentIds,
|
|
127
130
|
state: segmentsState,
|
|
128
131
|
};
|
|
129
132
|
}
|
|
@@ -24,6 +24,31 @@ export function emptyResponse(): Response {
|
|
|
24
24
|
return new Response(null, { status: 200 });
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Handle the X-RSC-Reload control header (server requests a full page reload on
|
|
29
|
+
* a version mismatch). Returns a short-circuit response when the header is
|
|
30
|
+
* present -- emptyResponse() if the URL was blocked by origin validation, or a
|
|
31
|
+
* never-resolving promise while the page reloads -- and null when absent, so
|
|
32
|
+
* the caller continues processing (e.g. the X-RSC-Redirect check). Scoped to
|
|
33
|
+
* X-RSC-Reload only; redirect handling differs between callers.
|
|
34
|
+
*/
|
|
35
|
+
export function handleReloadHeader(
|
|
36
|
+
response: Response,
|
|
37
|
+
opts: { onBlocked: () => void; onReload: (url: string) => void },
|
|
38
|
+
): Response | Promise<Response> | null {
|
|
39
|
+
const reload = extractRscHeaderUrl(response, "X-RSC-Reload");
|
|
40
|
+
if (reload === "blocked") {
|
|
41
|
+
opts.onBlocked();
|
|
42
|
+
return emptyResponse();
|
|
43
|
+
}
|
|
44
|
+
if (reload) {
|
|
45
|
+
opts.onReload(reload.url);
|
|
46
|
+
window.location.href = reload.url;
|
|
47
|
+
return new Promise<Response>(() => {});
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
27
52
|
/**
|
|
28
53
|
* Tee a response body for RSC parsing and stream completion tracking.
|
|
29
54
|
* Returns a new Response with one branch; the other is consumed to detect
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
isInterceptSegment,
|
|
29
29
|
splitInterceptSegments,
|
|
30
30
|
} from "./intercept-utils.js";
|
|
31
|
+
import { createAppShellRef } from "./app-shell.js";
|
|
31
32
|
|
|
32
33
|
// Vite HMR types are provided by vite/client
|
|
33
34
|
|
|
@@ -114,13 +115,20 @@ export interface BrowserAppContext {
|
|
|
114
115
|
warmupEnabled?: boolean;
|
|
115
116
|
/** App version for prefetch version mismatch detection */
|
|
116
117
|
version?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Live app-shell ref. Cross-app navigations replace its contents so the
|
|
120
|
+
* NavigationProvider and renderSegments pick up the target app's
|
|
121
|
+
* rootLayout, basename, and version without consumer rerenders. Theme,
|
|
122
|
+
* warmup, and prefetch TTL are document-lifetime (see AppShell).
|
|
123
|
+
*/
|
|
124
|
+
appShellRef?: import("./app-shell.js").AppShellRef;
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
// Module-level state for the initialized app
|
|
120
128
|
let browserAppContext: BrowserAppContext | null = null;
|
|
121
129
|
|
|
122
130
|
/**
|
|
123
|
-
* Initialize the browser app. Must be called before rendering
|
|
131
|
+
* Initialize the browser app. Must be called before rendering Rango.
|
|
124
132
|
*
|
|
125
133
|
* This function:
|
|
126
134
|
* - Loads the initial RSC payload from the stream
|
|
@@ -204,13 +212,23 @@ export async function initBrowserApp(
|
|
|
204
212
|
// Create composable utilities
|
|
205
213
|
const client = createNavigationClient(deps);
|
|
206
214
|
|
|
207
|
-
//
|
|
208
|
-
|
|
215
|
+
// Capture the per-router app-shell so cross-app navigations can replace
|
|
216
|
+
// it atomically. rootLayout, basename, and version live here and are
|
|
217
|
+
// read through the ref at call time rather than closed over. Theme,
|
|
218
|
+
// warmup, and prefetch TTL are deliberately excluded — they are
|
|
219
|
+
// document-lifetime and stay stable across smooth cross-app transitions.
|
|
209
220
|
const version = initialPayload.metadata?.version;
|
|
221
|
+
const appShellRef = createAppShellRef({
|
|
222
|
+
routerId: initialPayload.metadata?.routerId,
|
|
223
|
+
rootLayout: initialPayload.metadata?.rootLayout,
|
|
224
|
+
basename: initialPayload.metadata?.basename,
|
|
225
|
+
version,
|
|
226
|
+
});
|
|
210
227
|
|
|
211
228
|
// Initialize the localStorage state key for cache invalidation.
|
|
212
|
-
//
|
|
213
|
-
|
|
229
|
+
// The build version busts cached prefetches on deploy; the routerId
|
|
230
|
+
// namespaces the key so sibling apps on the same origin don't collide.
|
|
231
|
+
initRangoState(version ?? "0", initialPayload.metadata?.routerId);
|
|
214
232
|
setAppVersion(version);
|
|
215
233
|
|
|
216
234
|
// Initialize the in-memory prefetch cache TTL from server config.
|
|
@@ -220,11 +238,17 @@ export async function initBrowserApp(
|
|
|
220
238
|
initPrefetchCache(prefetchCacheTTL);
|
|
221
239
|
}
|
|
222
240
|
|
|
223
|
-
// Create a bound renderSegments that
|
|
241
|
+
// Create a bound renderSegments that reads rootLayout through the shell
|
|
242
|
+
// ref. On app switch the ref is updated before the tree re-renders, so
|
|
243
|
+
// the new app's Document (rootLayout) replaces the previous one.
|
|
224
244
|
const renderSegments = (
|
|
225
245
|
segments: ResolvedSegment[],
|
|
226
246
|
options?: RenderSegmentsOptions,
|
|
227
|
-
) =>
|
|
247
|
+
) =>
|
|
248
|
+
baseRenderSegments(segments, {
|
|
249
|
+
...options,
|
|
250
|
+
rootLayout: appShellRef.get().rootLayout,
|
|
251
|
+
});
|
|
228
252
|
|
|
229
253
|
// Lazy reference for navigation bridge — the action bridge is created first
|
|
230
254
|
// but may need to trigger SPA navigation for action redirects.
|
|
@@ -256,6 +280,7 @@ export async function initBrowserApp(
|
|
|
256
280
|
onUpdate: (update) => store.emitUpdate(update),
|
|
257
281
|
renderSegments,
|
|
258
282
|
version: version,
|
|
283
|
+
appShellRef,
|
|
259
284
|
});
|
|
260
285
|
|
|
261
286
|
// Connect action redirect → navigation bridge (now that both are initialized)
|
|
@@ -300,11 +325,11 @@ export async function initBrowserApp(
|
|
|
300
325
|
// full lifecycle (fetching + streaming, before commit) without
|
|
301
326
|
// blocking on server actions.
|
|
302
327
|
if (eventController.getState().isNavigating) {
|
|
303
|
-
console.log("[
|
|
328
|
+
console.log("[Rango] HMR: Skipping — navigation in progress");
|
|
304
329
|
return;
|
|
305
330
|
}
|
|
306
331
|
|
|
307
|
-
console.log("[
|
|
332
|
+
console.log("[Rango] HMR: Server update, refetching RSC");
|
|
308
333
|
|
|
309
334
|
const abort = new AbortController();
|
|
310
335
|
hmrAbort = abort;
|
|
@@ -339,11 +364,18 @@ export async function initBrowserApp(
|
|
|
339
364
|
// Update version BEFORE rebuilding state so that
|
|
340
365
|
// clearHistoryCache() runs first, then the fresh segment
|
|
341
366
|
// cache entry we create below survives.
|
|
367
|
+
//
|
|
368
|
+
// Compare against the bridge's live version, not the init-time
|
|
369
|
+
// `version` const: after the first HMR bump the const is stale, so a
|
|
370
|
+
// later update with an unchanged version would otherwise re-clear the
|
|
371
|
+
// cache and re-broadcast across tabs/apps. The live read fires only
|
|
372
|
+
// on a genuine version change.
|
|
342
373
|
const newVersion = payload.metadata.version;
|
|
343
|
-
|
|
374
|
+
const currentVersion = navigationBridge.getVersion();
|
|
375
|
+
if (newVersion && newVersion !== currentVersion) {
|
|
344
376
|
console.log(
|
|
345
|
-
"[
|
|
346
|
-
|
|
377
|
+
"[Rango] HMR: version changed",
|
|
378
|
+
currentVersion,
|
|
347
379
|
"→",
|
|
348
380
|
newVersion,
|
|
349
381
|
"clearing caches",
|
|
@@ -351,6 +383,13 @@ export async function initBrowserApp(
|
|
|
351
383
|
navigationBridge.updateVersion(newVersion);
|
|
352
384
|
}
|
|
353
385
|
|
|
386
|
+
// Apply only partial segment updates. A non-partial payload during
|
|
387
|
+
// HMR is transient: the worker route table is still rebuilding after
|
|
388
|
+
// the edit, so the URL momentarily resolves to not-found/catch-all.
|
|
389
|
+
// Skip it -- the debounced follow-up refetch returns the settled
|
|
390
|
+
// route's partial payload and renders it below. We never reload here:
|
|
391
|
+
// a paramless document GET would run the SSR path and surface the
|
|
392
|
+
// not-found page during that same transient.
|
|
354
393
|
if (payload.metadata?.isPartial) {
|
|
355
394
|
const segments = payload.metadata.segments || [];
|
|
356
395
|
const matched = payload.metadata.matched || [];
|
|
@@ -390,10 +429,10 @@ export async function initBrowserApp(
|
|
|
390
429
|
|
|
391
430
|
await streamComplete;
|
|
392
431
|
handle.complete(new URL(window.location.href));
|
|
393
|
-
console.log("[
|
|
432
|
+
console.log("[Rango] HMR: RSC stream complete");
|
|
394
433
|
} catch (err) {
|
|
395
434
|
if (abort.signal.aborted) return;
|
|
396
|
-
console.warn("[
|
|
435
|
+
console.warn("[Rango] HMR: Refetch failed, reloading page", err);
|
|
397
436
|
window.location.reload();
|
|
398
437
|
return;
|
|
399
438
|
} finally {
|
|
@@ -405,7 +444,7 @@ export async function initBrowserApp(
|
|
|
405
444
|
});
|
|
406
445
|
}
|
|
407
446
|
|
|
408
|
-
// Store context for
|
|
447
|
+
// Store context for Rango component
|
|
409
448
|
const context: BrowserAppContext = {
|
|
410
449
|
store,
|
|
411
450
|
eventController,
|
|
@@ -416,6 +455,7 @@ export async function initBrowserApp(
|
|
|
416
455
|
initialTheme: effectiveInitialTheme,
|
|
417
456
|
warmupEnabled: initialPayload.metadata?.warmupEnabled ?? true,
|
|
418
457
|
version,
|
|
458
|
+
appShellRef,
|
|
419
459
|
};
|
|
420
460
|
browserAppContext = context;
|
|
421
461
|
|
|
@@ -428,7 +468,7 @@ export async function initBrowserApp(
|
|
|
428
468
|
export function getBrowserAppContext(): BrowserAppContext {
|
|
429
469
|
if (!browserAppContext) {
|
|
430
470
|
throw new Error(
|
|
431
|
-
"
|
|
471
|
+
"Rango: initBrowserApp() must be called before rendering Rango",
|
|
432
472
|
);
|
|
433
473
|
}
|
|
434
474
|
return browserAppContext;
|
|
@@ -442,18 +482,18 @@ export function resetBrowserAppContext(): void {
|
|
|
442
482
|
}
|
|
443
483
|
|
|
444
484
|
/**
|
|
445
|
-
* Props for the
|
|
485
|
+
* Props for the Rango component
|
|
446
486
|
*/
|
|
447
|
-
export interface
|
|
487
|
+
export interface RangoProps {}
|
|
448
488
|
|
|
449
489
|
/**
|
|
450
|
-
*
|
|
490
|
+
* Rango component - renders the RSC router with all internal wiring.
|
|
451
491
|
*
|
|
452
492
|
* Must be called after initBrowserApp() has completed.
|
|
453
493
|
*
|
|
454
494
|
* @example
|
|
455
495
|
* ```tsx
|
|
456
|
-
* import { initBrowserApp,
|
|
496
|
+
* import { initBrowserApp, Rango } from "rsc-router/browser";
|
|
457
497
|
* import { rscStream } from "rsc-html-stream/client";
|
|
458
498
|
* import * as rscBrowser from "@vitejs/plugin-rsc/browser";
|
|
459
499
|
*
|
|
@@ -463,14 +503,14 @@ export interface RSCRouterProps {}
|
|
|
463
503
|
* hydrateRoot(
|
|
464
504
|
* document,
|
|
465
505
|
* <React.StrictMode>
|
|
466
|
-
* <
|
|
506
|
+
* <Rango />
|
|
467
507
|
* </React.StrictMode>
|
|
468
508
|
* );
|
|
469
509
|
* }
|
|
470
510
|
* main();
|
|
471
511
|
* ```
|
|
472
512
|
*/
|
|
473
|
-
export function
|
|
513
|
+
export function Rango(_props: RangoProps): React.ReactElement {
|
|
474
514
|
const {
|
|
475
515
|
store,
|
|
476
516
|
eventController,
|
|
@@ -481,6 +521,7 @@ export function RSCRouter(_props: RSCRouterProps): React.ReactElement {
|
|
|
481
521
|
initialTheme,
|
|
482
522
|
warmupEnabled,
|
|
483
523
|
version,
|
|
524
|
+
appShellRef,
|
|
484
525
|
} = getBrowserAppContext();
|
|
485
526
|
|
|
486
527
|
// Signal that the React tree has hydrated. useEffect only fires after
|
|
@@ -501,6 +542,7 @@ export function RSCRouter(_props: RSCRouterProps): React.ReactElement {
|
|
|
501
542
|
warmupEnabled={warmupEnabled}
|
|
502
543
|
version={version}
|
|
503
544
|
basename={initialPayload.metadata?.basename}
|
|
545
|
+
appShellRef={appShellRef}
|
|
504
546
|
/>
|
|
505
547
|
);
|
|
506
548
|
}
|
|
@@ -332,6 +332,8 @@ export function scrollToHash(): boolean {
|
|
|
332
332
|
* Scroll to top of page
|
|
333
333
|
*/
|
|
334
334
|
export function scrollToTop(): void {
|
|
335
|
+
if (typeof window === "undefined") return;
|
|
336
|
+
if (typeof window.scrollTo !== "function") return;
|
|
335
337
|
window.scrollTo(0, 0);
|
|
336
338
|
}
|
|
337
339
|
|
|
@@ -374,20 +376,26 @@ export function handleNavigationEnd(options: {
|
|
|
374
376
|
// Fall through to hash or top if no saved position
|
|
375
377
|
}
|
|
376
378
|
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
379
|
+
// scrollToHash / scrollToTop run synchronously here.
|
|
380
|
+
// handleNavigationEnd is invoked from NavigationProvider's
|
|
381
|
+
// useLayoutEffect (post-commit, pre-paint), so a sync scrollTo is
|
|
382
|
+
// captured by the upcoming paint AND by startViewTransition's snapshot.
|
|
383
|
+
// Deferring via rAF here pushed the call past the snapshot capture,
|
|
384
|
+
// making forward navigations wrapped in a layout/route view transition
|
|
385
|
+
// skip scroll-to-top — the live DOM scrolled but the captured snapshot
|
|
386
|
+
// was at the previous scroll position, so the user-facing page stayed
|
|
387
|
+
// visually clamped at the source page's scrollY (often the new tree's
|
|
388
|
+
// max scroll for tall→short navs). Y=0 / a hash element are robust
|
|
389
|
+
// against unmeasured layout, so sync scroll is correct here even
|
|
390
|
+
// before the new tree's scrollHeight settles.
|
|
391
|
+
//
|
|
392
|
+
// (The restore branch above keeps deferToNextPaint because savedY
|
|
393
|
+
// depends on the new tree's max scroll; sync scrollTo against an
|
|
394
|
+
// unmeasured DOM would clamp savedY to whatever the old/zero max was.)
|
|
395
|
+
if (scrollToHash()) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
scrollToTop();
|
|
391
399
|
}
|
|
392
400
|
|
|
393
401
|
/**
|
|
@@ -48,7 +48,7 @@ export function assertSegmentStructure(
|
|
|
48
48
|
|
|
49
49
|
if (cachedCategory !== incomingCategory) {
|
|
50
50
|
console.warn(
|
|
51
|
-
`[
|
|
51
|
+
`[Rango] Tree structure mismatch detected in ${context} ` +
|
|
52
52
|
`for segment "${cached.id}": loading category changed from ` +
|
|
53
53
|
`"${cachedCategory}" (${describeLoading(cached.loading)}) to ` +
|
|
54
54
|
`"${incomingCategory}" (${describeLoading(incoming.loading)}). ` +
|
|
@@ -64,7 +64,7 @@ export function assertSegmentStructure(
|
|
|
64
64
|
const incomingHasMount = !!incoming.mountPath;
|
|
65
65
|
if (cachedHasMount !== incomingHasMount) {
|
|
66
66
|
console.warn(
|
|
67
|
-
`[
|
|
67
|
+
`[Rango] MountContextProvider mismatch detected in ${context} ` +
|
|
68
68
|
`for segment "${cached.id}": mountPath changed from ` +
|
|
69
69
|
`${cachedHasMount ? `"${cached.mountPath}"` : "undefined"} to ` +
|
|
70
70
|
`${incomingHasMount ? `"${incoming.mountPath}"` : "undefined"}. ` +
|
|
@@ -25,6 +25,7 @@ import { validateRedirectOrigin } from "./validate-redirect-origin.js";
|
|
|
25
25
|
import {
|
|
26
26
|
extractRscHeaderUrl,
|
|
27
27
|
emptyResponse,
|
|
28
|
+
handleReloadHeader,
|
|
28
29
|
teeWithCompletion,
|
|
29
30
|
} from "./response-adapter.js";
|
|
30
31
|
import { mergeLocationState } from "./history-state.js";
|
|
@@ -77,6 +78,20 @@ export function createServerActionBridge(
|
|
|
77
78
|
onNavigate,
|
|
78
79
|
} = config;
|
|
79
80
|
|
|
81
|
+
// SPA-navigate when onNavigate is set, else hard-reload. state is omitted (not
|
|
82
|
+
// passed as undefined) to match the header path's prior call shape.
|
|
83
|
+
async function dispatchRedirect(url: string, state?: unknown): Promise<void> {
|
|
84
|
+
if (onNavigate) {
|
|
85
|
+
await onNavigate(url, {
|
|
86
|
+
...(state !== undefined ? { state } : {}),
|
|
87
|
+
replace: true,
|
|
88
|
+
_skipCache: true,
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
window.location.href = url;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
80
95
|
let isRegistered = false;
|
|
81
96
|
|
|
82
97
|
const fetchPartialUpdate = createPartialUpdater({
|
|
@@ -222,18 +237,12 @@ export function createServerActionBridge(
|
|
|
222
237
|
handle.signal.removeEventListener("abort", onHandleAbort);
|
|
223
238
|
|
|
224
239
|
// Check for version mismatch - server wants us to reload
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
if (
|
|
231
|
-
log("version mismatch on action, reloading", {
|
|
232
|
-
reloadUrl: reload.url,
|
|
233
|
-
});
|
|
234
|
-
window.location.href = reload.url;
|
|
235
|
-
return new Promise<Response>(() => {});
|
|
236
|
-
}
|
|
240
|
+
const reloadResult = handleReloadHeader(response, {
|
|
241
|
+
onBlocked: resolveStreamComplete,
|
|
242
|
+
onReload: (url) =>
|
|
243
|
+
log("version mismatch on action, reloading", { reloadUrl: url }),
|
|
244
|
+
});
|
|
245
|
+
if (reloadResult) return reloadResult;
|
|
237
246
|
|
|
238
247
|
// Simple redirect from action (no state, no RSC payload).
|
|
239
248
|
// Short-circuits before createFromFetch — no Flight deserialization needed.
|
|
@@ -243,14 +252,7 @@ export function createServerActionBridge(
|
|
|
243
252
|
if (redirect && redirect !== "blocked" && !handle.signal.aborted) {
|
|
244
253
|
log("action simple redirect", { url: redirect.url });
|
|
245
254
|
handle.complete(undefined);
|
|
246
|
-
|
|
247
|
-
await onNavigate(redirect.url, {
|
|
248
|
-
replace: true,
|
|
249
|
-
_skipCache: true,
|
|
250
|
-
});
|
|
251
|
-
} else {
|
|
252
|
-
window.location.href = redirect.url;
|
|
253
|
-
}
|
|
255
|
+
await dispatchRedirect(redirect.url);
|
|
254
256
|
return new Promise<Response>(() => {});
|
|
255
257
|
}
|
|
256
258
|
if (redirect === "blocked") {
|
|
@@ -339,18 +341,9 @@ export function createServerActionBridge(
|
|
|
339
341
|
handle.complete(returnValue?.data);
|
|
340
342
|
return returnValue?.data;
|
|
341
343
|
}
|
|
342
|
-
const redirectState = metadata.locationState;
|
|
343
344
|
log("action redirect", { url: redirectUrl });
|
|
344
345
|
handle.complete(returnValue?.data);
|
|
345
|
-
|
|
346
|
-
await onNavigate(redirectUrl, {
|
|
347
|
-
state: redirectState,
|
|
348
|
-
replace: true,
|
|
349
|
-
_skipCache: true,
|
|
350
|
-
});
|
|
351
|
-
} else {
|
|
352
|
-
window.location.href = redirectUrl;
|
|
353
|
-
}
|
|
346
|
+
await dispatchRedirect(redirectUrl, metadata.locationState);
|
|
354
347
|
return returnValue?.data;
|
|
355
348
|
}
|
|
356
349
|
|
package/src/browser/types.ts
CHANGED
|
@@ -39,6 +39,12 @@ export interface RscMetadata {
|
|
|
39
39
|
isError?: boolean;
|
|
40
40
|
matched?: string[];
|
|
41
41
|
diff?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* All segment ids re-resolved on the server, including null-component
|
|
44
|
+
* ones excluded from `segments`/`diff`. Drives client-side handle-bucket
|
|
45
|
+
* cleanup. Superset of `diff`. See MatchResult.resolvedIds.
|
|
46
|
+
*/
|
|
47
|
+
resolvedIds?: string[];
|
|
42
48
|
/** Merged route params from the matched route */
|
|
43
49
|
params?: Record<string, string>;
|
|
44
50
|
/**
|
|
@@ -427,6 +433,12 @@ export interface NavigationStore {
|
|
|
427
433
|
markCacheAsStale(): void;
|
|
428
434
|
markCacheAsStaleAndBroadcast(): void;
|
|
429
435
|
clearHistoryCache(): void;
|
|
436
|
+
/**
|
|
437
|
+
* Clear this tab's nav + prefetch caches without broadcasting or rotating
|
|
438
|
+
* shared state. Intended for app-switch transitions that affect only this
|
|
439
|
+
* tab's session.
|
|
440
|
+
*/
|
|
441
|
+
clearHistoryCacheLocal(): void;
|
|
430
442
|
broadcastCacheInvalidation(): void;
|
|
431
443
|
|
|
432
444
|
// Cross-tab refresh callback (set by navigation bridge)
|
|
@@ -540,8 +552,17 @@ export interface NavigationBridge {
|
|
|
540
552
|
refresh(): Promise<void>;
|
|
541
553
|
handlePopstate(): Promise<void>;
|
|
542
554
|
registerLinkInterception(): () => void;
|
|
555
|
+
/** Current RSC version (live, reflects the latest updateVersion). */
|
|
556
|
+
getVersion(): string | undefined;
|
|
543
557
|
/** Update the RSC version (e.g. after HMR). Clears prefetch cache. */
|
|
544
558
|
updateVersion(newVersion: string): void;
|
|
559
|
+
/**
|
|
560
|
+
* Replace the active app-shell snapshot (rootLayout, basename, version)
|
|
561
|
+
* atomically. Used on cross-app navigations when the response's routerId
|
|
562
|
+
* indicates the user entered a different app. Theme, warmup, and prefetch
|
|
563
|
+
* TTL are document-lifetime and not part of the shell.
|
|
564
|
+
*/
|
|
565
|
+
updateAppShell(next: import("./app-shell.js").AppShell): void;
|
|
545
566
|
}
|
|
546
567
|
|
|
547
568
|
/**
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Collect the `"use client"` client-reference keys reachable from an error /
|
|
2
|
+
// notFound boundary registration, for routing them into the dedicated
|
|
3
|
+
// `app-fallback` chunk (see vite/utils/client-chunks.ts).
|
|
4
|
+
//
|
|
5
|
+
// A boundary registration is not always a bare client element. The common,
|
|
6
|
+
// load-bearing pattern wraps the client boundary in providers a thrown handler
|
|
7
|
+
// needs (the layout that would normally supply them did not mount):
|
|
8
|
+
//
|
|
9
|
+
// defaultErrorBoundary: ({ error }) => (
|
|
10
|
+
// <FallbackIntl locales={...}>
|
|
11
|
+
// <ThemedError error={error} /> // <- the real "use client" boundary
|
|
12
|
+
// </FallbackIntl>
|
|
13
|
+
// )
|
|
14
|
+
//
|
|
15
|
+
// So the value may be (a) a handler FUNCTION returning a tree, or (b) an element
|
|
16
|
+
// tree with the client boundary nested below server wrappers. We:
|
|
17
|
+
// 1. If it's a function, CALL it with synthetic props to get the returned tree.
|
|
18
|
+
// This only constructs JSX — the inner components are element `type`s, never
|
|
19
|
+
// invoked — so no hooks run. Guarded: a boundary that needs a real render
|
|
20
|
+
// context (request globals, etc.) throws and is skipped (graceful: it simply
|
|
21
|
+
// stays on the default grouping, as before).
|
|
22
|
+
// 2. Walk the resulting tree and report every element whose `.type` is a
|
|
23
|
+
// plugin-rsc client reference.
|
|
24
|
+
//
|
|
25
|
+
// Limit: a boundary that *conditionally* renders different client components based
|
|
26
|
+
// on the runtime error cannot be resolved statically — only the branch taken with
|
|
27
|
+
// the synthetic error is seen. Such cases fall back to the default chunk; the
|
|
28
|
+
// custom `clientChunks` function is the escape hatch.
|
|
29
|
+
|
|
30
|
+
const CLIENT_REF = Symbol.for("react.client.reference");
|
|
31
|
+
const MAX_DEPTH = 40;
|
|
32
|
+
|
|
33
|
+
// Synthetic props covering the error-boundary (`{ error, reset }`) and notFound
|
|
34
|
+
// (`{ pathname }`) handler shapes. The handler destructures what it needs.
|
|
35
|
+
const SYNTHETIC_PROPS = {
|
|
36
|
+
error: new Error("rango: build-time fallback-chunk discovery"),
|
|
37
|
+
reset: () => {},
|
|
38
|
+
pathname: "/",
|
|
39
|
+
info: { componentStack: "" },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
interface MaybeElement {
|
|
43
|
+
type?: { $$typeof?: symbol; $$id?: string };
|
|
44
|
+
props?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isReactNodeLike(v: unknown): boolean {
|
|
48
|
+
return (
|
|
49
|
+
Array.isArray(v) ||
|
|
50
|
+
(typeof v === "object" && v !== null && "$$typeof" in (v as object))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function walkElementTree(
|
|
55
|
+
node: unknown,
|
|
56
|
+
report: (refKey: string) => void,
|
|
57
|
+
depth: number,
|
|
58
|
+
): void {
|
|
59
|
+
if (node == null || depth > MAX_DEPTH) return;
|
|
60
|
+
if (Array.isArray(node)) {
|
|
61
|
+
for (const child of node) walkElementTree(child, report, depth + 1);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (typeof node !== "object") return;
|
|
65
|
+
|
|
66
|
+
const el = node as MaybeElement;
|
|
67
|
+
const type = el.type;
|
|
68
|
+
if (type?.$$typeof === CLIENT_REF && typeof type.$$id === "string") {
|
|
69
|
+
// $$id is `<referenceKey>#<exportName>` in build mode — keep the referenceKey.
|
|
70
|
+
report(type.$$id.split("#")[0]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const props = el.props;
|
|
74
|
+
if (props && typeof props === "object") {
|
|
75
|
+
// Children are always nodes; other props are followed only when they look
|
|
76
|
+
// like React nodes (slots/icons), never arbitrary data objects.
|
|
77
|
+
walkElementTree(props.children, report, depth + 1);
|
|
78
|
+
for (const key in props) {
|
|
79
|
+
if (key === "children") continue;
|
|
80
|
+
const value = props[key];
|
|
81
|
+
if (isReactNodeLike(value)) walkElementTree(value, report, depth + 1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Report every `"use client"` client-reference key reachable from a single
|
|
88
|
+
* error/notFound boundary registration (handler function or element tree).
|
|
89
|
+
*/
|
|
90
|
+
export function collectFallbackClientRefs(
|
|
91
|
+
boundary: unknown,
|
|
92
|
+
report: (refKey: string) => void,
|
|
93
|
+
): void {
|
|
94
|
+
try {
|
|
95
|
+
let node = boundary;
|
|
96
|
+
if (typeof node === "function") {
|
|
97
|
+
node = (node as (props: unknown) => unknown)(SYNTHETIC_PROPS);
|
|
98
|
+
}
|
|
99
|
+
walkElementTree(node, report, 0);
|
|
100
|
+
} catch {
|
|
101
|
+
// The boundary needs a real render context (request globals, hooks at the
|
|
102
|
+
// top level) or its tree has hostile getters. Its client refs can't be
|
|
103
|
+
// resolved statically — skip. It stays on the default grouping (no
|
|
104
|
+
// regression vs. not collecting), and the custom clientChunks fn is the
|
|
105
|
+
// escape hatch for such cases.
|
|
106
|
+
}
|
|
107
|
+
}
|