@rangojs/router 0.35.0 → 0.36.1

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.
Files changed (34) hide show
  1. package/dist/bin/{chunk-3CQXDX3A.js → chunk-THW7E5A2.js} +11 -5
  2. package/dist/bin/{client-urls-projection-2GBDM5YK.js → client-urls-projection-DHUUOJZM.js} +1 -1
  3. package/dist/bin/rango.js +1 -1
  4. package/dist/bin/{runtime-discovery-PA3V3IFQ.js → runtime-discovery-OPRGB3DF.js} +2 -2
  5. package/dist/bin/{temp-rsc-server-WDXEHDY7.js → temp-rsc-server-FV4ERMAS.js} +2 -2
  6. package/dist/types/browser/event-controller.d.ts +10 -0
  7. package/dist/types/browser/fetched-loader-handles.d.ts +33 -0
  8. package/dist/types/browser/react/use-link-status.d.ts +17 -8
  9. package/dist/types/browser/types.d.ts +2 -0
  10. package/dist/types/handles/deferred-resolution.d.ts +7 -0
  11. package/dist/types/handles/pushed-by.d.ts +25 -0
  12. package/dist/types/testing/flight.entry.d.ts +1 -1
  13. package/dist/types/testing/render-route.d.ts +5 -2
  14. package/dist/types/testing/serve-shell-request.d.ts +31 -0
  15. package/dist/vite/index.js +12 -6
  16. package/package.json +1 -1
  17. package/skills/hooks/navigation.md +10 -3
  18. package/skills/loader/SKILL.md +20 -0
  19. package/skills/testing/client-components.md +1 -1
  20. package/skills/testing/serve-shell-request.md +33 -14
  21. package/src/browser/event-controller.ts +49 -1
  22. package/src/browser/fetched-loader-handles.ts +96 -0
  23. package/src/browser/navigation-bridge.ts +2 -1
  24. package/src/browser/react/Link.tsx +13 -2
  25. package/src/browser/react/use-link-status.ts +40 -22
  26. package/src/browser/types.ts +2 -0
  27. package/src/handles/deferred-resolution.ts +29 -2
  28. package/src/handles/pushed-by.ts +75 -0
  29. package/src/rsc/loader-fetch.ts +47 -5
  30. package/src/ssr/ssr-root.tsx +1 -0
  31. package/src/testing/flight.entry.ts +1 -0
  32. package/src/testing/render-route.tsx +14 -3
  33. package/src/testing/serve-shell-request.ts +62 -1
  34. package/src/use-loader.tsx +33 -4
@@ -629,6 +629,7 @@ import {
629
629
  useCallback as useCallback5,
630
630
  useContext as useContext16,
631
631
  useEffect as useEffect13,
632
+ useId,
632
633
  useMemo as useMemo8,
633
634
  useRef as useRef10
634
635
  } from "react";
@@ -640,9 +641,7 @@ import {
640
641
  useState as useState9,
641
642
  useEffect as useEffect12
642
643
  } from "react";
643
- var LinkContext = createContext7(
644
- null
645
- );
644
+ var LinkContext = createContext7(null);
646
645
 
647
646
  // src/browser/prefetch/default-strategy.ts
648
647
  var ENVIRONMENT_DEFAULT_PREFETCH = process.env.NODE_ENV === "production" ? "viewport" : "none";
@@ -841,6 +840,11 @@ var Link = forwardRef(function Link2({
841
840
  () => isExternal ? to : prefixBasename(to, ctx?.basename),
842
841
  [to, isExternal, ctx?.basename]
843
842
  );
843
+ const linkId = useId();
844
+ const linkTarget = useMemo8(
845
+ () => ({ to: resolvedTo, id: linkId }),
846
+ [resolvedTo, linkId]
847
+ );
844
848
  const configuredStrategy = prefetch ?? ctx?.defaultPrefetch ?? ENVIRONMENT_DEFAULT_PREFETCH;
845
849
  const internalRef = useRef10(null);
846
850
  const setRef = useCallback5(
@@ -882,11 +886,13 @@ var Link = forwardRef(function Link2({
882
886
  scroll,
883
887
  state: state2,
884
888
  revalidate: revalidate3,
885
- transition: transition3
889
+ transition: transition3,
890
+ _linkId: linkId
886
891
  });
887
892
  },
888
893
  [
889
894
  resolvedTo,
895
+ linkId,
890
896
  isExternal,
891
897
  reloadDocument,
892
898
  replace,
@@ -998,7 +1004,7 @@ var Link = forwardRef(function Link2({
998
1004
  "data-revalidate": revalidate3 === false ? "false" : void 0,
999
1005
  "data-transition": transition3 === false ? "false" : void 0,
1000
1006
  ...props,
1001
- children: /* @__PURE__ */ jsx8(LinkContext.Provider, { value: resolvedTo, children })
1007
+ children: /* @__PURE__ */ jsx8(LinkContext.Provider, { value: linkTarget, children })
1002
1008
  }
1003
1009
  );
1004
1010
  });
@@ -10,7 +10,7 @@ import {
10
10
  refreshRecordedClientUrlProjections,
11
11
  resolveClientUrlsSource,
12
12
  scanForClientUrlModules
13
- } from "./chunk-3CQXDX3A.js";
13
+ } from "./chunk-THW7E5A2.js";
14
14
  import "./chunk-MWOHBDPM.js";
15
15
  import "./chunk-LD7UBHT4.js";
16
16
  export {
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-PA3V3IFQ.js");
232
+ const mod = await import("./runtime-discovery-OPRGB3DF.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-WDXEHDY7.js");
166
+ const { createTempRscServer } = await import("./temp-rsc-server-FV4ERMAS.js");
167
167
  const { createDiscoveryState } = await import("./state-ACD2MGKJ.js");
168
- const { discoverClientUrlProjections } = await import("./client-urls-projection-2GBDM5YK.js");
168
+ const { discoverClientUrlProjections } = await import("./client-urls-projection-DHUUOJZM.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-3CQXDX3A.js";
30
+ } from "./chunk-THW7E5A2.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.35.0",
50
+ version: "0.36.1",
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 LoaderReadPushes } from "../handles/pushed-by.js";
3
4
  import { type LocationStateSnapshot } from "./react/location-state-shared.js";
4
5
  /**
5
6
  * Phase of a navigation operation
@@ -247,6 +248,15 @@ export interface EventController {
247
248
  */
248
249
  resolvedIds?: string[]): void;
249
250
  getHandleState(): HandleState;
251
+ /**
252
+ * Apply the handle values a fetched read of `loaderId` pushed to the page's
253
+ * handle data, keeping its segment order: they replace the loader's earlier
254
+ * values in its segment (handles/pushed-by.ts mergeLoaderReadHandleData).
255
+ * Waits like setHandleData while the hydration window is open. False, and
256
+ * nothing applied, when no segment of the page's handle data registers the
257
+ * loader.
258
+ */
259
+ setLoaderReadHandleData(loaderId: string, pushes: LoaderReadPushes): boolean;
250
260
  /**
251
261
  * Open the hydration window. Until releaseHydrationLock(), getHandleState()
252
262
  * returns the state the document's HTML was rendered with, and handle writes
@@ -0,0 +1,33 @@
1
+ import type { EventController } from "./event-controller.js";
2
+ import type { NavigationStore } from "./types.js";
3
+ /**
4
+ * The handle values a fetched loader read pushed (`_rsc_loader`: `load()`, a
5
+ * `refreshGroup` refresh), by handle $$id, as the reply carries them
6
+ * (rsc/loader-fetch.ts). A pending push is its promise.
7
+ */
8
+ export type FetchedLoaderHandles = Record<string, unknown[]>;
9
+ /**
10
+ * Which loader's run pushed each of the reply's values, index-aligned per
11
+ * handle (null: the read loader's own body), as the reply carries it.
12
+ */
13
+ export type FetchedLoaderPushedBy = Record<string, (string | null)[]>;
14
+ /** The router state a read's handle values are applied to. */
15
+ export interface FetchedLoaderPage {
16
+ eventController: EventController;
17
+ store: NavigationStore;
18
+ }
19
+ /**
20
+ * Start a read of `loaderId` from the page on screen. Call it when the request
21
+ * is sent; the returned function applies the reply's handle values.
22
+ *
23
+ * The values replace the loader's earlier ones in its segment once the
24
+ * pending ones settle (a rejected or nullish one dropped, as on the
25
+ * navigation lane), on their own after the data: a handle value never holds
26
+ * the loader's data. They apply only while the page the read was sent from is
27
+ * still on screen (same history entry, no commit since, as NavigationProvider's
28
+ * handle stream checks) and no newer read of the loader was sent, and the
29
+ * history entry keeps them for Back. A loader no segment of the page
30
+ * registers has no segment to own its pushes: they are not applied (warned
31
+ * once per loader in development).
32
+ */
33
+ export declare function startFetchedLoaderRead(loaderId: string, page: FetchedLoaderPage | undefined): (handles: FetchedLoaderHandles | undefined, pushedBy?: FetchedLoaderPushedBy) => void;
@@ -1,9 +1,17 @@
1
1
  import { type Context } from "react";
2
2
  /**
3
- * Context for Link component to provide its destination URL
4
- * Used by useLinkStatus to determine if this specific link is pending
3
+ * What a Link hands to useLinkStatus: its resolved destination and an id for
4
+ * this Link instance, which its click puts on the navigation (`_linkId`).
5
5
  */
6
- export declare const LinkContext: Context<string | null>;
6
+ export interface LinkTarget {
7
+ readonly to: string;
8
+ readonly id: string;
9
+ }
10
+ /**
11
+ * Context for Link component to provide its destination and instance id.
12
+ * Used by useLinkStatus to determine if this specific link is pending.
13
+ */
14
+ export declare const LinkContext: Context<LinkTarget | null>;
7
15
  /**
8
16
  * Link status returned by useLinkStatus hook
9
17
  */
@@ -14,11 +22,12 @@ export interface LinkStatus {
14
22
  /**
15
23
  * Hook to track the pending state of a Link component
16
24
  *
17
- * Must be used inside a Link component. Returns `{ pending: true }` while a
18
- * navigation to the link's destination is in flight, until the page it
19
- * brings commits: under transition() while React holds that page, and
20
- * through a server redirect until the target page commits. A newer
21
- * navigation ends it at once.
25
+ * Must be used inside a Link component. Returns `{ pending: true }` while
26
+ * this link's navigation is in flight, until the page it brings commits:
27
+ * under transition() while React holds that page, and through a server
28
+ * redirect until the target page commits. A click marks only the clicked
29
+ * link; a navigation no link started (Back/Forward, router.push) marks every
30
+ * link to its URL. A newer navigation ends it at once.
22
31
  *
23
32
  * Useful for showing inline loading indicators on individual links.
24
33
  *
@@ -469,6 +469,8 @@ export interface NavigateOptionsInternal extends Omit<NavigateOptions, "state">
469
469
  _redirectHops?: number;
470
470
  /** The URL a redirected navigation chain started from: a link to it stays pending (useLinkStatus) */
471
471
  _redirectFrom?: string;
472
+ /** The Link instance whose click started this navigation chain: only that link is pending (useLinkStatus) */
473
+ _linkId?: string;
472
474
  }
473
475
  /**
474
476
  * Options for useRouter push/replace methods.
@@ -1,4 +1,5 @@
1
1
  import type { HandleData, HandleStore } from "../server/handle-store.js";
2
+ import { type LoaderReadPushes } from "./pushed-by.js";
2
3
  /**
3
4
  * Runtime-neutral resolution of deferred (Promise) handle values. Shared by the
4
5
  * server full-render path (resolve before the payload is finalized so SSR sees
@@ -28,6 +29,12 @@ export declare function deferredHandleNames(data: HandleData): Set<string>;
28
29
  * pushedBy record (pushed-by.ts) loses the entries of the dropped values.
29
30
  */
30
31
  export declare function resolveDeferredHandleValues(data: HandleData): Promise<HandleData>;
32
+ /**
33
+ * A fetched loader read's pushes, as its reply carries them, with deferred
34
+ * values awaited as resolveDeferredHandleValues awaits them; `pushedBy` loses
35
+ * the entries of the dropped values.
36
+ */
37
+ export declare function resolveDeferredPushes(pushes: Readonly<Record<string, readonly unknown[]>>, pushedBy?: Readonly<Record<string, readonly (string | null)[]>>): Promise<LoaderReadPushes>;
31
38
  /**
32
39
  * Full-render handle stream: a one-shot async generator that yields the FINAL
33
40
  * handle snapshot with every top-level deferred value resolved. Drop-in for
@@ -13,6 +13,31 @@ export declare function withoutPushedBy(data: HandleData): HandleData;
13
13
  * (navigation-store.ts) shares them.
14
14
  */
15
15
  export declare function withSegmentHandles(target: HandleData, source: HandleData, ids: ReadonlySet<string>): HandleData;
16
+ /**
17
+ * What a fetched loader read pushed, settled: the values by handle $$id, and
18
+ * the loader whose run pushed each (index-aligned; null, or no entry for the
19
+ * handle, for the read loader's own body).
20
+ */
21
+ export interface LoaderReadPushes {
22
+ values: Record<string, unknown[]>;
23
+ pushedBy: Record<string, (string | null)[]>;
24
+ }
25
+ /**
26
+ * The handle data after a fetched read of loader `loaderId` (the `_rsc_loader`
27
+ * lane: `load()`, a `refreshGroup` refresh) pushed `pushes`. The read renders
28
+ * no segment, so its pushes go where the page's run of the loader put its
29
+ * own: the first segment of `segmentOrder` holding a value the loader pushed,
30
+ * else the first segment of `matched` (the raw list `current` was built from)
31
+ * that registers it, where a render files them (loader-resolution.ts
32
+ * loaderOwner). The loader's earlier values give way to these in their
33
+ * position, in every segment that registers it, and every other run keeps its
34
+ * own (mergePartialHandleData, with the loader as the run that ran). A value
35
+ * pushed by another loader the page registers, one the body read with
36
+ * ctx.use, belongs to that loader's run, which the read did not refresh: the
37
+ * page keeps that run's values, as it keeps its data. Undefined when no
38
+ * segment registers the loader: its pushes have no segment to belong to.
39
+ */
40
+ export declare function mergeLoaderReadHandleData(current: HandleData, segmentOrder: readonly string[], matched: readonly string[], loaderId: string, pushes: LoaderReadPushes): HandleData | undefined;
16
41
  /**
17
42
  * The handle data after a partial response's snapshot `incoming` (each stream
18
43
  * yield holds everything the response pushed so far). A segment outside
@@ -33,4 +33,4 @@ export type { TestableHandler, RenderHandlerOptions, RenderHandlerResult, StateC
33
33
  export { createActionForm } from "./action-form.js";
34
34
  export type { CreateActionFormOptions } from "./action-form.js";
35
35
  export { serveShellRequest, resetShellTestState, } from "./serve-shell-request.js";
36
- export type { ServeShellRequestAction, ServeShellRequestOptions, ServeShellRequestResult, ShellRequestAction, ShellRequestHandles, } from "./serve-shell-request.js";
36
+ export type { ServeShellRequestAction, ServeShellRequestOptions, ServeShellRequestResult, ShellRequestAction, ShellRequestHandles, ShellRequestLoader, } from "./serve-shell-request.js";
@@ -25,8 +25,9 @@
25
25
  * This exercises the context read path, not the run path.
26
26
  * - navigate() drives the navigation lifecycle as a click does:
27
27
  * useNavigation() reads loading from the call and idle with the commit,
28
- * and useLinkStatus().pending is true for a link to the destination until
29
- * the commit, which React holds with it. A `transition` spec plus a pending
28
+ * and useLinkStatus().pending is true for every link to the destination
29
+ * (for a <Link> click, the clicked link only) until the commit, which
30
+ * React holds with it. A `transition` spec plus a pending
30
31
  * Promise seeded via navigate(url, { loaders }) commits through
31
32
  * production's commitInTransition (browser/partial-update.ts), which React
32
33
  * holds: useNavigation() stays loading and the held reader's
@@ -52,6 +53,8 @@
52
53
  * rejection is the loader's error. Needs the testing kit's
53
54
  * `@vitejs/plugin-rsc/browser` alias (rangoTestAliases). A load() with params
54
55
  * is answered with a loaderError; a body and non-GET loads are not answered.
56
+ * The answer carries no handle values: what a loader pushes on a read is
57
+ * serveShellRequest's readLoader() and e2e territory.
55
58
  * - A spec's transition({ when }) decides every commit with production's
56
59
  * browser decision: navigate() and useRouter().push model kind "push",
57
60
  * useRouter().replace kind "replace", refresh() kind "revalidate", and a
@@ -169,6 +169,30 @@ export interface ShellRequestAction {
169
169
  */
170
170
  revalidationError: Error | null;
171
171
  }
172
+ /**
173
+ * A fetchable loader read's answer (`?_rsc_loader=<id>`), as `load()` and a
174
+ * `refreshGroup` refresh read it (use-loader.tsx).
175
+ */
176
+ export interface ShellRequestLoader {
177
+ /** What the read resolves with; null when it rejects. */
178
+ result: unknown;
179
+ /** The message the read rejects with, or null. */
180
+ error: string | null;
181
+ /**
182
+ * The values the loader's body pushed to each handle, by handle $$id, in
183
+ * push order, a pending one settled (dropped when it rejects or resolves
184
+ * nullish, as the browser drops it). The browser applies them to the
185
+ * segment that registers the loader, in place of its earlier ones.
186
+ */
187
+ handles: Record<string, unknown[]>;
188
+ /**
189
+ * Which loader's run pushed each of `handles`, index-aligned per handle:
190
+ * another loader the body read with `ctx.use()`, or null for the body's
191
+ * own. A handle with no entry holds only the body's own. The browser leaves
192
+ * a value another loader on the page pushed to that loader's own run.
193
+ */
194
+ pushedBy: Record<string, (string | null)[]>;
195
+ }
172
196
  /** Result of {@link serveShellRequest}. */
173
197
  export interface ServeShellRequestResult {
174
198
  /** The handler's Response. Its body is already read: see `body`. */
@@ -248,6 +272,13 @@ export interface ServeShellRequestResult {
248
272
  * result.
249
273
  */
250
274
  readAction(): Promise<ShellRequestAction | undefined>;
275
+ /**
276
+ * For a fetchable loader read (`?_rsc_loader=<id>` with an `accept:
277
+ * text/x-component` header), its answer as the browser reads it: the
278
+ * loader's value or error, and the handle values its body pushed.
279
+ * Undefined when no Flight was rendered or the payload is not a loader's.
280
+ */
281
+ readLoader(): Promise<ShellRequestLoader | undefined>;
251
282
  }
252
283
  /**
253
284
  * Reset the per-isolate PPR state requests leave behind, so the next test
@@ -5510,6 +5510,7 @@ import {
5510
5510
  useCallback as useCallback5,
5511
5511
  useContext as useContext16,
5512
5512
  useEffect as useEffect13,
5513
+ useId,
5513
5514
  useMemo as useMemo8,
5514
5515
  useRef as useRef10
5515
5516
  } from "react";
@@ -5521,9 +5522,7 @@ import {
5521
5522
  useState as useState9,
5522
5523
  useEffect as useEffect12
5523
5524
  } from "react";
5524
- var LinkContext = createContext7(
5525
- null
5526
- );
5525
+ var LinkContext = createContext7(null);
5527
5526
 
5528
5527
  // src/browser/prefetch/default-strategy.ts
5529
5528
  var ENVIRONMENT_DEFAULT_PREFETCH = process.env.NODE_ENV === "production" ? "viewport" : "none";
@@ -5726,6 +5725,11 @@ var Link = forwardRef(function Link2({
5726
5725
  () => isExternal ? to : prefixBasename(to, ctx?.basename),
5727
5726
  [to, isExternal, ctx?.basename]
5728
5727
  );
5728
+ const linkId = useId();
5729
+ const linkTarget2 = useMemo8(
5730
+ () => ({ to: resolvedTo, id: linkId }),
5731
+ [resolvedTo, linkId]
5732
+ );
5729
5733
  const configuredStrategy = prefetch ?? ctx?.defaultPrefetch ?? ENVIRONMENT_DEFAULT_PREFETCH;
5730
5734
  const internalRef = useRef10(null);
5731
5735
  const setRef = useCallback5(
@@ -5767,11 +5771,13 @@ var Link = forwardRef(function Link2({
5767
5771
  scroll,
5768
5772
  state: state2,
5769
5773
  revalidate: revalidate3,
5770
- transition: transition3
5774
+ transition: transition3,
5775
+ _linkId: linkId
5771
5776
  });
5772
5777
  },
5773
5778
  [
5774
5779
  resolvedTo,
5780
+ linkId,
5775
5781
  isExternal,
5776
5782
  reloadDocument,
5777
5783
  replace,
@@ -5883,7 +5889,7 @@ var Link = forwardRef(function Link2({
5883
5889
  "data-revalidate": revalidate3 === false ? "false" : void 0,
5884
5890
  "data-transition": transition3 === false ? "false" : void 0,
5885
5891
  ...props,
5886
- children: /* @__PURE__ */ jsx8(LinkContext.Provider, { value: resolvedTo, children })
5892
+ children: /* @__PURE__ */ jsx8(LinkContext.Provider, { value: linkTarget2, children })
5887
5893
  }
5888
5894
  );
5889
5895
  });
@@ -7344,7 +7350,7 @@ function resolveVersionsFrom(table, routerId2) {
7344
7350
  // package.json
7345
7351
  var package_default = {
7346
7352
  name: "@rangojs/router",
7347
- version: "0.35.0",
7353
+ version: "0.36.1",
7348
7354
  description: "Django-inspired RSC router with composable URL patterns",
7349
7355
  keywords: [
7350
7356
  "react",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rangojs/router",
3
- "version": "0.35.0",
3
+ "version": "0.36.1",
4
4
  "description": "Django-inspired RSC router with composable URL patterns",
5
5
  "keywords": [
6
6
  "react",
@@ -262,9 +262,8 @@ after its commit, as handle values do (see
262
262
 
263
263
  ### useLinkStatus()
264
264
 
265
- Track pending state inside a Link component. `pending` is `true` while a
266
- navigation to the link's `to` is in flight, until the page it brings
267
- commits:
265
+ Track pending state inside a Link component. `pending` is `true` while this
266
+ link's navigation is in flight, until the page it brings commits:
268
267
 
269
268
  ```tsx
270
269
  "use client";
@@ -282,6 +281,14 @@ function LoadingIndicator() {
282
281
  </Link>;
283
282
  ```
284
283
 
284
+ A click marks the link that was clicked: with two links to the same `to` on
285
+ the page, only the clicked one reads `pending`, and a click on the other moves
286
+ it there. A navigation no link started (Back/Forward, `router.push()` or
287
+ `replace()`, a form post, an action's redirect) marks every link to its URL.
288
+ The mark belongs to the `<Link>` instance: a link that remounts while its
289
+ navigation is in flight (a new `key`, a parent of another type) is a new link
290
+ and reads `false`, so keep it mounted where a spinner should stay.
291
+
285
292
  The spinner ends in the commit that shows the destination: its `loading()`
286
293
  skeleton without `transition()`, or the page itself under `transition()`,
287
294
  where React holds the page being left until the new one is ready. Through a
@@ -1113,6 +1113,26 @@ no hydration mismatch there. A loader body may push after an `await`; a server
1113
1113
  component that does throws `LateHandlePushError`, so it resolves a slot its
1114
1114
  handler reserved with `.defer()` instead (`/breadcrumbs`, "Deferred content").
1115
1115
 
1116
+ A fetchable loader read on its own — `load()` / `refetch()`, or a
1117
+ `useRefreshLoaders()` group refresh — carries its pushes too (those of the
1118
+ loaders it awaits included). The browser applies them after the read's data,
1119
+ in place of the loader's earlier values in the segment that registers it, so
1120
+ `useHandle` readers and `<Html.Meta />` (the tab title) show them; a pushed
1121
+ promise applies once it settles. This is how a live part of a page keeps its
1122
+ title current: a rename that reaches the page through a refresh renames the
1123
+ tab too. They apply only while the page the read was sent from is still on
1124
+ screen, and the newest read of the loader wins. A value pushed by a loader the
1125
+ body awaits that the page also registers belongs to that loader's own run,
1126
+ which the read did not refresh: the page keeps that run's values, as it keeps
1127
+ its data. A loader that no segment on the page registers with `loader()` (a
1128
+ `useFetchLoader()` of an unregistered loader) has no segment to own its
1129
+ values: they are not applied, and development warns once. Register the loader
1130
+ on the route or layout whose title or crumbs it writes. A read for data the
1131
+ page does not show — `load()` with `params` (a hover preview of another
1132
+ item), or with a `body` or a method other than GET (a form post) — keeps its
1133
+ data and drops its pushes: the page's title and crumbs stay those of what it
1134
+ shows.
1135
+
1116
1136
  Under `cache()`, loader pushes are not stored with the cached segments: the
1117
1137
  loader re-runs on every hit and its live push is the only copy. (`ppr` keeps
1118
1138
  the pushes of an `ssr: "await"` loader, and of the loaders it awaits, in the
@@ -450,7 +450,7 @@ it("dims the held price while the next product streams", async () => {
450
450
  | navigate() without `transition`, pending seed | Urgent commit (production's cold-navigation lane): the read suspends to the nearest `<Suspense>` fallback (with none, React keeps the previous tree). No flag. |
451
451
  | `transition: { when }` returning false, or `navigate(url, { transition: false })` | Same as without `transition`: urgent, with production's decision (`kind: "push"`; `refresh()` is `"revalidate"`). `transition: false` calls no predicate. |
452
452
  | Production's other hold lanes (same-structure search/filter nav, fully-prefetched, optimistic) | NOT modeled — without `transition` navigate() stays urgent. Assert those at e2e. |
453
- | `useNavigation().state`, `useLinkStatus().pending` | Modeled: navigate() starts the navigation as a click does. `loading` from the call, `idle` in the commit, held with it; `pending` true for the destination's link until that commit, held with it too. |
453
+ | `useNavigation().state`, `useLinkStatus().pending` | Modeled: navigate() starts the navigation as a click does. `loading` from the call, `idle` in the commit, held with it; `pending` true for the destination's links until that commit, held with it too; a `<Link>` click marks that link only. |
454
454
  | `useAction().state` | Stays `idle`: navigate() runs no action. e2e. |
455
455
  | `useHandle()` on a held navigation, `navigate(url, { handles, loaders })` | Modeled: `handles` arrive on the response's handle stream, so readers keep the page being left's values while React holds the page and take the new ones with its commit. |
456
456
  | `useNavigation().isStreaming` past the commit, `navigate(url, { streamUntil })` | Modeled: the stream opens a task after the call (`pendingUrl` clears) and ends when the promise settles or a newer navigation aborts it; settle it inside `await act(async () => ...)`. |
@@ -30,20 +30,21 @@ A `Prerender` route is served as in production: from the artifact `router.matchF
30
30
 
31
31
  ### Returns — `ServeShellRequestResult`
32
32
 
33
- | Field | Type | Meaning |
34
- | ------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
35
- | `shellStatus` | `"HIT" \| "MISS" \| null` | `x-rango-shell`; null when the serve path did not consider the request (not a `ppr` route, a nonce'd request, a partial request). |
36
- | `replayStatus` | `PprReplayStatus \| null` | `x-rango-ppr-replay` on a partial request: `{ outcome: "HIT", freshness }` or `{ outcome: "BYPASS", reason }`. |
37
- | `prelude` | `string \| undefined` | The prelude a HIT served (the capture's Flight text). `undefined` unless `shellStatus` is `"HIT"`. |
38
- | `flight` | `string \| undefined` | The Flight payload this request rendered: a HIT's tail, a document render, or a partial response. `undefined` when no Flight rendered (a redirect, a middleware response). |
39
- | `key` | `string` | The shell key the serve path resolved for a document it read (MISS or HIT), request partition included. Otherwise (no `ppr`, a partial request) the URL's key without a partition. |
40
- | `readEntry` | `() => Promise<ShellCacheEntry \| null>` | Reads the document entry under `key` from the request's store (a passive `getShell`). A read: on a store with a shell memo it warms the memo, so call it after the reads you count. |
41
- | `readHandles` | `() => Promise<ShellRequestHandles \| undefined>` | Decodes the response's handle data as the browser reads it: `{ hydration, late }` (see "Handles and loader data"). `undefined` when no Flight rendered. |
42
- | `readDeferred` | `() => Promise<string[] \| undefined>` | The ids of the segments the payload marks deferred (a prefetch skipped them; the fill renders them), in payload order. `[]` when nothing was deferred, `undefined` when no Flight rendered. |
43
- | `readAction` | `() => Promise<ShellRequestAction \| undefined>` | For an `action` request, the call's answer as the browser reads it: `{ ok, result, revalidationError }` (see "A server action called from the page"). `undefined` when no Flight rendered or the payload carries no action result. |
44
- | `readLocationState` | `() => Promise<Record<string, unknown> \| undefined>` | The payload's location state as the browser reads it: `{ [Def.__rsc_ls_key]: value }` (see "Location state on a document"). `undefined` when it carries none or no Flight rendered. |
45
- | `response` | `Response` | Status and headers. Its body is already read. |
46
- | `body` | `string` | The body text. |
33
+ | Field | Type | Meaning |
34
+ | ------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
35
+ | `shellStatus` | `"HIT" \| "MISS" \| null` | `x-rango-shell`; null when the serve path did not consider the request (not a `ppr` route, a nonce'd request, a partial request). |
36
+ | `replayStatus` | `PprReplayStatus \| null` | `x-rango-ppr-replay` on a partial request: `{ outcome: "HIT", freshness }` or `{ outcome: "BYPASS", reason }`. |
37
+ | `prelude` | `string \| undefined` | The prelude a HIT served (the capture's Flight text). `undefined` unless `shellStatus` is `"HIT"`. |
38
+ | `flight` | `string \| undefined` | The Flight payload this request rendered: a HIT's tail, a document render, or a partial response. `undefined` when no Flight rendered (a redirect, a middleware response). |
39
+ | `key` | `string` | The shell key the serve path resolved for a document it read (MISS or HIT), request partition included. Otherwise (no `ppr`, a partial request) the URL's key without a partition. |
40
+ | `readEntry` | `() => Promise<ShellCacheEntry \| null>` | Reads the document entry under `key` from the request's store (a passive `getShell`). A read: on a store with a shell memo it warms the memo, so call it after the reads you count. |
41
+ | `readHandles` | `() => Promise<ShellRequestHandles \| undefined>` | Decodes the response's handle data as the browser reads it: `{ hydration, late }` (see "Handles and loader data"). `undefined` when no Flight rendered. |
42
+ | `readDeferred` | `() => Promise<string[] \| undefined>` | The ids of the segments the payload marks deferred (a prefetch skipped them; the fill renders them), in payload order. `[]` when nothing was deferred, `undefined` when no Flight rendered. |
43
+ | `readAction` | `() => Promise<ShellRequestAction \| undefined>` | For an `action` request, the call's answer as the browser reads it: `{ ok, result, revalidationError }` (see "A server action called from the page"). `undefined` when no Flight rendered or the payload carries no action result. |
44
+ | `readLoader` | `() => Promise<ShellRequestLoader \| undefined>` | For a fetchable loader read (`?_rsc_loader=<id>`), its answer as the browser reads it: `{ result, error, handles, pushedBy }` (see "A loader read from the page"). `undefined` when no Flight rendered or the payload is not a loader's. |
45
+ | `readLocationState` | `() => Promise<Record<string, unknown> \| undefined>` | The payload's location state as the browser reads it: `{ [Def.__rsc_ls_key]: value }` (see "Location state on a document"). `undefined` when it carries none or no Flight rendered. |
46
+ | `response` | `Response` | Status and headers. Its body is already read. |
47
+ | `body` | `string` | The body text. |
47
48
 
48
49
  ### `resetShellTestState(): Promise<void>`
49
50
 
@@ -493,6 +494,24 @@ expect(answer).toEqual({
493
494
  });
494
495
  ```
495
496
 
497
+ ## A loader read from the page
498
+
499
+ `load()`, `refetch()` and a `useRefreshLoaders()` group refresh send a GET for the page's URL with `_rsc_loader=<the loader's $$id>`. Serve it with an `accept: text/x-component` header and read the answer with `result.readLoader()`: `result` (what the read resolves with, `null` when it rejects), `error` (the message it rejects with, or `null`) and `handles`, the values the loader's body pushed to each handle (by handle `$$id`, in push order, a pushed promise settled), which the browser applies to the segment that registers the loader, and `pushedBy`, for each handle the loader whose run pushed each value (another loader the body awaited with `ctx.use()`, or `null` for the body's own; a handle with no entry holds only the body's own). The browser leaves a value pushed by a loader the page also registers to that loader's own run. The pinned example is `src/testing/__tests__/loader-read-handles.rsc-test.tsx`.
500
+
501
+ ```tsx
502
+ const answer = await (
503
+ await serveShellRequest(router, `/chat?_rsc_loader=${ChatLoader.$$id}`, {
504
+ headers: { accept: "text/x-component" },
505
+ })
506
+ ).readLoader();
507
+ expect(answer).toEqual({
508
+ result: { name: "Renamed" },
509
+ error: null,
510
+ handles: { [Meta.$$id]: [{ title: "Renamed" }] },
511
+ pushedBy: {},
512
+ });
513
+ ```
514
+
496
515
  ## A page middleware rewrites
497
516
 
498
517
  A request a middleware rewrites (`throw rewrite()`, see `/middleware`) runs through the same production handler: the visitor's pass, then the target's, with one request context. Assert what the visitor gets: the target's body and status, `x-rango-rewrite`, the visitor's pathname in the payload, and on a `ppr` target no shell (`shellStatus` `null`) unless the rewrite picked one (see "A rewritten request" above).