@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.
Files changed (74) hide show
  1. package/dist/bin/{chunk-THW7E5A2.js → chunk-A64EG6MI.js} +22 -19
  2. package/dist/bin/{client-urls-projection-DHUUOJZM.js → client-urls-projection-RLDSA3BL.js} +1 -1
  3. package/dist/bin/rango.js +1 -1
  4. package/dist/bin/{runtime-discovery-UECTPF6K.js → runtime-discovery-T7ZLA6E3.js} +2 -2
  5. package/dist/bin/{temp-rsc-server-QLNMTFEE.js → temp-rsc-server-FGGXPKVQ.js} +2 -2
  6. package/dist/types/browser/event-controller.d.ts +61 -0
  7. package/dist/types/browser/fetched-loader-handles.d.ts +76 -0
  8. package/dist/types/browser/navigation-store.d.ts +3 -2
  9. package/dist/types/browser/react/use-handle.d.ts +18 -5
  10. package/dist/types/browser/react/use-push-handle.d.ts +44 -0
  11. package/dist/types/browser/types.d.ts +44 -0
  12. package/dist/types/client.d.ts +1 -0
  13. package/dist/types/client.rsc.d.ts +1 -0
  14. package/dist/types/handle.d.ts +13 -5
  15. package/dist/types/handles/client-pushes.d.ts +51 -0
  16. package/dist/types/handles/deferred-resolution.d.ts +14 -0
  17. package/dist/types/handles/pushed-by.d.ts +36 -0
  18. package/dist/types/loader-store.d.ts +13 -0
  19. package/dist/types/rsc/prefetch-render-error.d.ts +2 -1
  20. package/dist/types/server/handle-store.d.ts +8 -0
  21. package/dist/types/testing/dom.entry.d.ts +1 -1
  22. package/dist/types/testing/flight.entry.d.ts +1 -1
  23. package/dist/types/testing/render-route.d.ts +76 -14
  24. package/dist/types/testing/serve-shell-request.d.ts +31 -0
  25. package/dist/vite/index.js +23 -20
  26. package/package.json +1 -1
  27. package/skills/breadcrumbs/SKILL.md +68 -6
  28. package/skills/caching/SKILL.md +4 -2
  29. package/skills/catalog.json +3 -3
  30. package/skills/client-urls/SKILL.md +13 -1
  31. package/skills/document-cache/SKILL.md +31 -1
  32. package/skills/hooks/SKILL.md +8 -4
  33. package/skills/hooks/data.md +10 -1
  34. package/skills/hooks/handle-and-actions.md +402 -26
  35. package/skills/hooks/navigation.md +4 -0
  36. package/skills/hooks/urls.md +3 -0
  37. package/skills/links/SKILL.md +5 -3
  38. package/skills/loader/SKILL.md +40 -1
  39. package/skills/migrate-nextjs/SKILL.md +5 -0
  40. package/skills/migrate-react-router/component-migration.md +4 -1
  41. package/skills/parallel/SKILL.md +8 -0
  42. package/skills/ppr/SKILL.md +1 -0
  43. package/skills/rango/SKILL.md +6 -3
  44. package/skills/testing/client-components.md +35 -32
  45. package/skills/testing/handles.md +58 -6
  46. package/skills/testing/serve-shell-request.md +33 -14
  47. package/skills/ux-architecture/SKILL.md +4 -0
  48. package/src/browser/event-controller.ts +311 -2
  49. package/src/browser/fetched-loader-handles.ts +269 -0
  50. package/src/browser/navigation-store.ts +261 -2
  51. package/src/browser/partial-update.ts +3 -2
  52. package/src/browser/react/use-handle.ts +74 -27
  53. package/src/browser/react/use-push-handle.ts +113 -0
  54. package/src/browser/rsc-router.tsx +11 -14
  55. package/src/browser/types.ts +48 -0
  56. package/src/cache/document-cache-policy.ts +6 -5
  57. package/src/client.rsc.tsx +1 -0
  58. package/src/client.tsx +31 -1
  59. package/src/handle.ts +13 -5
  60. package/src/handles/client-pushes.ts +120 -0
  61. package/src/handles/deferred-resolution.ts +41 -2
  62. package/src/handles/pushed-by.ts +130 -1
  63. package/src/loader-store.ts +26 -0
  64. package/src/rsc/loader-fetch.ts +64 -5
  65. package/src/rsc/prefetch-render-error.ts +2 -1
  66. package/src/rsc/request-stages.ts +7 -6
  67. package/src/rsc/rsc-rendering.ts +32 -14
  68. package/src/server/handle-store.ts +23 -0
  69. package/src/ssr/ssr-root.tsx +6 -0
  70. package/src/testing/dom.entry.ts +2 -0
  71. package/src/testing/flight.entry.ts +1 -0
  72. package/src/testing/render-route.tsx +319 -72
  73. package/src/testing/serve-shell-request.ts +62 -1
  74. package/src/use-loader.tsx +44 -4
@@ -697,12 +697,13 @@ export interface FinalizeRequestOptions<TEnv> {
697
697
  * reads the route's own header when it stores the response (s-maxage), the
698
698
  * browser gets this one, in place of any other the route set.
699
699
  *
700
- * Left as it is: a partial sent NOT_REUSED (scoped to its source page, or
701
- * carrying deferred units), a header that forbids storing it (`no-store`,
702
- * `no-cache`, a zero `max-age`), a redirect a middleware returned after the render (`redirect`,
703
- * converted to a Flight redirect above), and a response carrying one
704
- * client's state (a per-client signal header, location state), which a
705
- * stored copy would replay to later requests.
700
+ * Left as it is: a partial scoped to its source page or carrying deferred
701
+ * units (sent NOT_REUSED, or the route's own no-store), a header that
702
+ * forbids storing it (`no-store`, `no-cache`, a zero `max-age`), a redirect
703
+ * a middleware returned after the render (`redirect`, converted to a Flight
704
+ * redirect above), and a response carrying one client's state (a per-client
705
+ * signal header, location state), which a stored copy would replay to later
706
+ * requests.
706
707
  */
707
708
  function applyStoredPrefetchCacheControl(
708
709
  response: Response,
@@ -1141,19 +1141,20 @@ function renderPreparedRscResponse<TEnv>(
1141
1141
  reqCtx._payloadSourceScoped = true;
1142
1142
  }
1143
1143
  // Not reused by a shared cache or the document cache (which also refuses a
1144
- // payload marked `_payloadDeferred` or `_payloadSourceScoped`), whatever
1145
- // Cache-Control the route set: a partial scoped to its source page (above);
1146
- // a response that carries deferred units, which answers one page's prefetch,
1147
- // and a fill, the second half of one adoption (prefetch: false,
1148
- // docs/design/prefetch-false.md, R7); and a stale partial render, which a
1149
- // shared cache keyed by URL must not store or serve. Any other route keeps
1150
- // its headers.
1144
+ // payload marked `_payloadDeferred` or `_payloadSourceScoped`): a partial
1145
+ // scoped to its source page (above); a response that carries deferred
1146
+ // units, which answers one page's prefetch, and a fill, the second half of
1147
+ // one adoption (prefetch: false, docs/design/prefetch-false.md, R7); and a
1148
+ // stale partial render, which a shared cache keyed by URL must not store or
1149
+ // serve. A route's own `no-store` already forbids all of that and more, so
1150
+ // it is kept. Any other route keeps its headers.
1151
1151
  if (
1152
- reqCtx._payloadSourceScoped ||
1153
- reqCtx._payloadDeferred ||
1154
- (isPartial &&
1155
- (reqCtx._requestKind === "fill" ||
1156
- url.searchParams.get(WIRE.stale) === "true"))
1152
+ (reqCtx._payloadSourceScoped ||
1153
+ reqCtx._payloadDeferred ||
1154
+ (isPartial &&
1155
+ (reqCtx._requestKind === "fill" ||
1156
+ url.searchParams.get(WIRE.stale) === "true"))) &&
1157
+ !keepsRouteNoStore(reqCtx.res.headers.get("cache-control"))
1157
1158
  ) {
1158
1159
  rscHeaders["cache-control"] = NOT_REUSED;
1159
1160
  }
@@ -1650,8 +1651,9 @@ function publishTailTiming(
1650
1651
  const PENDING = Symbol("pending");
1651
1652
 
1652
1653
  /**
1653
- * Cache-Control of a response that is not to be reused: one that carries
1654
- * deferred units (`prefetch: false`), and a fill. `private` keeps it out of
1654
+ * Cache-Control of a response that is not to be reused: a partial scoped to
1655
+ * its source page, one that carries deferred units (`prefetch: false`), a
1656
+ * fill, and a stale partial render. `private` keeps it out of
1655
1657
  * shared caches; `no-cache` makes the browser ask again, and with no
1656
1658
  * validator on the response that is a full request. The browser may keep the
1657
1659
  * body all the same (Chromium does) and answers from it, without asking,
@@ -1661,9 +1663,25 @@ const PENDING = Symbol("pending");
1661
1663
  * Chromium reports a `no-store` fetch whose body is read through a stream
1662
1664
  * as canceled (net::ERR_ABORTED in DevTools, and Playwright's
1663
1665
  * response.finished() never settles), though every byte arrived.
1666
+ * A route that set `no-store` itself keeps it (keepsRouteNoStore) and takes
1667
+ * that report, as its navigations already do: replacing it with `no-cache`
1668
+ * would let the browser keep a page the route said must never be stored.
1664
1669
  */
1665
1670
  const NOT_REUSED = "private, no-cache";
1666
1671
 
1672
+ const NO_STORE_DIRECTIVE = /(^|[\s,;])no-store(?=$|[\s,;=])/i;
1673
+
1674
+ /**
1675
+ * Whether the route's own Cache-Control (set by a middleware before next()
1676
+ * or by a handler, read from the stub response) says `no-store`. Read at the
1677
+ * NOT_REUSED decision: every handler and middleware-before-next() write has
1678
+ * landed, and createResponseWithMergedHeaders copies the stub value onto the
1679
+ * response because the render then sets none.
1680
+ */
1681
+ function keepsRouteNoStore(cacheControl: string | null): boolean {
1682
+ return cacheControl !== null && NO_STORE_DIRECTIVE.test(cacheControl);
1683
+ }
1684
+
1667
1685
  /**
1668
1686
  * Whether `value` is not a promise, or a promise that has already settled:
1669
1687
  * racing it against an already-resolved promise, a settled one's reaction is
@@ -335,6 +335,15 @@ export interface HandleStore {
335
335
  */
336
336
  releaseRecordedValues(segmentId: string): void;
337
337
 
338
+ /**
339
+ * Stop recording pushes into `segmentId`: a later push() into it, a
340
+ * replayed copy included, records nothing and calls `onLate` with the
341
+ * handle's name. The fetchable-loader lane (rsc/loader-fetch.ts) closes
342
+ * its loader's segment once the reply holds the body's pushes, so a push
343
+ * the body makes after it returned is reported instead of lost unseen.
344
+ */
345
+ closeSegment(segmentId: string, onLate: (handleName: string) => void): void;
346
+
338
347
  /**
339
348
  * Get all collected handle data after all handlers have settled.
340
349
  * Waits for `settled` (handler lane), then returns the data at that point.
@@ -508,6 +517,8 @@ export function createHandleStore(): HandleStore {
508
517
  const placeholderLoaders = new Set<string>();
509
518
  // Segments whose restored record values a push still goes in front of.
510
519
  const held = new Set<string>();
520
+ // closeSegment: segments that record no more pushes, with what to call.
521
+ const closed = new Map<string, (handleName: string) => void>();
511
522
  let authority: ((loaderId: string) => RecordAuthority) | undefined;
512
523
  const isRestored = (loaderId: string): boolean =>
513
524
  restoredLoaders.has(loaderId) || authority?.(loaderId) === "pin";
@@ -914,6 +925,11 @@ export function createHandleStore(): HandleStore {
914
925
  loaderPush?: boolean,
915
926
  owner?: string,
916
927
  ): void {
928
+ const onLate = closed.get(segmentId);
929
+ if (onLate) {
930
+ onLate(handleName);
931
+ return;
932
+ }
917
933
  if (completed) {
918
934
  const error = createLateHandlePushError(handleName, segmentId);
919
935
  if (this.onError) this.onError(error);
@@ -1115,6 +1131,13 @@ export function createHandleStore(): HandleStore {
1115
1131
  held.delete(segmentId);
1116
1132
  },
1117
1133
 
1134
+ closeSegment(
1135
+ segmentId: string,
1136
+ onLate: (handleName: string) => void,
1137
+ ): void {
1138
+ closed.set(segmentId, onLate);
1139
+ },
1140
+
1118
1141
  replacePlaceholders(
1119
1142
  loaderIds: readonly string[],
1120
1143
  deliver: () => void,
@@ -119,10 +119,16 @@ function createSsrEventController(opts: {
119
119
  releaseRouteState: () => {},
120
120
  setHandleData: () => {},
121
121
  getHandleState: () => handleState,
122
+ setLoaderReadHandleData: () => false,
123
+ setLateHandleData: () => {},
122
124
  lockHydration: () => {},
123
125
  getHydrationSnapshot: () => undefined,
124
126
  releaseHydrationLock: () => {},
125
127
  setRouteSegmentIds: () => {},
128
+ setClientHandle: () => {},
129
+ withClientHandles: (data) => data,
130
+ subscribeToClientHandles: () => () => {},
131
+ getHeldHandleState: () => undefined,
126
132
  setParams: (nextParams) => {
127
133
  params = nextParams;
128
134
  },
@@ -20,4 +20,6 @@ export type {
20
20
  RenderRouteResult,
21
21
  RenderRouteHydrateResult,
22
22
  HandleDataSeed,
23
+ HandleSeed,
24
+ HandleSegment,
23
25
  } from "./render-route.js";
@@ -69,4 +69,5 @@ export type {
69
69
  ServeShellRequestResult,
70
70
  ShellRequestAction,
71
71
  ShellRequestHandles,
72
+ ShellRequestLoader,
72
73
  } from "./serve-shell-request.js";