react-router 8.5.0 → 8.5.1

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 (204) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/dist/development/dom-export.js +1 -1
  3. package/dist/development/index-react-server-client.js +1 -1
  4. package/dist/development/index-react-server.d.ts +50 -396
  5. package/dist/development/index-react-server.js +43 -15
  6. package/dist/development/index.js +1 -1
  7. package/dist/development/lib/actions.js +1 -1
  8. package/dist/development/lib/await.js +58 -0
  9. package/dist/development/lib/components.d.ts +41 -5
  10. package/dist/development/lib/components.js +62 -4
  11. package/dist/development/lib/context.d.ts +2 -2
  12. package/dist/development/lib/context.js +1 -1
  13. package/dist/development/lib/dom/dom.js +1 -1
  14. package/dist/development/lib/dom/lib.js +1 -1
  15. package/dist/development/lib/dom/server.js +1 -1
  16. package/dist/development/lib/dom/ssr/components.js +1 -1
  17. package/dist/development/lib/dom/ssr/data.js +1 -1
  18. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  19. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  20. package/dist/development/lib/dom/ssr/fog-of-war.js +12 -3
  21. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  22. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  23. package/dist/development/lib/dom/ssr/links.js +1 -1
  24. package/dist/development/lib/dom/ssr/markup.js +1 -1
  25. package/dist/development/lib/dom/ssr/route-discovery.d.ts +2 -2
  26. package/dist/development/lib/dom/ssr/route-discovery.js +3 -3
  27. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  28. package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
  29. package/dist/development/lib/dom/ssr/routes.js +1 -1
  30. package/dist/development/lib/dom/ssr/server.js +1 -1
  31. package/dist/development/lib/dom/ssr/single-fetch.d.ts +1 -1
  32. package/dist/development/lib/dom/ssr/single-fetch.js +7 -7
  33. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  34. package/dist/development/lib/dom-export/hydrated-router.js +2 -2
  35. package/dist/development/lib/errors.js +1 -1
  36. package/dist/development/lib/hooks.d.ts +0 -3
  37. package/dist/development/lib/hooks.js +5 -6
  38. package/dist/development/lib/href.js +1 -1
  39. package/dist/development/lib/router/history.js +1 -1
  40. package/dist/development/lib/router/instrumentation.js +1 -1
  41. package/dist/development/lib/router/matcher-route-pattern.js +1 -1
  42. package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
  43. package/dist/development/lib/router/matcher.js +6 -1
  44. package/dist/development/lib/router/navigation.js +1 -1
  45. package/dist/development/lib/router/router.d.ts +2 -0
  46. package/dist/development/lib/router/router.js +58 -28
  47. package/dist/development/lib/router/url.js +1 -1
  48. package/dist/development/lib/router/utils.d.ts +7 -0
  49. package/dist/development/lib/router/utils.js +1 -1
  50. package/dist/development/lib/rsc/browser.js +3 -3
  51. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  52. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  53. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  54. package/dist/development/lib/rsc/route-modules.js +1 -1
  55. package/dist/development/lib/rsc/server.ssr.js +1 -1
  56. package/dist/development/lib/server-runtime/cookies.js +1 -1
  57. package/dist/development/lib/server-runtime/crypto.js +1 -1
  58. package/dist/development/lib/server-runtime/data.js +1 -1
  59. package/dist/development/lib/server-runtime/dev.js +1 -1
  60. package/dist/development/lib/server-runtime/entry.js +1 -1
  61. package/dist/development/lib/server-runtime/errors.js +1 -1
  62. package/dist/development/lib/server-runtime/headers.js +1 -1
  63. package/dist/development/lib/server-runtime/invariant.js +1 -1
  64. package/dist/development/lib/server-runtime/mode.js +1 -1
  65. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  66. package/dist/development/lib/server-runtime/routes.js +1 -1
  67. package/dist/development/lib/server-runtime/server.js +13 -5
  68. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  69. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  70. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  71. package/dist/development/lib/server-runtime/sessions.js +2 -2
  72. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  73. package/dist/development/lib/server-runtime/urls.js +1 -1
  74. package/dist/development/lib/server-runtime/warnings.js +1 -1
  75. package/dist/development/lib/types/internal.js +1 -1
  76. package/dist/development/route-pattern.js +1 -1
  77. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  78. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  79. package/dist/development/vendor/turbo-stream-v2/unflatten.js +23 -3
  80. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  81. package/dist/production/dom-export.js +1 -1
  82. package/dist/production/index-react-server-client.js +1 -1
  83. package/dist/production/index-react-server.d.ts +50 -396
  84. package/dist/production/index-react-server.js +43 -15
  85. package/dist/production/index.js +1 -1
  86. package/dist/production/lib/actions.js +1 -1
  87. package/dist/production/lib/await.js +58 -0
  88. package/dist/production/lib/components.d.ts +41 -5
  89. package/dist/production/lib/components.js +62 -4
  90. package/dist/production/lib/context.d.ts +2 -2
  91. package/dist/production/lib/context.js +1 -1
  92. package/dist/production/lib/dom/dom.js +1 -1
  93. package/dist/production/lib/dom/lib.js +1 -1
  94. package/dist/production/lib/dom/server.js +1 -1
  95. package/dist/production/lib/dom/ssr/components.js +1 -1
  96. package/dist/production/lib/dom/ssr/data.js +1 -1
  97. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  98. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  99. package/dist/production/lib/dom/ssr/fog-of-war.js +12 -3
  100. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  101. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  102. package/dist/production/lib/dom/ssr/links.js +1 -1
  103. package/dist/production/lib/dom/ssr/markup.js +1 -1
  104. package/dist/production/lib/dom/ssr/route-discovery.d.ts +2 -2
  105. package/dist/production/lib/dom/ssr/route-discovery.js +3 -3
  106. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  107. package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
  108. package/dist/production/lib/dom/ssr/routes.js +1 -1
  109. package/dist/production/lib/dom/ssr/server.js +1 -1
  110. package/dist/production/lib/dom/ssr/single-fetch.d.ts +1 -1
  111. package/dist/production/lib/dom/ssr/single-fetch.js +7 -7
  112. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  113. package/dist/production/lib/dom-export/hydrated-router.js +2 -2
  114. package/dist/production/lib/errors.js +1 -1
  115. package/dist/production/lib/hooks.d.ts +0 -3
  116. package/dist/production/lib/hooks.js +5 -6
  117. package/dist/production/lib/href.js +1 -1
  118. package/dist/production/lib/router/history.js +1 -1
  119. package/dist/production/lib/router/instrumentation.js +1 -1
  120. package/dist/production/lib/router/matcher-route-pattern.js +1 -1
  121. package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
  122. package/dist/production/lib/router/matcher.js +6 -1
  123. package/dist/production/lib/router/navigation.js +1 -1
  124. package/dist/production/lib/router/router.d.ts +2 -0
  125. package/dist/production/lib/router/router.js +58 -28
  126. package/dist/production/lib/router/url.js +1 -1
  127. package/dist/production/lib/router/utils.d.ts +7 -0
  128. package/dist/production/lib/router/utils.js +1 -1
  129. package/dist/production/lib/rsc/browser.js +3 -3
  130. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  131. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  132. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  133. package/dist/production/lib/rsc/route-modules.js +1 -1
  134. package/dist/production/lib/rsc/server.ssr.js +1 -1
  135. package/dist/production/lib/server-runtime/cookies.js +1 -1
  136. package/dist/production/lib/server-runtime/crypto.js +1 -1
  137. package/dist/production/lib/server-runtime/data.js +1 -1
  138. package/dist/production/lib/server-runtime/dev.js +1 -1
  139. package/dist/production/lib/server-runtime/entry.js +1 -1
  140. package/dist/production/lib/server-runtime/errors.js +1 -1
  141. package/dist/production/lib/server-runtime/headers.js +1 -1
  142. package/dist/production/lib/server-runtime/invariant.js +1 -1
  143. package/dist/production/lib/server-runtime/mode.js +1 -1
  144. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  145. package/dist/production/lib/server-runtime/routes.js +1 -1
  146. package/dist/production/lib/server-runtime/server.js +13 -5
  147. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  148. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  149. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  150. package/dist/production/lib/server-runtime/sessions.js +2 -2
  151. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  152. package/dist/production/lib/server-runtime/urls.js +1 -1
  153. package/dist/production/lib/server-runtime/warnings.js +1 -1
  154. package/dist/production/lib/types/internal.js +1 -1
  155. package/dist/production/route-pattern.js +1 -1
  156. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  157. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  158. package/dist/production/vendor/turbo-stream-v2/unflatten.js +23 -3
  159. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  160. package/docs/explanation/backend-for-frontend.md +0 -3
  161. package/docs/explanation/code-splitting.md +0 -3
  162. package/docs/explanation/concurrency.md +0 -3
  163. package/docs/explanation/hot-module-replacement.md +0 -3
  164. package/docs/explanation/lazy-route-discovery.md +0 -3
  165. package/docs/explanation/progressive-enhancement.md +0 -3
  166. package/docs/explanation/race-conditions.md +0 -3
  167. package/docs/explanation/react-transitions.md +0 -3
  168. package/docs/explanation/sessions-and-cookies.md +1 -1
  169. package/docs/explanation/state-management.md +0 -3
  170. package/docs/explanation/styling.md +0 -3
  171. package/docs/explanation/type-safety.md +0 -3
  172. package/docs/how-to/accessibility.md +0 -6
  173. package/docs/how-to/client-data.md +0 -3
  174. package/docs/how-to/data-strategy.md +0 -3
  175. package/docs/how-to/error-boundary.md +0 -3
  176. package/docs/how-to/error-reporting.md +0 -3
  177. package/docs/how-to/fetchers.md +0 -3
  178. package/docs/how-to/file-route-conventions.md +0 -3
  179. package/docs/how-to/file-uploads.md +0 -3
  180. package/docs/how-to/form-validation.md +0 -3
  181. package/docs/how-to/headers.md +0 -3
  182. package/docs/how-to/instrumentation.md +0 -3
  183. package/docs/how-to/middleware.md +6 -3
  184. package/docs/how-to/navigation-blocking.md +0 -3
  185. package/docs/how-to/optimize-revalidation.md +0 -3
  186. package/docs/how-to/pre-rendering.md +0 -3
  187. package/docs/how-to/presets.md +0 -3
  188. package/docs/how-to/react-server-components.md +0 -3
  189. package/docs/how-to/resource-routes.md +0 -3
  190. package/docs/how-to/route-discovery.md +4 -2
  191. package/docs/how-to/route-module-type-safety.md +0 -3
  192. package/docs/how-to/security.md +0 -3
  193. package/docs/how-to/server-bundles.md +0 -3
  194. package/docs/how-to/spa.md +0 -3
  195. package/docs/how-to/status.md +0 -3
  196. package/docs/how-to/suspense.md +22 -6
  197. package/docs/how-to/using-handle.md +0 -3
  198. package/docs/how-to/view-transitions.md +0 -3
  199. package/docs/start/framework/data-loading.md +9 -0
  200. package/docs/upgrading/future.md +0 -12
  201. package/docs/upgrading/v7.md +3 -33
  202. package/package.json +1 -1
  203. package/dist/development/lib/dom/global.d.ts +0 -35
  204. package/dist/production/lib/dom/global.d.ts +0 -35
@@ -1,6 +1,5 @@
1
1
 
2
2
  import * as React from "react";
3
- import { ComponentType, ReactElement } from "react";
4
3
  import { CookieParseOptions, CookieParseOptions as CookieParseOptions$1, CookieSerializeOptions, CookieSerializeOptions as CookieSerializeOptions$1 } from "cookie-es";
5
4
  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";
6
5
  import { ReactFormState } from "react-dom/client";
@@ -353,6 +352,13 @@ interface DataFunctionArgs<Context> {
353
352
  * In Framework mode, this is a normalized URL with React-Router-specific
354
353
  * implementation details removed (`.data` suffixes, `index`/`_routes` search
355
354
  * params). For the raw incoming URL, use `request.url`.
355
+ *
356
+ * This normalization preserves standard URL pathname encoding and casing.
357
+ * For example, a request to `/%61dmin.data` produces a `url.pathname` of
358
+ * `/%61dmin`. This is not a canonical representation of the matched route.
359
+ * For authorization, attach {@link https://reactrouter.com/how-to/middleware#authentication server middleware}
360
+ * to the protected route or a common ancestor instead of relying on literal
361
+ * pathname-prefix comparisons.
356
362
  */
357
363
  url: URL;
358
364
  /**
@@ -837,30 +843,6 @@ interface UIMatch<Data = unknown, Handle = unknown> {
837
843
  */
838
844
  handle: Handle;
839
845
  }
840
- interface RouteMeta<RouteObjectType extends RouteObject = RouteObject> {
841
- relativePath: string;
842
- caseSensitive: boolean;
843
- childrenIndex: number;
844
- route: RouteObjectType;
845
- matcher?: RegExp;
846
- compiledParams?: CompiledPathParam[];
847
- }
848
- /**
849
- * @private
850
- * PRIVATE - DO NOT USE
851
- *
852
- * A "branch" of routes that match a given route pattern.
853
- * This is an internal interface not intended for direct external usage.
854
- */
855
- interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
856
- path: string;
857
- score: number;
858
- routesMeta: RouteMeta<RouteObjectType>[];
859
- }
860
- type CompiledPathParam = {
861
- paramName: string;
862
- isOptional?: boolean;
863
- };
864
846
  declare class DataWithResponseInit<D> {
865
847
  type: string;
866
848
  data: D;
@@ -1025,18 +1007,6 @@ type ErrorResponse = {
1025
1007
  declare function isRouteErrorResponse(error: any): error is ErrorResponse;
1026
1008
  //#endregion
1027
1009
  //#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
1010
  interface AwaitResolveRenderFunction<Resolve = any> {
1041
1011
  (data: Awaited<Resolve>): React.ReactNode;
1042
1012
  }
@@ -1044,6 +1014,8 @@ interface AwaitResolveRenderFunction<Resolve = any> {
1044
1014
  * @category Types
1045
1015
  */
1046
1016
  interface AwaitProps<Resolve> {
1017
+ /** Use either `resolve` or `unstable_promise`, never both. */
1018
+ unstable_promise?: never;
1047
1019
  /**
1048
1020
  * When using a function, the resolved value is provided as the parameter.
1049
1021
  *
@@ -1145,11 +1117,46 @@ interface AwaitProps<Resolve> {
1145
1117
  */
1146
1118
  resolve: Resolve;
1147
1119
  }
1120
+ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve" | "unstable_promise"> {
1121
+ resolve?: never;
1122
+ /**
1123
+ * A promise (or value) to read using React's `use()` API in client components.
1124
+ * Unlike `resolve` in client components, this accepts promise-like values
1125
+ * without modifying the source promise.
1126
+ *
1127
+ * `errorElement` handles promise rejections. Errors thrown while rendering
1128
+ * children bubble to the nearest React error boundary.
1129
+ *
1130
+ * ```tsx
1131
+ * <Await unstable_promise={reviewsPromise} errorElement={<ReviewsError />}>
1132
+ * {(reviews) => <Reviews items={reviews} />}
1133
+ * </Await>
1134
+ * ```
1135
+ *
1136
+ * Pass exactly one of `unstable_promise` or `resolve`.
1137
+ */
1138
+ unstable_promise: Resolve;
1139
+ }
1148
1140
  /**
1149
1141
  * Used to render promise values with automatic error handling.
1150
1142
  *
1151
1143
  * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
1152
1144
  *
1145
+ * Pass `unstable_promise` instead of `resolve` to opt into React's
1146
+ * [`use()`](https://react.dev/reference/react/use) implementation. With
1147
+ * `unstable_promise`, `errorElement` handles promise rejections, while errors
1148
+ * thrown by children bubble to the nearest React error boundary.
1149
+ *
1150
+ * In React Server Components, `resolve` already has this error-handling behavior:
1151
+ * `errorElement` handles only input rejections, while child render errors
1152
+ * propagate to the surrounding error boundary. Both props accept promise-like
1153
+ * values without modifying the source promise. Both props treat a falsy
1154
+ * `errorElement` as absent and propagate the rejection. Pass an empty fragment
1155
+ * to handle a rejection without rendering any content.
1156
+ *
1157
+ * <docs-warning>The `unstable_promise` prop is experimental and may change in
1158
+ * minor or patch releases.</docs-warning>
1159
+ *
1153
1160
  * @example
1154
1161
  * import { Await, useLoaderData } from "react-router";
1155
1162
  *
@@ -1190,294 +1197,12 @@ interface AwaitProps<Resolve> {
1190
1197
  * @param {AwaitProps.children} props.children n/a
1191
1198
  * @param {AwaitProps.errorElement} props.errorElement n/a
1192
1199
  * @param {AwaitProps.resolve} props.resolve n/a
1200
+ * @param props.unstable_promise A promise (or value) to read using React's `use()`
1201
+ * API in client components. Accepts promise-like values without modifying the
1202
+ * source promise. Pass exactly one of `unstable_promise` or `resolve`.
1193
1203
  * @returns React element for the rendered awaited value
1194
1204
  */
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
- }
1205
+ declare function Await$1<Resolve>(props: AwaitProps<Resolve> | AwaitPromiseProps<Resolve>): React.JSX.Element;
1481
1206
  //#endregion
1482
1207
  //#region lib/router/instrumentation.d.ts
1483
1208
  type ServerInstrumentation = {
@@ -1937,6 +1662,8 @@ interface StaticHandler {
1937
1662
  * The set of data routes managed by this handler
1938
1663
  */
1939
1664
  dataRoutes: DataRouteObject[];
1665
+ /** @private Estimated route metadata visits per regex match. */
1666
+ readonly _matchCost?: number;
1940
1667
  /**
1941
1668
  * @private
1942
1669
  * PRIVATE - DO NOT USE
@@ -2257,31 +1984,6 @@ interface CreateStaticHandlerOptions {
2257
1984
  */
2258
1985
  declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
2259
1986
  //#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
2285
1987
  //#region lib/router/links.d.ts
2286
1988
  type Primitive = null | undefined | string | number | boolean | symbol | bigint;
2287
1989
  type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
@@ -2469,36 +2171,6 @@ type ClientDataFunctionArgs<Params> = {
2469
2171
  type SerializeFrom<T> = T extends ((...args: infer Args) => unknown) ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
2470
2172
  //#endregion
2471
2173
  //#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
- }
2502
2174
  /**
2503
2175
  * A function that handles data mutations for a route on the client
2504
2176
  */
@@ -2521,10 +2193,6 @@ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<Load
2521
2193
  type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
2522
2194
  serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
2523
2195
  };
2524
- /**
2525
- * ErrorBoundary to display for this route
2526
- */
2527
- type ErrorBoundaryComponent = ComponentType;
2528
2196
  type HeadersArgs = {
2529
2197
  loaderHeaders: Headers;
2530
2198
  parentHeaders: Headers;
@@ -2538,19 +2206,6 @@ type HeadersArgs = {
2538
2206
  interface HeadersFunction {
2539
2207
  (args: HeadersArgs): Headers | HeadersInit;
2540
2208
  }
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
- }>;
2554
2209
  /**
2555
2210
  * A function that defines `<link>` tags to be inserted into the `<head>` of
2556
2211
  * the document on route transitions.
@@ -2658,7 +2313,6 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
2658
2313
  /**
2659
2314
  * A React component that is rendered for a route.
2660
2315
  */
2661
- type RouteComponent = ComponentType<{}>;
2662
2316
  /**
2663
2317
  * An arbitrary object that is associated with a route.
2664
2318
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
2
+ * react-router v8.5.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1038,12 +1038,17 @@ var V6RegExMatcher = class {
1038
1038
  #routes = [];
1039
1039
  #branches = [];
1040
1040
  #basename;
1041
+ #matchCost = 0;
1041
1042
  constructor(basename) {
1042
1043
  this.#basename = basename;
1043
1044
  }
1044
1045
  update(routes) {
1045
1046
  this.#routes = routes;
1046
1047
  this.#branches = flattenAndRankRoutes(routes);
1048
+ this.#matchCost = this.#branches.reduce((total, branch) => total + branch.routesMeta.length, 0);
1049
+ }
1050
+ get matchCost() {
1051
+ return this.#matchCost;
1047
1052
  }
1048
1053
  match(locationArg, allowPartial = false) {
1049
1054
  return matchRoutesImpl(this.#routes, locationArg, this.#basename, allowPartial, this.#branches);
@@ -1469,6 +1474,9 @@ function createStaticHandler(routes, opts) {
1469
1474
  }
1470
1475
  return {
1471
1476
  dataRoutes,
1477
+ get _matchCost() {
1478
+ return dataRouteMatcher instanceof V6RegExMatcher ? dataRouteMatcher.matchCost : void 0;
1479
+ },
1472
1480
  match,
1473
1481
  query,
1474
1482
  queryRoute
@@ -1580,6 +1588,9 @@ const loadLazyRouteProperty = ({ key, route, manifest, mapRouteProperties }) =>
1580
1588
  }
1581
1589
  })();
1582
1590
  cache[key] = propertyPromise;
1591
+ propertyPromise.catch(() => {
1592
+ if (cache[key] === propertyPromise) delete cache[key];
1593
+ });
1583
1594
  return propertyPromise;
1584
1595
  };
1585
1596
  const lazyRouteFunctionCache = /* @__PURE__ */ new WeakMap();
@@ -1621,7 +1632,9 @@ function loadLazyRoute(route, type, manifest, mapRouteProperties, lazyRoutePrope
1621
1632
  });
1622
1633
  })();
1623
1634
  lazyRouteFunctionCache.set(routeToUpdate, lazyRoutePromise);
1624
- lazyRoutePromise.catch(() => {});
1635
+ lazyRoutePromise.catch(() => {
1636
+ if (lazyRouteFunctionCache.get(routeToUpdate) === lazyRoutePromise) lazyRouteFunctionCache.delete(routeToUpdate);
1637
+ });
1625
1638
  return {
1626
1639
  lazyRoutePromise,
1627
1640
  lazyHandlerPromise: lazyRoutePromise
@@ -1909,10 +1922,13 @@ async function callLoaderOrAction({ request, path, pattern, match, lazyHandlerPr
1909
1922
  pathname,
1910
1923
  routeId: match.route.id
1911
1924
  });
1912
- } else return {
1913
- type: "data",
1914
- result: void 0
1915
- };
1925
+ } else {
1926
+ await lazyRoutePromise;
1927
+ return {
1928
+ type: "data",
1929
+ result: void 0
1930
+ };
1931
+ }
1916
1932
  }
1917
1933
  else if (!handler) {
1918
1934
  let url = new URL(request.url);
@@ -2242,6 +2258,12 @@ function getPathsWithAncestors(paths) {
2242
2258
  });
2243
2259
  return Array.from(result);
2244
2260
  }
2261
+ const MANIFEST_MATCH_COST_LIMIT = 5e4;
2262
+ const MANIFEST_MATCH_COST_SEGMENT_THRESHOLD = 10;
2263
+ function shouldUseInitialRouteDiscovery(pathname, matchCost = 0) {
2264
+ let segmentCount = pathname.split("/").length - 1;
2265
+ return Math.max(segmentCount - 1, 0) * pathname.length + 1 > 7680 || segmentCount > MANIFEST_MATCH_COST_SEGMENT_THRESHOLD && segmentCount * matchCost > MANIFEST_MATCH_COST_LIMIT;
2266
+ }
2245
2267
  //#endregion
2246
2268
  //#region lib/actions.ts
2247
2269
  function throwIfPotentialCSRFAttack(request, allowedActionOrigins) {
@@ -2337,12 +2359,15 @@ const replace = (...args) => {
2337
2359
  const cachedResolvePromise = React.cache(async (resolve) => {
2338
2360
  return Promise.allSettled([resolve]).then((r) => r[0]);
2339
2361
  });
2340
- const Await = (async ({ children, resolve, errorElement }) => {
2341
- let resolved = await cachedResolvePromise(resolve);
2362
+ const Await = (async (props) => {
2363
+ invariant$1("resolve" in props !== "unstable_promise" in props, "<Await> requires exactly one of `resolve` or `unstable_promise`");
2364
+ let { children, errorElement } = props;
2365
+ let usePromise = "unstable_promise" in props;
2366
+ let resolved = await cachedResolvePromise(usePromise ? props.unstable_promise : props.resolve);
2342
2367
  if (resolved.status === "rejected" && !errorElement) throw resolved.reason;
2343
2368
  if (resolved.status === "rejected") return React.createElement(UNSAFE_AwaitContextProvider, {
2344
2369
  children: React.createElement(React.Fragment, null, errorElement),
2345
- value: {
2370
+ value: usePromise ? resolved : {
2346
2371
  _tracked: true,
2347
2372
  _error: resolved.reason
2348
2373
  }
@@ -2350,7 +2375,7 @@ const Await = (async ({ children, resolve, errorElement }) => {
2350
2375
  const toRender = typeof children === "function" ? children(resolved.value) : children;
2351
2376
  return React.createElement(UNSAFE_AwaitContextProvider, {
2352
2377
  children: toRender,
2353
- value: {
2378
+ value: usePromise ? resolved : {
2354
2379
  _tracked: true,
2355
2380
  _data: resolved.value
2356
2381
  }
@@ -2667,7 +2692,7 @@ async function generateRenderResponse(request, staticHandler, basename, isDataRe
2667
2692
  let result = await processServerAction(request, basename, decodeReply, loadServerAction, decodeAction, decodeFormState, onError, temporaryReferences).finally(() => {
2668
2693
  ctx.runningAction = false;
2669
2694
  });
2670
- if (isResponse(result)) return generateRedirectResponse(result, actionResult, basename, isDataRequest, generateResponse, temporaryReferences, ctx.redirect?.headers);
2695
+ if (isResponse(result)) return generateRedirectResponse(result, actionResult, basename, isDataRequest, generateResponse, temporaryReferences, result === ctx.redirect ? void 0 : ctx.redirect?.headers);
2671
2696
  skipRevalidation = result?.skipRevalidation ?? false;
2672
2697
  actionResult = result?.actionResult;
2673
2698
  formState = result?.formState;
@@ -2701,7 +2726,7 @@ function generateRedirectResponse(response, actionResult, basename, isDataReques
2701
2726
  status: response.status,
2702
2727
  actionResult
2703
2728
  };
2704
- let headers = new Headers(sideEffectRedirectHeaders);
2729
+ let headers = new Headers(sideEffectRedirectHeaders === response.headers ? void 0 : sideEffectRedirectHeaders);
2705
2730
  for (const [key, value] of response.headers.entries()) headers.append(key, value);
2706
2731
  headers.delete("Location");
2707
2732
  headers.delete("X-Remix-Reload-Document");
@@ -2779,11 +2804,14 @@ async function getRenderPayload(baseRenderPayload, staticHandler, basename, rout
2779
2804
  parentId
2780
2805
  });
2781
2806
  }));
2807
+ let pathname = staticContext.location.pathname;
2808
+ let useInitialRouteDiscovery = routeDiscovery?.mode === "initial" && !isDataRequest || shouldUseInitialRouteDiscovery(pathname, staticHandler._matchCost);
2782
2809
  let patches;
2783
- if (routeDiscovery?.mode === "initial" && !isDataRequest) patches = getAllRoutePatches(routes, basename).then((patches) => patches.filter((patch) => !staticContext.matches.some((m) => m.route.id === patch.id)));
2784
- else patches = getAdditionalRoutePatches(getPathsWithAncestors([staticContext.location.pathname]), staticHandler, staticContext.matches.map((m) => m.route.id));
2810
+ if (useInitialRouteDiscovery) patches = getAllRoutePatches(routes, basename).then((patches) => patches.filter((patch) => !staticContext.matches.some((m) => m.route.id === patch.id)));
2811
+ else patches = getAdditionalRoutePatches(getPathsWithAncestors([pathname]).slice(0, -1), staticHandler, staticContext.matches.map((m) => m.route.id));
2785
2812
  return {
2786
2813
  ...baseRenderPayload,
2814
+ routeDiscovery: useInitialRouteDiscovery ? { mode: "initial" } : baseRenderPayload.routeDiscovery,
2787
2815
  matches: await matchesPromise,
2788
2816
  patches
2789
2817
  };
@@ -3242,7 +3270,7 @@ function createSessionStorage({ cookie: cookieArg, createData, readData, updateD
3242
3270
  return cookie.serialize(id, options);
3243
3271
  },
3244
3272
  async destroySession(session, options) {
3245
- await deleteData(session.id);
3273
+ if (session.id) await deleteData(session.id);
3246
3274
  return cookie.serialize("", {
3247
3275
  ...options,
3248
3276
  maxAge: void 0,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
2
+ * react-router v8.5.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *