@rangojs/router 0.0.0-experimental.dfdb0387 → 0.0.0-experimental.e16b7c00

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 (237) hide show
  1. package/README.md +120 -25
  2. package/dist/bin/rango.js +147 -57
  3. package/dist/vite/index.js +2106 -842
  4. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  5. package/package.json +13 -8
  6. package/skills/breadcrumbs/SKILL.md +3 -1
  7. package/skills/bundle-analysis/SKILL.md +159 -0
  8. package/skills/cache-guide/SKILL.md +222 -30
  9. package/skills/caching/SKILL.md +188 -8
  10. package/skills/composability/SKILL.md +27 -2
  11. package/skills/document-cache/SKILL.md +78 -55
  12. package/skills/handler-use/SKILL.md +364 -0
  13. package/skills/hooks/SKILL.md +229 -20
  14. package/skills/host-router/SKILL.md +45 -20
  15. package/skills/i18n/SKILL.md +276 -0
  16. package/skills/intercept/SKILL.md +46 -4
  17. package/skills/layout/SKILL.md +28 -7
  18. package/skills/links/SKILL.md +247 -17
  19. package/skills/loader/SKILL.md +219 -9
  20. package/skills/middleware/SKILL.md +47 -12
  21. package/skills/migrate-nextjs/SKILL.md +582 -0
  22. package/skills/migrate-react-router/SKILL.md +769 -0
  23. package/skills/mime-routes/SKILL.md +27 -0
  24. package/skills/observability/SKILL.md +137 -0
  25. package/skills/parallel/SKILL.md +71 -6
  26. package/skills/prerender/SKILL.md +14 -33
  27. package/skills/rango/SKILL.md +236 -22
  28. package/skills/react-compiler/SKILL.md +168 -0
  29. package/skills/response-routes/SKILL.md +66 -9
  30. package/skills/route/SKILL.md +57 -4
  31. package/skills/router-setup/SKILL.md +3 -3
  32. package/skills/server-actions/SKILL.md +751 -0
  33. package/skills/streams-and-websockets/SKILL.md +283 -0
  34. package/skills/typesafety/SKILL.md +319 -27
  35. package/skills/use-cache/SKILL.md +36 -5
  36. package/skills/view-transitions/SKILL.md +294 -0
  37. package/src/__augment-tests__/augment.ts +81 -0
  38. package/src/__augment-tests__/augmented.check.ts +117 -0
  39. package/src/browser/action-coordinator.ts +53 -36
  40. package/src/browser/app-shell.ts +52 -0
  41. package/src/browser/event-controller.ts +86 -70
  42. package/src/browser/history-state.ts +21 -0
  43. package/src/browser/index.ts +3 -3
  44. package/src/browser/navigation-bridge.ts +86 -11
  45. package/src/browser/navigation-client.ts +45 -25
  46. package/src/browser/navigation-store.ts +32 -9
  47. package/src/browser/navigation-transaction.ts +10 -28
  48. package/src/browser/partial-update.ts +61 -28
  49. package/src/browser/prefetch/cache.ts +124 -26
  50. package/src/browser/prefetch/fetch.ts +129 -37
  51. package/src/browser/prefetch/queue.ts +36 -5
  52. package/src/browser/rango-state.ts +53 -13
  53. package/src/browser/react/Link.tsx +18 -13
  54. package/src/browser/react/NavigationProvider.tsx +72 -31
  55. package/src/browser/react/filter-segment-order.ts +51 -7
  56. package/src/browser/react/index.ts +3 -0
  57. package/src/browser/react/location-state-shared.ts +175 -4
  58. package/src/browser/react/location-state.ts +39 -13
  59. package/src/browser/react/use-handle.ts +17 -9
  60. package/src/browser/react/use-navigation.ts +22 -2
  61. package/src/browser/react/use-params.ts +20 -8
  62. package/src/browser/react/use-reverse.ts +106 -0
  63. package/src/browser/react/use-router.ts +22 -2
  64. package/src/browser/react/use-segments.ts +11 -8
  65. package/src/browser/response-adapter.ts +25 -0
  66. package/src/browser/rsc-router.tsx +64 -22
  67. package/src/browser/scroll-restoration.ts +22 -14
  68. package/src/browser/segment-reconciler.ts +10 -14
  69. package/src/browser/segment-structure-assert.ts +2 -2
  70. package/src/browser/server-action-bridge.ts +23 -30
  71. package/src/browser/types.ts +21 -0
  72. package/src/build/collect-fallback-refs.ts +107 -0
  73. package/src/build/generate-manifest.ts +60 -35
  74. package/src/build/generate-route-types.ts +2 -0
  75. package/src/build/index.ts +2 -0
  76. package/src/build/route-trie.ts +52 -25
  77. package/src/build/route-types/codegen.ts +4 -4
  78. package/src/build/route-types/include-resolution.ts +1 -1
  79. package/src/build/route-types/per-module-writer.ts +7 -4
  80. package/src/build/route-types/router-processing.ts +55 -14
  81. package/src/build/route-types/scan-filter.ts +1 -1
  82. package/src/build/route-types/source-scan.ts +118 -0
  83. package/src/build/runtime-discovery.ts +9 -20
  84. package/src/cache/cache-error.ts +104 -0
  85. package/src/cache/cache-policy.ts +95 -1
  86. package/src/cache/cache-runtime.ts +79 -13
  87. package/src/cache/cache-scope.ts +77 -46
  88. package/src/cache/cache-tag.ts +135 -0
  89. package/src/cache/cf/cf-cache-store.ts +1067 -176
  90. package/src/cache/cf/index.ts +4 -1
  91. package/src/cache/document-cache.ts +59 -7
  92. package/src/cache/index.ts +6 -0
  93. package/src/cache/memory-segment-store.ts +158 -14
  94. package/src/cache/tag-invalidation.ts +206 -0
  95. package/src/cache/types.ts +27 -0
  96. package/src/client.rsc.tsx +3 -0
  97. package/src/client.tsx +92 -182
  98. package/src/context-var.ts +5 -5
  99. package/src/decode-loader-results.ts +36 -0
  100. package/src/errors.ts +30 -1
  101. package/src/handle.ts +4 -6
  102. package/src/host/index.ts +2 -2
  103. package/src/host/router.ts +129 -57
  104. package/src/host/types.ts +31 -2
  105. package/src/host/utils.ts +1 -1
  106. package/src/href-client.ts +140 -20
  107. package/src/index.rsc.ts +16 -4
  108. package/src/index.ts +65 -15
  109. package/src/loader-store.ts +500 -0
  110. package/src/loader.rsc.ts +2 -5
  111. package/src/loader.ts +3 -10
  112. package/src/missing-id-error.ts +68 -0
  113. package/src/outlet-context.ts +1 -1
  114. package/src/prerender.ts +4 -4
  115. package/src/response-utils.ts +37 -0
  116. package/src/reverse.ts +65 -36
  117. package/src/route-content-wrapper.tsx +6 -28
  118. package/src/route-definition/dsl-helpers.ts +384 -257
  119. package/src/route-definition/helper-factories.ts +29 -139
  120. package/src/route-definition/helpers-types.ts +100 -28
  121. package/src/route-definition/resolve-handler-use.ts +6 -0
  122. package/src/route-definition/use-item-types.ts +32 -0
  123. package/src/route-types.ts +26 -41
  124. package/src/router/content-negotiation.ts +15 -2
  125. package/src/router/error-handling.ts +1 -1
  126. package/src/router/handler-context.ts +21 -38
  127. package/src/router/intercept-resolution.ts +4 -18
  128. package/src/router/lazy-includes.ts +8 -8
  129. package/src/router/loader-resolution.ts +19 -2
  130. package/src/router/manifest.ts +22 -13
  131. package/src/router/match-api.ts +4 -3
  132. package/src/router/match-handlers.ts +1 -0
  133. package/src/router/match-middleware/cache-lookup.ts +46 -92
  134. package/src/router/match-middleware/cache-store.ts +3 -2
  135. package/src/router/match-result.ts +53 -32
  136. package/src/router/metrics.ts +1 -1
  137. package/src/router/middleware-types.ts +15 -26
  138. package/src/router/middleware.ts +99 -84
  139. package/src/router/pattern-matching.ts +101 -17
  140. package/src/router/prerender-match.ts +3 -1
  141. package/src/router/preview-match.ts +3 -1
  142. package/src/router/request-classification.ts +4 -28
  143. package/src/router/revalidation.ts +58 -2
  144. package/src/router/router-interfaces.ts +45 -28
  145. package/src/router/router-options.ts +25 -1
  146. package/src/router/router-registry.ts +2 -5
  147. package/src/router/segment-resolution/fresh.ts +27 -6
  148. package/src/router/segment-resolution/loader-cache.ts +8 -17
  149. package/src/router/segment-resolution/revalidation.ts +147 -106
  150. package/src/router/segment-resolution/view-transition-default.ts +36 -0
  151. package/src/router/substitute-pattern-params.ts +56 -0
  152. package/src/router/trie-matching.ts +18 -13
  153. package/src/router/types.ts +8 -0
  154. package/src/router/url-params.ts +49 -0
  155. package/src/router.ts +23 -18
  156. package/src/rsc/handler-context.ts +2 -2
  157. package/src/rsc/handler.ts +38 -70
  158. package/src/rsc/helpers.ts +72 -43
  159. package/src/rsc/index.ts +1 -1
  160. package/src/rsc/origin-guard.ts +28 -10
  161. package/src/rsc/progressive-enhancement.ts +4 -0
  162. package/src/rsc/response-route-handler.ts +54 -54
  163. package/src/rsc/rsc-rendering.ts +35 -51
  164. package/src/rsc/runtime-warnings.ts +9 -10
  165. package/src/rsc/server-action.ts +17 -37
  166. package/src/rsc/ssr-setup.ts +16 -0
  167. package/src/rsc/types.ts +8 -2
  168. package/src/search-params.ts +4 -4
  169. package/src/segment-content-promise.ts +67 -0
  170. package/src/segment-loader-promise.ts +122 -0
  171. package/src/segment-system.tsx +132 -116
  172. package/src/serialize.ts +243 -0
  173. package/src/server/context.ts +143 -53
  174. package/src/server/cookie-store.ts +28 -4
  175. package/src/server/request-context.ts +46 -44
  176. package/src/ssr/index.tsx +5 -1
  177. package/src/static-handler.ts +1 -1
  178. package/src/types/cache-types.ts +13 -4
  179. package/src/types/error-types.ts +5 -1
  180. package/src/types/global-namespace.ts +39 -26
  181. package/src/types/handler-context.ts +68 -50
  182. package/src/types/index.ts +1 -0
  183. package/src/types/loader-types.ts +5 -6
  184. package/src/types/request-scope.ts +126 -0
  185. package/src/types/route-entry.ts +11 -0
  186. package/src/types/segments.ts +35 -2
  187. package/src/urls/include-helper.ts +34 -67
  188. package/src/urls/index.ts +0 -3
  189. package/src/urls/path-helper-types.ts +41 -7
  190. package/src/urls/path-helper.ts +17 -52
  191. package/src/urls/pattern-types.ts +36 -19
  192. package/src/urls/response-types.ts +22 -29
  193. package/src/urls/type-extraction.ts +26 -116
  194. package/src/urls/urls-function.ts +1 -5
  195. package/src/use-loader.tsx +413 -42
  196. package/src/vite/debug.ts +185 -0
  197. package/src/vite/discovery/bundle-postprocess.ts +6 -6
  198. package/src/vite/discovery/discover-routers.ts +101 -51
  199. package/src/vite/discovery/discovery-errors.ts +194 -0
  200. package/src/vite/discovery/gate-state.ts +171 -0
  201. package/src/vite/discovery/prerender-collection.ts +67 -26
  202. package/src/vite/discovery/route-types-writer.ts +40 -84
  203. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  204. package/src/vite/discovery/state.ts +33 -0
  205. package/src/vite/discovery/virtual-module-codegen.ts +13 -23
  206. package/src/vite/index.ts +2 -0
  207. package/src/vite/plugin-types.ts +67 -0
  208. package/src/vite/plugins/cjs-to-esm.ts +8 -7
  209. package/src/vite/plugins/client-ref-dedup.ts +16 -0
  210. package/src/vite/plugins/client-ref-hashing.ts +28 -5
  211. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  212. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  213. package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
  214. package/src/vite/plugins/expose-action-id.ts +54 -30
  215. package/src/vite/plugins/expose-id-utils.ts +12 -8
  216. package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
  217. package/src/vite/plugins/expose-ids/handler-transform.ts +8 -61
  218. package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
  219. package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
  220. package/src/vite/plugins/expose-internal-ids.ts +496 -486
  221. package/src/vite/plugins/performance-tracks.ts +29 -25
  222. package/src/vite/plugins/use-cache-transform.ts +65 -50
  223. package/src/vite/plugins/version-injector.ts +39 -23
  224. package/src/vite/plugins/version-plugin.ts +59 -2
  225. package/src/vite/plugins/virtual-entries.ts +2 -2
  226. package/src/vite/rango.ts +116 -29
  227. package/src/vite/router-discovery.ts +750 -100
  228. package/src/vite/utils/ast-handler-extract.ts +15 -15
  229. package/src/vite/utils/banner.ts +1 -1
  230. package/src/vite/utils/bundle-analysis.ts +4 -2
  231. package/src/vite/utils/client-chunks.ts +190 -0
  232. package/src/vite/utils/forward-user-plugins.ts +193 -0
  233. package/src/vite/utils/manifest-utils.ts +21 -5
  234. package/src/vite/utils/package-resolution.ts +41 -1
  235. package/src/vite/utils/prerender-utils.ts +21 -6
  236. package/src/vite/utils/shared-utils.ts +107 -26
  237. package/src/browser/action-response-classifier.ts +0 -99
@@ -4,7 +4,7 @@
4
4
  * Evaluates whether segments should revalidate based on params, actions, and custom functions.
5
5
  */
6
6
 
7
- import type { ResolvedSegment, HandlerContext } from "../types";
7
+ import type { ResolvedSegment, HandlerContext, ActionRef } from "../types";
8
8
  import type { ActionContext } from "./types";
9
9
  import {
10
10
  debugLog,
@@ -15,6 +15,47 @@ import type { RevalidationTraceEntry } from "./logging.js";
15
15
  import { _getRequestContext } from "../server/request-context.js";
16
16
  import { isAutoGeneratedRouteName } from "../route-name.js";
17
17
 
18
+ /**
19
+ * Resolve a server-action reference's stable id, mirroring how the action
20
+ * boundary derives `actionContext.actionId` in `rsc/server-action.ts`
21
+ * (`$id ?? $$id`): the file-path `$id` set by the expose-action-id plugin in a
22
+ * production RSC build when present, otherwise React's `$$id`. Resolving both
23
+ * the incoming `actionId` and the reference with the same precedence makes
24
+ * `isAction()` form-agnostic across dev and production.
25
+ */
26
+ function resolveActionRefId(ref: unknown): string | undefined {
27
+ if (ref == null) return undefined;
28
+ const r = ref as { $id?: unknown; $$id?: unknown };
29
+ if (typeof r.$id === "string") return r.$id;
30
+ if (typeof r.$$id === "string") return r.$$id;
31
+ return undefined;
32
+ }
33
+
34
+ /**
35
+ * Build the `isAction()` helper bound to the current action's id. Matches a
36
+ * single imported action reference, several (variadic), or any export of a
37
+ * namespace import (`import * as Mod`). Returns `false` when there is no action
38
+ * (plain navigation) or nothing matches.
39
+ */
40
+ function makeIsAction(
41
+ currentActionId: string | undefined,
42
+ ): (...actions: ActionRef[]) => boolean {
43
+ return (...actions: ActionRef[]): boolean => {
44
+ if (!currentActionId) return false;
45
+ for (const action of actions) {
46
+ if (typeof action === "function") {
47
+ if (resolveActionRefId(action) === currentActionId) return true;
48
+ } else if (action && typeof action === "object") {
49
+ // Namespace import: match any export of the module.
50
+ for (const value of Object.values(action)) {
51
+ if (resolveActionRefId(value) === currentActionId) return true;
52
+ }
53
+ }
54
+ }
55
+ return false;
56
+ };
57
+ }
58
+
18
59
  function paramsEqual(
19
60
  a: Record<string, string>,
20
61
  b: Record<string, string>,
@@ -59,6 +100,14 @@ interface EvaluateRevalidationOptions<TEnv> {
59
100
  stale?: boolean;
60
101
  /** Trace source hint for the revalidation trace */
61
102
  traceSource?: RevalidationTraceEntry["source"];
103
+ /**
104
+ * Override the segment-type-derived default. When set, the value is used as
105
+ * the seed `defaultShouldRevalidate` passed to user revalidate fns and the
106
+ * reason flows into the trace. Callers use this when client-knowledge
107
+ * (e.g. parallel slot not in clientSegmentIds) should dictate the seed
108
+ * instead of the params/method-based heuristic.
109
+ */
110
+ defaultOverride?: { value: boolean; reason: string };
62
111
  }
63
112
 
64
113
  /**
@@ -81,6 +130,7 @@ export async function evaluateRevalidation<TEnv>(
81
130
  actionContext,
82
131
  stale,
83
132
  traceSource,
133
+ defaultOverride,
84
134
  } = options;
85
135
  const nextParams = segment.params || {};
86
136
  const paramsChanged = !paramsEqual(nextParams, prevParams);
@@ -110,7 +160,12 @@ export async function evaluateRevalidation<TEnv>(
110
160
  let defaultShouldRevalidate: boolean;
111
161
  let defaultReason: string;
112
162
 
113
- if (request.method === "POST") {
163
+ if (defaultOverride) {
164
+ // Caller injected the seed (e.g. parallel slot not in clientSegmentIds).
165
+ // Skip the type-derived heuristic — caller knows better in this context.
166
+ defaultShouldRevalidate = defaultOverride.value;
167
+ defaultReason = defaultOverride.reason;
168
+ } else if (request.method === "POST") {
114
169
  // Actions: revalidate segments that belong to the route, skip parent chain
115
170
  if (segment.type === "route") {
116
171
  // Route segment always revalidates on actions
@@ -226,6 +281,7 @@ export async function evaluateRevalidation<TEnv>(
226
281
  slotName: segment.slot,
227
282
  // Action context (only populated when triggered by server action)
228
283
  actionId: actionContext?.actionId,
284
+ isAction: makeIsAction(actionContext?.actionId),
229
285
  actionUrl: actionContext?.actionUrl,
230
286
  actionResult: actionContext?.actionResult,
231
287
  formData: actionContext?.formData,
@@ -2,7 +2,7 @@ import type { ComponentType, ReactNode } from "react";
2
2
  import type { SerializedManifest } from "../debug.js";
3
3
  import type { ReverseFunction } from "../reverse.js";
4
4
  import type { UrlPatterns } from "../urls.js";
5
- import type { UrlBuilder } from "../urls/pattern-types.js";
5
+ import type { UrlBuilder, EnvCompatible } from "../urls/pattern-types.js";
6
6
  import type { EntryData } from "../server/context";
7
7
  import type { ErrorInfo, MatchResult } from "../types";
8
8
  import type { NonceProvider } from "../rsc/types.js";
@@ -13,7 +13,7 @@ import type {
13
13
  } from "../cache/types.js";
14
14
  import type { MiddlewareEntry, MiddlewareFn } from "./middleware.js";
15
15
  import { RSC_ROUTER_BRAND } from "./router-registry.js";
16
- import type { RSCRouterOptions, RootLayoutProps } from "./router-options.js";
16
+ import type { RangoOptions, RootLayoutProps } from "./router-options.js";
17
17
  import type { DefaultVars } from "../types/global-namespace.js";
18
18
  import type { ResolvedTimeouts, OnTimeoutCallback } from "./timeout.js";
19
19
 
@@ -49,16 +49,16 @@ type MergeRoutesWithResponses<
49
49
  };
50
50
 
51
51
  /**
52
- * Public RSC Router interface — the user-facing API surface.
52
+ * Public Rango router interface — the user-facing API surface.
53
53
  *
54
54
  * Users interact with this type when building and using routers.
55
- * Internal framework code uses RSCRouterInternal (via toInternal()) to access
55
+ * Internal framework code uses RangoInternal (via toInternal()) to access
56
56
  * matching, build-time, and configuration members that are not part of the
57
57
  * public contract.
58
58
  *
59
59
  * TRoutes accumulates all registered route types through the builder chain.
60
60
  */
61
- export interface RSCRouter<
61
+ export interface Rango<
62
62
  TEnv = any,
63
63
  TRoutes extends Record<string, unknown> = Record<string, string>,
64
64
  > {
@@ -89,16 +89,16 @@ export interface RSCRouter<
89
89
  * ])
90
90
  * ```
91
91
  */
92
- routes<T extends UrlPatterns<TEnv, any>>(
93
- patterns: T,
94
- ): RSCRouter<
92
+ routes<T extends UrlPatterns<any, any, any>>(
93
+ patterns: T & EnvCompatible<T, TEnv>,
94
+ ): Rango<
95
95
  TEnv,
96
96
  TRoutes &
97
97
  (NonNullable<T["_routes"]> extends Record<string, unknown>
98
98
  ? MergeRoutesWithResponses<NonNullable<T["_routes"]>, T["_responses"]>
99
99
  : Record<string, string>)
100
100
  >;
101
- routes(builder: UrlBuilder<TEnv>): RSCRouter<TEnv, TRoutes>;
101
+ routes(builder: UrlBuilder<TEnv>): Rango<TEnv, TRoutes>;
102
102
 
103
103
  /**
104
104
  * Add global middleware that runs on all routes
@@ -114,7 +114,7 @@ export interface RSCRouter<
114
114
  use(
115
115
  patternOrMiddleware: string | MiddlewareFn<TEnv>,
116
116
  middleware?: MiddlewareFn<TEnv>,
117
- ): RSCRouter<TEnv, TRoutes>;
117
+ ): Rango<TEnv, TRoutes>;
118
118
 
119
119
  /**
120
120
  * Type-safe URL builder for registered routes
@@ -141,7 +141,7 @@ export interface RSCRouter<
141
141
  * type AppRoutes = typeof _router.routeMap;
142
142
  *
143
143
  * declare global {
144
- * namespace RSCRouter {
144
+ * namespace Rango {
145
145
  * interface RegisteredRoutes extends AppRoutes {}
146
146
  * }
147
147
  * }
@@ -177,16 +177,16 @@ export interface RSCRouter<
177
177
  }
178
178
 
179
179
  /**
180
- * Internal RSC Router interface — the full framework-facing API.
180
+ * Internal Rango router interface — the full framework-facing API.
181
181
  *
182
182
  * This type includes all members used by the Vite plugin, RSC handler,
183
183
  * pre-rendering pipeline, and other framework internals. It is NOT exported
184
184
  * from the public package API.
185
185
  *
186
- * Use toInternal(router) to assert a public RSCRouter into this type
186
+ * Use toInternal(router) to assert a public Rango into this type
187
187
  * at the boundary where framework code receives a user-provided router.
188
188
  */
189
- export interface RSCRouterInternal<
189
+ export interface RangoInternal<
190
190
  TEnv = any,
191
191
  TRoutes extends Record<string, unknown> = Record<string, string>,
192
192
  > {
@@ -206,18 +206,24 @@ export interface RSCRouterInternal<
206
206
  readonly basename: string | undefined;
207
207
 
208
208
  /**
209
- * Register routes using URL patterns from urls() or a builder function
210
- */
211
- routes<T extends UrlPatterns<TEnv, any>>(
212
- patterns: T,
213
- ): RSCRouter<
209
+ * Register routes using URL patterns from urls() or a builder function.
210
+ *
211
+ * Env compatibility is checked by EnvCompatible: an env-agnostic urls() block
212
+ * (its env is `unknown` — e.g. a shared module, or an app that does not augment
213
+ * `Rango.Env`) attaches to any router, while a urls<TEnv>() block carrying a
214
+ * concrete env is accepted only when this router's `TEnv` satisfies it. So a
215
+ * `urls<{ DB }>()` cannot be mounted on a `createRouter<{}>()`.
216
+ */
217
+ routes<T extends UrlPatterns<any, any, any>>(
218
+ patterns: T & EnvCompatible<T, TEnv>,
219
+ ): Rango<
214
220
  TEnv,
215
221
  TRoutes &
216
222
  (NonNullable<T["_routes"]> extends Record<string, unknown>
217
223
  ? MergeRoutesWithResponses<NonNullable<T["_routes"]>, T["_responses"]>
218
224
  : Record<string, string>)
219
225
  >;
220
- routes(builder: UrlBuilder<TEnv>): RSCRouter<TEnv, TRoutes>;
226
+ routes(builder: UrlBuilder<TEnv>): Rango<TEnv, TRoutes>;
221
227
 
222
228
  /**
223
229
  * Add global middleware that runs on all routes
@@ -225,7 +231,7 @@ export interface RSCRouterInternal<
225
231
  use(
226
232
  patternOrMiddleware: string | MiddlewareFn<TEnv>,
227
233
  middleware?: MiddlewareFn<TEnv>,
228
- ): RSCRouter<TEnv, TRoutes>;
234
+ ): Rango<TEnv, TRoutes>;
229
235
 
230
236
  /**
231
237
  * Type-safe URL builder for registered routes
@@ -247,17 +253,17 @@ export interface RSCRouterInternal<
247
253
  * Error callback for monitoring/alerting
248
254
  * Called when errors occur in loaders, actions, or routes
249
255
  */
250
- readonly onError?: RSCRouterOptions<TEnv>["onError"];
256
+ readonly onError?: RangoOptions<TEnv>["onError"];
251
257
 
252
258
  /**
253
259
  * Cache configuration
254
260
  */
255
- readonly cache?: RSCRouterOptions<TEnv>["cache"];
261
+ readonly cache?: RangoOptions<TEnv>["cache"];
256
262
 
257
263
  /**
258
264
  * Not found component to render when no route matches
259
265
  */
260
- readonly notFound?: RSCRouterOptions<TEnv>["notFound"];
266
+ readonly notFound?: RangoOptions<TEnv>["notFound"];
261
267
 
262
268
  /**
263
269
  * Resolved theme configuration (null if theme not enabled)
@@ -359,6 +365,17 @@ export interface RSCRouterInternal<
359
365
  /** @internal basename for runtime manifest generation */
360
366
  readonly __basename?: string;
361
367
 
368
+ /**
369
+ * @internal Router-level error/notFound fallbacks (`createRouter` options),
370
+ * exposed for the build-time clientChunks discovery so a `"use client"`
371
+ * default boundary is routed into the dedicated `app-fallback` chunk. Unlike
372
+ * the route-tree `errorBoundary()`/`notFoundBoundary()` helpers these never
373
+ * land in `EntryData`, so they are read directly off the router instance.
374
+ */
375
+ readonly __defaultErrorBoundary?: RangoOptions<TEnv>["defaultErrorBoundary"];
376
+ readonly __defaultNotFoundBoundary?: RangoOptions<TEnv>["defaultNotFoundBoundary"];
377
+ readonly __notFound?: RangoOptions<TEnv>["notFound"];
378
+
362
379
  match(
363
380
  request: Request,
364
381
  input?: RouterRequestInput<TEnv>,
@@ -469,16 +486,16 @@ export interface RSCRouterInternal<
469
486
  }
470
487
 
471
488
  /**
472
- * Assert a public RSCRouter into the internal type.
489
+ * Assert a public Rango into the internal type.
473
490
  *
474
491
  * Use this at the boundary where framework code receives a user-provided
475
492
  * router and needs access to internal members (match, config, build-time).
476
493
  * The cast is safe because createRouter() always produces an object that
477
- * satisfies RSCRouterInternal; the public type is just a narrower view.
494
+ * satisfies RangoInternal; the public type is just a narrower view.
478
495
  */
479
496
  export function toInternal<
480
497
  TEnv = any,
481
498
  TRoutes extends Record<string, unknown> = Record<string, string>,
482
- >(router: RSCRouter<TEnv, TRoutes>): RSCRouterInternal<TEnv, TRoutes> {
483
- return router as RSCRouterInternal<TEnv, TRoutes>;
499
+ >(router: Rango<TEnv, TRoutes>): RangoInternal<TEnv, TRoutes> {
500
+ return router as RangoInternal<TEnv, TRoutes>;
484
501
  }
@@ -73,7 +73,7 @@ export interface RootLayoutProps {
73
73
  /**
74
74
  * Router configuration options
75
75
  */
76
- export interface RSCRouterOptions<TEnv = any> {
76
+ export interface RangoOptions<TEnv = any> {
77
77
  /**
78
78
  * Unique identifier for this router instance.
79
79
  * Used to namespace static output files and route maps.
@@ -357,6 +357,30 @@ export interface RSCRouterOptions<TEnv = any> {
357
357
  */
358
358
  theme?: import("../theme/types.js").ThemeConfig | true;
359
359
 
360
+ /**
361
+ * Default for whether the router wraps `transition()` segments in its own
362
+ * React `<ViewTransition>` boundary (experimental React only).
363
+ *
364
+ * - "auto" (default): every route/layout that opts in via `transition()`
365
+ * gets a router-owned cross-fade.
366
+ * - false: the router never places its own boundary. Routes that use
367
+ * `transition()` still drive navigation through startTransition (so loaders
368
+ * hold instead of flashing a skeleton) and still let consumer-placed
369
+ * `<ViewTransition>` elements animate — the router just contributes no
370
+ * cross-fade of its own. This is the "router triggers, you place the
371
+ * transitions" model.
372
+ *
373
+ * A per-segment `transition({ viewTransition })` overrides this default.
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * // App-wide: drive + hold, but never auto-wrap. Place <ViewTransition>
378
+ * // yourself in components where you want a morph.
379
+ * const router = createRouter<AppEnv>({ viewTransition: false });
380
+ * ```
381
+ */
382
+ viewTransition?: "auto" | false;
383
+
360
384
  /**
361
385
  * URL patterns to register with the router.
362
386
  *
@@ -1,4 +1,4 @@
1
- import type { RSCRouterInternal } from "./router-interfaces.js";
1
+ import type { RangoInternal } from "./router-interfaces.js";
2
2
 
3
3
  /**
4
4
  * Brand marker for identifying router instances at build time.
@@ -12,10 +12,7 @@ export const RSC_ROUTER_BRAND = "__rsc_router__" as const;
12
12
  * Used by the Vite plugin at build time to discover routers and extract
13
13
  * manifests, prefix trees, and pre-render candidates.
14
14
  */
15
- export const RouterRegistry: Map<
16
- string,
17
- RSCRouterInternal<any, any>
18
- > = new Map();
15
+ export const RouterRegistry: Map<string, RangoInternal<any, any>> = new Map();
19
16
 
20
17
  export let routerAutoId = 0;
21
18
 
@@ -28,11 +28,12 @@ import {
28
28
  resolveLayoutComponent,
29
29
  resolveWithErrorBoundary,
30
30
  } from "./helpers.js";
31
+ import { applyViewTransitionDefault } from "./view-transition-default.js";
31
32
  import { getRouterContext } from "../router-context.js";
32
33
  import { resolveSink, safeEmit } from "../telemetry.js";
33
34
  import {
34
35
  track,
35
- RSCRouterContext,
36
+ RangoContext,
36
37
  runInsideLoaderScope,
37
38
  } from "../../server/context.js";
38
39
 
@@ -224,7 +225,10 @@ export async function resolveSegment<TEnv>(
224
225
  index: 0,
225
226
  component,
226
227
  loading: entry.loading === false ? null : entry.loading,
227
- transition: entry.transition,
228
+ transition: applyViewTransitionDefault(
229
+ entry.transition,
230
+ deps.viewTransitionDefault,
231
+ ),
228
232
  params,
229
233
  belongsToRoute: false,
230
234
  layoutName: entry.id,
@@ -359,7 +363,10 @@ export async function resolveSegment<TEnv>(
359
363
  index: 0,
360
364
  component: component ?? null,
361
365
  loading: entry.loading === false ? null : entry.loading,
362
- transition: entry.transition,
366
+ transition: applyViewTransitionDefault(
367
+ entry.transition,
368
+ deps.viewTransitionDefault,
369
+ ),
363
370
  params,
364
371
  belongsToRoute: true,
365
372
  ...(entry.mountPath ? { mountPath: entry.mountPath } : {}),
@@ -443,7 +450,10 @@ export async function resolveOrphanLayout<TEnv>(
443
450
  belongsToRoute,
444
451
  layoutName: orphan.id,
445
452
  loading: orphan.loading === false ? null : orphan.loading,
446
- transition: orphan.transition,
453
+ transition: applyViewTransitionDefault(
454
+ orphan.transition,
455
+ deps.viewTransitionDefault,
456
+ ),
447
457
  ...(orphan.mountPath ? { mountPath: orphan.mountPath } : {}),
448
458
  });
449
459
 
@@ -515,6 +525,14 @@ export async function resolveParallelEntry<TEnv>(
515
525
  if (handler === undefined) {
516
526
  continue;
517
527
  }
528
+ // Pin `_currentSegmentId` to the slot's own id so handle pushes from
529
+ // inside the slot handler get their own bucket in the HandleStore.
530
+ // Parent-keying would collapse them into the parent layout's bucket;
531
+ // the partial-update merge then replaces the parent's bucket on a
532
+ // slot-only revalidation and drops layout-pushed Meta/Breadcrumbs.
533
+ // filterSegmentOrder() retains slot ids so the client preserves them.
534
+ (context as InternalHandlerContext<any, TEnv>)._currentSegmentId =
535
+ `${parentShortCode}.${slot}`;
518
536
  const doneParallelHandler = track(
519
537
  `handler:${parallelEntry.id}.${slot}`,
520
538
  2,
@@ -557,7 +575,10 @@ export async function resolveParallelEntry<TEnv>(
557
575
  index: 0,
558
576
  component,
559
577
  loading: parallelEntry.loading === false ? null : parallelEntry.loading,
560
- transition: parallelEntry.transition,
578
+ transition: applyViewTransitionDefault(
579
+ parallelEntry.transition,
580
+ deps.viewTransitionDefault,
581
+ ),
561
582
  params,
562
583
  slot,
563
584
  belongsToRoute,
@@ -624,7 +645,7 @@ export async function resolveAllSegments<TEnv>(
624
645
  // can guard non-cacheable variable reads. Also guards response-level
625
646
  // side effects (headers.set). Persists for all descendant entries.
626
647
  if (entry.type === "cache") {
627
- const store = RSCRouterContext.getStore();
648
+ const store = RangoContext.getStore();
628
649
  if (store) store.insideCacheScope = true;
629
650
  }
630
651
  const doneEntry = track(`segment:${entry.id}`, 1);
@@ -28,9 +28,11 @@ import {
28
28
  resolveSwrWindow,
29
29
  resolveCacheKey,
30
30
  resolveCacheStore,
31
+ resolveTagsOption,
31
32
  DEFAULT_ROUTE_TTL,
32
33
  } from "../../cache/cache-policy.js";
33
34
  import { readThroughItem } from "../../cache/read-through-swr.js";
35
+ import { recordRequestTags } from "../../cache/cache-tag.js";
34
36
  // Lazy-loaded to avoid pulling @vitejs/plugin-rsc/rsc into modules that
35
37
  // import segment-resolution but never use loader caching.
36
38
  let _serializeResult: typeof import("../../cache/segment-codec.js").serializeResult;
@@ -87,23 +89,8 @@ async function resolveLoaderKey(
87
89
  */
88
90
  function resolveTags(loaderEntry: LoaderEntry): string[] | undefined {
89
91
  const options = loaderEntry.cache?.options;
90
- if (!options || !options.tags) return undefined;
91
-
92
- if (typeof options.tags === "function") {
93
- const requestCtx = getRequestContext();
94
- if (!requestCtx) return undefined;
95
- try {
96
- return options.tags(requestCtx);
97
- } catch (error) {
98
- console.error(
99
- `[LoaderCache] Tags function failed, caching without tags:`,
100
- error,
101
- );
102
- return undefined;
103
- }
104
- }
105
-
106
- return options.tags;
92
+ if (!options) return undefined;
93
+ return resolveTagsOption(options.tags, getRequestContext(), "LoaderCache");
107
94
  }
108
95
 
109
96
  function getLoaderStore(
@@ -152,6 +139,10 @@ export function resolveLoaderData<TEnv>(
152
139
  const swrWindow = resolveSwrWindow(options.swr, store.defaults);
153
140
  const swr = swrWindow || undefined;
154
141
  const tags = resolveTags(loaderEntry);
142
+ // Loader tags are config-derived, so they are the complete set whether this is
143
+ // a cache hit or miss; record them every time so a document built from this
144
+ // loader is tagged for invalidation.
145
+ recordRequestTags(tags);
155
146
 
156
147
  // Wrap ctx.use() so cache HIT primes the handler's memoization map.
157
148
  // ctx.use() closes over the match context's loaderPromises (not request context's).