@rangojs/router 0.36.0 → 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-UECTPF6K.js → runtime-discovery-T7ZLA6E3.js} +2 -2
- package/dist/bin/{temp-rsc-server-QLNMTFEE.js → temp-rsc-server-FGGXPKVQ.js} +2 -2
- package/dist/types/browser/event-controller.d.ts +61 -0
- package/dist/types/browser/fetched-loader-handles.d.ts +76 -0
- 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 +14 -0
- package/dist/types/handles/pushed-by.d.ts +36 -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/flight.entry.d.ts +1 -1
- package/dist/types/testing/render-route.d.ts +76 -14
- package/dist/types/testing/serve-shell-request.d.ts +31 -0
- 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 +40 -1
- 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/testing/serve-shell-request.md +33 -14
- package/skills/ux-architecture/SKILL.md +4 -0
- package/src/browser/event-controller.ts +311 -2
- package/src/browser/fetched-loader-handles.ts +269 -0
- 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 +41 -2
- package/src/handles/pushed-by.ts +130 -1
- package/src/loader-store.ts +26 -0
- package/src/rsc/loader-fetch.ts +64 -5
- 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 +6 -0
- package/src/testing/dom.entry.ts +2 -0
- package/src/testing/flight.entry.ts +1 -0
- package/src/testing/render-route.tsx +319 -72
- package/src/testing/serve-shell-request.ts +62 -1
- package/src/use-loader.tsx +44 -4
|
@@ -63,7 +63,10 @@ import {
|
|
|
63
63
|
} from "../rsc/shell-capture-constants.js";
|
|
64
64
|
import { SEGMENT_FRAGMENT_CAPABILITY_HEADER } from "../segment-fragments.js";
|
|
65
65
|
import { PREFETCH_HEADER } from "../prefetch-markers.js";
|
|
66
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
resolveDeferredHandleValues,
|
|
68
|
+
resolveDeferredPushes,
|
|
69
|
+
} from "../handles/deferred-resolution.js";
|
|
67
70
|
import { withoutPushedBy } from "../handles/pushed-by.js";
|
|
68
71
|
import type { HandleData } from "../server/handle-store.js";
|
|
69
72
|
import type { ResolvedSegment } from "../types.js";
|
|
@@ -209,6 +212,31 @@ export interface ShellRequestAction {
|
|
|
209
212
|
revalidationError: Error | null;
|
|
210
213
|
}
|
|
211
214
|
|
|
215
|
+
/**
|
|
216
|
+
* A fetchable loader read's answer (`?_rsc_loader=<id>`), as `load()` and a
|
|
217
|
+
* `refreshGroup` refresh read it (use-loader.tsx).
|
|
218
|
+
*/
|
|
219
|
+
export interface ShellRequestLoader {
|
|
220
|
+
/** What the read resolves with; null when it rejects. */
|
|
221
|
+
result: unknown;
|
|
222
|
+
/** The message the read rejects with, or null. */
|
|
223
|
+
error: string | null;
|
|
224
|
+
/**
|
|
225
|
+
* The values the loader's body pushed to each handle, by handle $$id, in
|
|
226
|
+
* push order, a pending one settled (dropped when it rejects or resolves
|
|
227
|
+
* nullish, as the browser drops it). The browser applies them to the
|
|
228
|
+
* segment that registers the loader, in place of its earlier ones.
|
|
229
|
+
*/
|
|
230
|
+
handles: Record<string, unknown[]>;
|
|
231
|
+
/**
|
|
232
|
+
* Which loader's run pushed each of `handles`, index-aligned per handle:
|
|
233
|
+
* another loader the body read with `ctx.use()`, or null for the body's
|
|
234
|
+
* own. A handle with no entry holds only the body's own. The browser leaves
|
|
235
|
+
* a value another loader on the page pushed to that loader's own run.
|
|
236
|
+
*/
|
|
237
|
+
pushedBy: Record<string, (string | null)[]>;
|
|
238
|
+
}
|
|
239
|
+
|
|
212
240
|
/** Result of {@link serveShellRequest}. */
|
|
213
241
|
export interface ServeShellRequestResult {
|
|
214
242
|
/** The handler's Response. Its body is already read: see `body`. */
|
|
@@ -288,6 +316,13 @@ export interface ServeShellRequestResult {
|
|
|
288
316
|
* result.
|
|
289
317
|
*/
|
|
290
318
|
readAction(): Promise<ShellRequestAction | undefined>;
|
|
319
|
+
/**
|
|
320
|
+
* For a fetchable loader read (`?_rsc_loader=<id>` with an `accept:
|
|
321
|
+
* text/x-component` header), its answer as the browser reads it: the
|
|
322
|
+
* loader's value or error, and the handle values its body pushed.
|
|
323
|
+
* Undefined when no Flight was rendered or the payload is not a loader's.
|
|
324
|
+
*/
|
|
325
|
+
readLoader(): Promise<ShellRequestLoader | undefined>;
|
|
291
326
|
}
|
|
292
327
|
|
|
293
328
|
type ShellHandler = ReturnType<typeof createRSCHandler>;
|
|
@@ -441,6 +476,29 @@ async function decodeAction(
|
|
|
441
476
|
};
|
|
442
477
|
}
|
|
443
478
|
|
|
479
|
+
/** A loader read's answer, read as use-loader.tsx reads it. */
|
|
480
|
+
async function decodeLoader(
|
|
481
|
+
flight: string,
|
|
482
|
+
): Promise<ShellRequestLoader | undefined> {
|
|
483
|
+
const payload = await decodePayload<{
|
|
484
|
+
loaderResult?: unknown;
|
|
485
|
+
loaderError?: { message: string };
|
|
486
|
+
handles?: Record<string, unknown[]>;
|
|
487
|
+
pushedBy?: Record<string, (string | null)[]>;
|
|
488
|
+
}>(flight);
|
|
489
|
+
if (!("loaderResult" in payload)) return undefined;
|
|
490
|
+
const { values, pushedBy } = await resolveDeferredPushes(
|
|
491
|
+
payload.handles ?? {},
|
|
492
|
+
payload.pushedBy,
|
|
493
|
+
);
|
|
494
|
+
return {
|
|
495
|
+
result: payload.loaderError ? null : payload.loaderResult,
|
|
496
|
+
error: payload.loaderError?.message ?? null,
|
|
497
|
+
handles: values,
|
|
498
|
+
pushedBy,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
444
502
|
/** The ids of the segments a payload marks deferred. */
|
|
445
503
|
async function decodeDeferredIds(flight: string): Promise<string[]> {
|
|
446
504
|
const { metadata } = await decodePayload<{
|
|
@@ -828,5 +886,8 @@ export async function serveShellRequest<TEnv = any>(
|
|
|
828
886
|
async readAction() {
|
|
829
887
|
return flight ? decodeAction(flight) : undefined;
|
|
830
888
|
},
|
|
889
|
+
async readLoader() {
|
|
890
|
+
return flight ? decodeLoader(flight) : undefined;
|
|
891
|
+
},
|
|
831
892
|
};
|
|
832
893
|
}
|
package/src/use-loader.tsx
CHANGED
|
@@ -25,6 +25,12 @@ import { decodeLoaderEntry } from "./decode-loader-results.js";
|
|
|
25
25
|
import { warnAwaitedSsrSuspension } from "./ssr-suspension-warning.js";
|
|
26
26
|
import { SETTLED_THENABLE } from "./thenable-status.js";
|
|
27
27
|
import { useReadAudit } from "./suspense-audit-react.js";
|
|
28
|
+
import {
|
|
29
|
+
startFetchedLoaderRead,
|
|
30
|
+
type FetchedLoaderHandles,
|
|
31
|
+
type FetchedLoaderPage,
|
|
32
|
+
type FetchedLoaderPushedBy,
|
|
33
|
+
} from "./browser/fetched-loader-handles.js";
|
|
28
34
|
import { INTERNAL_RANGO_SUSPENSE_AUDIT } from "./internal-suspense-audit.js";
|
|
29
35
|
import type { LoaderDefinition, LoadOptions } from "./types.js";
|
|
30
36
|
|
|
@@ -122,6 +128,10 @@ function extractContentLoaderData(
|
|
|
122
128
|
interface LoaderRscPayload<T = unknown> {
|
|
123
129
|
loaderResult: T;
|
|
124
130
|
loaderError?: { message: string; name: string };
|
|
131
|
+
/** What the loader's body pushed to each handle (rsc/loader-fetch.ts). */
|
|
132
|
+
handles?: FetchedLoaderHandles;
|
|
133
|
+
/** Which loader's run pushed each of `handles` (rsc/loader-fetch.ts). */
|
|
134
|
+
pushedBy?: FetchedLoaderPushedBy;
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
export type LoadFunction<T> = (options?: LoadOptions) => Promise<T>;
|
|
@@ -268,8 +278,18 @@ function useLoaderInternal<T>(
|
|
|
268
278
|
|
|
269
279
|
// The router store's loader data (loader-store.ts). None on the server,
|
|
270
280
|
// where the hook reads the route's loader data only.
|
|
271
|
-
const
|
|
272
|
-
|
|
281
|
+
const navigation = useContext(NavigationStoreContext);
|
|
282
|
+
const loaders: LoaderStore | undefined = navigation?.store?.loaders;
|
|
283
|
+
// Where a read's handle values go (browser/fetched-loader-handles.ts).
|
|
284
|
+
const navigationStore = navigation?.store;
|
|
285
|
+
const eventController = navigation?.eventController;
|
|
286
|
+
const page = useMemo<FetchedLoaderPage | undefined>(
|
|
287
|
+
() =>
|
|
288
|
+
navigationStore && eventController
|
|
289
|
+
? { store: navigationStore, eventController }
|
|
290
|
+
: undefined,
|
|
291
|
+
[navigationStore, eventController],
|
|
292
|
+
);
|
|
273
293
|
|
|
274
294
|
// Committed route data (updated by the reset effect below), read by the
|
|
275
295
|
// store when a refresh begins: the snapshot it produces belongs to it.
|
|
@@ -283,6 +303,10 @@ function useLoaderInternal<T>(
|
|
|
283
303
|
try {
|
|
284
304
|
const url = new URL(window.location.href);
|
|
285
305
|
url.searchParams.set("_rsc_loader", loaderId);
|
|
306
|
+
const landRead = startFetchedLoaderRead(loaderId, page, {
|
|
307
|
+
bucketKey,
|
|
308
|
+
requestId,
|
|
309
|
+
});
|
|
286
310
|
const response = fetch(url.toString(), {
|
|
287
311
|
method: "GET",
|
|
288
312
|
headers: { Accept: "text/x-component" },
|
|
@@ -293,6 +317,7 @@ function useLoaderInternal<T>(
|
|
|
293
317
|
throw new Error(payload.loaderError.message);
|
|
294
318
|
}
|
|
295
319
|
loaders.finishData(bucketKey, requestId, payload.loaderResult);
|
|
320
|
+
landRead(payload.loaderResult, payload.handles, payload.pushedBy);
|
|
296
321
|
} catch (e) {
|
|
297
322
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
298
323
|
loaders.finishError(bucketKey, requestId, err);
|
|
@@ -300,7 +325,7 @@ function useLoaderInternal<T>(
|
|
|
300
325
|
} finally {
|
|
301
326
|
loaders.setLoading(bucketKey, requestId, false);
|
|
302
327
|
}
|
|
303
|
-
}, [loaderId, bucketKey, loaders]);
|
|
328
|
+
}, [loaderId, bucketKey, loaders, page]);
|
|
304
329
|
|
|
305
330
|
// Held-navigation pin: a transition commit whose stream for this loader is
|
|
306
331
|
// still pending announces it (loader-store.ts announcePendingStreams, which
|
|
@@ -545,6 +570,20 @@ function useLoaderInternal<T>(
|
|
|
545
570
|
};
|
|
546
571
|
}
|
|
547
572
|
|
|
573
|
+
// Only a refetch of the page's own read (the page's params, no body)
|
|
574
|
+
// applies its handle values: a read with other params or a body is
|
|
575
|
+
// data the page does not show, and its pushes would retitle the page.
|
|
576
|
+
// A read that keeps its data local keeps its values local too
|
|
577
|
+
// (fetched-loader-handles.ts).
|
|
578
|
+
const landRead = isPlainRefetch(loadOptions)
|
|
579
|
+
? startFetchedLoaderRead(
|
|
580
|
+
id,
|
|
581
|
+
page,
|
|
582
|
+
shared
|
|
583
|
+
? { bucketKey: bucket, requestId: sharedRequestId }
|
|
584
|
+
: undefined,
|
|
585
|
+
)
|
|
586
|
+
: undefined;
|
|
548
587
|
const response = fetch(url.toString(), fetchOptions);
|
|
549
588
|
|
|
550
589
|
const { createFromFetch } = await import("./deps/browser.js");
|
|
@@ -563,6 +602,7 @@ function useLoaderInternal<T>(
|
|
|
563
602
|
setLocalIsLoading(false);
|
|
564
603
|
});
|
|
565
604
|
}
|
|
605
|
+
landRead?.(result, payload.handles, payload.pushedBy);
|
|
566
606
|
return result;
|
|
567
607
|
} catch (e) {
|
|
568
608
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
@@ -582,7 +622,7 @@ function useLoaderInternal<T>(
|
|
|
582
622
|
}
|
|
583
623
|
}
|
|
584
624
|
},
|
|
585
|
-
[throwOnError, loaders, routeDataOf],
|
|
625
|
+
[throwOnError, loaders, routeDataOf, page],
|
|
586
626
|
);
|
|
587
627
|
|
|
588
628
|
if (throwOnError) {
|