@rangojs/router 0.34.1 → 0.36.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 (105) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/{chunk-4HHFQSDC.js → chunk-THW7E5A2.js} +16 -10
  3. package/dist/bin/{client-urls-projection-4Q5EQDAL.js → client-urls-projection-DHUUOJZM.js} +1 -1
  4. package/dist/bin/rango.js +1 -1
  5. package/dist/bin/{runtime-discovery-RY6NMQM3.js → runtime-discovery-UECTPF6K.js} +2 -2
  6. package/dist/bin/{temp-rsc-server-F7AHOPV4.js → temp-rsc-server-QLNMTFEE.js} +2 -2
  7. package/dist/types/browser/react/use-link-status.d.ts +17 -8
  8. package/dist/types/browser/types.d.ts +2 -0
  9. package/dist/types/cache/shell-snapshot.d.ts +1 -1
  10. package/dist/types/cache/types.d.ts +1 -1
  11. package/dist/types/client-urls/server-projection.d.ts +1 -1
  12. package/dist/types/client-urls/types.d.ts +6 -6
  13. package/dist/types/decode-loader-results.d.ts +1 -1
  14. package/dist/types/errors.d.ts +3 -3
  15. package/dist/types/handles/meta.d.ts +2 -2
  16. package/dist/types/loader-store.d.ts +1 -1
  17. package/dist/types/outlet-context.d.ts +1 -1
  18. package/dist/types/route-definition/helpers-types.d.ts +5 -5
  19. package/dist/types/router/loader-resolution.d.ts +1 -1
  20. package/dist/types/router/segment-resolution/loader-cache.d.ts +7 -7
  21. package/dist/types/router/types.d.ts +1 -1
  22. package/dist/types/rsc/shell-capture-constants.d.ts +2 -2
  23. package/dist/types/server/context.d.ts +3 -3
  24. package/dist/types/server/request-context.d.ts +1 -1
  25. package/dist/types/ssr/index.d.ts +1 -1
  26. package/dist/types/ssr/ssr-root.d.ts +1 -1
  27. package/dist/types/ssr-suspension-warning.d.ts +1 -1
  28. package/dist/types/testing/render-route.d.ts +3 -2
  29. package/dist/types/types/loader-types.d.ts +19 -19
  30. package/dist/types/types/segments.d.ts +2 -2
  31. package/dist/types/urls/path-helper-types.d.ts +4 -4
  32. package/dist/types/urls/pattern-types.d.ts +1 -1
  33. package/dist/types/vite/plugin-types.d.ts +1 -1
  34. package/dist/vite/index.js +18 -12
  35. package/package.json +1 -1
  36. package/skills/app-structure/e-commerce.md +1 -1
  37. package/skills/breadcrumbs/SKILL.md +5 -5
  38. package/skills/cache-guide/SKILL.md +4 -4
  39. package/skills/caching/SKILL.md +1 -1
  40. package/skills/catalog.json +2 -2
  41. package/skills/client-urls/SKILL.md +20 -20
  42. package/skills/comparison/references/framework-comparison.md +6 -6
  43. package/skills/defer-hydration/SKILL.md +2 -2
  44. package/skills/handler-use/SKILL.md +5 -5
  45. package/skills/hooks/data.md +1 -1
  46. package/skills/hooks/handle-and-actions.md +9 -9
  47. package/skills/hooks/navigation.md +10 -3
  48. package/skills/loader/SKILL.md +52 -47
  49. package/skills/middleware/SKILL.md +2 -2
  50. package/skills/migrate-nextjs/SKILL.md +10 -10
  51. package/skills/migrate-react-router/SKILL.md +1 -1
  52. package/skills/migrate-react-router/component-migration.md +2 -2
  53. package/skills/migrate-react-router/data-and-actions.md +2 -2
  54. package/skills/migrate-react-router/route-mapping.md +2 -2
  55. package/skills/parallel/SKILL.md +2 -2
  56. package/skills/ppr/SKILL.md +91 -92
  57. package/skills/prerender/SKILL.md +5 -5
  58. package/skills/rango/SKILL.md +7 -7
  59. package/skills/route/SKILL.md +1 -1
  60. package/skills/router-setup/SKILL.md +2 -2
  61. package/skills/scripts/SKILL.md +3 -3
  62. package/skills/shell-manifest/SKILL.md +3 -3
  63. package/skills/testing/client-components.md +1 -1
  64. package/skills/testing/serve-shell-request.md +1 -1
  65. package/skills/theme/SKILL.md +2 -2
  66. package/skills/typesafety/env-and-bindings.md +2 -2
  67. package/skills/use-cache/SKILL.md +1 -1
  68. package/skills/ux-architecture/SKILL.md +7 -7
  69. package/src/browser/navigation-bridge.ts +2 -1
  70. package/src/browser/react/Link.tsx +13 -2
  71. package/src/browser/react/use-link-status.ts +40 -22
  72. package/src/browser/types.ts +2 -0
  73. package/src/cache/shell-snapshot.ts +1 -1
  74. package/src/cache/types.ts +1 -1
  75. package/src/client-urls/client-urls.ts +16 -9
  76. package/src/client-urls/server-projection.ts +4 -4
  77. package/src/client-urls/types.ts +6 -6
  78. package/src/decode-loader-results.ts +1 -1
  79. package/src/errors.ts +9 -9
  80. package/src/handles/meta.ts +2 -2
  81. package/src/loader-store.ts +1 -1
  82. package/src/outlet-context.ts +1 -1
  83. package/src/route-definition/dsl-helpers.ts +4 -8
  84. package/src/route-definition/helpers-types.ts +5 -5
  85. package/src/router/loader-resolution.ts +4 -4
  86. package/src/router/segment-resolution/loader-cache.ts +8 -8
  87. package/src/router/segment-resolution/prefetch-deferral.ts +1 -1
  88. package/src/router/segment-resolution/revalidation.ts +3 -3
  89. package/src/router/types.ts +1 -1
  90. package/src/rsc/shell-capture-constants.ts +3 -3
  91. package/src/rsc/shell-capture.ts +12 -12
  92. package/src/segment-system.tsx +3 -3
  93. package/src/server/context.ts +5 -5
  94. package/src/server/cookie-store.ts +1 -1
  95. package/src/server/request-context.ts +1 -1
  96. package/src/ssr/index.tsx +6 -6
  97. package/src/ssr/ssr-root.tsx +1 -1
  98. package/src/ssr-suspension-warning.ts +4 -4
  99. package/src/testing/render-route.tsx +12 -3
  100. package/src/types/loader-types.ts +19 -19
  101. package/src/types/segments.ts +2 -2
  102. package/src/urls/path-helper-types.ts +4 -4
  103. package/src/urls/pattern-types.ts +1 -1
  104. package/src/vite/discovery/shell-prerender-phase.ts +1 -1
  105. package/src/vite/plugin-types.ts +1 -1
@@ -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
@@ -1057,6 +1058,8 @@ export async function renderRoute(
1057
1058
  /** The loader data the response carries: a prefetch's (prefetch()). */
1058
1059
  seeds?: Record<string, unknown>;
1059
1060
  history?: Pick<NavigateOptionsInternal, "state" | "replace" | "transition">;
1061
+ /** A <Link> click: the clicked instance, as production's entry carries it. */
1062
+ linkId?: string;
1060
1063
  kind?: TransitionWhenKind;
1061
1064
  transition?: boolean;
1062
1065
  streamUntil?: Promise<unknown>;
@@ -1152,6 +1155,9 @@ export async function renderRoute(
1152
1155
  }
1153
1156
  const handle = eventController.startNavigation(
1154
1157
  new URL(target, TEST_ORIGIN).href,
1158
+ navOptions?.linkId === undefined
1159
+ ? undefined
1160
+ : { _linkId: navOptions.linkId },
1155
1161
  );
1156
1162
  // An action made the prefetch stale: once this navigation settled (its
1157
1163
  // commit and its stream), the page revalidates. Production's own guards
@@ -1546,7 +1552,10 @@ export async function renderRoute(
1546
1552
  let prefetchRoot: HTMLElement | undefined;
1547
1553
  const bridge: NavigationBridge = {
1548
1554
  navigate: (target, navigateOptions) =>
1549
- navigate(target, { history: navigateOptions ?? {} }),
1555
+ navigate(target, {
1556
+ history: navigateOptions ?? {},
1557
+ linkId: navigateOptions?._linkId,
1558
+ }),
1550
1559
  refresh: () => refresh(),
1551
1560
  // Back/forward onto the entry history.state holds. Its page is restored
1552
1561
  // when the mount or a navigation wrote the entry, history still holds that
@@ -75,7 +75,7 @@ export type LoaderContext<
75
75
  * later ones stream to the client and apply post-hydration (document lane)
76
76
  * or progressively (navigation/action lanes). To guarantee a loader's
77
77
  * handles are in the SSR'd document, register it as
78
- * `loader(Def, { ssr: false })` so the document render awaits it
78
+ * `loader(Def, { ssr: "await" })` so the document render awaits it
79
79
  * (see {@link LoaderOptions}).
80
80
  *
81
81
  * @example
@@ -175,29 +175,29 @@ export type LoaderFn<
175
175
  /**
176
176
  * SSR delivery for a DSL-registered loader: `loader(Def, { ssr })`.
177
177
  *
178
- * Default (omitted / `true`): the loader streams on every render. Its data,
179
- * its `ctx.use(Handle)` pushes, and any `notFound()`/`redirect()` it throws
180
- * may land AFTER the document Response is constructed, so none of them are
181
- * guaranteed to be in the SSR'd HTML.
178
+ * Default (omitted / `"stream"`): the loader streams on every render. Its
179
+ * data, its `ctx.use(Handle)` pushes, and any `notFound()`/`redirect()` it
180
+ * throws may land AFTER the document Response is constructed, so none of
181
+ * them are guaranteed to be in the SSR'd HTML.
182
182
  *
183
- * `ssr: false` turns SSR streaming off for this loader — the same knob
184
- * `loading(fallback, { ssr: false })` is for the fallback: on a DOCUMENT
185
- * request the loader is awaited before first flush, so no fallback paints for
186
- * it (`useLoader` still suspends, but on an already-settled promise). Client
187
- * navigations keep streaming it. This is the SSR-completeness opt-in. Choose
188
- * it when the loader feeds something that must exist in the document:
189
- * `<head>` meta via a handle, or a real 404 status (an awaited `notFound()`
190
- * deterministically precedes Response construction, where the streamed
191
- * default only wins that race opportunistically). Under ppr it is also the
192
- * BAKE lane: the loader executes at shell capture and its settled return is
183
+ * `ssr: "await"` makes the server renders that produce HTML await this
184
+ * loader: on a DOCUMENT request the loader is awaited before first flush, so
185
+ * no fallback paints for it (`useLoader` still suspends, but on an
186
+ * already-settled promise); a ppr shell capture, at runtime or at build time
187
+ * for a Prerender + ppr route, awaits it too. Client navigations keep
188
+ * streaming it. This is the SSR-completeness opt-in. Choose it when the
189
+ * loader feeds something that must exist in the document: `<head>` meta via
190
+ * a handle, or a real 404 status (an awaited `notFound()` deterministically
191
+ * precedes Response construction, where the streamed default only wins
192
+ * that race opportunistically). Under ppr it is also the BAKE lane: the loader executes at shell capture and its settled return is
193
193
  * shell material (nested promises stay live holes), and so are its handle
194
194
  * pushes, a pushed promise or `.defer()` included: the capture awaits it and
195
195
  * every HIT serves the value it settled to (#1182). A pushed promise that
196
196
  * rejects, or misses `ppr.captureTimeout`, keeps the route on MISS. A value
197
- * that must stay per request belongs to a loader without `ssr: false` — see
197
+ * that must stay per request belongs to a loader without `ssr: "await"` — see
198
198
  * the ppr docs.
199
199
  *
200
- * Scoped per LOADER, not per segment: an `ssr: false` loader alongside a
200
+ * Scoped per LOADER, not per segment: an `ssr: "await"` loader alongside a
201
201
  * deliberately streaming sibling awaits only itself, and the sibling keeps
202
202
  * streaming behind its `loading()`/Suspense boundary. Watch the scoping when
203
203
  * the boundary must be SSR-complete: ONE unflagged read under it still
@@ -206,7 +206,7 @@ export type LoaderFn<
206
206
  * site naming the unflagged loader (ssr-suspension-warning.ts).
207
207
  */
208
208
  export type LoaderOptions = {
209
- ssr?: boolean;
209
+ ssr?: "stream" | "await";
210
210
  /**
211
211
  * `prefetch: false` keeps this loader out of every `<Link>` prefetch: a
212
212
  * prefetch (a partial request with `X-Rango-Prefetch`) does not execute
@@ -236,7 +236,7 @@ export type LoaderOptions = {
236
236
  * Limits: a handler that awaits the loader with `ctx.use()` makes it run in
237
237
  * the prefetch anyway; the loader cannot call `ctx.rendered()` (it throws
238
238
  * on every request); on a `ppr` route the flag is ignored for an
239
- * `ssr: false` loader (the bake lane), with a dev warning. In the fill
239
+ * `ssr: "await"` loader (the bake lane), with a dev warning. In the fill
240
240
  * request only deferred work and middleware run, so values a held handler
241
241
  * would have set with `ctx.set()` are not visible.
242
242
  */
@@ -164,7 +164,7 @@ export interface ResolvedSegment {
164
164
  loaderData?: any; // For loaders: the resolved data from loader execution
165
165
  /**
166
166
  * True when this loader was awaited before first flush
167
- * (loader(Def, { ssr: false })). Stamped by resolveOwnerLoaders on
167
+ * (loader(Def, { ssr: "await" })). Stamped by resolveOwnerLoaders on
168
168
  * document AND shell-capture renders — capture bakes flagged loaders and
169
169
  * awaits the same lane. Feeds segment-system's settled-value delivery and
170
170
  * the dev SSR suspension warning (ssr-suspension-warning.ts).
@@ -185,7 +185,7 @@ export interface ResolvedSegment {
185
185
  loaderIds?: string[]; // IDs ($$id) of loaders for this segment
186
186
  /**
187
187
  * Per-loader UNDECODED results for a layout/route stream map.
188
- * Flagged (ssr:false) entries are settled values; unflagged siblings
188
+ * Flagged (ssr: "await") entries are settled values; unflagged siblings
189
189
  * stay promises. Parallel slots do not use this channel — they pin
190
190
  * loading() / live-lane holes via use(loaderDataPromise).
191
191
  */
@@ -356,10 +356,10 @@ export type PathHelpers<TEnv> = {
356
356
  /**
357
357
  * Attach a data loader to the current route/layout.
358
358
  *
359
- * Pass `{ ssr: false }` — the same knob as loading(fallback, { ssr:
360
- * false }) — to await this loader before first flush on DOCUMENT requests
361
- * (see {@link LoaderOptions}): the opt-in for loaders whose data, handle
362
- * pushes, or thrown notFound()/redirect() must be in the SSR'd HTML.
359
+ * Pass `{ ssr: "await" }` to await this loader before first flush on
360
+ * DOCUMENT requests (see {@link LoaderOptions}): the opt-in for loaders
361
+ * whose data, handle pushes, or thrown notFound()/redirect() must be in the
362
+ * SSR'd HTML.
363
363
  * Per-loader: a streaming sibling keeps streaming. Under a `ppr` route the
364
364
  * flag BAKES: the loader executes at shell capture and its settled return
365
365
  * freezes into the shell (nested promises stay live holes) — the pre-flush
@@ -67,7 +67,7 @@ export interface PartialPrerenderProps {
67
67
  * Upper bound (serialized UTF-8 bytes) on the loader pins in the capture
68
68
  * data snapshot: the bake-lane loader records. The doc record (the handler
69
69
  * layer every HIT replays) is exempt. A document HIT is served only from an
70
- * entry that holds a pin for every `ssr: false` loader its HTML baked, so
70
+ * entry that holds a pin for every `ssr: "await"` loader its HTML baked, so
71
71
  * over the cap no document shell is stored: documents render in full
72
72
  * (MISS), and client navigations still replay the handler layer and run
73
73
  * those loaders fresh. Reported once per key. Defaults to 8 MiB. The whole
@@ -188,7 +188,7 @@ export async function runShellPrerenderPhase(
188
188
  injectRSCPayload: htmlStream.injectRSCPayload,
189
189
  headScripts: "preinit",
190
190
  // Build-captured shells honor the explicit outlining budget, or the
191
- // ssr:false auto-raise without one (createShellCaptureHandler): the
191
+ // ssr: "await" auto-raise without one (createShellCaptureHandler): the
192
192
  // capture value rides the postponed state into every runtime resume().
193
193
  ...(s.opts?.progressiveChunkSize !== undefined && {
194
194
  progressiveChunkSize: s.opts.progressiveChunkSize,
@@ -190,7 +190,7 @@ interface RangoBaseOptions {
190
190
  * which is why React outlines by default.
191
191
  *
192
192
  * When UNSET, document renders and PPR shell captures whose matched chain
193
- * has a `loader(Def, { ssr: false })` entry auto-raise to MAX_SAFE_INTEGER —
193
+ * has a `loader(Def, { ssr: "await" })` entry auto-raise to MAX_SAFE_INTEGER —
194
194
  * the loader was awaited before first flush precisely so its content ships
195
195
  * in-place, and outlining the boundary it feeds would defeat that. A shell
196
196
  * HIT inherits the captured value, so it matches the live render. Setting