@rangojs/router 0.36.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.
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-UECTPF6K.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,7 +163,7 @@ 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-QLNMTFEE.js");
166
+ const { createTempRscServer } = await import("./temp-rsc-server-FV4ERMAS.js");
167
167
  const { createDiscoveryState } = await import("./state-ACD2MGKJ.js");
168
168
  const { discoverClientUrlProjections } = await import("./client-urls-projection-DHUUOJZM.js");
169
169
  const {
@@ -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.36.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,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";
@@ -53,6 +53,8 @@
53
53
  * rejection is the loader's error. Needs the testing kit's
54
54
  * `@vitejs/plugin-rsc/browser` alias (rangoTestAliases). A load() with params
55
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.
56
58
  * - A spec's transition({ when }) decides every commit with production's
57
59
  * browser decision: navigate() and useRouter().push model kind "push",
58
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
@@ -7350,7 +7350,7 @@ function resolveVersionsFrom(table, routerId2) {
7350
7350
  // package.json
7351
7351
  var package_default = {
7352
7352
  name: "@rangojs/router",
7353
- version: "0.36.0",
7353
+ version: "0.36.1",
7354
7354
  description: "Django-inspired RSC router with composable URL patterns",
7355
7355
  keywords: [
7356
7356
  "react",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rangojs/router",
3
- "version": "0.36.0",
3
+ "version": "0.36.1",
4
4
  "description": "Django-inspired RSC router with composable URL patterns",
5
5
  "keywords": [
6
6
  "react",
@@ -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
@@ -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).
@@ -15,7 +15,11 @@ import {
15
15
  filterRouteSegmentIds,
16
16
  } from "./react/filter-segment-order.js";
17
17
  import { notifyListeners } from "./notify-listeners.js";
18
- import { mergePartialHandleData } from "../handles/pushed-by.js";
18
+ import {
19
+ mergeLoaderReadHandleData,
20
+ mergePartialHandleData,
21
+ type LoaderReadPushes,
22
+ } from "../handles/pushed-by.js";
19
23
  import {
20
24
  locationStateSnapshot,
21
25
  type LocationStateSnapshot,
@@ -314,6 +318,15 @@ export interface EventController {
314
318
  resolvedIds?: string[],
315
319
  ): void;
316
320
  getHandleState(): HandleState;
321
+ /**
322
+ * Apply the handle values a fetched read of `loaderId` pushed to the page's
323
+ * handle data, keeping its segment order: they replace the loader's earlier
324
+ * values in its segment (handles/pushed-by.ts mergeLoaderReadHandleData).
325
+ * Waits like setHandleData while the hydration window is open. False, and
326
+ * nothing applied, when no segment of the page's handle data registers the
327
+ * loader.
328
+ */
329
+ setLoaderReadHandleData(loaderId: string, pushes: LoaderReadPushes): boolean;
317
330
  /**
318
331
  * Open the hydration window. Until releaseHydrationLock(), getHandleState()
319
332
  * returns the state the document's HTML was rendered with, and handle writes
@@ -601,6 +614,9 @@ export function createEventController(
601
614
 
602
615
  let handleData: HandleData = {};
603
616
  let handleSegmentOrder: string[] = [];
617
+ // The raw `matched` handleData was built from: which loaders each segment
618
+ // registers (setLoaderReadHandleData).
619
+ let handleMatched: string[] = [];
604
620
  let routeSegmentIds: string[] = [];
605
621
  // The hydration window (lockHydration): what the document's HTML was
606
622
  // rendered with, and the handle writes waiting for its release.
@@ -1231,11 +1247,42 @@ export function createEventController(
1231
1247
  handleData = data;
1232
1248
  }
1233
1249
  handleSegmentOrder = newSegmentOrder;
1250
+ handleMatched = rawMatched;
1234
1251
  routeSegmentIds = newRouteSegmentIds;
1235
1252
 
1236
1253
  notifyHandles.schedule();
1237
1254
  }
1238
1255
 
1256
+ function setLoaderReadHandleData(
1257
+ loaderId: string,
1258
+ pushes: LoaderReadPushes,
1259
+ ): boolean {
1260
+ const merge = () =>
1261
+ mergeLoaderReadHandleData(
1262
+ handleData,
1263
+ handleSegmentOrder,
1264
+ handleMatched,
1265
+ loaderId,
1266
+ pushes,
1267
+ );
1268
+ if (hydrationSnapshot) {
1269
+ // Decided on the data the waiting writes start from, applied after
1270
+ // them, in order, when the window closes.
1271
+ const applies = merge() !== undefined;
1272
+ if (applies) {
1273
+ writesAfterHydration.push(() => {
1274
+ setLoaderReadHandleData(loaderId, pushes);
1275
+ });
1276
+ }
1277
+ return applies;
1278
+ }
1279
+ const merged = merge();
1280
+ if (!merged) return false;
1281
+ handleData = merged;
1282
+ notifyHandles.schedule();
1283
+ return true;
1284
+ }
1285
+
1239
1286
  function getHandleState(): HandleState {
1240
1287
  if (hydrationSnapshot) return hydrationSnapshot.handles;
1241
1288
  return {
@@ -1361,6 +1408,7 @@ export function createEventController(
1361
1408
  // Handles
1362
1409
  setHandleData,
1363
1410
  getHandleState,
1411
+ setLoaderReadHandleData,
1364
1412
  lockHydration,
1365
1413
  getHydrationSnapshot: () => hydrationSnapshot,
1366
1414
  releaseHydrationLock,
@@ -0,0 +1,96 @@
1
+ import type { EventController } from "./event-controller.js";
2
+ import type { NavigationStore } from "./types.js";
3
+ import { resolveDeferredPushes } from "../handles/deferred-resolution.js";
4
+
5
+ /**
6
+ * The handle values a fetched loader read pushed (`_rsc_loader`: `load()`, a
7
+ * `refreshGroup` refresh), by handle $$id, as the reply carries them
8
+ * (rsc/loader-fetch.ts). A pending push is its promise.
9
+ */
10
+ export type FetchedLoaderHandles = Record<string, unknown[]>;
11
+
12
+ /**
13
+ * Which loader's run pushed each of the reply's values, index-aligned per
14
+ * handle (null: the read loader's own body), as the reply carries it.
15
+ */
16
+ export type FetchedLoaderPushedBy = Record<string, (string | null)[]>;
17
+
18
+ /** The router state a read's handle values are applied to. */
19
+ export interface FetchedLoaderPage {
20
+ eventController: EventController;
21
+ store: NavigationStore;
22
+ }
23
+
24
+ /** The newest read sent for each loader: an older reply leaves the handles. */
25
+ const latestRead = new Map<string, number>();
26
+ let readSeq = 0;
27
+ const warnedUnregistered = new Set<string>();
28
+
29
+ /**
30
+ * Start a read of `loaderId` from the page on screen. Call it when the request
31
+ * is sent; the returned function applies the reply's handle values.
32
+ *
33
+ * The values replace the loader's earlier ones in its segment once the
34
+ * pending ones settle (a rejected or nullish one dropped, as on the
35
+ * navigation lane), on their own after the data: a handle value never holds
36
+ * the loader's data. They apply only while the page the read was sent from is
37
+ * still on screen (same history entry, no commit since, as NavigationProvider's
38
+ * handle stream checks) and no newer read of the loader was sent, and the
39
+ * history entry keeps them for Back. A loader no segment of the page
40
+ * registers has no segment to own its pushes: they are not applied (warned
41
+ * once per loader in development).
42
+ */
43
+ export function startFetchedLoaderRead(
44
+ loaderId: string,
45
+ page: FetchedLoaderPage | undefined,
46
+ ): (
47
+ handles: FetchedLoaderHandles | undefined,
48
+ pushedBy?: FetchedLoaderPushedBy,
49
+ ) => void {
50
+ const seq = ++readSeq;
51
+ latestRead.set(loaderId, seq);
52
+ const historyKey = page?.store.getHistoryKey();
53
+ const navInstance = page?.store.getNavInstance();
54
+ const current = (): boolean =>
55
+ page !== undefined &&
56
+ latestRead.get(loaderId) === seq &&
57
+ page.store.getHistoryKey() === historyKey &&
58
+ page.store.getNavInstance() === navInstance;
59
+
60
+ const apply = async (
61
+ handles: FetchedLoaderHandles | undefined,
62
+ pushedBy: FetchedLoaderPushedBy | undefined,
63
+ ): Promise<void> => {
64
+ if (!handles || !current()) return;
65
+ const pushes = await resolveDeferredPushes(handles, pushedBy);
66
+ if (!current()) return;
67
+ const { eventController, store } = page!;
68
+ if (!eventController.setLoaderReadHandleData(loaderId, pushes)) {
69
+ if (
70
+ process.env.NODE_ENV !== "production" &&
71
+ Object.values(pushes.values).some((pushed) => pushed.length > 0) &&
72
+ !warnedUnregistered.has(loaderId)
73
+ ) {
74
+ warnedUnregistered.add(loaderId);
75
+ console.warn(
76
+ `[rango] Loader "${loaderId}" pushed handle values on a fetched read ` +
77
+ `(load(), useRefreshLoaders()), but no segment on this page ` +
78
+ `registers it with loader(), so they have no segment to belong to ` +
79
+ `and are not applied. Register the loader on the route or layout ` +
80
+ `whose handle values it writes.`,
81
+ );
82
+ }
83
+ return;
84
+ }
85
+ store.updateCacheHandleDataIfOwned(
86
+ historyKey!,
87
+ eventController.getHandleState().data,
88
+ navInstance!,
89
+ );
90
+ };
91
+ return (handles, pushedBy) => {
92
+ apply(handles, pushedBy).catch((error) =>
93
+ console.error("[rango] Error applying a loader read's handles:", error),
94
+ );
95
+ };
96
+ }
@@ -1,6 +1,10 @@
1
1
  import type { HandleData, HandleStore } from "../server/handle-store.js";
2
2
  import { isThenable } from "./is-thenable.js";
3
- import { isPushedByKey, pushedByKey } from "./pushed-by.js";
3
+ import {
4
+ isPushedByKey,
5
+ pushedByKey,
6
+ type LoaderReadPushes,
7
+ } from "./pushed-by.js";
4
8
 
5
9
  /**
6
10
  * Runtime-neutral resolution of deferred (Promise) handle values. Shared by the
@@ -68,6 +72,29 @@ export async function resolveDeferredHandleValues(
68
72
  return out;
69
73
  }
70
74
 
75
+ /**
76
+ * A fetched loader read's pushes, as its reply carries them, with deferred
77
+ * values awaited as resolveDeferredHandleValues awaits them; `pushedBy` loses
78
+ * the entries of the dropped values.
79
+ */
80
+ export async function resolveDeferredPushes(
81
+ pushes: Readonly<Record<string, readonly unknown[]>>,
82
+ pushedBy: Readonly<Record<string, readonly (string | null)[]>> = {},
83
+ ): Promise<LoaderReadPushes> {
84
+ const out: LoaderReadPushes = { values: {}, pushedBy: {} };
85
+ await Promise.all(
86
+ Object.entries(pushes).map(async ([handleName, values]) => {
87
+ const resolved = await resolveValues(values);
88
+ out.values[handleName] = keptValues(resolved);
89
+ const by = pushedBy[handleName];
90
+ if (by) {
91
+ out.pushedBy[handleName] = by.filter((_, i) => resolved[i].keep);
92
+ }
93
+ }),
94
+ );
95
+ return out;
96
+ }
97
+
71
98
  interface ResolvedValue {
72
99
  keep: boolean;
73
100
  value: unknown;
@@ -78,7 +105,7 @@ interface ResolvedValue {
78
105
  // A thenable is awaited and dropped when it rejects OR resolves to null/undefined
79
106
  // (the `.defer({ else })` skip semantics: a forgotten resolver times out to
80
107
  // `else ?? undefined`), so a nullish deferred slot never reaches a collector.
81
- function resolveValues(values: unknown[]): Promise<ResolvedValue[]> {
108
+ function resolveValues(values: readonly unknown[]): Promise<ResolvedValue[]> {
82
109
  return Promise.all(
83
110
  values.map(async (v) => {
84
111
  if (!isThenable(v)) return { keep: true, value: v };
@@ -75,6 +75,81 @@ export function withSegmentHandles(
75
75
  return out;
76
76
  }
77
77
 
78
+ /**
79
+ * What a fetched loader read pushed, settled: the values by handle $$id, and
80
+ * the loader whose run pushed each (index-aligned; null, or no entry for the
81
+ * handle, for the read loader's own body).
82
+ */
83
+ export interface LoaderReadPushes {
84
+ values: Record<string, unknown[]>;
85
+ pushedBy: Record<string, (string | null)[]>;
86
+ }
87
+
88
+ /**
89
+ * The handle data after a fetched read of loader `loaderId` (the `_rsc_loader`
90
+ * lane: `load()`, a `refreshGroup` refresh) pushed `pushes`. The read renders
91
+ * no segment, so its pushes go where the page's run of the loader put its
92
+ * own: the first segment of `segmentOrder` holding a value the loader pushed,
93
+ * else the first segment of `matched` (the raw list `current` was built from)
94
+ * that registers it, where a render files them (loader-resolution.ts
95
+ * loaderOwner). The loader's earlier values give way to these in their
96
+ * position, in every segment that registers it, and every other run keeps its
97
+ * own (mergePartialHandleData, with the loader as the run that ran). A value
98
+ * pushed by another loader the page registers, one the body read with
99
+ * ctx.use, belongs to that loader's run, which the read did not refresh: the
100
+ * page keeps that run's values, as it keeps its data. Undefined when no
101
+ * segment registers the loader: its pushes have no segment to belong to.
102
+ */
103
+ export function mergeLoaderReadHandleData(
104
+ current: HandleData,
105
+ segmentOrder: readonly string[],
106
+ matched: readonly string[],
107
+ loaderId: string,
108
+ pushes: LoaderReadPushes,
109
+ ): HandleData | undefined {
110
+ const registrations: string[] = [];
111
+ const registers = new Set<string>();
112
+ const otherLoaders = new Set<string | null>();
113
+ for (const id of matched) {
114
+ const marker = LOADER_SEGMENT_ID.exec(id);
115
+ if (!marker) continue;
116
+ const loader = id.slice(marker.index + marker[0].length);
117
+ if (loader !== loaderId) {
118
+ otherLoaders.add(loader);
119
+ continue;
120
+ }
121
+ registrations.push(id);
122
+ registers.add(id.slice(0, marker.index));
123
+ }
124
+ if (registrations.length === 0) return undefined;
125
+ const pushedHere = (segmentId: string): boolean =>
126
+ Object.keys(current).some(
127
+ (name) =>
128
+ isPushedByKey(name) &&
129
+ current[name][segmentId]?.includes(loaderId) === true,
130
+ );
131
+ const owner =
132
+ segmentOrder.find((id) => registers.has(id) && pushedHere(id)) ??
133
+ [...registers][0]!;
134
+ const incoming: HandleData = {};
135
+ for (const name in pushes.values) {
136
+ const by = pushes.pushedBy[name];
137
+ const own = pushes.values[name].filter(
138
+ (_, i) => !otherLoaders.has(by?.[i] ?? null),
139
+ );
140
+ if (own.length === 0) continue;
141
+ incoming[name] = { [owner]: own };
142
+ incoming[pushedByKey(name)] = { [owner]: own.map(() => loaderId) };
143
+ }
144
+ return mergePartialHandleData(
145
+ current,
146
+ incoming,
147
+ segmentOrder,
148
+ matched,
149
+ registrations,
150
+ );
151
+ }
152
+
78
153
  /**
79
154
  * The handle data after a partial response's snapshot `incoming` (each stream
80
155
  * yield holds everything the response pushed so far). A segment outside
@@ -38,6 +38,20 @@ import {
38
38
  } from "./helpers.js";
39
39
  import type { HandlerContext } from "./handler-context.js";
40
40
  import { WIRE } from "../wire-params.js";
41
+ import { isHandle } from "../handle.js";
42
+ import { runInsideLoaderBodyScope } from "../server/context.js";
43
+
44
+ /**
45
+ * A successful read's reply: the loader's value, the values its body pushed
46
+ * to each handle (by handle $$id, in push order), and which loader's run
47
+ * pushed each (index-aligned, null for the body's own; a handle with no entry
48
+ * holds only the body's own).
49
+ */
50
+ interface LoaderFetchPayload {
51
+ loaderResult: unknown;
52
+ handles: Record<string, unknown[]>;
53
+ pushedBy: Record<string, (string | null)[]>;
54
+ }
41
55
 
42
56
  export interface LoaderErrorMeta<TEnv> {
43
57
  request: Request;
@@ -255,6 +269,17 @@ export async function handleLoaderFetch<TEnv>(
255
269
  variables,
256
270
  async () => {
257
271
  const reqCtx = getRequestContext();
272
+ // ctx.use(Handle) pushes file under the request context's segment
273
+ // (request-context.ts createUseFunction), which throws without one,
274
+ // and this lane renders no segment: the loader's id stands in. The
275
+ // body's pushes, and those of the loaders it reads with ctx.use,
276
+ // file under the loader's id and ride the reply; the browser files
277
+ // them under the segments that register the loader
278
+ // (browser/fetched-loader-handles.ts). Set before the copy below:
279
+ // a "use cache" function handed the loader's ctx replays a HIT's
280
+ // pushes into its segment (cache-runtime.ts callerSegmentId).
281
+ (reqCtx as { _currentSegmentId?: string })._currentSegmentId =
282
+ loaderId;
258
283
  // Merge route params (from previewMatch) with explicit loader params.
259
284
  // Explicit params take precedence over route-matched params.
260
285
  const resolvedRouteParams = routeParams ?? {};
@@ -290,6 +315,17 @@ export async function handleLoaderFetch<TEnv>(
290
315
  : undefined,
291
316
  ),
292
317
  ...(loaderFormData ? { formData: loaderFormData } : {}),
318
+ // A loader the body reads runs as its own run, as a render runs
319
+ // it (loader-resolution.ts): its pushes name it
320
+ // (getHandlePushOwner), so the reply's pushedBy tells the browser
321
+ // they are that loader's, not this one's.
322
+ use: ((item: any) =>
323
+ isHandle(item)
324
+ ? reqCtx.use(item)
325
+ : runInsideLoaderBodyScope(
326
+ () => reqCtx.use(item),
327
+ item.$$id,
328
+ )) as typeof reqCtx.use,
293
329
  };
294
330
 
295
331
  // Meter the fetchable-loader execution via observePhase, the sole
@@ -299,13 +335,19 @@ export async function handleLoaderFetch<TEnv>(
299
335
  fn(loaderCtx),
300
336
  );
301
337
 
302
- interface LoaderPayload {
303
- loaderResult: unknown;
304
- }
305
- const loaderPayload: LoaderPayload = { loaderResult: result };
338
+ const loaderPayload: LoaderFetchPayload = {
339
+ loaderResult: result,
340
+ // The pushes the body made, a pending one as its promise: the
341
+ // browser applies them once they settle, after the data.
342
+ handles: reqCtx._handleStore.getDataForSegment(loaderId),
343
+ // A loader the body read with ctx.use pushed as its own run: the
344
+ // browser leaves the page's run of it alone when the page
345
+ // registers it (handles/pushed-by.ts mergeLoaderReadHandleData).
346
+ pushedBy: reqCtx._handleStore.getPushedBy(loaderId) ?? {},
347
+ };
306
348
  // Read once here: onError can fire outside the ALS frame.
307
349
  const requestContext = _getRequestContext();
308
- const rscStream = ctx.renderToReadableStream<LoaderPayload>(
350
+ const rscStream = ctx.renderToReadableStream<LoaderFetchPayload>(
309
351
  loaderPayload,
310
352
  {
311
353
  onError: (error: unknown) => {
@@ -119,6 +119,7 @@ function createSsrEventController(opts: {
119
119
  releaseRouteState: () => {},
120
120
  setHandleData: () => {},
121
121
  getHandleState: () => handleState,
122
+ setLoaderReadHandleData: () => false,
122
123
  lockHydration: () => {},
123
124
  getHydrationSnapshot: () => undefined,
124
125
  releaseHydrationLock: () => {},
@@ -69,4 +69,5 @@ export type {
69
69
  ServeShellRequestResult,
70
70
  ShellRequestAction,
71
71
  ShellRequestHandles,
72
+ ShellRequestLoader,
72
73
  } from "./serve-shell-request.js";
@@ -53,6 +53,8 @@
53
53
  * rejection is the loader's error. Needs the testing kit's
54
54
  * `@vitejs/plugin-rsc/browser` alias (rangoTestAliases). A load() with params
55
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.
56
58
  * - A spec's transition({ when }) decides every commit with production's
57
59
  * browser decision: navigate() and useRouter().push model kind "push",
58
60
  * useRouter().replace kind "replace", refresh() kind "revalidate", and a
@@ -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 { resolveDeferredHandleValues } from "../handles/deferred-resolution.js";
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
  }
@@ -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 loaders: LoaderStore | undefined = useContext(NavigationStoreContext)
272
- ?.store?.loaders;
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,7 @@ 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 applyHandles = startFetchedLoaderRead(loaderId, page);
286
307
  const response = fetch(url.toString(), {
287
308
  method: "GET",
288
309
  headers: { Accept: "text/x-component" },
@@ -293,6 +314,7 @@ function useLoaderInternal<T>(
293
314
  throw new Error(payload.loaderError.message);
294
315
  }
295
316
  loaders.finishData(bucketKey, requestId, payload.loaderResult);
317
+ applyHandles(payload.handles, payload.pushedBy);
296
318
  } catch (e) {
297
319
  const err = e instanceof Error ? e : new Error(String(e));
298
320
  loaders.finishError(bucketKey, requestId, err);
@@ -300,7 +322,7 @@ function useLoaderInternal<T>(
300
322
  } finally {
301
323
  loaders.setLoading(bucketKey, requestId, false);
302
324
  }
303
- }, [loaderId, bucketKey, loaders]);
325
+ }, [loaderId, bucketKey, loaders, page]);
304
326
 
305
327
  // Held-navigation pin: a transition commit whose stream for this loader is
306
328
  // still pending announces it (loader-store.ts announcePendingStreams, which
@@ -545,6 +567,12 @@ function useLoaderInternal<T>(
545
567
  };
546
568
  }
547
569
 
570
+ // Only a refetch of the page's own read (the page's params, no body)
571
+ // applies its handle values: a read with other params or a body is
572
+ // data the page does not show, and its pushes would retitle the page.
573
+ const applyHandles = isPlainRefetch(loadOptions)
574
+ ? startFetchedLoaderRead(id, page)
575
+ : undefined;
548
576
  const response = fetch(url.toString(), fetchOptions);
549
577
 
550
578
  const { createFromFetch } = await import("./deps/browser.js");
@@ -563,6 +591,7 @@ function useLoaderInternal<T>(
563
591
  setLocalIsLoading(false);
564
592
  });
565
593
  }
594
+ applyHandles?.(payload.handles, payload.pushedBy);
566
595
  return result;
567
596
  } catch (e) {
568
597
  const err = e instanceof Error ? e : new Error(String(e));
@@ -582,7 +611,7 @@ function useLoaderInternal<T>(
582
611
  }
583
612
  }
584
613
  },
585
- [throwOnError, loaders, routeDataOf],
614
+ [throwOnError, loaders, routeDataOf, page],
586
615
  );
587
616
 
588
617
  if (throwOnError) {