@rangojs/router 0.36.1 → 0.37.0
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/dist/bin/{chunk-THW7E5A2.js → chunk-A64EG6MI.js} +22 -19
- package/dist/bin/{client-urls-projection-DHUUOJZM.js → client-urls-projection-RLDSA3BL.js} +1 -1
- package/dist/bin/rango.js +1 -1
- package/dist/bin/{runtime-discovery-OPRGB3DF.js → runtime-discovery-T7ZLA6E3.js} +2 -2
- package/dist/bin/{temp-rsc-server-FV4ERMAS.js → temp-rsc-server-FGGXPKVQ.js} +2 -2
- package/dist/types/browser/event-controller.d.ts +53 -2
- package/dist/types/browser/fetched-loader-handles.d.ts +57 -14
- package/dist/types/browser/navigation-store.d.ts +3 -2
- package/dist/types/browser/react/use-handle.d.ts +18 -5
- package/dist/types/browser/react/use-push-handle.d.ts +44 -0
- package/dist/types/browser/types.d.ts +44 -0
- package/dist/types/client.d.ts +1 -0
- package/dist/types/client.rsc.d.ts +1 -0
- package/dist/types/handle.d.ts +13 -5
- package/dist/types/handles/client-pushes.d.ts +51 -0
- package/dist/types/handles/deferred-resolution.d.ts +7 -0
- package/dist/types/handles/pushed-by.d.ts +11 -0
- package/dist/types/loader-store.d.ts +13 -0
- package/dist/types/rsc/prefetch-render-error.d.ts +2 -1
- package/dist/types/server/handle-store.d.ts +8 -0
- package/dist/types/testing/dom.entry.d.ts +1 -1
- package/dist/types/testing/render-route.d.ts +74 -14
- package/dist/vite/index.js +23 -20
- package/package.json +1 -1
- package/skills/breadcrumbs/SKILL.md +68 -6
- package/skills/caching/SKILL.md +4 -2
- package/skills/catalog.json +3 -3
- package/skills/client-urls/SKILL.md +13 -1
- package/skills/document-cache/SKILL.md +31 -1
- package/skills/hooks/SKILL.md +8 -4
- package/skills/hooks/data.md +10 -1
- package/skills/hooks/handle-and-actions.md +402 -26
- package/skills/hooks/navigation.md +4 -0
- package/skills/hooks/urls.md +3 -0
- package/skills/links/SKILL.md +5 -3
- package/skills/loader/SKILL.md +28 -9
- package/skills/migrate-nextjs/SKILL.md +5 -0
- package/skills/migrate-react-router/component-migration.md +4 -1
- package/skills/parallel/SKILL.md +8 -0
- package/skills/ppr/SKILL.md +1 -0
- package/skills/rango/SKILL.md +6 -3
- package/skills/testing/client-components.md +35 -32
- package/skills/testing/handles.md +58 -6
- package/skills/ux-architecture/SKILL.md +4 -0
- package/src/browser/event-controller.ts +265 -4
- package/src/browser/fetched-loader-handles.ts +227 -54
- package/src/browser/navigation-store.ts +261 -2
- package/src/browser/partial-update.ts +3 -2
- package/src/browser/react/use-handle.ts +74 -27
- package/src/browser/react/use-push-handle.ts +113 -0
- package/src/browser/rsc-router.tsx +11 -14
- package/src/browser/types.ts +48 -0
- package/src/cache/document-cache-policy.ts +6 -5
- package/src/client.rsc.tsx +1 -0
- package/src/client.tsx +31 -1
- package/src/handle.ts +13 -5
- package/src/handles/client-pushes.ts +120 -0
- package/src/handles/deferred-resolution.ts +12 -0
- package/src/handles/pushed-by.ts +55 -1
- package/src/loader-store.ts +26 -0
- package/src/rsc/loader-fetch.ts +17 -0
- package/src/rsc/prefetch-render-error.ts +2 -1
- package/src/rsc/request-stages.ts +7 -6
- package/src/rsc/rsc-rendering.ts +32 -14
- package/src/server/handle-store.ts +23 -0
- package/src/ssr/ssr-root.tsx +5 -0
- package/src/testing/dom.entry.ts +2 -0
- package/src/testing/render-route.tsx +317 -72
- package/src/use-loader.tsx +16 -5
|
@@ -95,13 +95,13 @@ import {
|
|
|
95
95
|
Component as Component3,
|
|
96
96
|
createElement as createElement4,
|
|
97
97
|
isValidElement as isValidElement2,
|
|
98
|
-
useContext as
|
|
98
|
+
useContext as useContext19,
|
|
99
99
|
useMemo as useMemo9,
|
|
100
100
|
Suspense as Suspense2
|
|
101
101
|
} from "react";
|
|
102
102
|
|
|
103
103
|
// src/browser/react/use-handle.ts
|
|
104
|
-
import { useContext as useContext2,
|
|
104
|
+
import { useContext as useContext2, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
105
105
|
|
|
106
106
|
// src/missing-id-error.ts
|
|
107
107
|
var SELF_FILES = /* @__PURE__ */ new Set([
|
|
@@ -386,7 +386,7 @@ var Script = createHandle(collectScripts, "__rsc_router_script__");
|
|
|
386
386
|
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
387
387
|
|
|
388
388
|
// src/browser/react/ScrollRestoration.tsx
|
|
389
|
-
import { useEffect as
|
|
389
|
+
import { useEffect as useEffect2 } from "react";
|
|
390
390
|
|
|
391
391
|
// src/outlet-context.ts
|
|
392
392
|
import { createContext as createContext4 } from "react";
|
|
@@ -402,7 +402,7 @@ import {
|
|
|
402
402
|
} from "react";
|
|
403
403
|
|
|
404
404
|
// src/suspense-audit-react.tsx
|
|
405
|
-
import { useEffect as
|
|
405
|
+
import { useEffect as useEffect3, useLayoutEffect as useLayoutEffect3, useRef as useRef3 } from "react";
|
|
406
406
|
|
|
407
407
|
// src/internal-suspense-audit.ts
|
|
408
408
|
var INTERNAL_RANGO_SUSPENSE_AUDIT = typeof process !== "undefined" && Boolean(process.env?.INTERNAL_RANGO_SUSPENSE_AUDIT);
|
|
@@ -414,7 +414,7 @@ import { jsx as jsx3 } from "react/jsx-runtime";
|
|
|
414
414
|
import { createElement as createElement2 } from "react";
|
|
415
415
|
|
|
416
416
|
// src/loader-redirect.tsx
|
|
417
|
-
import { useEffect as
|
|
417
|
+
import { useEffect as useEffect4 } from "react";
|
|
418
418
|
|
|
419
419
|
// src/browser/react/use-router.ts
|
|
420
420
|
import { useContext as useContext7, useMemo as useMemo2 } from "react";
|
|
@@ -480,7 +480,7 @@ import {
|
|
|
480
480
|
use as use3,
|
|
481
481
|
useCallback,
|
|
482
482
|
useContext as useContext8,
|
|
483
|
-
useEffect as
|
|
483
|
+
useEffect as useEffect5,
|
|
484
484
|
useMemo as useMemo4,
|
|
485
485
|
useOptimistic,
|
|
486
486
|
useRef as useRef4,
|
|
@@ -506,7 +506,7 @@ function isHoistedRevalidateRef(value) {
|
|
|
506
506
|
}
|
|
507
507
|
|
|
508
508
|
// src/browser/react/use-navigation.ts
|
|
509
|
-
import { useContext as useContext9, useEffect as
|
|
509
|
+
import { useContext as useContext9, useEffect as useEffect6, useRef as useRef5 } from "react";
|
|
510
510
|
|
|
511
511
|
// src/browser/react/use-pathname.ts
|
|
512
512
|
import { useContext as useContext10 } from "react";
|
|
@@ -522,7 +522,7 @@ import { useCallback as useCallback2, useContext as useContext11, useMemo as use
|
|
|
522
522
|
import { useContext as useContext12 } from "react";
|
|
523
523
|
|
|
524
524
|
// src/browser/react/use-action.ts
|
|
525
|
-
import { useContext as useContext13, useState as useState5, useEffect as
|
|
525
|
+
import { useContext as useContext13, useState as useState5, useEffect as useEffect7, useRef as useRef6 } from "react";
|
|
526
526
|
|
|
527
527
|
// src/browser/react/location-state-shared.ts
|
|
528
528
|
function isLocationStateDefinition(value) {
|
|
@@ -582,13 +582,13 @@ function subscribeToLocationChange(eventController, listener) {
|
|
|
582
582
|
}
|
|
583
583
|
|
|
584
584
|
// src/browser/react/use-segments.ts
|
|
585
|
-
import { useContext as useContext14, useEffect as
|
|
585
|
+
import { useContext as useContext14, useEffect as useEffect8, useRef as useRef7 } from "react";
|
|
586
586
|
|
|
587
587
|
// src/browser/react/NavigationProvider.tsx
|
|
588
588
|
import {
|
|
589
589
|
useState as useState8,
|
|
590
|
-
useEffect as
|
|
591
|
-
useLayoutEffect as
|
|
590
|
+
useEffect as useEffect10,
|
|
591
|
+
useLayoutEffect as useLayoutEffect5,
|
|
592
592
|
useCallback as useCallback4,
|
|
593
593
|
useMemo as useMemo7,
|
|
594
594
|
useRef as useRef9,
|
|
@@ -603,8 +603,8 @@ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
|
603
603
|
// src/theme/ThemeProvider.tsx
|
|
604
604
|
import {
|
|
605
605
|
useCallback as useCallback3,
|
|
606
|
-
useEffect as
|
|
607
|
-
useLayoutEffect as
|
|
606
|
+
useEffect as useEffect9,
|
|
607
|
+
useLayoutEffect as useLayoutEffect4,
|
|
608
608
|
useMemo as useMemo6,
|
|
609
609
|
useState as useState7
|
|
610
610
|
} from "react";
|
|
@@ -628,7 +628,7 @@ import {
|
|
|
628
628
|
forwardRef,
|
|
629
629
|
useCallback as useCallback5,
|
|
630
630
|
useContext as useContext16,
|
|
631
|
-
useEffect as
|
|
631
|
+
useEffect as useEffect12,
|
|
632
632
|
useId,
|
|
633
633
|
useMemo as useMemo8,
|
|
634
634
|
useRef as useRef10
|
|
@@ -639,7 +639,7 @@ import {
|
|
|
639
639
|
createContext as createContext7,
|
|
640
640
|
useContext as useContext15,
|
|
641
641
|
useState as useState9,
|
|
642
|
-
useEffect as
|
|
642
|
+
useEffect as useEffect11
|
|
643
643
|
} from "react";
|
|
644
644
|
var LinkContext = createContext7(null);
|
|
645
645
|
|
|
@@ -917,7 +917,7 @@ var Link = forwardRef(function Link2({
|
|
|
917
917
|
);
|
|
918
918
|
}
|
|
919
919
|
}, [configuredStrategy, resolvedTo, isExternal, ctx, prefetchKey]);
|
|
920
|
-
|
|
920
|
+
useEffect12(() => {
|
|
921
921
|
if (isExternal || !ctx?.store) return;
|
|
922
922
|
if (configuredStrategy !== "viewport" && configuredStrategy !== "render" && configuredStrategy !== "adaptive") {
|
|
923
923
|
return;
|
|
@@ -1009,6 +1009,9 @@ var Link = forwardRef(function Link2({
|
|
|
1009
1009
|
);
|
|
1010
1010
|
});
|
|
1011
1011
|
|
|
1012
|
+
// src/browser/react/use-push-handle.ts
|
|
1013
|
+
import { useContext as useContext17, useLayoutEffect as useLayoutEffect6, useState as useState10 } from "react";
|
|
1014
|
+
|
|
1012
1015
|
// src/handles/breadcrumbs.ts
|
|
1013
1016
|
function collectBreadcrumbs(segments) {
|
|
1014
1017
|
const all = segments.flat();
|
|
@@ -1037,7 +1040,7 @@ var Breadcrumbs = createHandle(
|
|
|
1037
1040
|
);
|
|
1038
1041
|
|
|
1039
1042
|
// src/browser/react/location-state.ts
|
|
1040
|
-
import { useContext as
|
|
1043
|
+
import { useContext as useContext18, useEffect as useEffect13 } from "react";
|
|
1041
1044
|
|
|
1042
1045
|
// src/browser/react/use-href.tsx
|
|
1043
1046
|
import { useCallback as useCallback6 } from "react";
|
|
@@ -1204,9 +1207,9 @@ import {
|
|
|
1204
1207
|
Fragment as Fragment4,
|
|
1205
1208
|
Suspense as Suspense3,
|
|
1206
1209
|
useDeferredValue,
|
|
1207
|
-
useLayoutEffect as
|
|
1210
|
+
useLayoutEffect as useLayoutEffect7,
|
|
1208
1211
|
useMemo as useMemo10,
|
|
1209
|
-
useState as
|
|
1212
|
+
useState as useState11
|
|
1210
1213
|
} from "react";
|
|
1211
1214
|
|
|
1212
1215
|
// src/client-urls/navigation.ts
|
package/dist/bin/rango.js
CHANGED
|
@@ -229,7 +229,7 @@ ${formatNestedRouterConflictError(nestedRouterConflict, "[rango]")}
|
|
|
229
229
|
}
|
|
230
230
|
let discoverAndWriteRouteTypes;
|
|
231
231
|
try {
|
|
232
|
-
const mod = await import("./runtime-discovery-
|
|
232
|
+
const mod = await import("./runtime-discovery-T7ZLA6E3.js");
|
|
233
233
|
discoverAndWriteRouteTypes = mod.discoverAndWriteRouteTypes;
|
|
234
234
|
} catch (err) {
|
|
235
235
|
if (err.code === "ERR_MODULE_NOT_FOUND" || err.code === "MODULE_NOT_FOUND") {
|
|
@@ -163,9 +163,9 @@ async function discoverAndWriteRouteTypes(opts) {
|
|
|
163
163
|
"Runtime discovery requires '@vitejs/plugin-rsc'. Install it with: pnpm add -D @vitejs/plugin-rsc"
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
|
-
const { createTempRscServer } = await import("./temp-rsc-server-
|
|
166
|
+
const { createTempRscServer } = await import("./temp-rsc-server-FGGXPKVQ.js");
|
|
167
167
|
const { createDiscoveryState } = await import("./state-ACD2MGKJ.js");
|
|
168
|
-
const { discoverClientUrlProjections } = await import("./client-urls-projection-
|
|
168
|
+
const { discoverClientUrlProjections } = await import("./client-urls-projection-RLDSA3BL.js");
|
|
169
169
|
const {
|
|
170
170
|
isFrameworkPlugin,
|
|
171
171
|
pickForwardedRunnerConfig,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
propertyKeyIs,
|
|
28
28
|
recordClientUrlsModule,
|
|
29
29
|
unwrapExpression
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-A64EG6MI.js";
|
|
31
31
|
import "./chunk-MWOHBDPM.js";
|
|
32
32
|
import {
|
|
33
33
|
codeMatchIndices,
|
|
@@ -47,7 +47,7 @@ var DEFAULT_ROUTER_VERSIONS_KEY = "*";
|
|
|
47
47
|
// package.json
|
|
48
48
|
var package_default = {
|
|
49
49
|
name: "@rangojs/router",
|
|
50
|
-
version: "0.
|
|
50
|
+
version: "0.37.0",
|
|
51
51
|
description: "Django-inspired RSC router with composable URL patterns",
|
|
52
52
|
keywords: [
|
|
53
53
|
"react",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { NavigationLocation, NavigateOptionsInternal, TrackedActionState, InflightAction, RscMetadata, HandleData, StreamingToken } from "./types.js";
|
|
3
|
+
import { type ClientPushOwner } from "../handles/client-pushes.js";
|
|
3
4
|
import { type LoaderReadPushes } from "../handles/pushed-by.js";
|
|
4
5
|
import { type LocationStateSnapshot } from "./react/location-state-shared.js";
|
|
5
6
|
/**
|
|
@@ -254,9 +255,21 @@ export interface EventController {
|
|
|
254
255
|
* values in its segment (handles/pushed-by.ts mergeLoaderReadHandleData).
|
|
255
256
|
* Waits like setHandleData while the hydration window is open. False, and
|
|
256
257
|
* nothing applied, when no segment of the page's handle data registers the
|
|
257
|
-
* loader.
|
|
258
|
+
* loader. `applied` gets the handle data once the values are in it: at
|
|
259
|
+
* once, or when the hydration window closes, before the writes that waited
|
|
260
|
+
* after this one (the history entry's copy is written from it).
|
|
258
261
|
*/
|
|
259
|
-
setLoaderReadHandleData(loaderId: string, pushes: LoaderReadPushes): boolean;
|
|
262
|
+
setLoaderReadHandleData(loaderId: string, pushes: LoaderReadPushes, applied?: (data: HandleData) => void): boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Apply a late handle yield of the document (`metadata.handlesLate`, the
|
|
265
|
+
* document render's full state so far) to the page: swapped in whole but
|
|
266
|
+
* for the runs of the loaders `readRefreshed()` names, read when the write
|
|
267
|
+
* applies (handles/pushed-by.ts mergeLateHandleData). Waits like
|
|
268
|
+
* setHandleData while the hydration window is open. `applied` gets the
|
|
269
|
+
* handle data once the yield is in it (the history entry's copy is written
|
|
270
|
+
* from it).
|
|
271
|
+
*/
|
|
272
|
+
setLateHandleData(data: HandleData, matched: string[], readRefreshed: () => ReadonlySet<string>, applied?: (data: HandleData) => void): void;
|
|
260
273
|
/**
|
|
261
274
|
* Open the hydration window. Until releaseHydrationLock(), getHandleState()
|
|
262
275
|
* returns the state the document's HTML was rendered with, and handle writes
|
|
@@ -290,6 +303,44 @@ export interface EventController {
|
|
|
290
303
|
* its previous value until the deferred snapshot is applied.
|
|
291
304
|
*/
|
|
292
305
|
setRouteSegmentIds(matched: string[]): void;
|
|
306
|
+
/**
|
|
307
|
+
* The client handle layer (usePushHandle): set what `owner`, a mounted
|
|
308
|
+
* component, pushes for `handleId` in `segmentId`; `values` undefined or
|
|
309
|
+
* empty removes it. Kept apart from the server's handle data, so a history
|
|
310
|
+
* entry never stores it and a late server write never overwrites it, nor
|
|
311
|
+
* it one: readers merge the two when they read (withClientHandles). Values
|
|
312
|
+
* equal to the owner's last ones (samePushValue; a promise by reference)
|
|
313
|
+
* change nothing. A promise among `values` is awaited as a server
|
|
314
|
+
* push(promise) is (resolveDeferredList): the owner's values show as they
|
|
315
|
+
* were until it settles, and a newer call or a removal drops its result.
|
|
316
|
+
* Owners of one handle in one segment show in tree order: when one joins,
|
|
317
|
+
* each owner's `pusher.resync` renders it again, and the order they publish
|
|
318
|
+
* in from those renders (a `generation` past the one they were asked at)
|
|
319
|
+
* is kept. Readers subscribed with subscribeToClientHandles hear a change
|
|
320
|
+
* at once, in the caller's task; while the hydration window is open they
|
|
321
|
+
* hear it at its release.
|
|
322
|
+
*/
|
|
323
|
+
setClientHandle(handleId: string, segmentId: string, owner: ClientPushOwner, values: unknown[] | undefined): void;
|
|
324
|
+
/**
|
|
325
|
+
* `data` (server handle data) with the client layer of `handleId` after
|
|
326
|
+
* the server's values in each segment (handles/client-pushes.ts
|
|
327
|
+
* withClientPushes). `data` itself while the hydration window is open: the
|
|
328
|
+
* document's HTML was rendered from the server's values alone.
|
|
329
|
+
*/
|
|
330
|
+
withClientHandles(data: HandleData, handleId: string): HandleData;
|
|
331
|
+
/**
|
|
332
|
+
* `listener` hears the id of the handle whose client layer changed, or
|
|
333
|
+
* undefined for every handle (the hydration window's release).
|
|
334
|
+
*/
|
|
335
|
+
subscribeToClientHandles(listener: (handleId: string | undefined) => void): () => void;
|
|
336
|
+
/**
|
|
337
|
+
* From flushRouteState("anchor") until the page it announced commits: the
|
|
338
|
+
* server handle state readers show over the page being left; undefined
|
|
339
|
+
* otherwise. A client push made meanwhile comes from a component of that
|
|
340
|
+
* page, so a reader merges it with this state and shows it at once,
|
|
341
|
+
* instead of waiting for the held page (react/use-handle.ts).
|
|
342
|
+
*/
|
|
343
|
+
getHeldHandleState(): HandleState | undefined;
|
|
293
344
|
setParams(params: Record<string, string>): void;
|
|
294
345
|
getParams(): Record<string, string>;
|
|
295
346
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventController } from "./event-controller.js";
|
|
2
|
-
import type { NavigationStore } from "./types.js";
|
|
2
|
+
import type { HandleData, NavigationStore } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* The handle values a fetched loader read pushed (`_rsc_loader`: `load()`, a
|
|
5
5
|
* `refreshGroup` refresh), by handle $$id, as the reply carries them
|
|
@@ -11,23 +11,66 @@ export type FetchedLoaderHandles = Record<string, unknown[]>;
|
|
|
11
11
|
* handle (null: the read loader's own body), as the reply carries it.
|
|
12
12
|
*/
|
|
13
13
|
export type FetchedLoaderPushedBy = Record<string, (string | null)[]>;
|
|
14
|
-
/** The router state a read's handle values are applied to. */
|
|
14
|
+
/** The router state a read's data and handle values are applied to. */
|
|
15
15
|
export interface FetchedLoaderPage {
|
|
16
16
|
eventController: EventController;
|
|
17
17
|
store: NavigationStore;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* The loader store bucket a page read commits its data to, and the request
|
|
21
|
+
* id it reserved there (use-loader.tsx).
|
|
22
|
+
*/
|
|
23
|
+
export interface FetchedLoaderBucket {
|
|
24
|
+
bucketKey: string;
|
|
25
|
+
requestId: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Called with a read's reply once its data went to the loader store
|
|
29
|
+
* (`LoaderStore.finishData`, or the reader's own state for a local read).
|
|
30
|
+
*/
|
|
31
|
+
export type FetchedLoaderLanding = (result: unknown, handles: FetchedLoaderHandles | undefined, pushedBy?: FetchedLoaderPushedBy) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Start a read of `loaderId`. Call it when the request is sent; the returned
|
|
34
|
+
* function lands the reply.
|
|
35
|
+
*
|
|
36
|
+
* A page read (a plain refetch into `bucket`, which a reader with route
|
|
37
|
+
* context reads: LoaderStore.hasRouteReaders) changes what the page shows as one
|
|
38
|
+
* unit, its data and its handle values, and the history entry is written from
|
|
39
|
+
* that unit, so Back shows the page as it was left. It lands exactly when its
|
|
40
|
+
* data lands: the loader store holds its result in `bucket`
|
|
41
|
+
* (LoaderStore.holdsRequest: no newer request or route-data change since)
|
|
42
|
+
* and an entry of the page it was sent from (its key, a shallow navigation's
|
|
43
|
+
* twin, a commit written in their place) still holds the loader data it was
|
|
44
|
+
* requested for (NavigationStore.beginPageRead). Then each such entry takes
|
|
45
|
+
* the read's data (every loader segment of the loader, in place), and its
|
|
46
|
+
* handle values, once their pending
|
|
47
|
+
* pushes settle, replace the loader's earlier ones in its segment (a rejected
|
|
48
|
+
* or nullish one dropped, as on the navigation lane), on their own after the
|
|
49
|
+
* data: a handle value never holds the loader's data. They apply live while
|
|
50
|
+
* the entry still holds this read's result and is the page on screen, and the
|
|
51
|
+
* entry's copy is written from the live data when they apply; off screen they
|
|
52
|
+
* go to the entry directly, through the same merge. While the hydration
|
|
53
|
+
* window is open the entry takes the data with the values, when the window
|
|
54
|
+
* closes. When the loader store drops the data, nothing is written. A loader
|
|
55
|
+
* no segment of the page registers has no segment to own its pushes: they are
|
|
56
|
+
* not applied (warned once per loader in development).
|
|
22
57
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
58
|
+
* Any other read is local (no `bucket`: the reader keeps its data in its own
|
|
59
|
+
* state; or a bucket only readers with no route context read): its data stays
|
|
60
|
+
* off the page and its values are dropped, warned once per loader in
|
|
61
|
+
* development. A reader outside the route tree that shares a `key` bucket with
|
|
62
|
+
* a route reader refreshes the page's data, so its read is a page read.
|
|
63
|
+
*/
|
|
64
|
+
export declare function startFetchedLoaderRead(loaderId: string, page: FetchedLoaderPage | undefined, bucket: FetchedLoaderBucket | undefined): FetchedLoaderLanding;
|
|
65
|
+
/**
|
|
66
|
+
* Apply a late handle yield of the document (`metadata.handlesLate`, applied
|
|
67
|
+
* by rsc-router.tsx) to the page of `historyKey`, the document's entry.
|
|
68
|
+
* `late` is the document render's full state so far, `matched` its segment
|
|
69
|
+
* ids. A read that landed since the document is newer for its loader, so the
|
|
70
|
+
* yield is merged, not swapped in (handles/pushed-by.ts mergeLateHandleData).
|
|
71
|
+
* While the page is on screen the live store takes it first, waiting in the
|
|
72
|
+
* hydration window like any handle write, and the entry of every key of the
|
|
73
|
+
* page is written from the result; off screen, and during the window, each
|
|
74
|
+
* entry takes it directly, through the same merge.
|
|
32
75
|
*/
|
|
33
|
-
export declare function
|
|
76
|
+
export declare function applyLateHandles(page: FetchedLoaderPage, late: HandleData, matched: string[], historyKey: string): void;
|
|
@@ -16,8 +16,9 @@ export declare function cloneHandleData(handleData: HandleData): HandleData;
|
|
|
16
16
|
* Handle data to write into the history cache for the page on screen. During
|
|
17
17
|
* the hydration window getHandleState() is the document snapshot while late
|
|
18
18
|
* pushes sit queued in the controller (they are already in the cache entry,
|
|
19
|
-
* written by
|
|
20
|
-
* entry's own data is the
|
|
19
|
+
* written at arrival by fetched-loader-handles.ts applyLateHandles), so
|
|
20
|
+
* writing the snapshot back would drop them; the entry's own data is the
|
|
21
|
+
* live view then.
|
|
21
22
|
*/
|
|
22
23
|
export declare function liveHandleDataForCache(eventController: Pick<EventController, "getHandleState" | "getHydrationSnapshot">, store: Pick<NavigationStore, "getCachedSegments">, historyKey: string): HandleData;
|
|
23
24
|
/**
|
|
@@ -4,7 +4,8 @@ import type { RouteStateSignal } from "../event-controller.js";
|
|
|
4
4
|
* Hook to access collected handle data.
|
|
5
5
|
*
|
|
6
6
|
* Returns the collected value from all route segments that pushed to this handle.
|
|
7
|
-
* Re-renders when
|
|
7
|
+
* Re-renders when the collected value changes (navigation, actions); while
|
|
8
|
+
* its content is equal it keeps the reference it returned (useCommitAnchoredState).
|
|
8
9
|
*
|
|
9
10
|
* @param handle - The handle to read
|
|
10
11
|
* @param selector - Optional selector for performance (only re-render when selected value changes)
|
|
@@ -38,8 +39,20 @@ export declare function useHandle<T, A, S>(handle: Handle<T, A>, selector: (data
|
|
|
38
39
|
* useSegments reads can suspend, so it leaves it off and its path and
|
|
39
40
|
* location commit with their page.
|
|
40
41
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* `now`, from useHandle for a client push (usePushHandle) during a hold: set
|
|
43
|
+
* at once. The push comes from the page on screen and was merged with the
|
|
44
|
+
* server state shown there (EventController.getHeldHandleState); the release
|
|
45
|
+
* then sets the held page's state as before.
|
|
46
|
+
*
|
|
47
|
+
* A value equal to the last one sets nothing, so a reader renders only when
|
|
48
|
+
* its value moves and keeps its reference while the content is equal: a
|
|
49
|
+
* re-delivery (an action's revalidation, a refresh, a Back, a late push)
|
|
50
|
+
* decodes fresh objects, and an effect keyed on the value would run again.
|
|
51
|
+
* Equal is samePushValue's, the rule client pushes are compared with: arrays
|
|
52
|
+
* and plain objects by entries, React elements by type, key and props, dates
|
|
53
|
+
* by time, anything else (a promise, a URL, a function, a Map) by identity,
|
|
54
|
+
* and nothing past 32 levels. A value equal to what React committed keeps
|
|
55
|
+
* that reference, also when a different one waited in between. A release is
|
|
56
|
+
* compared with what React committed, as in useRouteState.
|
|
44
57
|
*/
|
|
45
|
-
export declare function useCommitAnchoredState<T>(init: () => T, waitForRelease?: boolean): [T, (value: T, signal?: RouteStateSignal) => void];
|
|
58
|
+
export declare function useCommitAnchoredState<T>(init: () => T, waitForRelease?: boolean): [T, (value: T, signal?: RouteStateSignal, now?: boolean) => void];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Handle } from "../../handle.js";
|
|
2
|
+
/**
|
|
3
|
+
* Push a handle's values from a client component: the client side of the
|
|
4
|
+
* server's `ctx.use(handle)`, for live data and live edits on the page (a
|
|
5
|
+
* value from `load()` or a fetch loader, a live count, a draft).
|
|
6
|
+
*
|
|
7
|
+
* The values belong to the segment the component renders in (its nearest
|
|
8
|
+
* route, layout or slot) and show after the server's values of that segment,
|
|
9
|
+
* in that position whatever arrives first; the handle's collect decides what
|
|
10
|
+
* wins (a later Meta title, a breadcrumb with the same href). Two components
|
|
11
|
+
* that push one handle in one segment show in tree order; one nested inside
|
|
12
|
+
* the other shows before it. They show with the render that pushed them: a
|
|
13
|
+
* render React discards or that suspends publishes nothing, and an unmount
|
|
14
|
+
* removes them.
|
|
15
|
+
*
|
|
16
|
+
* `push(value)` adds to the render in progress, so call it during render.
|
|
17
|
+
* Once that render commits, `push` throws: an effect, an event handler or a
|
|
18
|
+
* child that re-renders on its own calls `usePushHandle` itself, or passes
|
|
19
|
+
* the data down and pushes it in render.
|
|
20
|
+
*
|
|
21
|
+
* `push(promise)` works as on the server: the value takes its place when it
|
|
22
|
+
* is pushed, readers keep what they showed until it resolves, and one that
|
|
23
|
+
* rejects or resolves to null or undefined is dropped. A promise is the same
|
|
24
|
+
* value only as the same reference, so push a stable one (from a loader,
|
|
25
|
+
* `load()` kept in state, or `useMemo`); a newer render's push or an unmount
|
|
26
|
+
* drops a pending one's result.
|
|
27
|
+
*
|
|
28
|
+
* The values publish from a layout effect, which the server never runs: the
|
|
29
|
+
* SSR document and a PPR shell show the server's values alone. On the client
|
|
30
|
+
* they show in the commit of the render that pushed them, a navigation's
|
|
31
|
+
* included.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* "use client";
|
|
36
|
+
* function ChatTitle() {
|
|
37
|
+
* const { data } = useFetchLoader(ChatLoader);
|
|
38
|
+
* const push = usePushHandle(Meta);
|
|
39
|
+
* if (data) push({ title: `${data.unread} unread` });
|
|
40
|
+
* return null;
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function usePushHandle<T, A>(handle: Handle<T, A>): (value: T | Promise<T | null | undefined>) => void;
|
|
@@ -534,6 +534,31 @@ export type UpdateSubscriber = (update: NavigationUpdate) => void;
|
|
|
534
534
|
* State change listener for useNavigation hook subscriptions
|
|
535
535
|
*/
|
|
536
536
|
export type StateListener = () => void;
|
|
537
|
+
/**
|
|
538
|
+
* A page read in flight (NavigationStore.beginPageRead): the page it was
|
|
539
|
+
* sent from and the loader data that page held for the loader then. The
|
|
540
|
+
* page's entries are those of the key it was sent from, those a shallow
|
|
541
|
+
* navigation shares its segments with, and those a later commit wrote in
|
|
542
|
+
* their place.
|
|
543
|
+
*/
|
|
544
|
+
export interface PageRead {
|
|
545
|
+
/**
|
|
546
|
+
* The keys of the page's entries the read is for: those holding the data
|
|
547
|
+
* it was requested for, and once it landed, those holding its result.
|
|
548
|
+
*/
|
|
549
|
+
historyKeys(): string[];
|
|
550
|
+
/** An entry of the page still holds the data the read was requested for. */
|
|
551
|
+
current(): boolean;
|
|
552
|
+
/**
|
|
553
|
+
* Write `result` into every entry of the page that holds the data the read
|
|
554
|
+
* was requested for: each of their loader segments for the loader becomes
|
|
555
|
+
* a copy carrying it, in place, and the page's read record names it.
|
|
556
|
+
* False, and nothing written, when none does.
|
|
557
|
+
*/
|
|
558
|
+
land(result: unknown): boolean;
|
|
559
|
+
/** The read landed and an entry of the page still holds its result. */
|
|
560
|
+
holds(): boolean;
|
|
561
|
+
}
|
|
537
562
|
/**
|
|
538
563
|
* Navigation store interface
|
|
539
564
|
*
|
|
@@ -566,6 +591,25 @@ export interface NavigationStore {
|
|
|
566
591
|
getHistoryEntryMemory(entryKey?: string): HistoryEntryMemory | undefined;
|
|
567
592
|
/** Monotonic token of the most recently committed navigation. */
|
|
568
593
|
getNavInstance(): number;
|
|
594
|
+
/**
|
|
595
|
+
* Begin a page read of `loaderId` (`load()`, a group refresh) from the
|
|
596
|
+
* entry on screen: it captures, by identity, the loader data that entry
|
|
597
|
+
* holds in every loader segment of the loader
|
|
598
|
+
* (browser/fetched-loader-handles.ts).
|
|
599
|
+
*/
|
|
600
|
+
beginPageRead(loaderId: string): PageRead;
|
|
601
|
+
/**
|
|
602
|
+
* The loaders whose data a landed page read replaced on the page of
|
|
603
|
+
* `historyKey`'s entry, since the server last sent them: the run of each
|
|
604
|
+
* is newer on the page than the document's (a late handle push keeps it).
|
|
605
|
+
*/
|
|
606
|
+
getPageReadLoaders(historyKey: string): ReadonlySet<string>;
|
|
607
|
+
/**
|
|
608
|
+
* Rewrite an entry's segments array in place (a `prefetch: false` fill):
|
|
609
|
+
* the array keeps its identity, and the page's read record is carried over
|
|
610
|
+
* as cacheSegmentsForHistory carries it.
|
|
611
|
+
*/
|
|
612
|
+
replaceEntrySegments(segments: ResolvedSegment[], next: readonly ResolvedSegment[]): void;
|
|
569
613
|
cacheSegmentsForHistory(historyKey: string, segments: ResolvedSegment[], handleData?: HandleData): void;
|
|
570
614
|
getCachedSegments(historyKey: string): {
|
|
571
615
|
segments: ResolvedSegment[];
|
package/dist/types/client.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ export { useLinkStatus, type LinkStatus, } from "./browser/react/use-link-status
|
|
|
176
176
|
export { useScrollRestoration, type ScrollRestorationProps, } from "./browser/react/ScrollRestoration.js";
|
|
177
177
|
export { type Handle } from "./handle.js";
|
|
178
178
|
export { useHandle } from "./browser/react/use-handle.js";
|
|
179
|
+
export { usePushHandle } from "./browser/react/use-push-handle.js";
|
|
179
180
|
export { Meta } from "./handles/meta.js";
|
|
180
181
|
export type { MetaDescriptor, MetaDescriptorBase } from "./router/types.js";
|
|
181
182
|
export { Script, type ScriptConfig, type ScriptAttributes, } from "./handles/script.js";
|
|
@@ -38,4 +38,5 @@ export { createLocationState, type LocationStateDefinition, type LocationStateEn
|
|
|
38
38
|
export { useHref } from "./browser/react/use-href.js";
|
|
39
39
|
export { useReverse } from "./browser/react/use-reverse.js";
|
|
40
40
|
export { useHandle } from "./browser/react/use-handle.js";
|
|
41
|
+
export { usePushHandle } from "./browser/react/use-push-handle.js";
|
|
41
42
|
export { useLocationState } from "./browser/react/location-state.js";
|
package/dist/types/handle.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Handle definition for accumulating data across route segments.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A handle accumulates values across the matched route segments: each
|
|
5
|
+
* segment's values, in tree order, are collected into what `useHandle`
|
|
6
|
+
* returns. Values are pushed by the server, from a handler or a loader
|
|
7
|
+
* (`ctx.use(handle)`), and by client components, for data they learn or
|
|
8
|
+
* change after the server rendered (`usePushHandle(handle)`). In each
|
|
9
|
+
* segment the client's values follow the server's. Unlike loaders (which
|
|
10
|
+
* fetch data for specific routes), handles accumulate data across all
|
|
11
|
+
* matched route segments.
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
9
14
|
* ```ts
|
|
@@ -13,11 +18,14 @@
|
|
|
13
18
|
* (segments) => segments.flat(), // opt into a single flat list
|
|
14
19
|
* );
|
|
15
20
|
*
|
|
16
|
-
* //
|
|
21
|
+
* // Push from a handler or a loader
|
|
17
22
|
* const push = ctx.use(Breadcrumbs);
|
|
18
23
|
* push({ label: "Home", href: "/" });
|
|
19
24
|
*
|
|
20
|
-
* //
|
|
25
|
+
* // Push from a client component, during render
|
|
26
|
+
* usePushHandle(Breadcrumbs)({ label: draft.name, href: "/draft" });
|
|
27
|
+
*
|
|
28
|
+
* // Read in a client component
|
|
21
29
|
* const crumbs = useHandle(Breadcrumbs);
|
|
22
30
|
* ```
|
|
23
31
|
*/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HandleData } from "../server/handle-store.js";
|
|
2
|
+
/**
|
|
3
|
+
* A usePushHandle component's owner object, as setClientHandle sees it:
|
|
4
|
+
* `resync` renders it again; `generation` counts the renders resync asked
|
|
5
|
+
* for, as of the render that published. Both are set by the hook before it
|
|
6
|
+
* publishes; a bare owner has neither and is never asked to resync.
|
|
7
|
+
*/
|
|
8
|
+
export interface ClientPushOwner {
|
|
9
|
+
resync?: () => void;
|
|
10
|
+
generation?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The client handle layer (usePushHandle): handle id -> segment id -> pusher
|
|
14
|
+
* -> the values that pusher's last committed render pushed, its promises
|
|
15
|
+
* resolved. Pushers are kept in tree order (Map insertion order, which
|
|
16
|
+
* EventController.setClientHandle rebuilds when a pusher joins).
|
|
17
|
+
*/
|
|
18
|
+
export type ClientPushes = Map<string, Map<string, Map<ClientPushOwner, unknown[]>>>;
|
|
19
|
+
/**
|
|
20
|
+
* Structural equality for pushed values: arrays and plain objects by their
|
|
21
|
+
* entries, React elements by type, key and props, dates by time, anything
|
|
22
|
+
* else (a promise, a function, a Map, a Set, a class instance, a
|
|
23
|
+
* null-prototype object) by Object.is. A component that pushes a fresh
|
|
24
|
+
* literal on each render (nested objects included) and reads the same handle
|
|
25
|
+
* would otherwise re-render itself without end: each render's push would
|
|
26
|
+
* look new. useCommitAnchoredState (browser/react/use-handle.ts) compares
|
|
27
|
+
* what useHandle and useSegments return with it too, so a re-delivery of
|
|
28
|
+
* equal content keeps the reader's reference. The walk goes no deeper than
|
|
29
|
+
* 32 levels: what it cannot compare within them, a cyclic value included,
|
|
30
|
+
* counts as different.
|
|
31
|
+
*
|
|
32
|
+
* Each pair of objects is walked once. A shared sub-object (Flight keeps a
|
|
33
|
+
* shared reference shared) is reached once per path to it, so a walk that
|
|
34
|
+
* remembers nothing is exponential in the sharing: an equal binary DAG 20
|
|
35
|
+
* levels deep took 164 ms, 22 levels 685 ms. Pairs found equal are remembered once the walk has
|
|
36
|
+
* visited UNREMEMBERED_PAIRS of them, so a small value such as a breadcrumb
|
|
37
|
+
* trail allocates no map. A pair found different needs no entry: `every`
|
|
38
|
+
* stops there and the whole walk is false. A pair still being walked is not
|
|
39
|
+
* remembered yet, so a cycle still runs into the depth bound; a pair already
|
|
40
|
+
* found equal stays equal wherever the walk meets it again, past the bound
|
|
41
|
+
* too.
|
|
42
|
+
*/
|
|
43
|
+
export declare function samePushValue(a: unknown, b: unknown): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* `data` (the server's handle data) with `handleId`'s client pushes after the
|
|
46
|
+
* server's values in each segment: `[...server, ...pusher1, ...pusher2]`. A
|
|
47
|
+
* fixed position, so what arrives first never decides what shows. A segment
|
|
48
|
+
* only the client pushes into is collected in segment order like any other;
|
|
49
|
+
* one outside the order is skipped by collectHandleData.
|
|
50
|
+
*/
|
|
51
|
+
export declare function withClientPushes(data: HandleData, handleId: string, pushes: ClientPushes): HandleData;
|
|
@@ -35,6 +35,13 @@ export declare function resolveDeferredHandleValues(data: HandleData): Promise<H
|
|
|
35
35
|
* the entries of the dropped values.
|
|
36
36
|
*/
|
|
37
37
|
export declare function resolveDeferredPushes(pushes: Readonly<Record<string, readonly unknown[]>>, pushedBy?: Readonly<Record<string, readonly (string | null)[]>>): Promise<LoaderReadPushes>;
|
|
38
|
+
/**
|
|
39
|
+
* One list of pushed values with its deferred entries awaited, as
|
|
40
|
+
* resolveDeferredHandleValues awaits a segment's: shallow, in order, a
|
|
41
|
+
* rejected or nullish deferred dropped. A client component's pushes
|
|
42
|
+
* (usePushHandle) resolve through it, so they follow the server's rules.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveDeferredList(values: readonly unknown[]): Promise<unknown[]>;
|
|
38
45
|
/**
|
|
39
46
|
* Full-render handle stream: a one-shot async generator that yields the FINAL
|
|
40
47
|
* handle snapshot with every top-level deferred value resolved. Drop-in for
|