@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
@@ -21,7 +21,7 @@ The handler code and its imports are removed from the production bundle.
21
21
  ## Not this skill if…
22
22
 
23
23
  - You want a cached HTML shell captured at runtime, with holes staying live
24
- per request (loaders without `ssr: false` run per request; `ssr: false`
24
+ per request (loaders without `ssr: "await"` run per request; `ssr: "await"`
25
25
  loaders bake) — see `/ppr`.
26
26
  - You want runtime segment caching with TTL/SWR — that is the `cache()` DSL:
27
27
  see `/caching`. Prerender is the same cache filled at build time.
@@ -355,12 +355,12 @@ own shell identity and is captured at runtime. The runtime shell store is read
355
355
  first, so a runtime capture supersedes the baked entry once it exists.
356
356
 
357
357
  Handle values behave as on any `ppr` shell (`/ppr` → "Handles on a shell
358
- HIT"): a value an `ssr: false` loader pushes settled is in the shell's HTML and
358
+ HIT"): a value an `ssr: "await"` loader pushes settled is in the shell's HTML and
359
359
  in the data a HIT hydrates with, and one it pushes as a promise arrives after
360
360
  hydration. The prerendered payload holds only the handler's pushes (loaders
361
361
  never run at build), so the shell entry keeps the loader pushes its HTML
362
362
  rendered, on a build-baked shell and on one captured at runtime alike. A shell
363
- stored by router 0.21 or earlier lacks them, and a promise-free `ssr: false`
363
+ stored by router 0.21 or earlier lacks them, and a promise-free `ssr: "await"`
364
364
  loader's settled push fails hydration on its HITs until the shell is replaced
365
365
  (#1057).
366
366
 
@@ -384,7 +384,7 @@ entry STILL serves and a runtime recapture is scheduled that upgrades it in plac
384
384
  `Prerender` handler is evicted from the production bundle, that recapture never
385
385
  re-runs the handler — it replays the same build-time segments and only refreshes
386
386
  what the capture reads again: `cache()`-scoped data baked into the shell, and
387
- the data of `ssr: false` loaders, which run at every capture. **If the shell
387
+ the data of `ssr: "await"` loaders, which run at every capture. **If the shell
388
388
  bakes neither, `ttl` has nothing to refresh** — reach for `updateTag` (or a
389
389
  redeploy) instead of a shorter `ttl`.
390
390
 
@@ -661,7 +661,7 @@ Passthrough entries are logged distinctly:
661
661
  Loaders on pre-rendered routes run at request time. They are bundled normally
662
662
  and need `cache()` for caching. Do not use build-only APIs in loaders.
663
663
 
664
- The exception is an `ssr: false` loader on a `Prerender` + `ppr` route: the
664
+ The exception is an `ssr: "await"` loader on a `Prerender` + `ppr` route: the
665
665
  build-time shell capture runs it and bakes its settled data into the shell,
666
666
  and a shell HIT runs it only when its return carries promises (`/ppr` → "The
667
667
  bake lane"). The Flight payload collection itself still skips loaders.
@@ -27,7 +27,7 @@ with the shape, then pick a primitive.
27
27
  **stream**, so data latency overlaps first paint instead of blocking it (a
28
28
  cache hit streams UI instantly while loaders resolve fresh alongside). Opt into
29
29
  caching explicitly. See `/loader` → "Parallel and streaming". The one
30
- exception is a `ppr` route's `ssr: false` loader: it bakes into the shell
30
+ exception is a `ppr` route's `ssr: "await"` loader: it bakes into the shell
31
31
  and runs on a shell HIT only when its return carries promises (`/ppr`).
32
32
  - **One identity, one store** — loaders, handles, cached fns, and actions are all
33
33
  `path#export`; all caches share one store. Entries expire by TTL/SWR, and are
@@ -71,7 +71,7 @@ are immune to partial-revalidation staleness by construction.
71
71
 
72
72
  1. **A loader** (`loader()` + `useLoader()`). Loaders resolve fresh on every
73
73
  pass — full renders, action revalidations, cache hits, PPR shell HITs (on a
74
- `ppr` route, keep it off `ssr: false`, which bakes it into the shell).
74
+ `ppr` route, keep it off `ssr: "await"`, which bakes it into the shell).
75
75
  Nothing to keep in sync. If the data can be a loader, make it a loader.
76
76
  2. **Middleware `ctx.set()`**. Route middleware wraps every render pass,
77
77
  including post-action revalidation and PE re-renders, so its variables are
@@ -117,7 +117,7 @@ stated, greppable contract.
117
117
  | modal / soft navigation | `intercept()` | /intercept |
118
118
  | route group of client components | `clientUrls()` in `"use client"` | /client-urls |
119
119
  | set meta/breadcrumbs from loader data | `ctx.use(Handle)` in the loader | /loader |
120
- | guarantee loader output in the SSR HTML | `loader(L, { ssr: false })` | /loader |
120
+ | guarantee loader output in the SSR HTML | `loader(L, { ssr: "await" })` | /loader |
121
121
  | pre-render a route at build time | `Prerender(...)` wrapper | /prerender |
122
122
  | make a route ready before traffic | `router.prerender({ env })(url)` | /prerender |
123
123
  | feed live loaders from a cached shell | replayed handle + `ctx.rendered()` | /shell-manifest |
@@ -130,7 +130,7 @@ stated, greppable contract.
130
130
  - `path()`/`include()` are always visible in `urls()`; config helpers are extractable.
131
131
  - **Cache decides freshness; `revalidate()` decides client-update.** Orthogonal; compose.
132
132
  - Loaders resolve fresh every request (even inside `cache()`) and never run twice/request.
133
- The exception is a `ppr` route's `ssr: false` loader: it bakes into the shell
133
+ The exception is a `ppr` route's `ssr: "await"` loader: it bakes into the shell
134
134
  and runs on a shell HIT only when its return carries promises.
135
135
  - **The consumption-lane rule.** For every shared artifact (`cache()`,
136
136
  `"use cache"`, the PPR shell): server-side handler consumption
@@ -143,14 +143,14 @@ stated, greppable contract.
143
143
  `loader()` binding, or the cached function itself) and REFUSE a PPR capture: the route serves uncached until
144
144
  the read moves to a live loader. Client-side consumption
145
145
  (`useLoader` in a `"use client"` component) is the LIVE lane. DSL
146
- `loader()` segments follow their PPR lane (only `ssr: false` bakes; see
146
+ `loader()` segments follow their PPR lane (only `ssr: "await"` bakes; see
147
147
  `/ppr` → The loader lane rule).
148
148
  - **A PPR shell HIT never runs a handler.** Everything a handler produces
149
149
  (promises it passes under `<Suspense>`, async server components, handle
150
150
  pushes, loaders it awaits) is shell material, as under `cache()`; a HIT
151
- runs middleware and live loaders only (an `ssr: false` loader runs there
151
+ runs middleware and live loaders only (an `ssr: "await"` loader runs there
152
152
  only when its return carries promises). Live data belongs in a loader without
153
- `ssr: false`, read with `useLoader` under `loading()` or an inline
153
+ `ssr: "await"`, read with `useLoader` under `loading()` or an inline
154
154
  `<Suspense>`.
155
155
  - Inside `"use cache"`: `cookies()`/`headers()`/`ctx.request.headers` and `ctx` side-effects
156
156
  (`set`/`header`/`setTheme`/`onResponse`/`setLocationState`) throw; `ctx.use(Handle)`
@@ -482,7 +482,7 @@ loader re-runs on every hit — but a `"use cache"` function a loader calls is
482
482
  not, and neither is a loader bound with its own `cache()` without a `key()` (any
483
483
  `key()` switches the check off, so it must include the value; `/loader` → "Cache
484
484
  Key"). On a `ppr` route the exemption does not cover a loader the shell capture
485
- waits for (`ssr: false`, or awaited by a handler via `ctx.use()`): the read
485
+ waits for (`ssr: "await"`, or awaited by a handler via `ctx.use()`): the read
486
486
  refuses the capture. Cacheable vars (the default) can be read freely inside
487
487
  cache scopes. See `/cache-guide` → "Context Variable Cache Safety".
488
488
 
@@ -254,7 +254,7 @@ Notes:
254
254
  them.
255
255
  - `progressiveChunkSize` sets React's Fizz `progressiveChunkSize` for document
256
256
  renders and PPR shell capture. Unset, documents whose route has a
257
- `loader(Def, { ssr: false })` raise it automatically so that content stays
257
+ `loader(Def, { ssr: "await" })` raise it automatically so that content stays
258
258
  in place; see `/loader`.
259
259
  - `encryptionKey` is the key that encrypts inline server-action bound
260
260
  arguments: base64-encoded 32 bytes (`openssl rand -base64 32`). Pass it as
@@ -504,7 +504,7 @@ When `notFound()` is thrown, the router uses the first of:
504
504
  Handler-thrown and no-match 404s always set HTTP status 404. A loader-thrown
505
505
  `notFound()` on a document request always renders the not-found UI, but the
506
506
  404 status is set only if the loader rejects before the document Response is
507
- constructed (loaders stream). Register the loader as `loader(Def, { ssr: false })` to
507
+ constructed (loaders stream). Register the loader as `loader(Def, { ssr: "await" })` to
508
508
  make the 404 status deterministic. On client navigations the 404 UI swaps in
509
509
  with the URL preserved and the payload stays 200. See `/loader` → "Loader
510
510
  Authority".
@@ -112,11 +112,11 @@ during navigation.
112
112
  > settles before the handler barrier. A push that lands after a slow fetch
113
113
  > arrives post-hydration — and for an inline/ordered script the frozen set
114
114
  > means it is silently dropped. If a loader must contribute an inline script
115
- > to the document, register it `loader(Def, { ssr: false })` so the
115
+ > to the document, register it `loader(Def, { ssr: "await" })` so the
116
116
  > document render awaits the push; otherwise push from a handler (or use an
117
117
  > `async` config, which stays reactive). On a `ppr` route a loader without
118
- > `ssr: false` never runs during the shell capture, so its inline/ordered
119
- > script is dropped on every shell HIT; with `ssr: false` the push bakes into
118
+ > `ssr: "await"` never runs during the shell capture, so its inline/ordered
119
+ > script is dropped on every shell HIT; with `ssr: "await"` the push bakes into
120
120
  > the shell.
121
121
 
122
122
  **Nonce caveat for soft-nav async.** The "nonce is applied automatically" claim
@@ -9,7 +9,7 @@ argument-hint:
9
9
  Use this when a cached or prerendered shell has dynamic holes, and the live
10
10
  data layer needs to know **what the shell actually contains** — which
11
11
  products, which slots, which keys. The frozen render describes itself
12
- through a handle; live loaders (no `ssr: false`) read that description and
12
+ through a handle; live loaders (no `ssr: "await"`) read that description and
13
13
  fetch exactly the dynamic data the shell needs, in one batch.
14
14
 
15
15
  Canonical case: a prerendered product list where prices must stay live.
@@ -36,7 +36,7 @@ batched.
36
36
  cache miss for `cache()`. (Loader bodies can push handles too — see `/loader`
37
37
  — but a live loader's push is request-time and is NOT part of the replayed
38
38
  artifact; a manifest handle must be pushed by the code that gets frozen with
39
- the shell. An `ssr: false` loader on a `ppr` route is the exception: its
39
+ the shell. An `ssr: "await"` loader on a `ppr` route is the exception: its
40
40
  settled pushes are recorded with the shell. On a HIT, one whose return has no
41
41
  promises does not run (unless the capture marked it to run), so the recorded
42
42
  pushes are what the page shows; one whose return carries promises runs on
@@ -157,7 +157,7 @@ cache({ ttl: 600, tags: ["products"] }, () => [
157
157
  fetchable/standalone loader calls that run outside a route render, in
158
158
  handler-invoked loaders (a handler already awaiting the loader via
159
159
  `ctx.use()` is a detected deadlock), and in loaders registered with
160
- `{ ssr: false }` (the document render awaits the loader before
160
+ `{ ssr: "await" }` (the document render awaits the loader before
161
161
  the barrier — a cycle by construction; see `/loader`).
162
162
  - **The reading loader serializes after the shell.** `await ctx.rendered()`
163
163
  deliberately gives up loader/render parallelism — on a miss the loader
@@ -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 () => ...)`. |
@@ -250,7 +250,7 @@ Vitest runs no Vite id transform, so give each router an explicit `id` when a te
250
250
  | `hydration` | What the document hydrates with (`metadata.handles`, read to its end before hydration starts). For a `partial` request, the last state it streamed. |
251
251
  | `late` | The states that arrived on the late channel (`metadata.handlesLate`), in order. Each replaces the client's handle data after hydration. Often `[]`. |
252
252
 
253
- On a HIT the client hydrates with exactly what the shell was rendered from, so `hydration` is also what the shell's HTML holds (the handlers' pushes and the `ssr: false` loaders', a pushed promise resolved), and whatever this request's loaders push, replace or drop is in `late` (see `/ppr`, "Handles on a shell HIT"):
253
+ On a HIT the client hydrates with exactly what the shell was rendered from, so `hydration` is also what the shell's HTML holds (the handlers' pushes and the `ssr: "await"` loaders', a pushed promise resolved), and whatever this request's loaders push, replace or drop is in `late` (see `/ppr`, "Handles on a shell HIT"):
254
254
 
255
255
  ```ts
256
256
  // The handler pushed ctx.use(Notes)("from-handler"); a live loader pushes
@@ -141,10 +141,10 @@ Read the theme where it is per request instead:
141
141
  visitor with no stored theme sees the default, and one with a stored theme
142
142
  sees it after hydration. Any other render, a 404 included, starts at the
143
143
  visitor's own theme.
144
- - A live loader (no `ssr: false`). Loaders do not get `ctx.theme` or
144
+ - A live loader (no `ssr: "await"`). Loaders do not get `ctx.theme` or
145
145
  `ctx.setTheme`; read the cookie directly. A live loader runs on every
146
146
  request, HITs included, and on a `ppr` route needs `loading()` or an inline
147
- `<Suspense>` above its reader. A bake-lane loader (`ssr: false`) runs at
147
+ `<Suspense>` above its reader. A bake-lane loader (`ssr: "await"`) runs at
148
148
  capture, where this `cookies()` read refuses the capture, and so does a
149
149
  loader a handler awaits with `ctx.use()`.
150
150
 
@@ -118,9 +118,9 @@ marks a specific write as non-cacheable even if the var itself is cacheable.
118
118
  "Least cacheable wins" — if either says `cache: false`, the value throws on
119
119
  read inside `cache()` or `"use cache"`. On a `ppr` route the read also throws
120
120
  anywhere the shell capture waits for it (a handler, a promise it passes or
121
- pushes, an async server component, an `ssr: false` loader, a loader a handler
121
+ pushes, an async server component, an `ssr: "await"` loader, a loader a handler
122
122
  awaits) and refuses the capture: the route keeps rendering without a shell,
123
- and a warning fires once per key. A loader without `ssr: false` that no
123
+ and a warning fires once per key. A loader without `ssr: "await"` that no
124
124
  handler awaits may read it, unless it is bound with its own `cache()` and no
125
125
  `key()`: that miss fails, since the entry is shared (`/loader` → "Cache
126
126
  Key").
@@ -655,7 +655,7 @@ this isolate's invalidations are caught; ttl+swr bounds the rest.
655
655
 
656
656
  Inside a `ppr` shell, a `"use cache"` value that renders as shell material is
657
657
  pinned at capture time for the life of that shell (see `/ppr` → Pitfalls). A
658
- hole's own read (in a loader without `ssr: false` under `loading()` or an
658
+ hole's own read (in a loader without `ssr: "await"` under `loading()` or an
659
659
  inline `<Suspense>`) always returns the store's current entry, never the
660
660
  shell's copy, even when a loader the capture ran read the same entry.
661
661
 
@@ -53,10 +53,10 @@ hand, is a router bug: report it.
53
53
 
54
54
  ### 2.1 A server urls() page or a clientUrls() group?
55
55
 
56
- | Pick | When | What you get |
57
- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
58
- | A server `urls()` route with a handler | Pages people mostly reach by a document load (marketing, docs, articles, landing pages). Pages built from server components you don't want to ship as client code. Routes that need `cache()`, `Prerender()`, `parallel()`, `middleware()` or an `errorBoundary()` on the route itself. | The handler renders on the server, and `cache()` or a prerender can store its output. A click with no prefetch waits for the server before the page changes; a prefetched click does not. |
59
- | A `clientUrls()` group | An area where people move a lot inside one layout: dashboards, admin, settings, tabs, filters, master and detail. Pages that are client components anyway. | The browser matches the group, so a click to another route of the group renders the destination at once, before the server answers. Param and search changes on one route reconcile and hold. There are no handlers: every read is a `useLoader` under its own boundary. A document load is still rendered on the server, and `loader(Def, { ssr: false })` puts a loader's data and handles in that HTML. |
56
+ | Pick | When | What you get |
57
+ | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
58
+ | A server `urls()` route with a handler | Pages people mostly reach by a document load (marketing, docs, articles, landing pages). Pages built from server components you don't want to ship as client code. Routes that need `cache()`, `Prerender()`, `parallel()`, `middleware()` or an `errorBoundary()` on the route itself. | The handler renders on the server, and `cache()` or a prerender can store its output. A click with no prefetch waits for the server before the page changes; a prefetched click does not. |
59
+ | A `clientUrls()` group | An area where people move a lot inside one layout: dashboards, admin, settings, tabs, filters, master and detail. Pages that are client components anyway. | The browser matches the group, so a click to another route of the group renders the destination at once, before the server answers. Param and search changes on one route reconcile and hold. There are no handlers: every read is a `useLoader` under its own boundary. A document load is still rendered on the server, and `loader(Def, { ssr: "await" })` puts a loader's data and handles in that HTML. |
60
60
 
61
61
  Two limits of a group decide some cases:
62
62
 
@@ -436,7 +436,7 @@ The rule: **prefetch broadly, and flag what is expensive.**
436
436
  `ctx.use(Breadcrumbs)({ label, href })`. This is how a group, which has no
437
437
  handlers, sets them (`/breadcrumbs`, "Pushing from Loaders").
438
438
  - Read them in chrome with `useHandle(Breadcrumbs)`, in a layout that stays.
439
- - `loader(Def, { ssr: false })` puts its pushes in the document's HTML (a
439
+ - `loader(Def, { ssr: "await" })` puts its pushes in the document's HTML (a
440
440
  title for search engines, a real 404 from `notFound()`). The document waits
441
441
  for that loader; flag only the one that needs it.
442
442
  - A loader an action skips keeps its title and crumbs
@@ -633,7 +633,7 @@ export default clientUrls(({ path, layout, loader, revalidate }) => [
633
633
  loader(ProductsLoader, () => [revalidate(bySearch)]),
634
634
  ]),
635
635
  path("/product/:slug", ProductPage, { name: "product" }, () => [
636
- loader(ProductLoader, { ssr: false }, () => [revalidate(bySlug)]),
636
+ loader(ProductLoader, { ssr: "await" }, () => [revalidate(bySlug)]),
637
637
  loader(RelatedLoader, () => [revalidate(bySlug)]),
638
638
  loader(ReviewsLoader, { prefetch: false }, () => [revalidate(bySlug)]),
639
639
  ]),
@@ -647,7 +647,7 @@ Why each placement:
647
647
  | ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
648
648
  | Catalog and product in one group | A card click renders the product page at the click; the filters and tabs are same-route navigations that hold. |
649
649
  | `CartLoader` on the server layout, ternary predicate | Held on every navigation (a server layout loader's default), re-run only after a cart action. It survives entering and leaving the group. The badge updates in the add-to-cart response itself. |
650
- | `ProductLoader` with `ssr: false` | The product's title and a real 404 for an unknown slug are in the document's HTML. Client navigations still stream it. |
650
+ | `ProductLoader` with `ssr: "await"` | The product's title and a real 404 for an unknown slug are in the document's HTML. Client navigations still stream it. |
651
651
  | `bySlug` on the product loaders | Product to product re-runs them; a tab switch and an add to cart hold them. One action, three outcomes: the badge refreshes, product and related keep their data (`client-shop-cart.test.ts`). |
652
652
  | `ReviewsLoader` flagged `prefetch: false` | Every visible card prefetches; reviews are the expensive, rarely read part. The click still shows the product at once and the reviews fill behind their own boundary. A prefetch from another product page (the related links) still runs it: only a segment new to the page is deferred. |
653
653
  | One `<Suspense>` per section | A slow product loader fills its section without holding the related list, and the other way round (the demo's product loader takes 2 s). |
@@ -285,7 +285,7 @@ export function createNavigationBridge(
285
285
  hops: number,
286
286
  options: Pick<
287
287
  NavigateOptionsInternal,
288
- "replace" | "transition" | "_redirectFrom"
288
+ "replace" | "transition" | "_redirectFrom" | "_linkId"
289
289
  >,
290
290
  ): Promise<void> {
291
291
  const redirectUrl = validateRedirectOrigin(
@@ -715,6 +715,7 @@ export function createNavigationBridge(
715
715
  replace: options?.replace,
716
716
  transition: options?.transition,
717
717
  _redirectFrom: options?._redirectFrom,
718
+ _linkId: options?._linkId,
718
719
  },
719
720
  );
720
721
  }
@@ -5,13 +5,14 @@ import React, {
5
5
  useCallback,
6
6
  useContext,
7
7
  useEffect,
8
+ useId,
8
9
  useMemo,
9
10
  useRef,
10
11
  type ForwardRefExoticComponent,
11
12
  type RefAttributes,
12
13
  } from "react";
13
14
  import { NavigationStoreContext } from "./context.js";
14
- import { LinkContext } from "./use-link-status.js";
15
+ import { LinkContext, type LinkTarget } from "./use-link-status.js";
15
16
  import type { HistoryState } from "../types.js";
16
17
  import {
17
18
  isHashOnlyNavigation,
@@ -258,6 +259,14 @@ export const Link: ForwardRefExoticComponent<
258
259
  [to, isExternal, ctx?.basename],
259
260
  );
260
261
 
262
+ // This instance's id: its click names it on the navigation, so
263
+ // useLinkStatus marks this link and not every link to the same URL.
264
+ const linkId = useId();
265
+ const linkTarget = useMemo<LinkTarget>(
266
+ () => ({ to: resolvedTo, id: linkId }),
267
+ [resolvedTo, linkId],
268
+ );
269
+
261
270
  // No explicit `prefetch` prop: fall back to the router-wide default from
262
271
  // the router store. Adaptive is resolved against the input capability when a
263
272
  // prefetch is armed or triggered, never during render.
@@ -344,10 +353,12 @@ export const Link: ForwardRefExoticComponent<
344
353
  state,
345
354
  revalidate,
346
355
  transition,
356
+ _linkId: linkId,
347
357
  });
348
358
  },
349
359
  [
350
360
  resolvedTo,
361
+ linkId,
351
362
  isExternal,
352
363
  reloadDocument,
353
364
  replace,
@@ -494,7 +505,7 @@ export const Link: ForwardRefExoticComponent<
494
505
  data-transition={transition === false ? "false" : undefined}
495
506
  {...props}
496
507
  >
497
- <LinkContext.Provider value={resolvedTo}>{children}</LinkContext.Provider>
508
+ <LinkContext.Provider value={linkTarget}>{children}</LinkContext.Provider>
498
509
  </a>
499
510
  );
500
511
  });
@@ -11,12 +11,20 @@ import { NavigationStoreContext } from "./context.js";
11
11
  import type { EventController, NavigationEntry } from "../event-controller.js";
12
12
 
13
13
  /**
14
- * Context for Link component to provide its destination URL
15
- * Used by useLinkStatus to determine if this specific link is pending
14
+ * What a Link hands to useLinkStatus: its resolved destination and an id for
15
+ * this Link instance, which its click puts on the navigation (`_linkId`).
16
16
  */
17
- export const LinkContext: Context<string | null> = createContext<string | null>(
18
- null,
19
- );
17
+ export interface LinkTarget {
18
+ readonly to: string;
19
+ readonly id: string;
20
+ }
21
+
22
+ /**
23
+ * Context for Link component to provide its destination and instance id.
24
+ * Used by useLinkStatus to determine if this specific link is pending.
25
+ */
26
+ export const LinkContext: Context<LinkTarget | null> =
27
+ createContext<LinkTarget | null>(null);
20
28
 
21
29
  /**
22
30
  * Link status returned by useLinkStatus hook
@@ -53,18 +61,25 @@ function visibleNavigation(ec: EventController): NavigationEntry | null {
53
61
  }
54
62
 
55
63
  /**
56
- * Whether `navigation` goes to `linkTo`: its URL or, after a server redirect,
57
- * the URL its chain started from.
64
+ * Whether `navigation` is this link's. A Link's click names the link
65
+ * (`_linkId`, kept through a server redirect chain), so only that link is
66
+ * pending, not every link to the same URL. A navigation no Link started
67
+ * (Back/Forward, router.push, an action's redirect) goes to every link to its
68
+ * URL or, after a server redirect, to the URL its chain started from.
58
69
  */
59
70
  function isPendingFor(
60
- linkTo: string | null,
71
+ link: LinkTarget | null,
61
72
  navigation: NavigationEntry | null,
62
73
  origin: string,
63
74
  ): boolean {
64
- if (linkTo === null || !navigation) {
75
+ if (link === null || !navigation) {
65
76
  return false;
66
77
  }
67
- const to = normalizeUrl(linkTo, origin);
78
+ const linkId = navigation.options?._linkId;
79
+ if (linkId !== undefined) {
80
+ return linkId === link.id;
81
+ }
82
+ const to = normalizeUrl(link.to, origin);
68
83
  const from = navigation.options?._redirectFrom;
69
84
  return (
70
85
  normalizeUrl(navigation.url, origin) === to ||
@@ -75,11 +90,12 @@ function isPendingFor(
75
90
  /**
76
91
  * Hook to track the pending state of a Link component
77
92
  *
78
- * Must be used inside a Link component. Returns `{ pending: true }` while a
79
- * navigation to the link's destination is in flight, until the page it
80
- * brings commits: under transition() while React holds that page, and
81
- * through a server redirect until the target page commits. A newer
82
- * navigation ends it at once.
93
+ * Must be used inside a Link component. Returns `{ pending: true }` while
94
+ * this link's navigation is in flight, until the page it brings commits:
95
+ * under transition() while React holds that page, and through a server
96
+ * redirect until the target page commits. A click marks only the clicked
97
+ * link; a navigation no link started (Back/Forward, router.push) marks every
98
+ * link to its URL. A newer navigation ends it at once.
83
99
  *
84
100
  * Useful for showing inline loading indicators on individual links.
85
101
  *
@@ -98,7 +114,7 @@ function isPendingFor(
98
114
  * ```
99
115
  */
100
116
  export function useLinkStatus(): LinkStatus {
101
- const linkTo = useContext(LinkContext);
117
+ const link = useContext(LinkContext);
102
118
  const ctx = useContext(NavigationStoreContext);
103
119
 
104
120
  const origin = ctx?.origin ?? "http://localhost";
@@ -108,7 +124,7 @@ export function useLinkStatus(): LinkStatus {
108
124
  () =>
109
125
  !!ctx &&
110
126
  !ctx.eventController.getHydrationSnapshot() &&
111
- isPendingFor(linkTo, visibleNavigation(ctx.eventController), origin),
127
+ isPendingFor(link, visibleNavigation(ctx.eventController), origin),
112
128
  );
113
129
 
114
130
  // The value commits in the lane of the notification that carries it, as
@@ -117,9 +133,11 @@ export function useLinkStatus(): LinkStatus {
117
133
  // notification inside the page's update). Set once per navigation: a
118
134
  // repeated urgent set would commit ahead of a held page's settle. A
119
135
  // background navigation (an action's refetch) is not a newer one, so a
120
- // held link stays pending.
136
+ // held link stays pending. Deps are the link's fields, not the object: a
137
+ // provider's new object with the same fields must not resubscribe and set
138
+ // the value again.
121
139
  useEffect(() => {
122
- if (!ctx || linkTo === null) {
140
+ if (!ctx || link === null) {
123
141
  return;
124
142
  }
125
143
 
@@ -128,7 +146,7 @@ export function useLinkStatus(): LinkStatus {
128
146
  const navigation = visibleNavigation(ctx.eventController);
129
147
  if (navigation === last) return;
130
148
  last = navigation;
131
- setPending(isPendingFor(linkTo, navigation, origin));
149
+ setPending(isPendingFor(link, navigation, origin));
132
150
  };
133
151
 
134
152
  // Catch-up: re-read state synchronously on mount before subscribing, so a
@@ -138,10 +156,10 @@ export function useLinkStatus(): LinkStatus {
138
156
  update();
139
157
 
140
158
  return ctx.eventController.subscribe(update);
141
- }, [linkTo, origin]);
159
+ }, [link?.to, link?.id, origin]);
142
160
 
143
161
  // If not inside a Link, return not pending
144
- if (linkTo === null) {
162
+ if (link === null) {
145
163
  return { pending: false };
146
164
  }
147
165
 
@@ -525,6 +525,8 @@ export interface NavigateOptionsInternal extends Omit<
525
525
  _redirectHops?: number;
526
526
  /** The URL a redirected navigation chain started from: a link to it stays pending (useLinkStatus) */
527
527
  _redirectFrom?: string;
528
+ /** The Link instance whose click started this navigation chain: only that link is pending (useLinkStatus) */
529
+ _linkId?: string;
528
530
  }
529
531
 
530
532
  /**
@@ -5,7 +5,7 @@
5
5
  * that must agree with them byte for byte. The handler layer's part of that
6
6
  * payload is the capture's own doc segment record: the capture writes it
7
7
  * first, renders its prelude from it, and every HIT replays it (no handler
8
- * runs on a HIT). The loader layer's part is the bake-lane (`ssr: false`)
8
+ * runs on a HIT). The loader layer's part is the bake-lane (`ssr: "await"`)
9
9
  * loader pins: a promise-free bake-lane loader is served from its pin and
10
10
  * does not run; one whose return carries promises (`holes`), or whose pushes
11
11
  * the record could not keep (`runs`), runs on the HIT. See
@@ -841,7 +841,7 @@ export type SegmentHandleData = Record<string, unknown[]>;
841
841
  /**
842
842
  * segmentId -> handleName -> the owning loader id of each recorded value, by
843
843
  * index (null: not owned). Only a PPR shell capture writes owners: the
844
- * settled pushes of the loader bodies it ran (an `ssr: false` loader's own,
844
+ * settled pushes of the loader bodies it ran (an `ssr: "await"` loader's own,
845
845
  * the loaders it awaits, and its own cache() replays), which the record keeps
846
846
  * because the prelude rendered them. A restore of the record
847
847
  * (handle-snapshot.ts restoreHandles) keeps an owner's value where the
@@ -141,7 +141,7 @@ interface LoaderItem extends ItemBase {
141
141
  readonly type: "loader";
142
142
  readonly definition: LoaderDefinition<any, any>;
143
143
  readonly revalidate: ClientUrlLoaderRecord["revalidate"];
144
- readonly ssr?: false;
144
+ readonly ssr?: "await";
145
145
  readonly prefetch?: PrefetchFlag;
146
146
  }
147
147
 
@@ -348,14 +348,21 @@ export const loader: ClientUrlHelpers["loader"] = (
348
348
  const use = typeof optionsOrUse === "function" ? optionsOrUse : maybeUse;
349
349
  if ((options as { stream?: unknown } | undefined)?.stream !== undefined) {
350
350
  throw new Error(
351
- "clientUrls() loader() stream was replaced: use loader(Def, { ssr: false }) — the same knob as loading(fallback, { ssr: false }) — to await the loader before first flush on document requests.",
351
+ 'clientUrls() loader() stream was replaced: use loader(Def, { ssr: "await" }) to await the loader before first flush on document requests.',
352
352
  );
353
353
  }
354
- // Inline, not errors.ts assertBooleanOption: this module is in the
355
- // client router chunk, where the helper costs 20 B gzip.
356
- if (options?.ssr !== undefined && typeof options.ssr !== "boolean") {
354
+ // Inline, not errors.ts assertLoaderSsrOption: this module is in the
355
+ // client router chunk, where the helper costs bytes on every page.
356
+ if (
357
+ options?.ssr !== undefined &&
358
+ options.ssr !== "stream" &&
359
+ options.ssr !== "await"
360
+ ) {
357
361
  throw new Error(
358
- `clientUrls() loader() ssr must be a boolean (got ${JSON.stringify(options.ssr)}). Omit it (or pass true) to stream on every render.`,
362
+ process.env.NODE_ENV !== "production" &&
363
+ (options.ssr as unknown) === false
364
+ ? 'clientUrls() loader() ssr: false was replaced: use loader(Def, { ssr: "await" }) to await the loader before first flush on document requests.'
365
+ : `clientUrls() loader() ssr must be "stream" or "await" (got ${JSON.stringify(options.ssr)}). Omit it (or pass "stream") to stream on every render.`,
359
366
  );
360
367
  }
361
368
  if (
@@ -380,7 +387,7 @@ export const loader: ClientUrlHelpers["loader"] = (
380
387
  item.type === "revalidate",
381
388
  )
382
389
  .map((item) => item.fn),
383
- ...(options?.ssr === false ? { ssr: false as const } : {}),
390
+ ...(options?.ssr === "await" ? { ssr: "await" as const } : {}),
384
391
  ...(isPrefetchFlag(options?.prefetch)
385
392
  ? { prefetch: options.prefetch }
386
393
  : {}),
@@ -580,7 +587,7 @@ function createHelpers(): ClientUrlHelpers {
580
587
  // await can never apply, so accepting the flag would be silently inert.
581
588
  if (item.type === "loader" && item.ssr !== undefined) {
582
589
  throw new Error(
583
- "clientUrls() intercept() loaders cannot use ssr: false — intercepts render on client navigations only",
590
+ 'clientUrls() intercept() loaders cannot use ssr: "await" — intercepts render on client navigations only',
584
591
  );
585
592
  }
586
593
  }
@@ -633,7 +640,7 @@ function applyConfig(
633
640
  Object.freeze({
634
641
  loader: item.definition,
635
642
  revalidate: Object.freeze([...item.revalidate]),
636
- ...(item.ssr === false ? { ssr: false as const } : {}),
643
+ ...(item.ssr === "await" ? { ssr: "await" as const } : {}),
637
644
  ...(item.prefetch !== undefined ? { prefetch: item.prefetch } : {}),
638
645
  }),
639
646
  );
@@ -103,7 +103,7 @@ export interface ClientUrlProjectionRoute {
103
103
  readonly options: ClientUrlProjectionOptions;
104
104
  readonly loaderIds: readonly string[];
105
105
  readonly hasLoading: boolean;
106
- /** Indices into loaderIds of loaders declared loader(Def, { ssr: false });
106
+ /** Indices into loaderIds of loaders declared loader(Def, { ssr: "await" });
107
107
  * materialization passes the option through to the server loader() so
108
108
  * document renders await them before first flush. Absent (= none) in
109
109
  * projections serialized before the option existed. */
@@ -348,7 +348,7 @@ function serializeRoute(
348
348
 
349
349
  const awaitedLoaderIndices = indicesWhere(
350
350
  route.loaders,
351
- ({ ssr }) => ssr === false,
351
+ ({ ssr }) => ssr === "await",
352
352
  );
353
353
 
354
354
  const transition = serializeTransition(route);
@@ -832,7 +832,7 @@ function materializeRouteItems(
832
832
  };
833
833
 
834
834
  // The loader() items of a route's or an intercept's projected loaders: each
835
- // stub with its `ssr: false` and `prefetch` flags and its revalidate()
835
+ // stub with its `ssr: "await"` and `prefetch` flags and its revalidate()
836
836
  // predicates.
837
837
  const materializeLoaders = (owner: ProjectedLoaders) =>
838
838
  owner.projected.loaderIds.map((id, loaderIndex) => {
@@ -841,7 +841,7 @@ function materializeRouteItems(
841
841
  createLoaderStub(id),
842
842
  {
843
843
  ...(owner.projected.awaitedLoaderIndices?.includes(loaderIndex) && {
844
- ssr: false,
844
+ ssr: "await" as const,
845
845
  }),
846
846
  ...(owner.projected.deferrableLoaderIndices?.includes(
847
847
  loaderIndex,