@rangojs/router 0.24.4 → 0.26.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 (301) hide show
  1. package/README.md +1 -0
  2. package/dist/bin/rango.js +363 -39
  3. package/dist/testing/vitest.js +37 -4
  4. package/dist/types/browser/event-controller.d.ts +24 -5
  5. package/dist/types/browser/intercept-utils.d.ts +5 -2
  6. package/dist/types/browser/merge-segment-loaders.d.ts +0 -23
  7. package/dist/types/browser/navigation-transaction.d.ts +5 -5
  8. package/dist/types/browser/partial-update.d.ts +21 -13
  9. package/dist/types/browser/prefetch/cache.d.ts +8 -0
  10. package/dist/types/browser/rango-marker.d.ts +7 -0
  11. package/dist/types/browser/react/filter-segment-order.d.ts +10 -0
  12. package/dist/types/browser/react/use-handle.d.ts +20 -0
  13. package/dist/types/browser/react/use-href.d.ts +6 -0
  14. package/dist/types/browser/react/use-router.d.ts +6 -1
  15. package/dist/types/browser/response-adapter.d.ts +5 -3
  16. package/dist/types/browser/scroll-restoration.d.ts +9 -3
  17. package/dist/types/browser/segment-reconciler.d.ts +10 -13
  18. package/dist/types/browser/types.d.ts +38 -8
  19. package/dist/types/build/route-types/per-module-writer.d.ts +12 -0
  20. package/dist/types/cache/cf/cf-cache-store.d.ts +0 -2
  21. package/dist/types/cache/cf/cf-cache-types.d.ts +0 -16
  22. package/dist/types/cache/cf/cf-shell-frame.d.ts +2 -0
  23. package/dist/types/cache/handle-snapshot.d.ts +2 -2
  24. package/dist/types/cache/types.d.ts +16 -6
  25. package/dist/types/cache/vercel/vercel-cache-store.d.ts +1 -15
  26. package/dist/types/client-urls/client-urls.d.ts +6 -2
  27. package/dist/types/client-urls/revalidate-registry.d.ts +1 -1
  28. package/dist/types/client-urls/server-projection.d.ts +9 -5
  29. package/dist/types/client-urls/types.d.ts +29 -16
  30. package/dist/types/client.d.ts +2 -2
  31. package/dist/types/client.rsc.d.ts +2 -2
  32. package/dist/types/decode-loader-results.d.ts +28 -7
  33. package/dist/types/handles/deferred-resolution.d.ts +3 -2
  34. package/dist/types/handles/meta.d.ts +5 -0
  35. package/dist/types/href-client.d.ts +3 -1
  36. package/dist/types/index.rsc.d.ts +1 -1
  37. package/dist/types/loader-redirect.d.ts +2 -3
  38. package/dist/types/outlet-context.d.ts +7 -6
  39. package/dist/types/prefetch-markers.d.ts +14 -5
  40. package/dist/types/prerender/build-shell-capture.d.ts +1 -2
  41. package/dist/types/prerender/writable-store.d.ts +2 -3
  42. package/dist/types/route-content-wrapper.d.ts +17 -14
  43. package/dist/types/route-definition/helpers-types.d.ts +7 -2
  44. package/dist/types/route-definition/resolve-handler-use.d.ts +6 -1
  45. package/dist/types/route-definition/rewrite.d.ts +48 -5
  46. package/dist/types/route-types.d.ts +2 -2
  47. package/dist/types/router/handler-context.d.ts +14 -2
  48. package/dist/types/router/intercept-resolution.d.ts +19 -46
  49. package/dist/types/router/lazy-includes.d.ts +7 -0
  50. package/dist/types/router/match-middleware/intercept-resolution.d.ts +2 -2
  51. package/dist/types/router/middleware.d.ts +0 -16
  52. package/dist/types/router/navigation-snapshot.d.ts +2 -0
  53. package/dist/types/router/prefetch-cache-ttl.d.ts +8 -11
  54. package/dist/types/router/revalidation.d.ts +8 -1
  55. package/dist/types/router/router-context.d.ts +4 -16
  56. package/dist/types/router/router-interfaces.d.ts +0 -11
  57. package/dist/types/router/router-options.d.ts +4 -27
  58. package/dist/types/router/segment-resolution/mask-nested.d.ts +5 -3
  59. package/dist/types/router/segment-resolution/prefetch-deferral.d.ts +31 -8
  60. package/dist/types/router/segment-resolution/revalidation.d.ts +38 -4
  61. package/dist/types/router/segment-resolution.d.ts +1 -1
  62. package/dist/types/router/segment-wrappers.d.ts +3 -5
  63. package/dist/types/router/substitute-pattern-params.d.ts +3 -2
  64. package/dist/types/router/tracing.d.ts +2 -2
  65. package/dist/types/router-versions.d.ts +8 -6
  66. package/dist/types/rsc/full-payload.d.ts +14 -2
  67. package/dist/types/rsc/helpers.d.ts +8 -0
  68. package/dist/types/rsc/manifest-init.d.ts +20 -0
  69. package/dist/types/rsc/prefetch-render-error.d.ts +22 -0
  70. package/dist/types/rsc/progressive-enhancement.d.ts +20 -0
  71. package/dist/types/rsc/rewrite-passes.d.ts +12 -2
  72. package/dist/types/rsc/server-action.d.ts +6 -0
  73. package/dist/types/rsc/shell-capture-constants.d.ts +14 -4
  74. package/dist/types/rsc/shell-capture.d.ts +23 -2
  75. package/dist/types/rsc/types.d.ts +5 -8
  76. package/dist/types/segment-system.d.ts +15 -0
  77. package/dist/types/server/build-version-table.d.ts +10 -13
  78. package/dist/types/server/context.d.ts +90 -6
  79. package/dist/types/server/handle-store.d.ts +17 -6
  80. package/dist/types/server/request-context.d.ts +45 -7
  81. package/dist/types/server/request-headers.d.ts +12 -0
  82. package/dist/types/server/rewrite-trail.d.ts +8 -1
  83. package/dist/types/testing/build-versions.d.ts +0 -3
  84. package/dist/types/testing/e2e/index.d.ts +1 -1
  85. package/dist/types/testing/flight.entry.d.ts +1 -1
  86. package/dist/types/testing/index.d.ts +1 -1
  87. package/dist/types/testing/internal/client-urls-projection.d.ts +4 -3
  88. package/dist/types/testing/internal/seed-vars.d.ts +4 -4
  89. package/dist/types/testing/render-route.d.ts +21 -11
  90. package/dist/types/testing/run-loader.d.ts +7 -0
  91. package/dist/types/testing/run-middleware.d.ts +7 -0
  92. package/dist/types/testing/run-revalidate.d.ts +5 -4
  93. package/dist/types/testing/serve-shell-request.d.ts +42 -5
  94. package/dist/types/testing/shell-status.d.ts +17 -0
  95. package/dist/types/testing/vitest-stubs/version.d.ts +1 -0
  96. package/dist/types/testing/vitest.d.ts +10 -1
  97. package/dist/types/thenable-status.d.ts +0 -6
  98. package/dist/types/types/handler-context.d.ts +12 -1
  99. package/dist/types/types/loader-types.d.ts +10 -4
  100. package/dist/types/types/route-entry.d.ts +2 -1
  101. package/dist/types/urls/path-helper-types.d.ts +4 -2
  102. package/dist/types/vite/discovery/client-urls-projection.d.ts +55 -5
  103. package/dist/types/vite/discovery/state.d.ts +20 -0
  104. package/dist/types/vite/plugins/client-urls-revalidate-hoist.d.ts +28 -16
  105. package/dist/types/vite/plugins/hoist/source.d.ts +8 -7
  106. package/dist/types/vite/plugins/virtual-entries.d.ts +6 -0
  107. package/dist/types/vite/utils/prerender-utils.d.ts +7 -0
  108. package/dist/vite/index.js +6819 -6555
  109. package/package.json +1 -1
  110. package/skills/app-structure/SKILL.md +255 -0
  111. package/skills/app-structure/content-site.md +333 -0
  112. package/skills/app-structure/e-commerce.md +435 -0
  113. package/skills/app-structure/large-app.md +885 -0
  114. package/skills/app-structure/multi-app.md +280 -0
  115. package/skills/breadcrumbs/SKILL.md +6 -1
  116. package/skills/cache-guide/SKILL.md +4 -8
  117. package/skills/caching/SKILL.md +6 -6
  118. package/skills/catalog.json +12 -0
  119. package/skills/client-urls/SKILL.md +185 -32
  120. package/skills/comparison/references/framework-comparison.md +1 -1
  121. package/skills/composability/SKILL.md +10 -8
  122. package/skills/handler-use/SKILL.md +48 -9
  123. package/skills/hooks/handle-and-actions.md +104 -0
  124. package/skills/hooks/navigation.md +24 -10
  125. package/skills/hooks/urls.md +1 -1
  126. package/skills/host-router/SKILL.md +1 -1
  127. package/skills/i18n/SKILL.md +2 -1
  128. package/skills/intercept/SKILL.md +60 -29
  129. package/skills/layout/SKILL.md +6 -3
  130. package/skills/links/SKILL.md +151 -17
  131. package/skills/loader/SKILL.md +42 -19
  132. package/skills/middleware/SKILL.md +111 -15
  133. package/skills/observability/SKILL.md +11 -0
  134. package/skills/parallel/SKILL.md +5 -5
  135. package/skills/ppr/SKILL.md +103 -52
  136. package/skills/prerender/SKILL.md +4 -5
  137. package/skills/rango/SKILL.md +3 -0
  138. package/skills/response-routes/SKILL.md +4 -1
  139. package/skills/router-setup/SKILL.md +0 -2
  140. package/skills/scripts/SKILL.md +12 -1
  141. package/skills/server-actions/SKILL.md +60 -20
  142. package/skills/testing/SKILL.md +1 -0
  143. package/skills/testing/client-components.md +13 -10
  144. package/skills/testing/loader.md +25 -24
  145. package/skills/testing/middleware.md +11 -11
  146. package/skills/testing/render-handler.md +17 -17
  147. package/skills/testing/response-routes.md +4 -1
  148. package/skills/testing/serve-shell-request.md +86 -22
  149. package/skills/testing/server-actions.md +16 -16
  150. package/skills/ux-architecture/SKILL.md +980 -0
  151. package/skills/vercel/SKILL.md +1 -1
  152. package/skills/view-transitions/SKILL.md +43 -10
  153. package/src/__augment-tests__/augmented.check.ts +28 -0
  154. package/src/browser/event-controller.ts +44 -18
  155. package/src/browser/intercept-utils.ts +3 -2
  156. package/src/browser/merge-segment-loaders.ts +0 -85
  157. package/src/browser/navigation-bridge.ts +112 -84
  158. package/src/browser/navigation-client.ts +20 -15
  159. package/src/browser/navigation-store.ts +4 -2
  160. package/src/browser/navigation-transaction.ts +9 -8
  161. package/src/browser/partial-update.ts +90 -32
  162. package/src/browser/prefetch/cache.ts +8 -0
  163. package/src/browser/prefetch/fetch.ts +13 -3
  164. package/src/browser/rango-marker.ts +13 -0
  165. package/src/browser/react/NavigationProvider.tsx +25 -7
  166. package/src/browser/react/filter-segment-order.ts +13 -0
  167. package/src/browser/react/use-action.ts +9 -15
  168. package/src/browser/react/use-handle.ts +63 -71
  169. package/src/browser/react/use-href.tsx +24 -5
  170. package/src/browser/react/use-link-status.ts +1 -1
  171. package/src/browser/react/use-navigation.ts +30 -40
  172. package/src/browser/react/use-router.ts +37 -6
  173. package/src/browser/react/use-segments.ts +8 -12
  174. package/src/browser/response-adapter.ts +11 -5
  175. package/src/browser/rsc-router.tsx +3 -1
  176. package/src/browser/scroll-restoration.ts +34 -20
  177. package/src/browser/segment-reconciler.ts +11 -29
  178. package/src/browser/server-action-bridge.ts +52 -16
  179. package/src/browser/types.ts +40 -8
  180. package/src/build/generate-manifest.ts +12 -1
  181. package/src/build/route-types/codegen.ts +6 -2
  182. package/src/build/route-types/per-module-writer.ts +94 -61
  183. package/src/cache/cache-runtime.ts +9 -0
  184. package/src/cache/cache-scope.ts +2 -1
  185. package/src/cache/cf/cf-cache-store.ts +6 -7
  186. package/src/cache/cf/cf-cache-types.ts +0 -17
  187. package/src/cache/cf/cf-shell-frame.ts +3 -0
  188. package/src/cache/handle-snapshot.ts +2 -2
  189. package/src/cache/types.ts +16 -6
  190. package/src/cache/vercel/vercel-cache-store.ts +8 -19
  191. package/src/client-urls/client-urls.ts +202 -153
  192. package/src/client-urls/revalidate-registry.ts +12 -3
  193. package/src/client-urls/server-projection.ts +137 -66
  194. package/src/client-urls/types.ts +30 -15
  195. package/src/client.rsc.tsx +11 -1
  196. package/src/client.tsx +9 -1
  197. package/src/decode-loader-results.ts +64 -31
  198. package/src/handles/deferred-resolution.ts +3 -2
  199. package/src/handles/meta.ts +5 -0
  200. package/src/href-client.ts +3 -1
  201. package/src/index.rsc.ts +1 -0
  202. package/src/index.ts +12 -4
  203. package/src/loader-redirect.tsx +2 -3
  204. package/src/outlet-context.ts +7 -6
  205. package/src/prefetch-markers.ts +15 -5
  206. package/src/prerender/build-shell-capture.ts +1 -2
  207. package/src/prerender/writable-store.ts +2 -3
  208. package/src/reverse.ts +3 -3
  209. package/src/route-content-wrapper.tsx +19 -17
  210. package/src/route-definition/dsl-helpers.ts +41 -21
  211. package/src/route-definition/helpers-types.ts +7 -2
  212. package/src/route-definition/resolve-handler-use.ts +23 -10
  213. package/src/route-definition/rewrite.ts +86 -19
  214. package/src/route-types.ts +1 -2
  215. package/src/router/find-match.ts +37 -1
  216. package/src/router/handler-context.ts +85 -40
  217. package/src/router/intercept-resolution.ts +161 -307
  218. package/src/router/lazy-includes.ts +43 -27
  219. package/src/router/loader-resolution.ts +21 -1
  220. package/src/router/manifest.ts +15 -10
  221. package/src/router/match-api.ts +11 -1
  222. package/src/router/match-middleware/background-revalidation.ts +2 -4
  223. package/src/router/match-middleware/cache-lookup.ts +16 -20
  224. package/src/router/match-middleware/intercept-resolution.ts +41 -60
  225. package/src/router/match-result.ts +31 -2
  226. package/src/router/middleware.ts +6 -147
  227. package/src/router/navigation-snapshot.ts +38 -2
  228. package/src/router/prefetch-cache-ttl.ts +10 -18
  229. package/src/router/prerender-match.ts +2 -1
  230. package/src/router/revalidation.ts +24 -3
  231. package/src/router/router-context.ts +5 -18
  232. package/src/router/router-interfaces.ts +0 -13
  233. package/src/router/router-options.ts +4 -28
  234. package/src/router/segment-resolution/fresh.ts +6 -2
  235. package/src/router/segment-resolution/helpers.ts +7 -1
  236. package/src/router/segment-resolution/loader-cache.ts +4 -3
  237. package/src/router/segment-resolution/mask-nested.ts +5 -3
  238. package/src/router/segment-resolution/prefetch-deferral.ts +62 -12
  239. package/src/router/segment-resolution/revalidation.ts +75 -35
  240. package/src/router/segment-resolution.ts +0 -1
  241. package/src/router/segment-wrappers.ts +8 -13
  242. package/src/router/substitute-pattern-params.ts +3 -2
  243. package/src/router/tracing.ts +2 -2
  244. package/src/router-versions.ts +7 -7
  245. package/src/router.ts +5 -17
  246. package/src/rsc/full-payload.ts +26 -4
  247. package/src/rsc/handler.ts +86 -48
  248. package/src/rsc/helpers.ts +13 -0
  249. package/src/rsc/manifest-init.ts +56 -3
  250. package/src/rsc/prefetch-render-error.ts +38 -0
  251. package/src/rsc/progressive-enhancement.ts +161 -211
  252. package/src/rsc/rewrite-passes.ts +56 -9
  253. package/src/rsc/rsc-rendering.ts +79 -23
  254. package/src/rsc/server-action.ts +25 -2
  255. package/src/rsc/shell-capture-constants.ts +26 -3
  256. package/src/rsc/shell-capture.ts +137 -51
  257. package/src/rsc/types.ts +5 -9
  258. package/src/segment-system.tsx +125 -119
  259. package/src/server/build-version-table.ts +12 -24
  260. package/src/server/context.ts +160 -7
  261. package/src/server/handle-store.ts +80 -12
  262. package/src/server/request-context.ts +46 -6
  263. package/src/server/request-headers.ts +32 -0
  264. package/src/server/rewrite-trail.ts +55 -9
  265. package/src/ssr/ssr-root.tsx +6 -10
  266. package/src/testing/build-versions.ts +0 -3
  267. package/src/testing/dispatch.ts +5 -8
  268. package/src/testing/e2e/index.ts +1 -0
  269. package/src/testing/flight.entry.ts +1 -0
  270. package/src/testing/index.ts +1 -0
  271. package/src/testing/internal/client-urls-projection.ts +31 -11
  272. package/src/testing/internal/seed-vars.ts +4 -4
  273. package/src/testing/render-route.tsx +83 -40
  274. package/src/testing/run-loader.ts +26 -2
  275. package/src/testing/run-middleware.ts +10 -0
  276. package/src/testing/run-revalidate.ts +13 -6
  277. package/src/testing/serve-shell-request.ts +79 -9
  278. package/src/testing/shell-status.ts +40 -0
  279. package/src/testing/vitest-stubs/version.ts +1 -0
  280. package/src/testing/vitest.ts +74 -7
  281. package/src/thenable-status.ts +0 -11
  282. package/src/types/handler-context.ts +12 -1
  283. package/src/types/loader-types.ts +10 -4
  284. package/src/types/route-entry.ts +2 -1
  285. package/src/urls/include-helper.ts +38 -11
  286. package/src/urls/path-helper-types.ts +4 -2
  287. package/src/vite/discovery/client-urls-projection.ts +205 -16
  288. package/src/vite/discovery/discover-routers.ts +2 -2
  289. package/src/vite/discovery/prerender-collection.ts +2 -6
  290. package/src/vite/discovery/shell-prerender-phase.ts +1 -5
  291. package/src/vite/discovery/state.ts +26 -0
  292. package/src/vite/plugins/client-urls-revalidate-hoist.ts +190 -77
  293. package/src/vite/plugins/expose-internal-ids.ts +46 -40
  294. package/src/vite/plugins/hoist/source.ts +8 -7
  295. package/src/vite/plugins/transition-when-hoist.ts +1 -0
  296. package/src/vite/plugins/version-plugin.ts +7 -0
  297. package/src/vite/plugins/version.d.ts +7 -0
  298. package/src/vite/plugins/virtual-entries.ts +20 -0
  299. package/src/vite/rango.ts +4 -1
  300. package/src/vite/router-discovery.ts +39 -7
  301. package/src/vite/utils/prerender-utils.ts +17 -0
package/src/index.ts CHANGED
@@ -134,6 +134,14 @@ function serverOnlyStubError(name: string): Error {
134
134
  );
135
135
  }
136
136
 
137
+ /** A stub whose name `@rangojs/router/client` exports for clientUrls(). */
138
+ function clientUrlsHelperStubError(name: string): Error {
139
+ return new Error(
140
+ `${name}() is only available from "@rangojs/router" in a react-server/RSC environment. ` +
141
+ `In a "use client" module (a clientUrls() component's .use), import ${name}() from "@rangojs/router/client".`,
142
+ );
143
+ }
144
+
137
145
  /**
138
146
  * Error-throwing stub for server-only `urls` function.
139
147
  */
@@ -276,7 +284,7 @@ export function middleware(): never {
276
284
  throw serverOnlyStubError("middleware");
277
285
  }
278
286
  export function revalidate(): never {
279
- throw serverOnlyStubError("revalidate");
287
+ throw clientUrlsHelperStubError("revalidate");
280
288
  }
281
289
  // Cache tag APIs are server-only (real implementations in index.rsc.ts). These
282
290
  // stubs keep the named-export shape identical under the default/non-react-server
@@ -291,10 +299,10 @@ export function revalidateTag(): never {
291
299
  throw serverOnlyStubError("revalidateTag");
292
300
  }
293
301
  export function loader(): never {
294
- throw serverOnlyStubError("loader");
302
+ throw clientUrlsHelperStubError("loader");
295
303
  }
296
304
  export function loading(): never {
297
- throw serverOnlyStubError("loading");
305
+ throw clientUrlsHelperStubError("loading");
298
306
  }
299
307
  export function parallel(): never {
300
308
  throw serverOnlyStubError("parallel");
@@ -309,7 +317,7 @@ export function notFoundBoundary(): never {
309
317
  throw serverOnlyStubError("notFoundBoundary");
310
318
  }
311
319
  export function transition(): never {
312
- throw serverOnlyStubError("transition");
320
+ throw clientUrlsHelperStubError("transition");
313
321
  }
314
322
 
315
323
  // Request context type (safe for client)
@@ -19,9 +19,8 @@ import { resolveSameOriginRedirect } from "./redirect-origin.js";
19
19
  *
20
20
  * Own module (not route-content-wrapper.tsx) because BOTH consumers need it
21
21
  * without a cycle: the StreamedLoaderErrorBoundary redirect branch (read-site
22
- * throw path) and decodeLoaderResults (aggregate forceAwait/action path, which
23
- * runs during the server tree build and cannot throw — it plants this element
24
- * in the errorFallback slot instead).
22
+ * throw path) and decodeLoaderResults (the tree build's settled results, which
23
+ * cannot throw — it plants this element in the errorFallback slot instead).
25
24
  */
26
25
  export function LoaderRedirect({
27
26
  to,
@@ -13,18 +13,19 @@ export interface OutletContextValue {
13
13
  * $$id. A value may be a pending Promise (loader still streaming) or an
14
14
  * already-settled result entry. useLoader `use()`es a pending value at the
15
15
  * read site — implicit suspension to the nearest consumer Suspense boundary —
16
- * and decodes via decodeLoaderEntry. Populated instead of `loaderData` on
17
- * streaming lanes (plain navs, document SSR); forceAwait/action lanes keep
18
- * the resolved `loaderData` record.
16
+ * and decodes via decodeLoaderEntry. Populated instead of `loaderData` for
17
+ * a route's or layout's loaders on every lane; forceAwait/action lanes hand
18
+ * settled entries. `loaderData` is a slot's decoded aggregate.
19
19
  */
20
20
  loaderStreams?: Record<string, unknown>;
21
21
  /**
22
22
  * Loader $$ids on this segment that the render awaited before first flush
23
23
  * (loader(Def, { ssr: false })). Dev-diagnostic input only: useLoader uses
24
24
  * it to warn when a read still suspends during SSR on a render that awaited
25
- * flagged loaders (ssr-suspension-warning.ts). Present only on streaming
26
- * lanes with flagged loaders (document and shell-capture renders); absent
27
- * on forceAwait/action lanes.
25
+ * flagged loaders (ssr-suspension-warning.ts). Present only where a
26
+ * segment carries flagged loaders (document and shell-capture renders, and
27
+ * a client lane that re-renders their segments); a settled read never
28
+ * suspends, so it never warns.
28
29
  */
29
30
  awaitedLoaderIds?: readonly string[];
30
31
  parent?: OutletContextValue | null;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * The wire markers of `prefetch: false` (docs/design/prefetch-false.md):
3
- * shared by the browser that sends them and the server that reads them
4
- * (router/segment-resolution/prefetch-deferral.ts requestKind). Dependency
5
- * free, like segment-fragments.ts: the browser must not import the server
6
- * module that reads them.
2
+ * The wire markers of prefetches and of `prefetch: false`
3
+ * (docs/design/prefetch-false.md): shared by the browser and the server
4
+ * (router/segment-resolution/prefetch-deferral.ts requestKind,
5
+ * rsc/prefetch-render-error.ts). Dependency free, like segment-fragments.ts:
6
+ * the browser must not import the server modules that use them.
7
7
  */
8
8
 
9
9
  /** Request header of a `<Link>` prefetch (browser/prefetch/fetch.ts). */
@@ -11,3 +11,13 @@ export const PREFETCH_HEADER = "X-Rango-Prefetch";
11
11
 
12
12
  /** Query param of a fill request (browser/navigation-client.ts). */
13
13
  export const FILL_PARAM = "_rsc_fill";
14
+
15
+ /**
16
+ * The last row of a prefetch whose render reported an error
17
+ * (rsc/prefetch-render-error.ts): a Flight hint with a code React does not
18
+ * dispatch, so the decoder skips it (pinned by
19
+ * src/__tests__/flight-unknown-hint.test.ts), and browser/response-adapter.ts
20
+ * reads the stream as not ended cleanly. Five bytes: teeWithCompletion keeps
21
+ * the last five.
22
+ */
23
+ export const PREFETCH_FAILED_ROW = ":H_0\n";
@@ -106,8 +106,7 @@ export interface BuildShellCaptureOptions {
106
106
  /** Build-time env bindings (rango plugin buildEnv), if configured. */
107
107
  buildEnv?: unknown;
108
108
  /**
109
- * The versions the SHIPPED build serves this router with (the build table,
110
- * or the router's consumer-set version) — NOT the temp server's own
109
+ * The versions the SHIPPED build serves this router with (the build table) — NOT the temp server's own
111
110
  * version-plugin stamp. The serve-side isValidShellHit gate compares
112
111
  * entry.buildVersion against the running worker's ctx.version, which is the
113
112
  * document version; stamping the temp server's would make every build entry
@@ -22,9 +22,8 @@ import { paramsEqual } from "../router/params-util.js";
22
22
  export interface PrerenderKey {
23
23
  routerId: string;
24
24
  /**
25
- * The owning router's cache version (its data version, or
26
- * `createRouter({ version })`). Opaque: never set or read by app code; a
27
- * store keys off it as given.
25
+ * The owning router's cache version (its data version). Opaque: never set
26
+ * or read by app code; a store keys off it as given.
28
27
  */
29
28
  version: string;
30
29
  routeName: string;
package/src/reverse.ts CHANGED
@@ -406,9 +406,9 @@ export function createReverse<TRoutes extends Record<string, string>>(
406
406
  throw new Error(`Unknown route: ${name}`);
407
407
  }
408
408
 
409
- let result = params
410
- ? substitutePatternParams(pattern, params, name)
411
- : pattern;
409
+ // Always substitute: a required param with no params object throws
410
+ // `Missing param` rather than returning the raw `:param` pattern.
411
+ let result = substitutePatternParams(pattern, params ?? {}, name);
412
412
 
413
413
  // Append search params as query string
414
414
  if (search) {
@@ -18,6 +18,7 @@ import {
18
18
  useRevealAudit,
19
19
  } from "./suspense-audit-react.js";
20
20
  import { SETTLED_THENABLE } from "./thenable-status.js";
21
+ import { shallowEqual } from "./browser/react/shallow-equal.js";
21
22
 
22
23
  /**
23
24
  * Router-owned error boundary for read-site loader errors. segment-system
@@ -40,12 +41,12 @@ import { SETTLED_THENABLE } from "./thenable-status.js";
40
41
  * Errors without any marker rethrow to the app's own boundaries.
41
42
  */
42
43
  export class StreamedLoaderErrorBoundary extends Component<
43
- { children: ReactNode; resetKey?: string },
44
- { error: unknown; resetKey?: string }
44
+ { children: ReactNode; reset: unknown[] },
45
+ { error: unknown; reset: unknown[] }
45
46
  > {
46
- state: { error: unknown; resetKey?: string } = {
47
+ state: { error: unknown; reset: unknown[] } = {
47
48
  error: null,
48
- resetKey: this.props.resetKey,
49
+ reset: this.props.reset,
49
50
  };
50
51
 
51
52
  static getDerivedStateFromError(error: unknown): { error: unknown } {
@@ -54,20 +55,21 @@ export class StreamedLoaderErrorBoundary extends Component<
54
55
 
55
56
  /**
56
57
  * A caught marker (redirect, notFound, error fallback) belongs to ONE route
57
- * + params. Group-keyed segments (ResolvedSegment.clientGroup) keep this
58
- * instance alive across in-group navigations, so the error must clear when
59
- * the route or params change — otherwise a redirect caught for /legacy
60
- * keeps rendering LoaderRedirect for /state. `resetKey` is the segment's
61
- * id-params identity, the cadence the per-route remount used to provide.
58
+ * + params and ONE delivery of the segment's loader data. `reset` is the
59
+ * segment's id-params identity followed by each of its loaders' data; the
60
+ * error clears when any of them changes. Group-keyed segments
61
+ * (ResolvedSegment.clientGroup) keep this instance alive across in-group
62
+ * navigations, so a redirect caught for /legacy must not keep rendering
63
+ * LoaderRedirect for /state. A rerun hands a loader new data, a held loader
64
+ * keeps its own: a later action or navigation that re-ran the loader clears
65
+ * an error fallback left by an earlier failure, and a tree that re-ran
66
+ * nothing here keeps it.
62
67
  */
63
68
  static getDerivedStateFromProps(
64
- props: { resetKey?: string },
65
- state: { error: unknown; resetKey?: string },
66
- ): { error: unknown; resetKey?: string } | null {
67
- if (props.resetKey !== state.resetKey) {
68
- return { error: null, resetKey: props.resetKey };
69
- }
70
- return null;
69
+ { reset }: { reset: unknown[] },
70
+ state: { reset: unknown[] },
71
+ ): { error: null; reset: unknown[] } | null {
72
+ return shallowEqual(reset, state.reset) ? null : { error: null, reset };
71
73
  }
72
74
 
73
75
  render(): ReactNode {
@@ -311,7 +313,7 @@ function AuditedLoaderResolver({
311
313
  * Without streams, the pre-spike behavior is preserved: a pending aggregate
312
314
  * resolves ABOVE via use() (parallel/intercept slots still take this path —
313
315
  * ResolvedSegment carries only the aggregate for slots), and a resolved
314
- * array decodes synchronously (forceAwait/action lanes commit whole).
316
+ * array decodes synchronously (a slot on the forceAwait/action lanes).
315
317
  */
316
318
  function LoaderResolver({
317
319
  loaderDataPromise,
@@ -9,8 +9,11 @@ import type {
9
9
  TransitionConfig,
10
10
  } from "../types.js";
11
11
  import {
12
+ applyDocumentModeLoading,
13
+ documentModeLoader,
12
14
  getContext,
13
15
  getNamePrefix,
16
+ getReverseScope,
14
17
  getUrlPrefix,
15
18
  requireDslContext,
16
19
  stampStaticDefScope,
@@ -52,6 +55,7 @@ import {
52
55
  validateInterceptUseItems,
53
56
  } from "./resolve-handler-use.js";
54
57
  import { ALL_USE_ITEM_TYPES } from "./use-item-types.js";
58
+ import { toShouldRevalidateFn } from "../router/revalidation.js";
55
59
 
56
60
  /**
57
61
  * Check if an item contains routes (directly or inside nested wrappers).
@@ -189,6 +193,10 @@ const revalidate: RouteHelpers<any, any>["revalidate"] = (fn) => {
189
193
  const { store, ctx } = requireDslContext(
190
194
  "revalidate() must be called inside urls()",
191
195
  );
196
+ invariant(
197
+ typeof fn === "function" || typeof fn === "boolean",
198
+ `revalidate() expects a predicate or a boolean, got ${fn === null ? "null" : typeof fn}`,
199
+ );
192
200
 
193
201
  // Attach to last entry in stack
194
202
  const parent = ctx.parent;
@@ -196,7 +204,7 @@ const revalidate: RouteHelpers<any, any>["revalidate"] = (fn) => {
196
204
  invariant(false, "No parent entry available for revalidate()");
197
205
  }
198
206
  const name = `$${store.getNextIndex("revalidate")}`;
199
- parent.revalidate.push(fn);
207
+ parent.revalidate.push(toShouldRevalidateFn(fn));
200
208
  return { name, type: "revalidate" } as RevalidateItem;
201
209
  };
202
210
 
@@ -394,6 +402,7 @@ const cache: RouteHelpers<any, any>["cache"] = (
394
402
  cache: cacheConfig,
395
403
  handler: RootLayout,
396
404
  ...(urlPrefix ? { mountPath: urlPrefix } : {}),
405
+ reverseScope: getReverseScope(),
397
406
  } satisfies EntryData;
398
407
 
399
408
  // Attach to parent's layout array (cache entries are structural like layouts)
@@ -433,6 +442,7 @@ const cache: RouteHelpers<any, any>["cache"] = (
433
442
  // Cache entries render like layouts (with Outlet as default handler)
434
443
  handler: RootLayout, // RootLayout just renders <Outlet />
435
444
  ...(urlPrefix ? { mountPath: urlPrefix } : {}),
445
+ reverseScope: getReverseScope(),
436
446
  } satisfies EntryData;
437
447
 
438
448
  // Run children with cache entry as parent
@@ -522,6 +532,7 @@ const middleware: RouteHelpers<any, any>["middleware"] = (...args: any[]) => {
522
532
  handler: RootLayout,
523
533
  middleware: [...fns],
524
534
  ...(urlPrefix ? { mountPath: urlPrefix } : {}),
535
+ reverseScope: getReverseScope(),
525
536
  } satisfies EntryData;
526
537
 
527
538
  // Run children callback. If the second arg was actually a middleware fn
@@ -643,6 +654,7 @@ const parallel: RouteHelpers<any, any>["parallel"] = (slots, use) => {
643
654
  parent: null, // Parallels don't participate in parent chain traversal
644
655
  handler: unwrappedSlots,
645
656
  ...(parallelUrlPrefix ? { mountPath: parallelUrlPrefix } : {}),
657
+ reverseScope: getReverseScope(),
646
658
  ...(hasStaticSlot
647
659
  ? {
648
660
  isStaticPrerender: true as const,
@@ -777,12 +789,11 @@ const intercept = (
777
789
  const prefixedRouteName =
778
790
  isLocal && namePrefix ? `${namePrefix}.${bareRouteName}` : bareRouteName;
779
791
 
780
- // Create intercept entry with its own loaders/middleware/when
792
+ // Create intercept entry with its own loaders/when
781
793
  const entry: InterceptEntry = {
782
794
  slotName: slotName as `@${string}`,
783
795
  routeName: prefixedRouteName,
784
796
  handler,
785
- middleware: [],
786
797
  loader: [],
787
798
  when: [], // Selector conditions for conditional interception
788
799
  };
@@ -800,12 +811,12 @@ const intercept = (
800
811
  const handlerUseFn = resolveHandlerUse(handler);
801
812
  const mergedUse = mergeHandlerUse(handlerUseFn, useFn, null);
802
813
 
803
- // Run merged use callback to collect loaders, middleware, etc.
814
+ // Run merged use callback to collect loaders, loading, layout, etc.
804
815
  if (mergedUse) {
805
816
  // Capture layout() calls into a temporary array
806
817
  const capturedLayouts: EntryData[] = [];
807
818
 
808
- // Temporary parent so middleware/loader attach to the intercept entry;
819
+ // Temporary parent so loader() attaches to the intercept entry;
809
820
  // the loading get/set accessor mirrors writes onto `entry`. It is a
810
821
  // shallow spread of the enclosing entry, so every field a rejected helper
811
822
  // writes to points at a throwaway here: a helper called but not returned
@@ -814,8 +825,12 @@ const intercept = (
814
825
  // is a route.
815
826
  //
816
827
  // Why an intercept rejects these (validateInterceptUseItems):
828
+ // - middleware(): only the live render resolved the intercept's own
829
+ // middleware; a cache() hit or a Prerender() target skipped it, so a
830
+ // guard in it was bypassed. The target route's middleware runs on every
831
+ // pass, the modal's included.
817
832
  // - revalidate(): an intercept only evaluates its loaders' revalidate()
818
- // (router/intercept-resolution.ts).
833
+ // (loader segments of its slot, router/intercept-resolution.ts).
819
834
  // - errorBoundary()/notFoundBoundary(): error lookup walks EntryData
820
835
  // parent chains (router/error-handling.ts), which never include an
821
836
  // InterceptEntry; intercept loader errors resolve against the declaring
@@ -824,7 +839,7 @@ const intercept = (
824
839
  // cache() scope, with its own "intercept:" key (cache/cache-scope.ts).
825
840
  const tempParent = {
826
841
  ...ctx.parent,
827
- middleware: entry.middleware,
842
+ middleware: [],
828
843
  loader: entry.loader,
829
844
  layout: capturedLayouts,
830
845
  revalidate: [],
@@ -833,6 +848,8 @@ const intercept = (
833
848
  parallel: {},
834
849
  intercept: [],
835
850
  cache: undefined,
851
+ // Its loaders resolve `.name` like the intercept handler: from the route.
852
+ reverseScope: undefined,
836
853
  get loading() {
837
854
  return entry.loading;
838
855
  },
@@ -913,18 +930,19 @@ const loader: RouteHelpers<any, any>["loader"] = (
913
930
 
914
931
  const name = `${ctx.namespace}.$${store.getNextIndex("loader")}`;
915
932
 
916
- // Create loader entry with empty revalidate array. awaitBeforeFlush is
917
- // resolved here, at DSL-evaluation time, for the same reason
918
- // loading({ ssr: false }) is (below) — per-isSSR entry caching makes the
919
- // flag request-mode-correct with no isSSR threading; see LoaderEntry.
920
- // `bake` is the lane, the same on both evaluations.
933
+ // Create loader entry with empty revalidate array. `bake` is the lane, the
934
+ // same on both evaluations; a document evaluation adds awaitBeforeFlush at
935
+ // the push (documentModeLoader) — per-isSSR entry caching makes the flag
936
+ // request-mode-correct with no isSSR threading; see LoaderEntry.
921
937
  const loaderEntry: LoaderEntry = {
922
938
  loader: loaderDef,
923
939
  revalidate: [] as ShouldRevalidateFn<any, any>[],
924
940
  ...(optionsGiven?.ssr === false && { bake: true as const }),
925
- ...(optionsGiven?.ssr === false &&
926
- ctx.isSSR && { awaitBeforeFlush: true as const }),
927
941
  ...(optionsGiven?.prefetch === false && { prefetch: false as const }),
942
+ // The declaring layout's / parallel's / cache()'s scope. A route's (and
943
+ // an intercept's) loaders have none: they resolve from the route's name,
944
+ // like the handler.
945
+ ...(ctx.parent.reverseScope && { reverseScope: ctx.parent.reverseScope }),
928
946
  };
929
947
 
930
948
  // Merge handler.use defaults (attached to the loader definition) with explicit use
@@ -959,7 +977,9 @@ const loader: RouteHelpers<any, any>["loader"] = (
959
977
  validateUseItems(result, name, "loader", "use");
960
978
  }
961
979
 
962
- ctx.parent.loader.push(loaderEntry);
980
+ ctx.parent.loader.push(
981
+ ctx.isSSR ? documentModeLoader(loaderEntry) : loaderEntry,
982
+ );
963
983
  return { name, type: "loader" } as LoaderItem;
964
984
  };
965
985
 
@@ -987,12 +1007,11 @@ const loading: RouteHelpers<any, any>["loading"] = (component, options) => {
987
1007
  const resolved =
988
1008
  typeof component === "function" ? (component as () => any)() : component;
989
1009
 
990
- // If ssr: false and we're in SSR, set loading to false
991
- if (options?.ssr === false && ctx.isSSR) {
992
- parent.loading = false;
993
- } else {
994
- parent.loading = resolved;
995
- }
1010
+ // `loadingSsr` records ssr: false on both evaluations; a document drops
1011
+ // the fallback (applyDocumentModeLoading).
1012
+ parent.loading = resolved;
1013
+ parent.loadingSsr = options?.ssr === false ? false : undefined;
1014
+ if (ctx.isSSR) applyDocumentModeLoading(parent);
996
1015
 
997
1016
  // The flag means "what this fallback covers": without a fallback to show
998
1017
  // there is nothing to defer behind. Recorded from `resolved`, not
@@ -1156,6 +1175,7 @@ const layout: RouteHelpers<any, any>["layout"] = (handler, use) => {
1156
1175
  parent: ctx.parent,
1157
1176
  handler: unwrappedHandler,
1158
1177
  ...(urlPrefix ? { mountPath: urlPrefix } : {}),
1178
+ reverseScope: getReverseScope(),
1159
1179
  ...(isStatic
1160
1180
  ? {
1161
1181
  isStaticPrerender: true as const,
@@ -183,7 +183,7 @@ export type RouteHelpers<T extends RouteDefinition, TEnv> = {
183
183
  * // With loaders and revalidation (revalidate() goes on the loader;
184
184
  * // an intercept-level revalidate() throws)
185
185
  * intercept("@modal", "card", () => <CardModal />, () => [
186
- * loader(CardModalLoader, () => [revalidate(() => false)]),
186
+ * loader(CardModalLoader, () => [revalidate(false)]),
187
187
  * ])
188
188
  *
189
189
  * // Conditional activation via the config object's `when` selector
@@ -288,6 +288,9 @@ export type RouteHelpers<T extends RouteDefinition, TEnv> = {
288
288
  * revalidate(({ defaultShouldRevalidate }) =>
289
289
  * ({ defaultShouldRevalidate: true })
290
290
  * )
291
+ *
292
+ * // Shorthand for a constant hard decision: revalidate(() => false)
293
+ * revalidate(false)
291
294
  * ```
292
295
  * Not valid directly inside intercept() use() (throws at definition time):
293
296
  * intercepts only revalidate their loaders, so attach it there with
@@ -298,8 +301,10 @@ export type RouteHelpers<T extends RouteDefinition, TEnv> = {
298
301
  * for downstream revalidators),
299
302
  * - or nothing / `null` / `undefined` (defer — leaves the suggestion
300
303
  * unchanged and continues to the next revalidator).
304
+ * Or `true` / `false`: shorthand for `() => true` / `() => false`. A
305
+ * defer has no shorthand; write the function.
301
306
  */
302
- revalidate: (fn: ShouldRevalidateFn<any, TEnv>) => RevalidateItem;
307
+ revalidate: (fn: ShouldRevalidateFn<any, TEnv> | boolean) => RevalidateItem;
303
308
  /**
304
309
  * Attach a data loader to the current route/layout
305
310
  * ```typescript
@@ -93,14 +93,7 @@ const MOUNT_SITE_ALLOWED_TYPES: Record<string, Set<string>> = {
93
93
  ]),
94
94
  // intercept() checks its whole merged use() (explicit and handler.use)
95
95
  // against this set via validateInterceptUseItems below.
96
- intercept: new Set([
97
- "middleware",
98
- "loader",
99
- "loading",
100
- "layout",
101
- "route",
102
- "transition",
103
- ]),
96
+ intercept: new Set(["loader", "loading", "layout", "route", "transition"]),
104
97
  // LoaderUseItem — only revalidate + cache can attach to a loader entry
105
98
  loader: new Set(["revalidate", "cache"]),
106
99
  };
@@ -113,6 +106,8 @@ const INTERCEPT_BOUNDARY_HINT =
113
106
  * hold them is documented at intercept() in dsl-helpers.ts.
114
107
  */
115
108
  const INTERCEPT_REJECTION_HINTS: Record<string, string> = {
109
+ middleware:
110
+ "move it to the route's middleware() (it runs for the modal too) or into the loaders",
116
111
  revalidate:
117
112
  "attach it to the intercept's loader: loader(YourLoader, () => [revalidate(...)])",
118
113
  errorBoundary: INTERCEPT_BOUNDARY_HINT,
@@ -134,7 +129,7 @@ function rejectInterceptItem(
134
129
 
135
130
  /**
136
131
  * Validate every item an intercept's merged use() returned (explicit use()
137
- * and handler.use) against MOUNT_SITE_ALLOWED_TYPES.intercept, plus two
132
+ * and handler.use) against MOUNT_SITE_ALLOWED_TYPES.intercept, plus three
138
133
  * structural rules:
139
134
  * - a nested layout() is only the modal chrome (intercept() keeps its
140
135
  * handler), so it may not carry use() items of its own;
@@ -142,13 +137,20 @@ function rejectInterceptItem(
142
137
  * it was not returned; its orphan form re-parents the following siblings
143
138
  * onto that entry, so it is rejected the same way. Inside a path, cache()
144
139
  * writes `sinks.cache` instead (dsl-helpers.ts cache()).
140
+ * - middleware on a `capturedLayouts` entry is rejected like `sinks.middleware`:
141
+ * it is an unreturned middleware(fn, () => [...]) or one called inside the
142
+ * chrome layout's use(), and nothing would run it.
145
143
  */
146
144
  export function validateInterceptUseItems(
147
145
  items: AllUseItems[],
148
- capturedLayouts: readonly { type: string }[],
146
+ capturedLayouts: readonly {
147
+ type: string;
148
+ middleware?: readonly unknown[];
149
+ }[],
149
150
  slotName: string,
150
151
  routeName: string,
151
152
  sinks: {
153
+ readonly middleware: readonly unknown[];
152
154
  readonly revalidate: readonly unknown[];
153
155
  readonly errorBoundary: readonly unknown[];
154
156
  readonly notFoundBoundary: readonly unknown[];
@@ -206,6 +208,17 @@ export function validateInterceptUseItems(
206
208
  routeName,
207
209
  );
208
210
  }
211
+ if (
212
+ sinks.middleware.length > 0 ||
213
+ capturedLayouts.some((l) => l.middleware?.length)
214
+ ) {
215
+ rejectInterceptItem(
216
+ "middleware()",
217
+ INTERCEPT_REJECTION_HINTS.middleware!,
218
+ slotName,
219
+ routeName,
220
+ );
221
+ }
209
222
  if (
210
223
  capturedLayouts.some((l) => l.type === "cache") ||
211
224
  sinks.cache !== undefined