react-router 8.3.1 → 8.5.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 (218) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/development/dom-export.d.ts +2 -1
  3. package/dist/development/dom-export.js +1 -1
  4. package/dist/development/index-react-server-client.js +2 -2
  5. package/dist/development/index-react-server.d.ts +601 -189
  6. package/dist/development/index-react-server.js +100 -48
  7. package/dist/development/index.d.ts +10 -9
  8. package/dist/development/index.js +6 -5
  9. package/dist/development/lib/actions.js +1 -1
  10. package/dist/development/lib/components.js +66 -10
  11. package/dist/development/lib/context.d.ts +19 -6
  12. package/dist/development/lib/context.js +11 -3
  13. package/dist/development/lib/dom/dom.d.ts +3 -0
  14. package/dist/development/lib/dom/dom.js +1 -1
  15. package/dist/development/lib/dom/global.d.ts +35 -0
  16. package/dist/development/lib/dom/lib.d.ts +34 -9
  17. package/dist/development/lib/dom/lib.js +30 -37
  18. package/dist/development/lib/dom/server.d.ts +6 -1
  19. package/dist/development/lib/dom/server.js +41 -15
  20. package/dist/development/lib/dom/ssr/components.js +26 -31
  21. package/dist/development/lib/dom/ssr/data.js +1 -1
  22. package/dist/development/lib/dom/ssr/entry.d.ts +13 -2
  23. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  24. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  25. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +3 -2
  26. package/dist/development/lib/dom/ssr/fog-of-war.js +46 -22
  27. package/dist/development/lib/dom/ssr/hydration.d.ts +3 -1
  28. package/dist/development/lib/dom/ssr/hydration.js +6 -4
  29. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  30. package/dist/development/lib/dom/ssr/links.js +1 -1
  31. package/dist/development/lib/dom/ssr/markup.js +5 -2
  32. package/dist/development/lib/dom/ssr/route-discovery.d.ts +120 -0
  33. package/dist/development/lib/dom/ssr/route-discovery.js +415 -0
  34. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  35. package/dist/development/lib/dom/ssr/routes-test-stub.js +2 -2
  36. package/dist/development/lib/dom/ssr/routes.d.ts +2 -2
  37. package/dist/development/lib/dom/ssr/routes.js +8 -8
  38. package/dist/development/lib/dom/ssr/server.js +4 -2
  39. package/dist/development/lib/dom/ssr/single-fetch.d.ts +28 -2
  40. package/dist/development/lib/dom/ssr/single-fetch.js +80 -71
  41. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  42. package/dist/development/lib/dom-export/hydrated-router.d.ts +28 -0
  43. package/dist/development/lib/dom-export/hydrated-router.js +33 -12
  44. package/dist/development/lib/errors.js +1 -1
  45. package/dist/development/lib/hooks.d.ts +3 -3
  46. package/dist/development/lib/hooks.js +52 -47
  47. package/dist/development/lib/href.js +1 -1
  48. package/dist/development/lib/router/history.js +1 -1
  49. package/dist/development/lib/router/instrumentation.js +1 -1
  50. package/dist/development/lib/router/matcher-route-pattern.d.ts +2 -0
  51. package/dist/development/lib/router/matcher-route-pattern.js +216 -0
  52. package/dist/development/lib/router/matcher-route-pattern.preload.d.ts +20 -0
  53. package/dist/development/lib/router/matcher-route-pattern.preload.js +36 -0
  54. package/dist/development/lib/router/matcher.d.ts +2 -0
  55. package/dist/development/lib/router/matcher.js +29 -0
  56. package/dist/development/lib/router/navigation.js +1 -1
  57. package/dist/development/lib/router/router.d.ts +19 -7
  58. package/dist/development/lib/router/router.js +235 -128
  59. package/dist/development/lib/router/url.js +1 -1
  60. package/dist/development/lib/router/utils.d.ts +30 -5
  61. package/dist/development/lib/router/utils.js +8 -5
  62. package/dist/development/lib/rsc/browser.js +3 -2
  63. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  64. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  65. package/dist/development/lib/rsc/html-stream/server.js +25 -15
  66. package/dist/development/lib/rsc/route-modules.js +1 -1
  67. package/dist/development/lib/rsc/server.rsc.d.ts +10 -2
  68. package/dist/development/lib/rsc/server.ssr.js +25 -21
  69. package/dist/development/lib/server-runtime/build.d.ts +14 -0
  70. package/dist/development/lib/server-runtime/cookies.js +1 -1
  71. package/dist/development/lib/server-runtime/crypto.js +1 -1
  72. package/dist/development/lib/server-runtime/data.js +1 -1
  73. package/dist/development/lib/server-runtime/dev.js +1 -1
  74. package/dist/development/lib/server-runtime/entry.js +1 -1
  75. package/dist/development/lib/server-runtime/errors.js +1 -1
  76. package/dist/development/lib/server-runtime/headers.js +1 -1
  77. package/dist/development/lib/server-runtime/invariant.js +1 -1
  78. package/dist/development/lib/server-runtime/mode.js +1 -1
  79. package/dist/development/lib/server-runtime/routeMatching.js +3 -4
  80. package/dist/development/lib/server-runtime/routes.d.ts +1 -1
  81. package/dist/development/lib/server-runtime/routes.js +1 -1
  82. package/dist/development/lib/server-runtime/server.js +18 -9
  83. package/dist/development/lib/server-runtime/serverHandoff.d.ts +17 -0
  84. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  85. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  86. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  87. package/dist/development/lib/server-runtime/sessions.js +1 -1
  88. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  89. package/dist/development/lib/server-runtime/urls.js +1 -1
  90. package/dist/development/lib/server-runtime/warnings.js +1 -1
  91. package/dist/development/lib/types/internal.js +1 -1
  92. package/dist/development/lib/types/route-data.d.ts +2 -2
  93. package/dist/development/lib/types/route-module-annotations.d.ts +1 -1
  94. package/dist/development/route-pattern.d.ts +3 -0
  95. package/dist/development/route-pattern.js +12 -0
  96. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  97. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  98. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  99. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  100. package/dist/production/dom-export.d.ts +2 -1
  101. package/dist/production/dom-export.js +1 -1
  102. package/dist/production/index-react-server-client.js +2 -2
  103. package/dist/production/index-react-server.d.ts +601 -189
  104. package/dist/production/index-react-server.js +100 -48
  105. package/dist/production/index.d.ts +10 -9
  106. package/dist/production/index.js +6 -5
  107. package/dist/production/lib/actions.js +1 -1
  108. package/dist/production/lib/components.js +66 -10
  109. package/dist/production/lib/context.d.ts +19 -6
  110. package/dist/production/lib/context.js +11 -3
  111. package/dist/production/lib/dom/dom.d.ts +3 -0
  112. package/dist/production/lib/dom/dom.js +1 -1
  113. package/dist/production/lib/dom/global.d.ts +35 -0
  114. package/dist/production/lib/dom/lib.d.ts +34 -9
  115. package/dist/production/lib/dom/lib.js +30 -37
  116. package/dist/production/lib/dom/server.d.ts +6 -1
  117. package/dist/production/lib/dom/server.js +41 -15
  118. package/dist/production/lib/dom/ssr/components.js +26 -31
  119. package/dist/production/lib/dom/ssr/data.js +1 -1
  120. package/dist/production/lib/dom/ssr/entry.d.ts +13 -2
  121. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  122. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  123. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +3 -2
  124. package/dist/production/lib/dom/ssr/fog-of-war.js +46 -22
  125. package/dist/production/lib/dom/ssr/hydration.d.ts +3 -1
  126. package/dist/production/lib/dom/ssr/hydration.js +6 -4
  127. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  128. package/dist/production/lib/dom/ssr/links.js +1 -1
  129. package/dist/production/lib/dom/ssr/markup.js +5 -2
  130. package/dist/production/lib/dom/ssr/route-discovery.d.ts +120 -0
  131. package/dist/production/lib/dom/ssr/route-discovery.js +415 -0
  132. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  133. package/dist/production/lib/dom/ssr/routes-test-stub.js +2 -2
  134. package/dist/production/lib/dom/ssr/routes.d.ts +2 -2
  135. package/dist/production/lib/dom/ssr/routes.js +8 -8
  136. package/dist/production/lib/dom/ssr/server.js +4 -2
  137. package/dist/production/lib/dom/ssr/single-fetch.d.ts +28 -2
  138. package/dist/production/lib/dom/ssr/single-fetch.js +80 -71
  139. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  140. package/dist/production/lib/dom-export/hydrated-router.d.ts +28 -0
  141. package/dist/production/lib/dom-export/hydrated-router.js +33 -12
  142. package/dist/production/lib/errors.js +1 -1
  143. package/dist/production/lib/hooks.d.ts +3 -3
  144. package/dist/production/lib/hooks.js +51 -46
  145. package/dist/production/lib/href.js +1 -1
  146. package/dist/production/lib/router/history.js +1 -1
  147. package/dist/production/lib/router/instrumentation.js +1 -1
  148. package/dist/production/lib/router/matcher-route-pattern.d.ts +2 -0
  149. package/dist/production/lib/router/matcher-route-pattern.js +216 -0
  150. package/dist/production/lib/router/matcher-route-pattern.preload.d.ts +20 -0
  151. package/dist/production/lib/router/matcher-route-pattern.preload.js +36 -0
  152. package/dist/production/lib/router/matcher.d.ts +2 -0
  153. package/dist/production/lib/router/matcher.js +29 -0
  154. package/dist/production/lib/router/navigation.js +1 -1
  155. package/dist/production/lib/router/router.d.ts +19 -7
  156. package/dist/production/lib/router/router.js +235 -128
  157. package/dist/production/lib/router/url.js +1 -1
  158. package/dist/production/lib/router/utils.d.ts +30 -5
  159. package/dist/production/lib/router/utils.js +8 -5
  160. package/dist/production/lib/rsc/browser.js +3 -2
  161. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  162. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  163. package/dist/production/lib/rsc/html-stream/server.js +25 -15
  164. package/dist/production/lib/rsc/route-modules.js +1 -1
  165. package/dist/production/lib/rsc/server.rsc.d.ts +10 -2
  166. package/dist/production/lib/rsc/server.ssr.js +25 -21
  167. package/dist/production/lib/server-runtime/build.d.ts +14 -0
  168. package/dist/production/lib/server-runtime/cookies.js +1 -1
  169. package/dist/production/lib/server-runtime/crypto.js +1 -1
  170. package/dist/production/lib/server-runtime/data.js +1 -1
  171. package/dist/production/lib/server-runtime/dev.js +1 -1
  172. package/dist/production/lib/server-runtime/entry.js +1 -1
  173. package/dist/production/lib/server-runtime/errors.js +1 -1
  174. package/dist/production/lib/server-runtime/headers.js +1 -1
  175. package/dist/production/lib/server-runtime/invariant.js +1 -1
  176. package/dist/production/lib/server-runtime/mode.js +1 -1
  177. package/dist/production/lib/server-runtime/routeMatching.js +3 -4
  178. package/dist/production/lib/server-runtime/routes.d.ts +1 -1
  179. package/dist/production/lib/server-runtime/routes.js +1 -1
  180. package/dist/production/lib/server-runtime/server.js +18 -9
  181. package/dist/production/lib/server-runtime/serverHandoff.d.ts +17 -0
  182. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  183. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  184. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  185. package/dist/production/lib/server-runtime/sessions.js +1 -1
  186. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  187. package/dist/production/lib/server-runtime/urls.js +1 -1
  188. package/dist/production/lib/server-runtime/warnings.js +1 -1
  189. package/dist/production/lib/types/internal.js +1 -1
  190. package/dist/production/lib/types/route-data.d.ts +2 -2
  191. package/dist/production/lib/types/route-module-annotations.d.ts +1 -1
  192. package/dist/production/route-pattern.d.ts +3 -0
  193. package/dist/production/route-pattern.js +12 -0
  194. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  195. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  196. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  197. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  198. package/docs/explanation/lazy-route-discovery.md +4 -0
  199. package/docs/explanation/sessions-and-cookies.md +108 -4
  200. package/docs/how-to/custom-fetch.md +218 -0
  201. package/docs/how-to/data-strategy.md +23 -1
  202. package/docs/how-to/fetchers.md +6 -1
  203. package/docs/how-to/middleware.md +4 -1
  204. package/docs/how-to/optimize-revalidation.md +178 -5
  205. package/docs/how-to/pre-rendering.md +23 -1
  206. package/docs/how-to/react-server-components.md +26 -3
  207. package/docs/how-to/resource-routes.md +3 -0
  208. package/docs/how-to/route-discovery.md +145 -0
  209. package/docs/how-to/spa.md +2 -0
  210. package/docs/how-to/view-transitions.md +80 -13
  211. package/docs/start/data/actions.md +2 -1
  212. package/docs/start/data/route-object.md +21 -6
  213. package/docs/start/framework/actions.md +4 -2
  214. package/docs/start/framework/navigating.md +5 -9
  215. package/docs/start/framework/rendering.md +37 -0
  216. package/docs/start/framework/route-module.md +32 -5
  217. package/docs/upgrading/future.md +68 -0
  218. package/package.json +19 -1
@@ -1,5 +1,6 @@
1
1
 
2
2
  import * as React from "react";
3
+ import { ComponentType, ReactElement } from "react";
3
4
  import { CookieParseOptions, CookieParseOptions as CookieParseOptions$1, CookieSerializeOptions, CookieSerializeOptions as CookieSerializeOptions$1 } from "cookie-es";
4
5
  import { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from "react-router/internal/react-server-client";
5
6
  import { ReactFormState } from "react-dom/client";
@@ -50,7 +51,7 @@ interface Path {
50
51
  * An entry in a history stack. A location contains information about the
51
52
  * URL path, as well as possibly some arbitrary state and a key.
52
53
  */
53
- interface Location<State = any> extends Path {
54
+ interface Location$1<State = any> extends Path {
54
55
  /**
55
56
  * A value of arbitrary data associated with this location.
56
57
  */
@@ -79,7 +80,7 @@ interface Update {
79
80
  /**
80
81
  * The new location.
81
82
  */
82
- location: Location;
83
+ location: Location$1;
83
84
  /**
84
85
  * The delta between this location and the former location in the history stack
85
86
  */
@@ -113,7 +114,7 @@ interface History {
113
114
  /**
114
115
  * The current location. This value is mutable.
115
116
  */
116
- readonly location: Location;
117
+ readonly location: Location$1;
117
118
  /**
118
119
  * Returns a valid href for the given `to` value that may be used as
119
120
  * the value of an <a href> attribute.
@@ -556,6 +557,11 @@ interface DataStrategyMatch extends RouteMatch<string, DataRouteObject> {
556
557
  */
557
558
  resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
558
559
  }
560
+ /**
561
+ * The operation that initiated a data strategy execution. Static handler
562
+ * executions use `"static"`.
563
+ */
564
+ type DataStrategyInitiator = "initialization" | "navigation" | "fetcher" | "revalidation" | "static";
559
565
  interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
560
566
  /**
561
567
  * Matches for this route extended with Data strategy APIs
@@ -563,8 +569,23 @@ interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctio
563
569
  matches: DataStrategyMatch[];
564
570
  runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
565
571
  /**
566
- * The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
567
- * for navigational executions
572
+ * The operation that initiated this data strategy execution
573
+ *
574
+ * This field is experimental and subject to breaking changes.
575
+ */
576
+ unstable_initiator: DataStrategyInitiator;
577
+ /**
578
+ * The history action (`"PUSH"`, `"REPLACE"`, or `"POP"`) for a navigation-
579
+ * initiated execution, including fetchers reloaded by that navigation.
580
+ * `null` for initialization, fetcher, revalidation, and static executions.
581
+ *
582
+ * This field is experimental and subject to breaking changes.
583
+ */
584
+ unstable_navigationType: Action | null;
585
+ /**
586
+ * The key of the fetcher targeted by this data strategy execution, otherwise
587
+ * `null`. Fetchers reloaded during a navigation or revalidation retain that
588
+ * `unstable_initiator` while providing their key here.
568
589
  */
569
590
  fetcherKey: string | null;
570
591
  }
@@ -597,7 +618,7 @@ interface MapRoutePropertiesFunction {
597
618
  * onto the route. Either they're meaningful to the router, or they'll get
598
619
  * ignored.
599
620
  */
600
- type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
621
+ type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children" | "unstable_validateParams";
601
622
  /**
602
623
  * Keys we cannot change from within a lazy() function. We spread all other keys
603
624
  * onto the route. Either they're meaningful to the router, or they'll get
@@ -655,6 +676,11 @@ type BaseRouteObject = {
655
676
  * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
656
677
  */
657
678
  shouldRevalidate?: ShouldRevalidateFunction;
679
+ /**
680
+ * A map of route param names to regular expressions used to validate params
681
+ * after a route-pattern match.
682
+ */
683
+ unstable_validateParams?: Record<string, RegExp>;
658
684
  /**
659
685
  * The route handle.
660
686
  */
@@ -791,7 +817,7 @@ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {}
791
817
  * Defaults to `/`.
792
818
  * @returns An array of matched routes, or `null` if no matches were found.
793
819
  */
794
- declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
820
+ declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location$1> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
795
821
  interface UIMatch<Data = unknown, Handle = unknown> {
796
822
  id: string;
797
823
  pathname: string;
@@ -998,6 +1024,461 @@ type ErrorResponse = {
998
1024
  */
999
1025
  declare function isRouteErrorResponse(error: any): error is ErrorResponse;
1000
1026
  //#endregion
1027
+ //#region lib/components.d.ts
1028
+ /**
1029
+ * Function signature for client side error handling for loader/actions errors
1030
+ * and rendering errors via `componentDidCatch`
1031
+ */
1032
+ interface ClientOnErrorFunction {
1033
+ (error: unknown, info: {
1034
+ location: Location$1;
1035
+ params: Params;
1036
+ pattern: string;
1037
+ errorInfo?: React.ErrorInfo;
1038
+ }): void;
1039
+ }
1040
+ interface AwaitResolveRenderFunction<Resolve = any> {
1041
+ (data: Awaited<Resolve>): React.ReactNode;
1042
+ }
1043
+ /**
1044
+ * @category Types
1045
+ */
1046
+ interface AwaitProps<Resolve> {
1047
+ /**
1048
+ * When using a function, the resolved value is provided as the parameter.
1049
+ *
1050
+ * ```tsx [2]
1051
+ * <Await resolve={reviewsPromise}>
1052
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
1053
+ * </Await>
1054
+ * ```
1055
+ *
1056
+ * When using React elements, {@link useAsyncValue} will provide the
1057
+ * resolved value:
1058
+ *
1059
+ * ```tsx [2]
1060
+ * <Await resolve={reviewsPromise}>
1061
+ * <Reviews />
1062
+ * </Await>
1063
+ *
1064
+ * function Reviews() {
1065
+ * const resolvedReviews = useAsyncValue();
1066
+ * return <div>...</div>;
1067
+ * }
1068
+ * ```
1069
+ */
1070
+ children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
1071
+ /**
1072
+ * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1073
+ * rejects.
1074
+ *
1075
+ * ```tsx
1076
+ * <Await
1077
+ * errorElement={<div>Oops</div>}
1078
+ * resolve={reviewsPromise}
1079
+ * >
1080
+ * <Reviews />
1081
+ * </Await>
1082
+ * ```
1083
+ *
1084
+ * To provide a more contextual error, you can use the {@link useAsyncError} in a
1085
+ * child component
1086
+ *
1087
+ * ```tsx
1088
+ * <Await
1089
+ * errorElement={<ReviewsError />}
1090
+ * resolve={reviewsPromise}
1091
+ * >
1092
+ * <Reviews />
1093
+ * </Await>
1094
+ *
1095
+ * function ReviewsError() {
1096
+ * const error = useAsyncError();
1097
+ * return <div>Error loading reviews: {error.message}</div>;
1098
+ * }
1099
+ * ```
1100
+ *
1101
+ * If you do not provide an `errorElement`, the rejected value will bubble up
1102
+ * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
1103
+ * and be accessible via the {@link useRouteError} hook.
1104
+ */
1105
+ errorElement?: React.ReactNode;
1106
+ /**
1107
+ * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1108
+ * returned from a [`loader`](../../start/framework/route-module#loader) to be
1109
+ * resolved and rendered.
1110
+ *
1111
+ * ```tsx
1112
+ * import { Await, useLoaderData } from "react-router";
1113
+ *
1114
+ * export async function loader() {
1115
+ * let reviews = getReviews(); // not awaited
1116
+ * let book = await getBook();
1117
+ * return {
1118
+ * book,
1119
+ * reviews, // this is a promise
1120
+ * };
1121
+ * }
1122
+ *
1123
+ * export default function Book() {
1124
+ * const {
1125
+ * book,
1126
+ * reviews, // this is the same promise
1127
+ * } = useLoaderData();
1128
+ *
1129
+ * return (
1130
+ * <div>
1131
+ * <h1>{book.title}</h1>
1132
+ * <p>{book.description}</p>
1133
+ * <React.Suspense fallback={<ReviewsSkeleton />}>
1134
+ * <Await
1135
+ * // and is the promise we pass to Await
1136
+ * resolve={reviews}
1137
+ * >
1138
+ * <Reviews />
1139
+ * </Await>
1140
+ * </React.Suspense>
1141
+ * </div>
1142
+ * );
1143
+ * }
1144
+ * ```
1145
+ */
1146
+ resolve: Resolve;
1147
+ }
1148
+ /**
1149
+ * Used to render promise values with automatic error handling.
1150
+ *
1151
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
1152
+ *
1153
+ * @example
1154
+ * import { Await, useLoaderData } from "react-router";
1155
+ *
1156
+ * export async function loader() {
1157
+ * // not awaited
1158
+ * const reviews = getReviews();
1159
+ * // awaited (blocks the transition)
1160
+ * const book = await fetch("/api/book").then((res) => res.json());
1161
+ * return { book, reviews };
1162
+ * }
1163
+ *
1164
+ * function Book() {
1165
+ * const { book, reviews } = useLoaderData();
1166
+ * return (
1167
+ * <div>
1168
+ * <h1>{book.title}</h1>
1169
+ * <p>{book.description}</p>
1170
+ * <React.Suspense fallback={<ReviewsSkeleton />}>
1171
+ * <Await
1172
+ * resolve={reviews}
1173
+ * errorElement={
1174
+ * <div>Could not load reviews 😬</div>
1175
+ * }
1176
+ * children={(resolvedReviews) => (
1177
+ * <Reviews items={resolvedReviews} />
1178
+ * )}
1179
+ * />
1180
+ * </React.Suspense>
1181
+ * </div>
1182
+ * );
1183
+ * }
1184
+ *
1185
+ * @public
1186
+ * @category Components
1187
+ * @mode framework
1188
+ * @mode data
1189
+ * @param props Props
1190
+ * @param {AwaitProps.children} props.children n/a
1191
+ * @param {AwaitProps.errorElement} props.errorElement n/a
1192
+ * @param {AwaitProps.resolve} props.resolve n/a
1193
+ * @returns React element for the rendered awaited value
1194
+ */
1195
+ declare function Await$1<Resolve>({
1196
+ children,
1197
+ errorElement,
1198
+ resolve
1199
+ }: AwaitProps<Resolve>): React.JSX.Element;
1200
+ //#endregion
1201
+ //#region lib/server-runtime/serverHandoff.d.ts
1202
+ type ServerHandoff = {
1203
+ criticalCss?: CriticalCss;
1204
+ basename: string | undefined;
1205
+ future: FutureConfig$1;
1206
+ ssr: boolean;
1207
+ isSpaMode: boolean;
1208
+ unstable_apiOnly?: boolean;
1209
+ unstable_apiServerOrigin?: string;
1210
+ routeDiscovery: ServerBuild["routeDiscovery"];
1211
+ };
1212
+ //#endregion
1213
+ //#region lib/dom/global.d.ts
1214
+ type WindowReactRouterContext = ServerHandoff & {
1215
+ state: HydrationState;
1216
+ stream: ReadableStream<Uint8Array> | undefined;
1217
+ streamController: ReadableStreamDefaultController<Uint8Array>;
1218
+ };
1219
+ interface ViewTransition {
1220
+ finished: Promise<void>;
1221
+ ready: Promise<void>;
1222
+ updateCallbackDone: Promise<void>;
1223
+ skipTransition(): void;
1224
+ }
1225
+ declare global {
1226
+ var __staticRouterHydrationData: HydrationState | undefined;
1227
+ var __reactRouterVersion: string;
1228
+ interface Document {
1229
+ startViewTransition(cb: () => Promise<void> | void): ViewTransition;
1230
+ }
1231
+ var __reactRouterContext: WindowReactRouterContext | undefined;
1232
+ var __reactRouterManifest: AssetsManifest | undefined;
1233
+ var __reactRouterRouteModules: RouteModules | undefined;
1234
+ var __reactRouterDataRouter: Router$1 | undefined;
1235
+ var __reactRouterHdrActive: boolean;
1236
+ var $RefreshRuntime$: {
1237
+ performReactRefresh: () => void;
1238
+ } | undefined;
1239
+ }
1240
+ //#endregion
1241
+ //#region lib/dom/ssr/single-fetch.d.ts
1242
+ /**
1243
+ * Describes the operation that initiated an internal router request.
1244
+ *
1245
+ * Requests that reload fetchers as part of a navigation, revalidation, or
1246
+ * initialization redirect keep that initiating `type`. `fetcherKey` identifies
1247
+ * the fetcher being loaded, or is `null` when the request targets route loaders
1248
+ * or actions.
1249
+ *
1250
+ * `navigationType` is the history action (`"PUSH"`, `"REPLACE"`, or `"POP"`)
1251
+ * for navigation-initiated data requests, including reloaded fetchers. It is
1252
+ * `null` for initialization, fetcher, and revalidation requests. Manifest
1253
+ * requests have no navigation type.
1254
+ */
1255
+ type RouterFetchContext = {
1256
+ type: "manifest";
1257
+ } | {
1258
+ type: "navigation";
1259
+ fetcherKey: string | null;
1260
+ navigationType: Action;
1261
+ } | {
1262
+ type: "initialization" | "fetcher" | "revalidation";
1263
+ fetcherKey: string | null;
1264
+ navigationType: null;
1265
+ };
1266
+ type RouterFetch = (request: Request, context: RouterFetchContext) => Promise<Response>;
1267
+ //#endregion
1268
+ //#region lib/dom/ssr/route-discovery.d.ts
1269
+ /** A discovery response from a different build. */
1270
+ type ManifestMismatchEvent = {
1271
+ source: "eager" | "navigation" | "fetcher" | "imperative";
1272
+ version: string;
1273
+ reloadUrl: string | null;
1274
+ loadAllRoutes(): Promise<void>;
1275
+ stopPropagation(): void; /** Run built-in recovery for this source, at most once per mismatch event. */
1276
+ defaultBehavior(): Promise<void>;
1277
+ };
1278
+ /** The result of imperative route discovery. */
1279
+ type DiscoveryResult = {
1280
+ type: "success";
1281
+ } | {
1282
+ type: "version-mismatch";
1283
+ } | {
1284
+ type: "aborted";
1285
+ };
1286
+ /** Options for {@link unstable_useRouteDiscovery}. */
1287
+ type RouteDiscoveryOptions = {
1288
+ onManifestMismatch?: (event: ManifestMismatchEvent) => void | Promise<void>;
1289
+ };
1290
+ type Registration = {
1291
+ current: RouteDiscoveryOptions;
1292
+ };
1293
+ type DiscoveryState = "partial" | "loading" | "complete";
1294
+ type RouteDiscoverySsrInfo = {
1295
+ manifest: AssetsManifest;
1296
+ routeModules: RouteModules;
1297
+ router: Router$1 | undefined;
1298
+ context: Pick<WindowReactRouterContext, "ssr" | "routeDiscovery" | "isSpaMode" | "basename" | "unstable_apiServerOrigin" | "unstable_apiOnly">;
1299
+ };
1300
+ declare class RouteDiscoveryRuntime {
1301
+ private ssrInfo;
1302
+ readonly enabled: boolean;
1303
+ readonly discoveredPaths: Set<string>;
1304
+ readonly nextPaths: Set<string>;
1305
+ state: DiscoveryState;
1306
+ ready: boolean;
1307
+ private registrations;
1308
+ private listeners;
1309
+ private fullLoadErrorListeners;
1310
+ private fullLoad?;
1311
+ private loadedManifest?;
1312
+ private mismatch?;
1313
+ private fetchImplementation;
1314
+ private loadManifest;
1315
+ onError?: ClientOnErrorFunction;
1316
+ constructor(ssrInfo: RouteDiscoverySsrInfo, {
1317
+ fetch: fetchImplementation,
1318
+ loadManifest
1319
+ }?: {
1320
+ fetch?: RouterFetch;
1321
+ loadManifest?: () => Promise<AssetsManifest>;
1322
+ });
1323
+ private get router();
1324
+ private loadManifestAsset;
1325
+ subscribe: (listener: () => void) => () => void;
1326
+ private update;
1327
+ markReady: () => void;
1328
+ register(registration: Registration): () => void;
1329
+ private isComplete;
1330
+ loadAllRoutes: () => Promise<void>;
1331
+ reportError(error: unknown): void;
1332
+ private dispatchMismatch;
1333
+ private requestUrl;
1334
+ discoverRoutes: (paths: string[], options?: {
1335
+ signal?: AbortSignal;
1336
+ }) => Promise<DiscoveryResult>;
1337
+ discover(paths: string[], source: ManifestMismatchEvent["source"], reloadUrl: string | null, signal?: AbortSignal, patch?: (routeId: string | null, children: RouteObject[], unstable_allowElementMutations?: boolean) => void): Promise<DiscoveryResult>;
1338
+ }
1339
+ //#endregion
1340
+ //#region lib/dom/ssr/entry.d.ts
1341
+ type SerializedError = {
1342
+ message: string;
1343
+ stack?: string;
1344
+ };
1345
+ interface FrameworkContextObject {
1346
+ routeDiscoveryRuntime?: RouteDiscoveryRuntime;
1347
+ routeDiscoveryState?: DiscoveryState;
1348
+ manifest: AssetsManifest;
1349
+ routeModules: RouteModules;
1350
+ criticalCss?: CriticalCss;
1351
+ serverHandoffString?: string;
1352
+ future: FutureConfig$1;
1353
+ ssr: boolean;
1354
+ isSpaMode: boolean;
1355
+ unstable_apiOnly?: boolean;
1356
+ unstable_apiServerOrigin?: string;
1357
+ routeDiscovery: ServerBuild["routeDiscovery"];
1358
+ nonce?: string;
1359
+ serializeError?(error: Error): SerializedError;
1360
+ renderMeta?: {
1361
+ didRenderScripts?: boolean;
1362
+ streamCache?: Record<number, Promise<void> & {
1363
+ result?: {
1364
+ done: boolean;
1365
+ value: string;
1366
+ };
1367
+ error?: unknown;
1368
+ }>;
1369
+ };
1370
+ }
1371
+ interface EntryContext extends FrameworkContextObject {
1372
+ /**
1373
+ * @deprecated This property was an internal implementation detail and was
1374
+ * never intended for use in `entry.server.tsx`. It is always an empty array.
1375
+ */
1376
+ branches: RouteBranch<DataRouteObject>[];
1377
+ staticHandlerContext: StaticHandlerContext;
1378
+ serverHandoffStream?: ReadableStream<Uint8Array>;
1379
+ }
1380
+ interface FutureConfig$1 {
1381
+ unstable_customRouteDiscovery?: boolean;
1382
+ }
1383
+ type CriticalCss = string | {
1384
+ rel: "stylesheet";
1385
+ href: string;
1386
+ };
1387
+ interface AssetsManifest {
1388
+ entry: {
1389
+ imports: string[];
1390
+ module: string;
1391
+ };
1392
+ routes: RouteManifest<EntryRoute>;
1393
+ url: string;
1394
+ version: string;
1395
+ hmr?: {
1396
+ timestamp?: number;
1397
+ runtime: string;
1398
+ };
1399
+ sri?: Record<string, string> | true;
1400
+ }
1401
+ //#endregion
1402
+ //#region lib/server-runtime/routes.d.ts
1403
+ type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
1404
+ interface ServerRoute extends Route$1 {
1405
+ children: ServerRoute[];
1406
+ module: ServerRouteModule;
1407
+ }
1408
+ //#endregion
1409
+ //#region lib/server-runtime/build.d.ts
1410
+ type OptionalCriticalCss = CriticalCss | undefined;
1411
+ /**
1412
+ * The output of the compiler for the server build.
1413
+ */
1414
+ interface ServerBuild {
1415
+ entry: {
1416
+ module: ServerEntryModule;
1417
+ };
1418
+ routes: ServerRouteManifest;
1419
+ assets: AssetsManifest;
1420
+ basename?: string;
1421
+ publicPath: string;
1422
+ assetsBuildDirectory: string;
1423
+ future: FutureConfig$1;
1424
+ /**
1425
+ * Whether runtime server requests are supported, including API-only builds.
1426
+ */
1427
+ ssr: boolean;
1428
+ /**
1429
+ * The origin to use for server requests in API-only mode.
1430
+ * @internal
1431
+ */
1432
+ unstable_apiServerOrigin?: string;
1433
+ /**
1434
+ * Whether production document rendering is disabled while data and route
1435
+ * discovery requests remain supported.
1436
+ * @internal
1437
+ */
1438
+ unstable_apiOnly?: boolean;
1439
+ unstable_getCriticalCss?: (args: {
1440
+ pathname: string;
1441
+ }) => OptionalCriticalCss | Promise<OptionalCriticalCss>;
1442
+ /**
1443
+ * @deprecated This is now done via a custom header during prerendering
1444
+ */
1445
+ isSpaMode: boolean;
1446
+ prerender: string[];
1447
+ routeDiscovery: {
1448
+ mode: "lazy" | "initial";
1449
+ manifestPath: string;
1450
+ };
1451
+ allowedActionOrigins?: string[] | false;
1452
+ }
1453
+ interface HandleDocumentRequestFunction {
1454
+ (request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: RouterContextProvider): Promise<Response> | Response;
1455
+ }
1456
+ interface HandleDataRequestFunction {
1457
+ (response: Response, args: {
1458
+ request: LoaderFunctionArgs["request"] | ActionFunctionArgs["request"];
1459
+ context: LoaderFunctionArgs["context"] | ActionFunctionArgs["context"];
1460
+ params: LoaderFunctionArgs["params"] | ActionFunctionArgs["params"];
1461
+ }): Promise<Response> | Response;
1462
+ }
1463
+ interface HandleErrorFunction {
1464
+ (error: unknown, args: {
1465
+ request: LoaderFunctionArgs["request"] | ActionFunctionArgs["request"];
1466
+ context: LoaderFunctionArgs["context"] | ActionFunctionArgs["context"];
1467
+ params: LoaderFunctionArgs["params"] | ActionFunctionArgs["params"];
1468
+ }): void;
1469
+ }
1470
+ /**
1471
+ * A module that serves as the entry point for a Remix app during server
1472
+ * rendering.
1473
+ */
1474
+ interface ServerEntryModule {
1475
+ default: HandleDocumentRequestFunction;
1476
+ handleDataRequest?: HandleDataRequestFunction;
1477
+ handleError?: HandleErrorFunction;
1478
+ instrumentations?: ServerInstrumentation[];
1479
+ streamTimeout?: number;
1480
+ }
1481
+ //#endregion
1001
1482
  //#region lib/router/instrumentation.d.ts
1002
1483
  type ServerInstrumentation = {
1003
1484
  handler?: InstrumentRequestHandlerFunction;
@@ -1143,9 +1624,10 @@ interface Router$1 {
1143
1624
  * @private
1144
1625
  * PRIVATE - DO NOT USE
1145
1626
  *
1146
- * Return the route branches for this router instance
1627
+ * Match routes against a location using the router's configured route
1628
+ * matching implementation.
1147
1629
  */
1148
- get branches(): RouteBranch<DataRouteObject>[] | undefined;
1630
+ match(locationArg: Partial<Location$1> | string): DataRouteMatch[] | null;
1149
1631
  /**
1150
1632
  * @private
1151
1633
  * PRIVATE - DO NOT USE
@@ -1230,7 +1712,7 @@ interface Router$1 {
1230
1712
  * Utility function to create an href for the given location
1231
1713
  * @param location
1232
1714
  */
1233
- createHref(location: Location | URL): string;
1715
+ createHref(location: Location$1 | URL): string;
1234
1716
  /**
1235
1717
  * @private
1236
1718
  * PRIVATE - DO NOT USE
@@ -1346,7 +1828,7 @@ interface RouterState {
1346
1828
  /**
1347
1829
  * The current location reflected by the router
1348
1830
  */
1349
- location: Location;
1831
+ location: Location$1;
1350
1832
  /**
1351
1833
  * The current set of route matches
1352
1834
  */
@@ -1407,7 +1889,12 @@ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "e
1407
1889
  /**
1408
1890
  * Future flags to toggle new feature behavior
1409
1891
  */
1410
- interface FutureConfig {}
1892
+ interface FutureConfig {
1893
+ /** @internal Enables application-controlled Framework route discovery. */
1894
+ unstable_customRouteDiscovery?: boolean;
1895
+ /** Enables route-pattern matching after calling `unstable_preloadRoutePattern()`. */
1896
+ unstable_routePatternMatching?: boolean;
1897
+ }
1411
1898
  /**
1412
1899
  * Initialization options for createRouter
1413
1900
  */
@@ -1439,6 +1926,8 @@ interface StaticHandlerContext {
1439
1926
  loaderHeaders: Record<string, Headers>;
1440
1927
  actionHeaders: Record<string, Headers>;
1441
1928
  _deepestRenderedBoundaryId?: string | null;
1929
+ /** @private */
1930
+ _match: StaticHandler["match"];
1442
1931
  }
1443
1932
  /**
1444
1933
  * A StaticHandler instance manages a singular SSR navigation/fetch event
@@ -1452,10 +1941,10 @@ interface StaticHandler {
1452
1941
  * @private
1453
1942
  * PRIVATE - DO NOT USE
1454
1943
  *
1455
- * The route branches derived from the data routes, used for internal route
1456
- * matching in Framework Mode
1944
+ * Match routes against a location using the handler's configured route
1945
+ * matching implementation.
1457
1946
  */
1458
- _internalRouteBranches: RouteBranch<DataRouteObject>[];
1947
+ match(locationArg: Partial<Location$1> | string): DataRouteMatch[] | null;
1459
1948
  /**
1460
1949
  * Perform a query for a given request - executing all matched route
1461
1950
  * loaders/actions. Used for document requests.
@@ -1503,8 +1992,8 @@ interface StaticHandler {
1503
1992
  }): Promise<any>;
1504
1993
  }
1505
1994
  type ViewTransitionOpts = {
1506
- currentLocation: Location;
1507
- nextLocation: Location;
1995
+ currentLocation: Location$1;
1996
+ nextLocation: Location$1;
1508
1997
  };
1509
1998
  /**
1510
1999
  * Subscriber function signature for changes to router state
@@ -1522,7 +2011,7 @@ interface RouterSubscriber {
1522
2011
  * for a given location
1523
2012
  */
1524
2013
  interface GetScrollRestorationKeyFunction {
1525
- (location: Location, matches: UIMatch[]): string | null;
2014
+ (location: Location$1, matches: UIMatch[]): string | null;
1526
2015
  }
1527
2016
  /**
1528
2017
  * Function signature for determining the current scroll position
@@ -1549,6 +2038,10 @@ type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
1549
2038
  replace?: boolean;
1550
2039
  state?: any;
1551
2040
  fromRouteId?: string;
2041
+ /**
2042
+ * @deprecated Use React's `<ViewTransition>` component instead. See the
2043
+ * [migration guide](https://reactrouter.com/how-to/view-transitions).
2044
+ */
1552
2045
  viewTransition?: boolean;
1553
2046
  mask?: To;
1554
2047
  };
@@ -1604,7 +2097,7 @@ type NavigationStates = {
1604
2097
  };
1605
2098
  Loading: {
1606
2099
  state: "loading";
1607
- location: Location;
2100
+ location: Location$1;
1608
2101
  matches: DataRouteMatch[];
1609
2102
  historyAction: Action;
1610
2103
  formMethod: Submission["formMethod"] | undefined;
@@ -1616,7 +2109,7 @@ type NavigationStates = {
1616
2109
  };
1617
2110
  Submitting: {
1618
2111
  state: "submitting";
1619
- location: Location;
2112
+ location: Location$1;
1620
2113
  matches: DataRouteMatch[];
1621
2114
  historyAction: Action;
1622
2115
  formMethod: Submission["formMethod"];
@@ -1706,7 +2199,7 @@ interface BlockerBlocked {
1706
2199
  state: "blocked";
1707
2200
  reset: () => void;
1708
2201
  proceed: () => void;
1709
- location: Location;
2202
+ location: Location$1;
1710
2203
  }
1711
2204
  interface BlockerUnblocked {
1712
2205
  state: "unblocked";
@@ -1718,12 +2211,12 @@ interface BlockerProceeding {
1718
2211
  state: "proceeding";
1719
2212
  reset: undefined;
1720
2213
  proceed: undefined;
1721
- location: Location;
2214
+ location: Location$1;
1722
2215
  }
1723
2216
  type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1724
2217
  type BlockerFunction = (args: {
1725
- currentLocation: Location;
1726
- nextLocation: Location;
2218
+ currentLocation: Location$1;
2219
+ nextLocation: Location$1;
1727
2220
  historyAction: Action;
1728
2221
  }) => boolean;
1729
2222
  interface CreateStaticHandlerOptions {
@@ -1764,6 +2257,31 @@ interface CreateStaticHandlerOptions {
1764
2257
  */
1765
2258
  declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
1766
2259
  //#endregion
2260
+ //#region lib/dom/ssr/routes.d.ts
2261
+ interface Route$1 {
2262
+ index?: boolean;
2263
+ caseSensitive?: boolean;
2264
+ id: string;
2265
+ parentId?: string;
2266
+ path?: string;
2267
+ }
2268
+ interface EntryRoute extends Route$1 {
2269
+ hasAction: boolean;
2270
+ hasLoader: boolean;
2271
+ hasClientAction: boolean;
2272
+ hasClientLoader: boolean;
2273
+ hasClientMiddleware: boolean;
2274
+ hasErrorBoundary: boolean;
2275
+ imports?: string[];
2276
+ css?: string[];
2277
+ module: string;
2278
+ clientActionModule: string | undefined;
2279
+ clientLoaderModule: string | undefined;
2280
+ clientMiddlewareModule: string | undefined;
2281
+ hydrateFallbackModule: string | undefined;
2282
+ parentId?: string;
2283
+ }
2284
+ //#endregion
1767
2285
  //#region lib/router/links.d.ts
1768
2286
  type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1769
2287
  type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
@@ -1951,6 +2469,36 @@ type ClientDataFunctionArgs<Params> = {
1951
2469
  type SerializeFrom<T> = T extends ((...args: infer Args) => unknown) ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1952
2470
  //#endregion
1953
2471
  //#region lib/dom/ssr/routeModules.d.ts
2472
+ interface RouteModules {
2473
+ [routeId: string]: RouteModule | undefined;
2474
+ }
2475
+ /**
2476
+ * The shape of a route module shipped to the client
2477
+ */
2478
+ interface RouteModule {
2479
+ clientAction?: ClientActionFunction;
2480
+ clientLoader?: ClientLoaderFunction;
2481
+ clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
2482
+ ErrorBoundary?: ErrorBoundaryComponent;
2483
+ HydrateFallback?: HydrateFallbackComponent;
2484
+ Layout?: LayoutComponent;
2485
+ default: RouteComponent;
2486
+ handle?: RouteHandle;
2487
+ links?: LinksFunction;
2488
+ meta?: MetaFunction;
2489
+ shouldRevalidate?: ShouldRevalidateFunction;
2490
+ }
2491
+ /**
2492
+ * The shape of a route module on the server
2493
+ */
2494
+ interface ServerRouteModule extends RouteModule {
2495
+ action?: ActionFunction;
2496
+ headers?: HeadersFunction | {
2497
+ [name: string]: string;
2498
+ };
2499
+ loader?: LoaderFunction;
2500
+ middleware?: MiddlewareFunction<Response>[];
2501
+ }
1954
2502
  /**
1955
2503
  * A function that handles data mutations for a route on the client
1956
2504
  */
@@ -1973,6 +2521,10 @@ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<Load
1973
2521
  type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1974
2522
  serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1975
2523
  };
2524
+ /**
2525
+ * ErrorBoundary to display for this route
2526
+ */
2527
+ type ErrorBoundaryComponent = ComponentType;
1976
2528
  type HeadersArgs = {
1977
2529
  loaderHeaders: Headers;
1978
2530
  parentHeaders: Headers;
@@ -1986,6 +2538,19 @@ type HeadersArgs = {
1986
2538
  interface HeadersFunction {
1987
2539
  (args: HeadersArgs): Headers | HeadersInit;
1988
2540
  }
2541
+ /**
2542
+ * `<Route HydrateFallback>` component to render on initial loads
2543
+ * when client loaders are present
2544
+ */
2545
+ type HydrateFallbackComponent = ComponentType;
2546
+ /**
2547
+ * Optional, root-only `<Route Layout>` component to wrap the root content in.
2548
+ * Useful for defining the <html>/<head>/<body> document shell shared by the
2549
+ * Component, HydrateFallback, and ErrorBoundary
2550
+ */
2551
+ type LayoutComponent = ComponentType<{
2552
+ children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
2553
+ }>;
1989
2554
  /**
1990
2555
  * A function that defines `<link>` tags to be inserted into the `<head>` of
1991
2556
  * the document on route transitions.
@@ -2008,7 +2573,7 @@ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoad
2008
2573
  interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
2009
2574
  loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
2010
2575
  params: Params;
2011
- location: Location;
2576
+ location: Location$1;
2012
2577
  matches: MetaMatches<MatchLoaders>;
2013
2578
  error?: unknown;
2014
2579
  }
@@ -2093,6 +2658,7 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
2093
2658
  /**
2094
2659
  * A React component that is rendered for a route.
2095
2660
  */
2661
+ type RouteComponent = ComponentType<{}>;
2096
2662
  /**
2097
2663
  * An arbitrary object that is associated with a route.
2098
2664
  *
@@ -2100,168 +2666,6 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
2100
2666
  */
2101
2667
  type RouteHandle = unknown;
2102
2668
  //#endregion
2103
- //#region lib/components.d.ts
2104
- interface AwaitResolveRenderFunction<Resolve = any> {
2105
- (data: Awaited<Resolve>): React.ReactNode;
2106
- }
2107
- /**
2108
- * @category Types
2109
- */
2110
- interface AwaitProps<Resolve> {
2111
- /**
2112
- * When using a function, the resolved value is provided as the parameter.
2113
- *
2114
- * ```tsx [2]
2115
- * <Await resolve={reviewsPromise}>
2116
- * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
2117
- * </Await>
2118
- * ```
2119
- *
2120
- * When using React elements, {@link useAsyncValue} will provide the
2121
- * resolved value:
2122
- *
2123
- * ```tsx [2]
2124
- * <Await resolve={reviewsPromise}>
2125
- * <Reviews />
2126
- * </Await>
2127
- *
2128
- * function Reviews() {
2129
- * const resolvedReviews = useAsyncValue();
2130
- * return <div>...</div>;
2131
- * }
2132
- * ```
2133
- */
2134
- children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
2135
- /**
2136
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
2137
- * rejects.
2138
- *
2139
- * ```tsx
2140
- * <Await
2141
- * errorElement={<div>Oops</div>}
2142
- * resolve={reviewsPromise}
2143
- * >
2144
- * <Reviews />
2145
- * </Await>
2146
- * ```
2147
- *
2148
- * To provide a more contextual error, you can use the {@link useAsyncError} in a
2149
- * child component
2150
- *
2151
- * ```tsx
2152
- * <Await
2153
- * errorElement={<ReviewsError />}
2154
- * resolve={reviewsPromise}
2155
- * >
2156
- * <Reviews />
2157
- * </Await>
2158
- *
2159
- * function ReviewsError() {
2160
- * const error = useAsyncError();
2161
- * return <div>Error loading reviews: {error.message}</div>;
2162
- * }
2163
- * ```
2164
- *
2165
- * If you do not provide an `errorElement`, the rejected value will bubble up
2166
- * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
2167
- * and be accessible via the {@link useRouteError} hook.
2168
- */
2169
- errorElement?: React.ReactNode;
2170
- /**
2171
- * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
2172
- * returned from a [`loader`](../../start/framework/route-module#loader) to be
2173
- * resolved and rendered.
2174
- *
2175
- * ```tsx
2176
- * import { Await, useLoaderData } from "react-router";
2177
- *
2178
- * export async function loader() {
2179
- * let reviews = getReviews(); // not awaited
2180
- * let book = await getBook();
2181
- * return {
2182
- * book,
2183
- * reviews, // this is a promise
2184
- * };
2185
- * }
2186
- *
2187
- * export default function Book() {
2188
- * const {
2189
- * book,
2190
- * reviews, // this is the same promise
2191
- * } = useLoaderData();
2192
- *
2193
- * return (
2194
- * <div>
2195
- * <h1>{book.title}</h1>
2196
- * <p>{book.description}</p>
2197
- * <React.Suspense fallback={<ReviewsSkeleton />}>
2198
- * <Await
2199
- * // and is the promise we pass to Await
2200
- * resolve={reviews}
2201
- * >
2202
- * <Reviews />
2203
- * </Await>
2204
- * </React.Suspense>
2205
- * </div>
2206
- * );
2207
- * }
2208
- * ```
2209
- */
2210
- resolve: Resolve;
2211
- }
2212
- /**
2213
- * Used to render promise values with automatic error handling.
2214
- *
2215
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
2216
- *
2217
- * @example
2218
- * import { Await, useLoaderData } from "react-router";
2219
- *
2220
- * export async function loader() {
2221
- * // not awaited
2222
- * const reviews = getReviews();
2223
- * // awaited (blocks the transition)
2224
- * const book = await fetch("/api/book").then((res) => res.json());
2225
- * return { book, reviews };
2226
- * }
2227
- *
2228
- * function Book() {
2229
- * const { book, reviews } = useLoaderData();
2230
- * return (
2231
- * <div>
2232
- * <h1>{book.title}</h1>
2233
- * <p>{book.description}</p>
2234
- * <React.Suspense fallback={<ReviewsSkeleton />}>
2235
- * <Await
2236
- * resolve={reviews}
2237
- * errorElement={
2238
- * <div>Could not load reviews 😬</div>
2239
- * }
2240
- * children={(resolvedReviews) => (
2241
- * <Reviews items={resolvedReviews} />
2242
- * )}
2243
- * />
2244
- * </React.Suspense>
2245
- * </div>
2246
- * );
2247
- * }
2248
- *
2249
- * @public
2250
- * @category Components
2251
- * @mode framework
2252
- * @mode data
2253
- * @param props Props
2254
- * @param {AwaitProps.children} props.children n/a
2255
- * @param {AwaitProps.errorElement} props.errorElement n/a
2256
- * @param {AwaitProps.resolve} props.resolve n/a
2257
- * @returns React element for the rendered awaited value
2258
- */
2259
- declare function Await$1<Resolve>({
2260
- children,
2261
- errorElement,
2262
- resolve
2263
- }: AwaitProps<Resolve>): React.JSX.Element;
2264
- //#endregion
2265
2669
  //#region lib/rsc/server.rsc.d.ts
2266
2670
  declare function getRequest(): Request;
2267
2671
  declare const redirect: typeof redirect$1;
@@ -2280,6 +2684,7 @@ type RSCRouteConfigEntryBase = {
2280
2684
  links?: LinksFunction;
2281
2685
  loader?: LoaderFunction;
2282
2686
  meta?: MetaFunction;
2687
+ middleware?: MiddlewareFunction<any>[];
2283
2688
  shouldRevalidate?: ShouldRevalidateFunction;
2284
2689
  };
2285
2690
  type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
@@ -2329,7 +2734,7 @@ type RSCRenderPayload = {
2329
2734
  clientVersion?: string;
2330
2735
  errors: Record<string, any> | null;
2331
2736
  loaderData: Record<string, any>;
2332
- location: Location;
2737
+ location: Location$1;
2333
2738
  routeDiscovery: RouteDiscovery;
2334
2739
  matches: RSCRouteMatch[];
2335
2740
  patches?: Promise<RSCRouteManifest[]>;
@@ -2377,6 +2782,13 @@ type RouteDiscovery = {
2377
2782
  * encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
2378
2783
  * enabled client router.
2379
2784
  *
2785
+ * Treat every React Server Function as a public endpoint. Server Functions are
2786
+ * not inherently associated with a route. Any route middleware that runs is
2787
+ * selected from the URL used to call a Server Function, but the client controls
2788
+ * both the Server Function identifier and the URL. Perform all access control
2789
+ * checks within each Server Function, or use a route action for
2790
+ * middleware-driven access control.
2791
+ *
2380
2792
  * @example
2381
2793
  * import {
2382
2794
  * createTemporaryReferenceSet,
@@ -2458,7 +2870,7 @@ declare function matchRSCServerRequest({
2458
2870
  onError,
2459
2871
  request,
2460
2872
  routes,
2461
- generateResponse
2873
+ generateResponse: encodeResponse
2462
2874
  }: {
2463
2875
  allowedActionOrigins?: string[];
2464
2876
  createTemporaryReferenceSet: () => unknown;