@rangojs/router 0.0.0-experimental.122 → 0.0.0-experimental.125

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 (260) hide show
  1. package/dist/bin/rango.js +10 -6
  2. package/dist/testing/vitest.js +82 -0
  3. package/dist/vite/index.js +55 -48
  4. package/package.json +61 -21
  5. package/skills/caching/SKILL.md +2 -1
  6. package/skills/hooks/SKILL.md +40 -29
  7. package/skills/host-router/SKILL.md +16 -2
  8. package/skills/intercept/SKILL.md +4 -2
  9. package/skills/layout/SKILL.md +11 -6
  10. package/skills/loader/SKILL.md +6 -2
  11. package/skills/middleware/SKILL.md +4 -2
  12. package/skills/migrate-nextjs/SKILL.md +3 -1
  13. package/skills/parallel/SKILL.md +9 -4
  14. package/skills/rango/SKILL.md +12 -0
  15. package/skills/route/SKILL.md +10 -2
  16. package/skills/testing/SKILL.md +129 -0
  17. package/skills/testing/bindings.md +89 -0
  18. package/skills/testing/cache-prerender.md +98 -0
  19. package/skills/testing/client-components.md +122 -0
  20. package/skills/testing/e2e-parity.md +125 -0
  21. package/skills/testing/flight.md +89 -0
  22. package/skills/testing/handles.md +129 -0
  23. package/skills/testing/loader.md +128 -0
  24. package/skills/testing/middleware.md +99 -0
  25. package/skills/testing/render-handler.md +118 -0
  26. package/skills/testing/response-routes.md +95 -0
  27. package/skills/testing/reverse-and-types.md +84 -0
  28. package/skills/testing/server-actions.md +107 -0
  29. package/skills/testing/server-tree.md +128 -0
  30. package/skills/testing/setup.md +120 -0
  31. package/src/__internal.ts +0 -65
  32. package/src/browser/action-coordinator.ts +1 -1
  33. package/src/browser/action-fence.ts +47 -0
  34. package/src/browser/cookie-name.ts +140 -0
  35. package/src/browser/event-controller.ts +1 -83
  36. package/src/browser/invalidate-client-cache.ts +52 -0
  37. package/src/browser/navigation-bridge.ts +14 -1
  38. package/src/browser/navigation-client.ts +14 -1
  39. package/src/browser/navigation-store-handle.ts +38 -0
  40. package/src/browser/navigation-store.ts +26 -51
  41. package/src/browser/navigation-transaction.ts +0 -32
  42. package/src/browser/partial-update.ts +1 -83
  43. package/src/browser/prefetch/cache.ts +6 -45
  44. package/src/browser/prefetch/fetch.ts +7 -0
  45. package/src/browser/prefetch/queue.ts +6 -3
  46. package/src/browser/rango-state.ts +157 -99
  47. package/src/browser/react/Link.tsx +0 -2
  48. package/src/browser/react/NavigationProvider.tsx +2 -1
  49. package/src/browser/react/ScrollRestoration.tsx +10 -6
  50. package/src/browser/react/filter-segment-order.ts +0 -2
  51. package/src/browser/react/index.ts +0 -51
  52. package/src/browser/react/location-state-shared.ts +0 -13
  53. package/src/browser/react/location-state.ts +0 -1
  54. package/src/browser/react/use-action.ts +6 -15
  55. package/src/browser/react/use-handle.ts +0 -5
  56. package/src/browser/react/use-link-status.ts +0 -4
  57. package/src/browser/react/use-navigation.ts +0 -3
  58. package/src/browser/react/use-params.ts +0 -2
  59. package/src/browser/react/use-search-params.ts +0 -5
  60. package/src/browser/react/use-segments.ts +0 -13
  61. package/src/browser/rsc-router.tsx +12 -4
  62. package/src/browser/server-action-bridge.ts +77 -15
  63. package/src/browser/types.ts +7 -2
  64. package/src/browser/validate-redirect-origin.ts +4 -5
  65. package/src/build/route-trie.ts +3 -0
  66. package/src/build/route-types/param-extraction.ts +6 -3
  67. package/src/build/route-types/router-processing.ts +0 -8
  68. package/src/cache/cache-policy.ts +0 -54
  69. package/src/cache/cache-runtime.ts +27 -24
  70. package/src/cache/cache-scope.ts +0 -27
  71. package/src/cache/cache-tag.ts +0 -37
  72. package/src/cache/cf/cf-cache-store.ts +94 -46
  73. package/src/cache/cf/index.ts +0 -24
  74. package/src/cache/document-cache.ts +11 -36
  75. package/src/cache/handle-snapshot.ts +0 -40
  76. package/src/cache/index.ts +0 -27
  77. package/src/cache/memory-segment-store.ts +2 -48
  78. package/src/cache/profile-registry.ts +7 -3
  79. package/src/cache/read-through-swr.ts +41 -11
  80. package/src/cache/segment-codec.ts +0 -16
  81. package/src/cache/types.ts +0 -98
  82. package/src/client.rsc.tsx +1 -22
  83. package/src/client.tsx +14 -38
  84. package/src/component-utils.ts +19 -0
  85. package/src/deps/ssr.ts +0 -1
  86. package/src/handle.ts +28 -18
  87. package/src/handles/MetaTags.tsx +0 -14
  88. package/src/handles/meta.ts +0 -39
  89. package/src/host/cookie-handler.ts +0 -36
  90. package/src/host/errors.ts +0 -24
  91. package/src/host/index.ts +6 -0
  92. package/src/host/pattern-matcher.ts +7 -50
  93. package/src/host/router.ts +1 -65
  94. package/src/host/testing.ts +40 -27
  95. package/src/host/types.ts +6 -2
  96. package/src/href-client.ts +0 -4
  97. package/src/index.rsc.ts +42 -3
  98. package/src/index.ts +31 -1
  99. package/src/internal-debug.ts +2 -4
  100. package/src/loader.rsc.ts +19 -9
  101. package/src/loader.ts +12 -4
  102. package/src/network-error-thrower.tsx +1 -6
  103. package/src/outlet-provider.tsx +1 -5
  104. package/src/prerender/param-hash.ts +10 -11
  105. package/src/prerender/store.ts +23 -30
  106. package/src/prerender.ts +58 -3
  107. package/src/root-error-boundary.tsx +1 -19
  108. package/src/route-content-wrapper.tsx +1 -44
  109. package/src/route-definition/dsl-helpers.ts +7 -19
  110. package/src/route-definition/helpers-types.ts +3 -3
  111. package/src/route-definition/redirect.ts +11 -1
  112. package/src/route-map-builder.ts +0 -16
  113. package/src/router/basename.ts +14 -0
  114. package/src/router/content-negotiation.ts +0 -13
  115. package/src/router/error-handling.ts +12 -16
  116. package/src/router/find-match.ts +4 -30
  117. package/src/router/intercept-resolution.ts +10 -1
  118. package/src/router/lazy-includes.ts +1 -57
  119. package/src/router/loader-resolution.ts +3 -2
  120. package/src/router/logging.ts +0 -6
  121. package/src/router/manifest.ts +1 -25
  122. package/src/router/match-api.ts +0 -20
  123. package/src/router/match-context.ts +0 -22
  124. package/src/router/match-handlers.ts +57 -58
  125. package/src/router/match-middleware/background-revalidation.ts +0 -7
  126. package/src/router/match-middleware/cache-lookup.ts +1 -54
  127. package/src/router/match-middleware/cache-store.ts +0 -31
  128. package/src/router/match-middleware/intercept-resolution.ts +0 -22
  129. package/src/router/match-middleware/segment-resolution.ts +0 -21
  130. package/src/router/match-pipelines.ts +1 -42
  131. package/src/router/match-result.ts +1 -52
  132. package/src/router/metrics.ts +0 -34
  133. package/src/router/middleware-cookies.ts +0 -13
  134. package/src/router/middleware-types.ts +0 -115
  135. package/src/router/middleware.ts +7 -30
  136. package/src/router/navigation-snapshot.ts +0 -51
  137. package/src/router/params-util.ts +23 -0
  138. package/src/router/pattern-matching.ts +1 -33
  139. package/src/router/prerender-match.ts +33 -45
  140. package/src/router/request-classification.ts +1 -38
  141. package/src/router/revalidation.ts +5 -58
  142. package/src/router/router-context.ts +0 -26
  143. package/src/router/router-interfaces.ts +7 -0
  144. package/src/router/router-options.ts +30 -0
  145. package/src/router/segment-resolution/fresh.ts +25 -57
  146. package/src/router/segment-resolution/helpers.ts +34 -0
  147. package/src/router/segment-resolution/loader-cache.ts +10 -13
  148. package/src/router/segment-resolution/revalidation.ts +5 -42
  149. package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
  150. package/src/router/segment-resolution.ts +4 -1
  151. package/src/router/state-cookie-name.ts +33 -0
  152. package/src/router/telemetry-otel.ts +0 -20
  153. package/src/router/telemetry.ts +96 -19
  154. package/src/router/timeout.ts +0 -20
  155. package/src/router/trie-matching.ts +63 -40
  156. package/src/router/types.ts +1 -63
  157. package/src/router/url-params.ts +0 -5
  158. package/src/router.ts +40 -9
  159. package/src/rsc/handler.ts +14 -2
  160. package/src/rsc/helpers.ts +34 -0
  161. package/src/rsc/origin-guard.ts +0 -12
  162. package/src/rsc/progressive-enhancement.ts +4 -1
  163. package/src/rsc/rsc-rendering.ts +4 -7
  164. package/src/rsc/runtime-warnings.ts +14 -0
  165. package/src/rsc/server-action.ts +30 -28
  166. package/src/rsc/types.ts +2 -1
  167. package/src/runtime-env.ts +18 -0
  168. package/src/search-params.ts +0 -16
  169. package/src/segment-loader-promise.ts +14 -2
  170. package/src/segment-system.tsx +79 -88
  171. package/src/server/cookie-store.ts +52 -1
  172. package/src/server/handle-store.ts +7 -24
  173. package/src/server/loader-registry.ts +5 -24
  174. package/src/server/request-context.ts +74 -77
  175. package/src/ssr/index.tsx +14 -14
  176. package/src/static-handler.ts +10 -13
  177. package/src/testing/cache-status.ts +119 -0
  178. package/src/testing/collect-handle.ts +40 -0
  179. package/src/testing/dispatch.ts +581 -0
  180. package/src/testing/dom.entry.ts +22 -0
  181. package/src/testing/e2e/fixture.ts +188 -0
  182. package/src/testing/e2e/index.ts +127 -0
  183. package/src/testing/e2e/matchers.ts +35 -0
  184. package/src/testing/e2e/page-helpers.ts +272 -0
  185. package/src/testing/e2e/parity.ts +387 -0
  186. package/src/testing/e2e/server.ts +195 -0
  187. package/src/testing/flight-matchers.ts +97 -0
  188. package/src/testing/flight-normalize.ts +11 -0
  189. package/src/testing/flight-runtime.d.ts +57 -0
  190. package/src/testing/flight-tree.ts +682 -0
  191. package/src/testing/flight.entry.ts +52 -0
  192. package/src/testing/flight.ts +186 -0
  193. package/src/testing/generated-routes.ts +183 -0
  194. package/src/testing/index.ts +98 -0
  195. package/src/testing/internal/context.ts +348 -0
  196. package/src/testing/internal/flight-client-globals.ts +30 -0
  197. package/src/testing/internal/seed-vars.ts +54 -0
  198. package/src/testing/render-handler.ts +311 -0
  199. package/src/testing/render-route.tsx +504 -0
  200. package/src/testing/run-loader.ts +378 -0
  201. package/src/testing/run-middleware.ts +205 -0
  202. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  203. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  204. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  205. package/src/testing/vitest-stubs/version.ts +5 -0
  206. package/src/testing/vitest.ts +305 -0
  207. package/src/theme/ThemeProvider.tsx +0 -52
  208. package/src/theme/ThemeScript.tsx +0 -6
  209. package/src/theme/constants.ts +0 -12
  210. package/src/theme/index.ts +0 -7
  211. package/src/theme/theme-context.ts +1 -5
  212. package/src/theme/theme-script.ts +0 -14
  213. package/src/theme/use-theme.ts +0 -3
  214. package/src/types/boundaries.ts +0 -35
  215. package/src/types/error-types.ts +25 -89
  216. package/src/types/global-namespace.ts +15 -15
  217. package/src/types/handler-context.ts +16 -13
  218. package/src/types/index.ts +0 -10
  219. package/src/types/request-scope.ts +0 -19
  220. package/src/types/route-config.ts +6 -50
  221. package/src/types/route-entry.ts +0 -6
  222. package/src/types/segments.ts +0 -13
  223. package/src/urls/include-helper.ts +0 -4
  224. package/src/urls/index.ts +0 -6
  225. package/src/urls/path-helper-types.ts +2 -2
  226. package/src/urls/path-helper.ts +0 -54
  227. package/src/urls/urls-function.ts +0 -13
  228. package/src/use-loader.tsx +0 -186
  229. package/src/vite/discovery/bundle-postprocess.ts +2 -1
  230. package/src/vite/discovery/discover-routers.ts +6 -7
  231. package/src/vite/discovery/virtual-module-codegen.ts +1 -11
  232. package/src/vite/plugin-types.ts +3 -1
  233. package/src/vite/plugins/cjs-to-esm.ts +0 -11
  234. package/src/vite/plugins/client-ref-dedup.ts +0 -11
  235. package/src/vite/plugins/client-ref-hashing.ts +0 -10
  236. package/src/vite/plugins/cloudflare-protocol-stub.ts +0 -20
  237. package/src/vite/plugins/expose-action-id.ts +2 -73
  238. package/src/vite/plugins/expose-id-utils.ts +0 -55
  239. package/src/vite/plugins/expose-ids/export-analysis.ts +0 -38
  240. package/src/vite/plugins/expose-ids/handler-transform.ts +0 -15
  241. package/src/vite/plugins/expose-ids/loader-transform.ts +0 -15
  242. package/src/vite/plugins/expose-ids/router-transform.ts +0 -13
  243. package/src/vite/plugins/expose-internal-ids.ts +10 -0
  244. package/src/vite/plugins/performance-tracks.ts +0 -3
  245. package/src/vite/plugins/use-cache-transform.ts +0 -36
  246. package/src/vite/plugins/version-injector.ts +0 -20
  247. package/src/vite/plugins/version-plugin.ts +1 -49
  248. package/src/vite/plugins/virtual-entries.ts +0 -15
  249. package/src/vite/rango.ts +1 -108
  250. package/src/vite/router-discovery.ts +2 -1
  251. package/src/vite/utils/ast-handler-extract.ts +0 -16
  252. package/src/vite/utils/bundle-analysis.ts +6 -13
  253. package/src/vite/utils/client-chunks.ts +0 -6
  254. package/src/vite/utils/forward-user-plugins.ts +0 -22
  255. package/src/vite/utils/manifest-utils.ts +0 -4
  256. package/src/vite/utils/package-resolution.ts +1 -73
  257. package/src/vite/utils/prerender-utils.ts +0 -35
  258. package/src/vite/utils/shared-utils.ts +3 -35
  259. package/src/browser/react/use-client-cache.ts +0 -58
  260. package/src/browser/shallow.ts +0 -40
@@ -27,9 +27,6 @@ import type { UseThemeReturn } from "./types.js";
27
27
  *
28
28
  * Must be used within a ThemeProvider (which is automatically included
29
29
  * in NavigationProvider when theme is enabled in router config).
30
- *
31
- * @returns Theme state and methods
32
- * @throws Error if used outside ThemeProvider
33
30
  */
34
31
  export function useTheme(): UseThemeReturn {
35
32
  const ctx = requireThemeContext();
@@ -1,22 +1,12 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
- /**
4
- * Error information passed to error boundary fallback components
5
- */
6
3
  export interface ErrorInfo {
7
- /** Error message (always available) */
8
4
  message: string;
9
- /** Error name/type (e.g., "RouteNotFoundError", "MiddlewareError") */
10
5
  name: string;
11
- /** Optional error code for programmatic handling */
12
6
  code?: string;
13
- /** Stack trace (only in development) */
14
7
  stack?: string;
15
- /** Original error cause if available */
16
8
  cause?: unknown;
17
- /** Segment ID where the error occurred */
18
9
  segmentId: string;
19
- /** Segment type where the error occurred */
20
10
  segmentType:
21
11
  | "layout"
22
12
  | "route"
@@ -46,13 +36,9 @@ export interface ErrorInfo {
46
36
  * ```
47
37
  */
48
38
  export interface ErrorBoundaryFallbackProps {
49
- /** Error information */
50
39
  error: ErrorInfo;
51
40
  }
52
41
 
53
- /**
54
- * Error boundary handler - receives error info and returns fallback UI
55
- */
56
42
  export type ErrorBoundaryHandler = (
57
43
  props: ErrorBoundaryFallbackProps,
58
44
  ) => ReactNode;
@@ -77,17 +63,10 @@ export type ErrorBoundaryHandler = (
77
63
  * ```
78
64
  */
79
65
  export interface ClientErrorBoundaryFallbackProps {
80
- /** Error information */
81
66
  error: ErrorInfo;
82
- /** Function to reset error state and retry rendering */
83
67
  reset: () => void;
84
68
  }
85
69
 
86
- /**
87
- * Wrapped loader data result for deferred resolution with error handling.
88
- * When loaders are deferred to client-side resolution, errors need to be
89
- * wrapped so the client can handle them appropriately.
90
- */
91
70
  export type LoaderDataResult<T = unknown> =
92
71
  | { __loaderResult: true; ok: true; data: T }
93
72
  | {
@@ -97,9 +76,6 @@ export type LoaderDataResult<T = unknown> =
97
76
  fallback: ReactNode | null;
98
77
  };
99
78
 
100
- /**
101
- * Type guard to check if a value is a wrapped loader result
102
- */
103
79
  export function isLoaderDataResult(value: unknown): value is LoaderDataResult {
104
80
  return (
105
81
  typeof value === "object" &&
@@ -109,15 +85,9 @@ export function isLoaderDataResult(value: unknown): value is LoaderDataResult {
109
85
  );
110
86
  }
111
87
 
112
- /**
113
- * Not found information passed to notFound boundary fallback components
114
- */
115
88
  export interface NotFoundInfo {
116
- /** Not found message */
117
89
  message: string;
118
- /** Segment ID where notFound was thrown */
119
90
  segmentId: string;
120
- /** Segment type where notFound was thrown */
121
91
  segmentType:
122
92
  | "layout"
123
93
  | "route"
@@ -125,7 +95,6 @@ export interface NotFoundInfo {
125
95
  | "loader"
126
96
  | "middleware"
127
97
  | "cache";
128
- /** The pathname that triggered the not found */
129
98
  pathname?: string;
130
99
  }
131
100
 
@@ -146,13 +115,9 @@ export interface NotFoundInfo {
146
115
  * ```
147
116
  */
148
117
  export interface NotFoundBoundaryFallbackProps {
149
- /** Not found information */
150
118
  notFound: NotFoundInfo;
151
119
  }
152
120
 
153
- /**
154
- * NotFound boundary handler - receives not found info and returns fallback UI
155
- */
156
121
  export type NotFoundBoundaryHandler = (
157
122
  props: NotFoundBoundaryFallbackProps,
158
123
  ) => ReactNode;
@@ -14,19 +14,19 @@
14
14
  * - "unknown": Fallback for unclassified errors (not currently invoked)
15
15
  */
16
16
  export type ErrorPhase =
17
- | "routing" // During route matching
18
- | "manifest" // During manifest loading (reserved, not currently invoked)
19
- | "middleware" // During middleware execution (errors propagate to handler phase)
20
- | "loader" // During loader execution
21
- | "handler" // During route/layout handler execution
22
- | "rendering" // During RSC/SSR rendering (SSR handler uses separate callback)
23
- | "action" // During server action execution
24
- | "revalidation" // During revalidation evaluation
25
- | "cache" // During "use cache" background operations (stale revalidation, async cache writes)
26
- | "prerender" // During build-time pre-rendering (Vite closeBundle)
27
- | "static" // During build-time static handler rendering (Vite closeBundle)
28
- | "origin" // During cross-origin request validation (CSRF protection)
29
- | "unknown"; // Fallback for unclassified errors
17
+ | "routing"
18
+ | "manifest"
19
+ | "middleware"
20
+ | "loader"
21
+ | "handler"
22
+ | "rendering"
23
+ | "action"
24
+ | "revalidation"
25
+ | "cache"
26
+ | "prerender"
27
+ | "static"
28
+ | "origin"
29
+ | "unknown";
30
30
 
31
31
  /**
32
32
  * Comprehensive context passed to onError callback
@@ -59,99 +59,35 @@ export type ErrorPhase =
59
59
  * ```
60
60
  */
61
61
  export interface OnErrorContext<TEnv = any> {
62
- /**
63
- * The error that occurred
64
- */
65
62
  error: Error;
66
-
67
- /**
68
- * Phase where the error occurred
69
- */
70
63
  phase: ErrorPhase;
71
-
72
- /**
73
- * The original request
74
- */
75
64
  request: Request;
76
-
77
- /**
78
- * Parsed URL from the request
79
- */
80
65
  url: URL;
81
-
82
- /**
83
- * Request pathname
84
- */
85
66
  pathname: string;
86
-
87
- /**
88
- * HTTP method
89
- */
90
67
  method: string;
91
-
92
- /**
93
- * Matched route key (if available)
94
- * e.g., "shop.products.detail"
95
- */
68
+ /** Matched route key (if available) e.g., "shop.products.detail" */
96
69
  routeKey?: string;
97
-
98
- /**
99
- * Route params (if available)
100
- * e.g., { slug: "headphones" }
101
- */
70
+ /** Route params (if available) e.g., { slug: "headphones" } */
102
71
  params?: Record<string, string>;
103
-
104
- /**
105
- * Segment ID where error occurred (if available)
106
- * e.g., "M1L0" for a layout, "M1R0" for a route
107
- */
72
+ /** Segment ID where error occurred (if available) e.g., "M1L0" for a layout, "M1R0" for a route */
108
73
  segmentId?: string;
109
-
110
- /**
111
- * Segment type where error occurred (if available)
112
- */
74
+ /** Segment type where error occurred (if available) */
113
75
  segmentType?: "layout" | "route" | "parallel" | "loader" | "middleware";
114
-
115
- /**
116
- * Loader name (if error occurred in a loader)
117
- */
76
+ /** Loader name (if error occurred in a loader) */
118
77
  loaderName?: string;
119
-
120
- /**
121
- * Middleware name/id (if error occurred in middleware)
122
- */
78
+ /** Middleware name/id (if error occurred in middleware) */
123
79
  middlewareId?: string;
124
-
125
- /**
126
- * Action ID (if error occurred during server action)
127
- * e.g., "src/actions.ts#addToCart"
128
- */
80
+ /** Action ID (if error occurred during server action) e.g., "src/actions.ts#addToCart" */
129
81
  actionId?: string;
130
-
131
- /**
132
- * Environment/bindings (platform context)
133
- */
82
+ /** Environment/bindings (platform context) */
134
83
  env?: TEnv;
135
-
136
- /**
137
- * Duration from request start to error (milliseconds)
138
- */
84
+ /** Duration from request start to error (milliseconds) */
139
85
  duration?: number;
140
-
141
- /**
142
- * Whether this is a partial/navigation request
143
- */
86
+ /** Whether this is a partial/navigation request */
144
87
  isPartial?: boolean;
145
-
146
- /**
147
- * Whether an error boundary caught the error
148
- * If true, the error was handled and a fallback UI was rendered
149
- */
88
+ /** Whether an error boundary caught the error */
150
89
  handledByBoundary?: boolean;
151
-
152
- /**
153
- * Stack trace (if available)
154
- */
90
+ /** Stack trace (if available) */
155
91
  stack?: string;
156
92
 
157
93
  /**
@@ -20,26 +20,16 @@
20
20
  declare global {
21
21
  namespace Rango {
22
22
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
23
- interface Env {
24
- // Empty by default - users augment with their bindings (e.g., { DB: D1Database })
25
- }
23
+ interface Env {}
26
24
 
27
25
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
28
- interface Vars {
29
- // Empty by default - users augment with their variables (e.g., { user?: User })
30
- }
26
+ interface Vars {}
31
27
 
32
28
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
33
- interface RegisteredRoutes {
34
- // Empty by default - users augment with their merged route maps for type-safe href()
35
- // Values are string (pattern) for RSC routes, or { path: string; response: T } for response routes
36
- }
29
+ interface RegisteredRoutes {}
37
30
 
38
31
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
39
- interface GeneratedRouteMap {
40
- // Empty by default - populated by generated named-routes.gen.ts
41
- // Maps route names to URL pattern strings for Handler<"routeName"> support
42
- }
32
+ interface GeneratedRouteMap {}
43
33
  }
44
34
  }
45
35
 
@@ -97,7 +87,17 @@ export type DefaultHandlerRouteMap = keyof Rango.GeneratedRouteMap extends never
97
87
  export type DefaultEnv = keyof Rango.Env extends never ? unknown : Rango.Env;
98
88
 
99
89
  /**
100
- * Default variables type - uses global augmentation if available, Record<string, any> otherwise
90
+ * Variables type backing the string-key `ctx.get` / `ctx.set` overloads.
91
+ *
92
+ * Uses `Rango.Vars` augmentation when present; otherwise falls back to
93
+ * `Record<string, any>` so an un-augmented app can use string-key vars with
94
+ * zero config -- at the cost of a typo'd key being silently `any`.
95
+ *
96
+ * This `any` fallback is deliberate (see #561) and is an intentional asymmetry
97
+ * with `DefaultEnv` above, which falls back to `unknown`: env bindings are
98
+ * platform-critical and should be registered, so a forgotten binding is made a
99
+ * compile error; vars are ad-hoc and middleware-set, so the zero-config path
100
+ * wins. Augment `Rango.Vars` for type-safe keys.
101
101
  */
102
102
  export type DefaultVars = keyof Rango.Vars extends never
103
103
  ? Record<string, any>
@@ -107,14 +107,6 @@ type StrictLocalParamsWithExtras<TEntry> =
107
107
  ? Record<string, string>
108
108
  : ExtractParamsFromEntry<TEntry, {}> & Record<string, string>;
109
109
 
110
- // HandlerContext.reverse is the only reverse surface with runtime param autofill
111
- // from the current matched request. Middleware/loaders/request context do not
112
- // have the same local-route guarantees, so they keep plain ScopedReverseFunction.
113
- //
114
- // When a handler has an explicit local route map, enforce that local route
115
- // params declared by that map are present while still allowing extra mount
116
- // params to be passed through. Global names remain autofill-friendly because
117
- // parent include() params are often unknown at the module definition site.
118
110
  type StrictLocalAutofillGlobalReverseFunction<TLocalRoutes, TGlobalRoutes> =
119
111
  ScopedReverseFunction<TLocalRoutes, TGlobalRoutes> & {
120
112
  <TName extends keyof TGlobalRoutes & string>(
@@ -535,13 +527,24 @@ export type ActionRef =
535
527
  * downstream revalidators, or nothing (`void` / `null` / `undefined`) to defer
536
528
  * to the current suggestion without changing it.
537
529
  *
530
+ * Two idioms cover almost every case; they differ only in what an _unrelated_
531
+ * action does. Match actions by reference with `ctx.isAction()` (rename-safe)
532
+ * rather than `actionId?.includes("...")` (a renamed or moved action silently
533
+ * stops matching). Because `isAction` returns a raw boolean, combine it with
534
+ * `|| undefined` to defer or leave it bare to suppress.
535
+ *
538
536
  * @example
539
537
  * ```ts
540
- * // Re-render when a cart action happened or the browser signals staleness;
541
- * // defer otherwise (|| undefined) so the segment default still applies
542
- * revalidate(({ actionId, stale }) =>
543
- * actionId?.includes("cart") || stale || undefined
544
- * )
538
+ * import * as CartActions from "./actions/cart";
539
+ *
540
+ * // Idiom A — "mine, else defer": re-render on my actions, otherwise return
541
+ * // undefined so the segment's default decision still applies (and downstream
542
+ * // revalidators get a say).
543
+ * revalidate((ctx) => ctx.isAction(CartActions) || undefined)
544
+ *
545
+ * // Idiom B — "mine only": re-render on my actions and suppress everything
546
+ * // else (isAction returns a raw boolean, so an unrelated action yields false).
547
+ * revalidate((ctx) => ctx.isAction(CartActions))
545
548
  *
546
549
  * // Always re-render when params change (default behavior made explicit)
547
550
  * revalidate(({ defaultShouldRevalidate }) => defaultShouldRevalidate)
@@ -1,14 +1,11 @@
1
- // Global namespace (must be imported for side effects: `declare global`)
2
1
  export type {
3
2
  GetRegisteredRoutes,
4
3
  DefaultHandlerRouteMap,
5
4
  DefaultReverseRouteMap,
6
5
  DefaultEnv,
7
6
  } from "./global-namespace.js";
8
- // Ensure the global namespace declaration is evaluated
9
7
  import "./global-namespace.js";
10
8
 
11
- // Route configuration
12
9
  export type {
13
10
  DocumentProps,
14
11
  ExtractParams,
@@ -19,7 +16,6 @@ export type {
19
16
  ResolvedRouteMap,
20
17
  } from "./route-config.js";
21
18
 
22
- // Boundaries (error/notFound)
23
19
  export type {
24
20
  ErrorInfo,
25
21
  ErrorBoundaryFallbackProps,
@@ -32,7 +28,6 @@ export type {
32
28
  } from "./boundaries.js";
33
29
  export { isLoaderDataResult } from "./boundaries.js";
34
30
 
35
- // Handler context and related types
36
31
  export type {
37
32
  MiddlewareFn,
38
33
  ScopedRouteMap,
@@ -50,7 +45,6 @@ export type {
50
45
  Middleware,
51
46
  } from "./handler-context.js";
52
47
 
53
- // Segments
54
48
  export type {
55
49
  ViewTransitionClass,
56
50
  TransitionConfig,
@@ -61,10 +55,8 @@ export type {
61
55
  MatchResult,
62
56
  } from "./segments.js";
63
57
 
64
- // Route entries
65
58
  export type { LazyIncludeContext, RouteEntry } from "./route-entry.js";
66
59
 
67
- // Loader types
68
60
  export type {
69
61
  LoaderContext,
70
62
  LoaderFn,
@@ -73,7 +65,6 @@ export type {
73
65
  LoaderDefinition,
74
66
  } from "./loader-types.js";
75
67
 
76
- // Cache types
77
68
  export type {
78
69
  CacheContext,
79
70
  CacheOptions,
@@ -81,7 +72,6 @@ export type {
81
72
  EntryCacheConfig,
82
73
  } from "./cache-types.js";
83
74
 
84
- // Error handling types
85
75
  export type {
86
76
  ErrorPhase,
87
77
  OnErrorContext,
@@ -1,22 +1,3 @@
1
- /**
2
- * RequestScope: the fields every user-facing context shares.
3
- *
4
- * A handler, middleware, loader, response handler, and the ALS-bound
5
- * RequestContext are all different phases of the same request, and they
6
- * all carry the same set of request-scoped capabilities: the raw Request,
7
- * the parsed URL pair (`url` is cleaned of internal `_rsc*` params,
8
- * `originalUrl` retains them), pathname/searchParams, platform bindings
9
- * (`env`), and two escape hatches for work that outlives the response
10
- * (`waitUntil`) or needs the raw Cloudflare runtime object
11
- * (`executionContext`).
12
- *
13
- * Each public context type intersects `RequestScope<TEnv>` with its own
14
- * phase-specific fields (e.g. `params`/`reverse` on HandlerContext,
15
- * `headers`/`header()` on MiddlewareContext). That keeps platform surface
16
- * in one place and lets the next runtime escape hatch we need land in
17
- * one file instead of four.
18
- */
19
-
20
1
  import type { DefaultEnv } from "./global-namespace.js";
21
2
 
22
3
  /**
@@ -7,47 +7,24 @@ export type DocumentProps = {
7
7
  children: ReactNode;
8
8
  };
9
9
 
10
- /**
11
- * Parse constraint values into a union type
12
- * "a|b|c" -> "a" | "b" | "c"
13
- */
14
10
  type ParseConstraint<T extends string> =
15
11
  T extends `${infer First}|${infer Rest}` ? First | ParseConstraint<Rest> : T;
16
12
 
17
- /**
18
- * Extract param info from a param segment
19
- *
20
- * Handles:
21
- * - :param -> { name: "param", optional: false, type: string }
22
- * - :param? -> { name: "param", optional: true, type: string }
23
- * - :param(a|b) -> { name: "param", optional: false, type: "a" | "b" }
24
- * - :param(a|b)? -> { name: "param", optional: true, type: "a" | "b" }
25
- */
26
13
  type ExtractParamInfo<T extends string> =
27
- // Optional + constrained (with optional suffix): :param(a|b)?suffix
28
14
  T extends `${infer Name}(${infer Constraint})?${string}`
29
15
  ? { name: Name; optional: true; type: ParseConstraint<Constraint> }
30
- : // Constrained (with optional suffix): :param(a|b)suffix
31
- T extends `${infer Name}(${infer Constraint})${string}`
16
+ : T extends `${infer Name}(${infer Constraint})${string}`
32
17
  ? { name: Name; optional: false; type: ParseConstraint<Constraint> }
33
- : // Optional (with optional suffix): :param?suffix
34
- T extends `${infer Name}?${string}`
18
+ : T extends `${infer Name}?${string}`
35
19
  ? { name: Name; optional: true; type: string }
36
- : // Param with dot-suffix: :param.html
37
- T extends `${infer Name}.${string}`
20
+ : T extends `${infer Name}.${string}`
38
21
  ? { name: Name; optional: false; type: string }
39
- : // Param with dash-suffix: :param-slug
40
- T extends `${infer Name}-${string}`
22
+ : T extends `${infer Name}-${string}`
41
23
  ? { name: Name; optional: false; type: string }
42
- : // Param with tilde-suffix: :param~v2
43
- T extends `${infer Name}~${string}`
24
+ : T extends `${infer Name}~${string}`
44
25
  ? { name: Name; optional: false; type: string }
45
- : // Required: :param (no suffix)
46
- { name: T; optional: false; type: string };
26
+ : { name: T; optional: false; type: string };
47
27
 
48
- /**
49
- * Build param object from info
50
- */
51
28
  type ParamFromInfo<Info> = Info extends {
52
29
  name: infer N extends string;
53
30
  optional: true;
@@ -62,10 +39,6 @@ type ParamFromInfo<Info> = Info extends {
62
39
  ? { [K in N]: V }
63
40
  : never;
64
41
 
65
- /**
66
- * Merge two param objects preserving optionality
67
- * Uses Pick to preserve the modifiers from source types
68
- */
69
42
  type MergeParams<A, B> = Pick<A, keyof A> & Pick<B, keyof B> extends infer O
70
43
  ? { [K in keyof O]: O[K] }
71
44
  : never;
@@ -109,17 +82,11 @@ export type ExtractParams<
109
82
  */
110
83
  export type TrailingSlashMode = "never" | "always" | "ignore";
111
84
 
112
- /**
113
- * Route configuration object (alternative to string path)
114
- */
115
85
  export type RouteConfig = {
116
86
  path: string;
117
87
  trailingSlash?: TrailingSlashMode;
118
88
  };
119
89
 
120
- /**
121
- * Route definition options (global defaults)
122
- */
123
90
  export type RouteDefinitionOptions = {
124
91
  trailingSlash?: TrailingSlashMode;
125
92
  };
@@ -128,11 +95,6 @@ export type RouteDefinition = {
128
95
  [key: string]: string | RouteConfig | RouteDefinition;
129
96
  };
130
97
 
131
- /**
132
- * Recursively flatten nested routes with depth limit to prevent infinite recursion
133
- * Transforms: { products: { detail: "/product/:slug" } } => { "products.detail": "/product/:slug" }
134
- * Also handles RouteConfig objects: { api: { path: "/api" } } => { "api": "/api" }
135
- */
136
98
  type FlattenRoutes<
137
99
  T extends RouteDefinition,
138
100
  Prefix extends string = "",
@@ -153,18 +115,12 @@ type FlattenRoutes<
153
115
  : never;
154
116
  }[keyof T];
155
117
 
156
- /**
157
- * Union to intersection helper
158
- */
159
118
  type UnionToIntersection<U> = (
160
119
  U extends unknown ? (k: U) => void : never
161
120
  ) extends (k: infer I) => void
162
121
  ? I
163
122
  : never;
164
123
 
165
- /**
166
- * Resolved route map - flattened route definitions with full paths
167
- */
168
124
  export type ResolvedRouteMap<T extends RouteDefinition> = UnionToIntersection<
169
125
  FlattenRoutes<T>
170
126
  >;
@@ -1,9 +1,6 @@
1
1
  import type { AllUseItems } from "../route-types.js";
2
2
  import type { TrailingSlashMode, ResolvedRouteMap } from "./route-config.js";
3
3
 
4
- /**
5
- * Context captured for lazy include evaluation
6
- */
7
4
  export interface LazyIncludeContext {
8
5
  urlPrefix: string;
9
6
  namePrefix: string | undefined;
@@ -25,9 +22,6 @@ export interface LazyIncludeContext {
25
22
  includeScope?: string;
26
23
  }
27
24
 
28
- /**
29
- * Internal route entry stored in router
30
- */
31
25
  export interface RouteEntry<TEnv = any> {
32
26
  prefix: string;
33
27
  /**
@@ -41,14 +41,6 @@ export interface TransitionConfig {
41
41
  /**
42
42
  * Resolved segment with component
43
43
  *
44
- * Segment types:
45
- * - layout: Wraps child content via <Outlet />
46
- * - route: The leaf content for a URL
47
- * - parallel: Named slots rendered via <ParallelOutlet name="@slot" />
48
- * - loader: Data segment (no visual rendering, carries loaderData)
49
- * - error: Error fallback segment (replaces failed segment with error UI)
50
- * - notFound: Not found fallback segment (replaces segment when data not found)
51
- *
52
44
  * @internal This type is an implementation detail and may change without notice.
53
45
  */
54
46
  export interface ResolvedSegment {
@@ -89,11 +81,6 @@ export interface ResolvedSegment {
89
81
  _handlerRan?: boolean;
90
82
  }
91
83
 
92
- /**
93
- * Segment metadata (without component)
94
- *
95
- * @internal This type is an implementation detail and may change without notice.
96
- */
97
84
  export interface SegmentMetadata {
98
85
  id: string;
99
86
  type: "layout" | "route" | "parallel" | "loader" | "error" | "notFound";
@@ -37,10 +37,8 @@ export function processItems(items: readonly AllUseItems[]): AllUseItems[] {
37
37
  if (!item) continue;
38
38
 
39
39
  if (item.type === "include") {
40
- // All includes are lazy; the router expands them on first matching request.
41
40
  result.push(item);
42
41
  } else if (item.type === "layout" && (item as any).uses) {
43
- // Process nested items in layout
44
42
  const layoutItem = item as any;
45
43
  layoutItem.uses = processItems(layoutItem.uses);
46
44
  result.push(layoutItem);
@@ -141,8 +139,6 @@ export function createIncludeHelper<TEnv>(): IncludeFn<TEnv> {
141
139
  ? (parentRootScoped ?? false)
142
140
  : parentRootScoped;
143
141
 
144
- // All includes are lazy - patterns are evaluated on first matching request
145
- // This improves cold start time significantly for large route sets
146
142
  return {
147
143
  type: "include",
148
144
  name,
package/src/urls/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- // Response types and symbols
2
1
  export {
3
2
  RESPONSE_TYPE,
4
3
  type ResponseHandler,
@@ -8,7 +7,6 @@ export {
8
7
  type ResponseHandlerContext,
9
8
  } from "./response-types.js";
10
9
 
11
- // Pattern types
12
10
  export type {
13
11
  UnnamedRoute,
14
12
  LocalOnlyInclude,
@@ -17,7 +15,6 @@ export type {
17
15
  IncludeOptions,
18
16
  } from "./pattern-types.js";
19
17
 
20
- // Type extraction utilities
21
18
  export type {
22
19
  ExtractRoutes,
23
20
  ExtractResponses,
@@ -25,7 +22,6 @@ export type {
25
22
  RouteResponse,
26
23
  } from "./type-extraction.js";
27
24
 
28
- // Path helper types
29
25
  export type {
30
26
  PathFn,
31
27
  ResponsePathFn,
@@ -35,10 +31,8 @@ export type {
35
31
  PathHelpers,
36
32
  } from "./path-helper-types.js";
37
33
 
38
- // Main entry point
39
34
  export { urls } from "./urls-function.js";
40
35
 
41
- // Re-exports from route-types
42
36
  export type {
43
37
  AllUseItems,
44
38
  IncludeItem,
@@ -348,9 +348,9 @@ export type PathHelpers<TEnv> = {
348
348
  <const TChildren extends readonly (AllUseItems | readonly AllUseItems[])[]>(
349
349
  children: () => TChildren,
350
350
  ): TypedCacheItem<ExtractRoutes<TChildren>, ExtractResponses<TChildren>>;
351
- (options: PartialCacheOptions | false): TypedCacheItem<{}, {}>;
351
+ (options: PartialCacheOptions<TEnv> | false): TypedCacheItem<{}, {}>;
352
352
  <const TChildren extends readonly (AllUseItems | readonly AllUseItems[])[]>(
353
- options: PartialCacheOptions | false,
353
+ options: PartialCacheOptions<TEnv> | false,
354
354
  use: () => TChildren,
355
355
  ): TypedCacheItem<ExtractRoutes<TChildren>, ExtractResponses<TChildren>>;
356
356
  };