react-router 8.5.1 → 8.5.3

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 (167) hide show
  1. package/CHANGELOG.md +79 -3
  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 +46 -39
  5. package/dist/development/index-react-server.js +104 -41
  6. package/dist/development/index.js +1 -1
  7. package/dist/development/lib/actions.js +1 -1
  8. package/dist/development/lib/await.js +1 -1
  9. package/dist/development/lib/components.d.ts +42 -38
  10. package/dist/development/lib/components.js +34 -36
  11. package/dist/development/lib/context.js +3 -2
  12. package/dist/development/lib/dom/dom.js +16 -5
  13. package/dist/development/lib/dom/lib.d.ts +2 -2
  14. package/dist/development/lib/dom/lib.js +22 -8
  15. package/dist/development/lib/dom/server.js +5 -3
  16. package/dist/development/lib/dom/ssr/components.js +4 -1
  17. package/dist/development/lib/dom/ssr/data.js +1 -1
  18. package/dist/development/lib/dom/ssr/errorBoundaries.js +2 -1
  19. package/dist/development/lib/dom/ssr/fallback.js +2 -1
  20. package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
  21. package/dist/development/lib/dom/ssr/hydration.d.ts +1 -0
  22. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  23. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  24. package/dist/development/lib/dom/ssr/links.js +1 -1
  25. package/dist/development/lib/dom/ssr/markup.js +1 -1
  26. package/dist/development/lib/dom/ssr/route-discovery.js +1 -1
  27. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  28. package/dist/development/lib/dom/ssr/routes-test-stub.js +3 -1
  29. package/dist/development/lib/dom/ssr/routes.js +2 -1
  30. package/dist/development/lib/dom/ssr/server.js +1 -1
  31. package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
  32. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  33. package/dist/development/lib/dom-export/hydrated-router.d.ts +1 -1
  34. package/dist/development/lib/dom-export/hydrated-router.js +4 -2
  35. package/dist/development/lib/errors.js +1 -1
  36. package/dist/development/lib/hooks.d.ts +30 -0
  37. package/dist/development/lib/hooks.js +46 -7
  38. package/dist/development/lib/href.js +4 -4
  39. package/dist/development/lib/router/history.js +10 -4
  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 +1 -1
  44. package/dist/development/lib/router/navigation.js +17 -2
  45. package/dist/development/lib/router/router.js +26 -9
  46. package/dist/development/lib/router/url.js +1 -1
  47. package/dist/development/lib/router/utils.d.ts +8 -5
  48. package/dist/development/lib/router/utils.js +24 -9
  49. package/dist/development/lib/rsc/browser.js +27 -4
  50. package/dist/development/lib/rsc/errorBoundaries.js +3 -2
  51. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  52. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  53. package/dist/development/lib/rsc/route-modules.js +1 -1
  54. package/dist/development/lib/rsc/server.rsc.d.ts +4 -1
  55. package/dist/development/lib/rsc/server.ssr.d.ts +1 -0
  56. package/dist/development/lib/rsc/server.ssr.js +5 -4
  57. package/dist/development/lib/server-runtime/cookies.js +1 -1
  58. package/dist/development/lib/server-runtime/crypto.js +1 -1
  59. package/dist/development/lib/server-runtime/data.js +1 -1
  60. package/dist/development/lib/server-runtime/dev.js +1 -1
  61. package/dist/development/lib/server-runtime/entry.js +1 -1
  62. package/dist/development/lib/server-runtime/errors.js +1 -1
  63. package/dist/development/lib/server-runtime/headers.js +1 -1
  64. package/dist/development/lib/server-runtime/invariant.js +1 -1
  65. package/dist/development/lib/server-runtime/mode.js +1 -1
  66. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  67. package/dist/development/lib/server-runtime/routes.js +1 -1
  68. package/dist/development/lib/server-runtime/server.js +9 -6
  69. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  70. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +3 -2
  71. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  72. package/dist/development/lib/server-runtime/sessions.d.ts +1 -1
  73. package/dist/development/lib/server-runtime/sessions.js +5 -3
  74. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  75. package/dist/development/lib/server-runtime/urls.js +1 -1
  76. package/dist/development/lib/server-runtime/warnings.js +1 -1
  77. package/dist/development/lib/types/internal.js +1 -1
  78. package/dist/development/lib/types/route-module-annotations.d.ts +16 -9
  79. package/dist/development/route-pattern.js +1 -1
  80. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  81. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +83 -73
  82. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  83. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  84. package/dist/production/dom-export.js +1 -1
  85. package/dist/production/index-react-server-client.js +1 -1
  86. package/dist/production/index-react-server.d.ts +46 -39
  87. package/dist/production/index-react-server.js +104 -41
  88. package/dist/production/index.js +1 -1
  89. package/dist/production/lib/actions.js +1 -1
  90. package/dist/production/lib/await.js +1 -1
  91. package/dist/production/lib/components.d.ts +42 -38
  92. package/dist/production/lib/components.js +34 -36
  93. package/dist/production/lib/context.js +3 -2
  94. package/dist/production/lib/dom/dom.js +16 -5
  95. package/dist/production/lib/dom/lib.d.ts +2 -2
  96. package/dist/production/lib/dom/lib.js +22 -8
  97. package/dist/production/lib/dom/server.js +5 -3
  98. package/dist/production/lib/dom/ssr/components.js +4 -1
  99. package/dist/production/lib/dom/ssr/data.js +1 -1
  100. package/dist/production/lib/dom/ssr/errorBoundaries.js +2 -1
  101. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  102. package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
  103. package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
  104. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  105. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  106. package/dist/production/lib/dom/ssr/links.js +1 -1
  107. package/dist/production/lib/dom/ssr/markup.js +1 -1
  108. package/dist/production/lib/dom/ssr/route-discovery.js +1 -1
  109. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  110. package/dist/production/lib/dom/ssr/routes-test-stub.js +3 -1
  111. package/dist/production/lib/dom/ssr/routes.js +2 -1
  112. package/dist/production/lib/dom/ssr/server.js +1 -1
  113. package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
  114. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  115. package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
  116. package/dist/production/lib/dom-export/hydrated-router.js +4 -2
  117. package/dist/production/lib/errors.js +1 -1
  118. package/dist/production/lib/hooks.d.ts +30 -0
  119. package/dist/production/lib/hooks.js +45 -6
  120. package/dist/production/lib/href.js +4 -4
  121. package/dist/production/lib/router/history.js +10 -4
  122. package/dist/production/lib/router/instrumentation.js +1 -1
  123. package/dist/production/lib/router/matcher-route-pattern.js +1 -1
  124. package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
  125. package/dist/production/lib/router/matcher.js +1 -1
  126. package/dist/production/lib/router/navigation.js +17 -2
  127. package/dist/production/lib/router/router.js +26 -9
  128. package/dist/production/lib/router/url.js +1 -1
  129. package/dist/production/lib/router/utils.d.ts +8 -5
  130. package/dist/production/lib/router/utils.js +24 -9
  131. package/dist/production/lib/rsc/browser.js +27 -4
  132. package/dist/production/lib/rsc/errorBoundaries.js +3 -2
  133. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  134. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  135. package/dist/production/lib/rsc/route-modules.js +1 -1
  136. package/dist/production/lib/rsc/server.rsc.d.ts +4 -1
  137. package/dist/production/lib/rsc/server.ssr.d.ts +1 -0
  138. package/dist/production/lib/rsc/server.ssr.js +5 -4
  139. package/dist/production/lib/server-runtime/cookies.js +1 -1
  140. package/dist/production/lib/server-runtime/crypto.js +1 -1
  141. package/dist/production/lib/server-runtime/data.js +1 -1
  142. package/dist/production/lib/server-runtime/dev.js +1 -1
  143. package/dist/production/lib/server-runtime/entry.js +1 -1
  144. package/dist/production/lib/server-runtime/errors.js +1 -1
  145. package/dist/production/lib/server-runtime/headers.js +1 -1
  146. package/dist/production/lib/server-runtime/invariant.js +1 -1
  147. package/dist/production/lib/server-runtime/mode.js +1 -1
  148. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  149. package/dist/production/lib/server-runtime/routes.js +1 -1
  150. package/dist/production/lib/server-runtime/server.js +9 -6
  151. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  152. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +3 -2
  153. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  154. package/dist/production/lib/server-runtime/sessions.d.ts +1 -1
  155. package/dist/production/lib/server-runtime/sessions.js +5 -3
  156. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  157. package/dist/production/lib/server-runtime/urls.js +1 -1
  158. package/dist/production/lib/server-runtime/warnings.js +1 -1
  159. package/dist/production/lib/types/internal.js +1 -1
  160. package/dist/production/lib/types/route-module-annotations.d.ts +16 -9
  161. package/dist/production/route-pattern.js +1 -1
  162. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  163. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +83 -73
  164. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  165. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  166. package/docs/upgrading/v7.md +11 -0
  167. package/package.json +1 -1
@@ -447,7 +447,7 @@ interface PathRouteProps {
447
447
  action?: NonIndexRouteObject["action"];
448
448
  /**
449
449
  * The route shouldRevalidate function.
450
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
450
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
451
451
  */
452
452
  shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
453
453
  /**
@@ -537,7 +537,7 @@ interface IndexRouteProps {
537
537
  action?: IndexRouteObject["action"];
538
538
  /**
539
539
  * The route shouldRevalidate function.
540
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
540
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
541
541
  */
542
542
  shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
543
543
  /**
@@ -768,7 +768,25 @@ interface AwaitResolveRenderFunction<Resolve = any> {
768
768
  * @category Types
769
769
  */
770
770
  interface AwaitProps<Resolve> {
771
- /** Use either `resolve` or `unstable_promise`, never both. */
771
+ /**
772
+ * <docs-warning>This prop is currently unstable and may change in minor or patch
773
+ * releases.</docs-warning>
774
+ *
775
+ * A promise (or value) to read using React's `use()` API in client components.
776
+ * Unlike `resolve` in client components, this accepts promise-like values
777
+ * without modifying the source promise.
778
+ *
779
+ * `errorElement` handles promise rejections. Errors thrown while rendering
780
+ * children bubble to the nearest React error boundary.
781
+ *
782
+ * ```tsx
783
+ * <Await unstable_promise={reviewsPromise} errorElement={<ReviewsError />}>
784
+ * {(reviews) => <Reviews items={reviews} />}
785
+ * </Await>
786
+ * ```
787
+ *
788
+ * Pass exactly one of `unstable_promise` or `resolve`.
789
+ */
772
790
  unstable_promise?: never;
773
791
  /**
774
792
  * When using a function, the resolved value is provided as the parameter.
@@ -795,14 +813,17 @@ interface AwaitProps<Resolve> {
795
813
  */
796
814
  children: React$1.ReactNode | AwaitResolveRenderFunction<Resolve>;
797
815
  /**
798
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
816
+ * The error element renders instead of the `children` when the
817
+ * [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
799
818
  * rejects.
800
819
  *
820
+ * When using `resolve`, errors thrown while rendering `children` are
821
+ * also caught and rendered here. With `unstable_promise`, only promise
822
+ * rejections are handled; errors thrown while rendering `children` bubble to
823
+ * the nearest React error boundary.
824
+ *
801
825
  * ```tsx
802
- * <Await
803
- * errorElement={<div>Oops</div>}
804
- * resolve={reviewsPromise}
805
- * >
826
+ * <Await resolve={reviewsPromise} errorElement={<div>Oops</div>}>
806
827
  * <Reviews />
807
828
  * </Await>
808
829
  * ```
@@ -811,10 +832,7 @@ interface AwaitProps<Resolve> {
811
832
  * child component
812
833
  *
813
834
  * ```tsx
814
- * <Await
815
- * errorElement={<ReviewsError />}
816
- * resolve={reviewsPromise}
817
- * >
835
+ * <Await resolve={reviewsPromise} errorElement={<ReviewsError />}>
818
836
  * <Reviews />
819
837
  * </Await>
820
838
  *
@@ -894,22 +912,16 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
894
912
  /**
895
913
  * Used to render promise values with automatic error handling.
896
914
  *
897
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
915
+ * Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
916
+ * it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
917
+ * API.
898
918
  *
899
- * Pass `unstable_promise` instead of `resolve` to opt into React's
900
- * [`use()`](https://react.dev/reference/react/use) implementation. With
901
- * `unstable_promise`, `errorElement` handles promise rejections, while errors
902
- * thrown by children bubble to the nearest React error boundary.
903
- *
904
- * In React Server Components, `resolve` already has this error-handling behavior:
905
- * `errorElement` handles only input rejections, while child render errors
906
- * propagate to the surrounding error boundary. Both props accept promise-like
907
- * values without modifying the source promise. Both props treat a falsy
908
- * `errorElement` as absent and propagate the rejection. Pass an empty fragment
909
- * to handle a rejection without rendering any content.
919
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
910
920
  *
911
- * <docs-warning>The `unstable_promise` prop is experimental and may change in
912
- * minor or patch releases.</docs-warning>
921
+ * <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
922
+ * releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
923
+ * drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
924
+ * between the two approaches.</docs-warning>
913
925
  *
914
926
  * @example
915
927
  * import { Await, useLoaderData } from "react-router";
@@ -929,15 +941,9 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
929
941
  * <h1>{book.title}</h1>
930
942
  * <p>{book.description}</p>
931
943
  * <React.Suspense fallback={<ReviewsSkeleton />}>
932
- * <Await
933
- * resolve={reviews}
934
- * errorElement={
935
- * <div>Could not load reviews 😬</div>
936
- * }
937
- * children={(resolvedReviews) => (
938
- * <Reviews items={resolvedReviews} />
939
- * )}
940
- * />
944
+ * <Await resolve={reviews} errorElement={<BookError />}>
945
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
946
+ * </Await>
941
947
  * </React.Suspense>
942
948
  * </div>
943
949
  * );
@@ -951,9 +957,7 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
951
957
  * @param {AwaitProps.children} props.children n/a
952
958
  * @param {AwaitProps.errorElement} props.errorElement n/a
953
959
  * @param {AwaitProps.resolve} props.resolve n/a
954
- * @param props.unstable_promise A promise (or value) to read using React's `use()`
955
- * API in client components. Accepts promise-like values without modifying the
956
- * source promise. Pass exactly one of `unstable_promise` or `resolve`.
960
+ * @param {AwaitProps.unstable_promise} props.unstable_promise n/a
957
961
  * @returns React element for the rendered awaited value
958
962
  */
959
963
  declare function Await<Resolve>(props: AwaitProps<Resolve> | AwaitPromiseProps<Resolve>): React$1.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,8 +9,8 @@
9
9
  * @license MIT
10
10
  */
11
11
  import { createMemoryHistory, createPath, invariant, parsePath, warning } from "./router/history.js";
12
- import { defaultMapRouteProperties, getResolveToMatches, getRoutePattern, resolveTo, stripBasename } from "./router/utils.js";
13
12
  import { getNavigatorCurrentUrl, validateNavigationTarget } from "./router/navigation.js";
13
+ import { defaultMapRouteProperties, getResolveToMatches, getRoutePattern, resolveTo, stripBasename } from "./router/utils.js";
14
14
  import { clientErrors, createRouter } from "./router/router.js";
15
15
  import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, LocationContext, NavigationContext, RouteContext, ViewTransitionContext, useIsRSCRouterContext } from "./context.js";
16
16
  import { getAwaitPromise, getPromiseResult } from "./await.js";
@@ -284,13 +284,14 @@ function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, onError, use
284
284
  encodeLocation: router.encodeLocation,
285
285
  go: (n) => router.navigate(n),
286
286
  push: (to, state, opts) => router.navigate(to, {
287
- state,
288
- preventScrollReset: opts?.preventScrollReset
287
+ ...opts,
288
+ replace: opts?.replace === false ? false : void 0,
289
+ state: state !== void 0 ? state : opts?.state
289
290
  }),
290
291
  replace: (to, state, opts) => router.navigate(to, {
292
+ ...opts,
291
293
  replace: true,
292
- state,
293
- preventScrollReset: opts?.preventScrollReset
294
+ state: state !== void 0 ? state : opts?.state
294
295
  })
295
296
  };
296
297
  }, [router]);
@@ -343,6 +344,7 @@ function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, onError, use
343
344
  fetchers: state.fetchers,
344
345
  fetcherData: fetcherData.current
345
346
  }), [state.fetchers]);
347
+ let discoveryRuntime = React$1.useContext(FrameworkContext)?.routeDiscoveryRuntime;
346
348
  return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement(DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React$1.createElement(DataRouterStateContext.Provider, { value: dataRouterState }, /* @__PURE__ */ React$1.createElement(DataRouterNavigationContext.Provider, { value: dataRouterNavigation }, /* @__PURE__ */ React$1.createElement(DataRouterDataContext.Provider, { value: dataRouterData }, /* @__PURE__ */ React$1.createElement(FetchersContext.Provider, { value: fetchersContext }, /* @__PURE__ */ React$1.createElement(ViewTransitionContext.Provider, { value: vtContext }, /* @__PURE__ */ React$1.createElement(Router, {
347
349
  basename,
348
350
  location: state.location,
@@ -354,7 +356,8 @@ function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, onError, use
354
356
  manifest: router.manifest,
355
357
  state,
356
358
  isStatic: false,
357
- onError
359
+ onError,
360
+ discoveryRuntime
358
361
  })))))))), null);
359
362
  }
360
363
  function getOptimisticRouterState(currentState, newState) {
@@ -367,10 +370,9 @@ function getOptimisticRouterState(currentState, newState) {
367
370
  };
368
371
  }
369
372
  const MemoizedDataRoutes = React$1.memo(DataRoutes);
370
- function DataRoutes({ routes, manifest, state, isStatic, onError }) {
373
+ function DataRoutes({ routes, manifest, state, isStatic, onError, discoveryRuntime }) {
371
374
  let dataRouterContext = React$1.useContext(DataRouterContext);
372
375
  invariant(dataRouterContext, "You must render this element inside a <DataRouterContext.Provider> element");
373
- let discoveryRuntime = React$1.useContext(FrameworkContext)?.routeDiscoveryRuntime;
374
376
  React$1.useEffect(() => {
375
377
  if (state.initialized) discoveryRuntime?.markReady();
376
378
  }, [state.initialized, discoveryRuntime]);
@@ -649,22 +651,16 @@ function Routes({ children, location }) {
649
651
  /**
650
652
  * Used to render promise values with automatic error handling.
651
653
  *
652
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
653
- *
654
- * Pass `unstable_promise` instead of `resolve` to opt into React's
655
- * [`use()`](https://react.dev/reference/react/use) implementation. With
656
- * `unstable_promise`, `errorElement` handles promise rejections, while errors
657
- * thrown by children bubble to the nearest React error boundary.
654
+ * Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
655
+ * it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
656
+ * API.
658
657
  *
659
- * In React Server Components, `resolve` already has this error-handling behavior:
660
- * `errorElement` handles only input rejections, while child render errors
661
- * propagate to the surrounding error boundary. Both props accept promise-like
662
- * values without modifying the source promise. Both props treat a falsy
663
- * `errorElement` as absent and propagate the rejection. Pass an empty fragment
664
- * to handle a rejection without rendering any content.
658
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
665
659
  *
666
- * <docs-warning>The `unstable_promise` prop is experimental and may change in
667
- * minor or patch releases.</docs-warning>
660
+ * <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
661
+ * releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
662
+ * drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
663
+ * between the two approaches.</docs-warning>
668
664
  *
669
665
  * @example
670
666
  * import { Await, useLoaderData } from "react-router";
@@ -684,15 +680,9 @@ function Routes({ children, location }) {
684
680
  * <h1>{book.title}</h1>
685
681
  * <p>{book.description}</p>
686
682
  * <React.Suspense fallback={<ReviewsSkeleton />}>
687
- * <Await
688
- * resolve={reviews}
689
- * errorElement={
690
- * <div>Could not load reviews 😬</div>
691
- * }
692
- * children={(resolvedReviews) => (
693
- * <Reviews items={resolvedReviews} />
694
- * )}
695
- * />
683
+ * <Await resolve={reviews} errorElement={<BookError />}>
684
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
685
+ * </Await>
696
686
  * </React.Suspense>
697
687
  * </div>
698
688
  * );
@@ -706,9 +696,7 @@ function Routes({ children, location }) {
706
696
  * @param {AwaitProps.children} props.children n/a
707
697
  * @param {AwaitProps.errorElement} props.errorElement n/a
708
698
  * @param {AwaitProps.resolve} props.resolve n/a
709
- * @param props.unstable_promise A promise (or value) to read using React's `use()`
710
- * API in client components. Accepts promise-like values without modifying the
711
- * source promise. Pass exactly one of `unstable_promise` or `resolve`.
699
+ * @param {AwaitProps.unstable_promise} props.unstable_promise n/a
712
700
  * @returns React element for the rendered awaited value
713
701
  */
714
702
  function Await(props) {
@@ -746,11 +734,21 @@ function AwaitPromise({ value, children, errorElement, onError }) {
746
734
  var AwaitErrorBoundary = class extends React$1.Component {
747
735
  constructor(props) {
748
736
  super(props);
749
- this.state = { error: null };
737
+ this.state = {
738
+ error: null,
739
+ resolve: props.resolve
740
+ };
750
741
  }
751
742
  static getDerivedStateFromError(error) {
752
743
  return { error };
753
744
  }
745
+ static getDerivedStateFromProps(props, state) {
746
+ if (props.resolve !== state.resolve) return {
747
+ error: null,
748
+ resolve: props.resolve
749
+ };
750
+ return null;
751
+ }
754
752
  componentDidCatch(error, errorInfo) {
755
753
  if (this.props.onError) this.props.onError(error, errorInfo);
756
754
  else console.error("<Await> caught the following error during render", error, errorInfo);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -19,6 +19,7 @@ DataRouterDataContext.displayName = "DataRouterData";
19
19
  const DataRouterNavigationContext = React$1.createContext(null);
20
20
  DataRouterNavigationContext.displayName = "DataRouterNavigation";
21
21
  const RSCRouterContext = React$1.createContext(false);
22
+ const RSCErrorAlreadyReportedContext = React$1.createContext(false);
22
23
  function useIsRSCRouterContext() {
23
24
  return React$1.useContext(RSCRouterContext);
24
25
  }
@@ -46,4 +47,4 @@ RouteIdContext.displayName = "RouteId";
46
47
  const RouteErrorContext = React$1.createContext(null);
47
48
  RouteErrorContext.displayName = "RouteError";
48
49
  //#endregion
49
- export { AwaitContext, AwaitContextProvider, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext, ViewTransitionContext, useIsRSCRouterContext };
50
+ export { AwaitContext, AwaitContextProvider, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCErrorAlreadyReportedContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext, ViewTransitionContext, useIsRSCRouterContext };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { warning } from "../router/history.js";
11
+ import { createPath, parsePath, warning } from "../router/history.js";
12
12
  import { stripBasename } from "../router/utils.js";
13
13
  const defaultEncType = "application/x-www-form-urlencoded";
14
14
  function isHtmlElement(object) {
@@ -27,7 +27,8 @@ function isModifiedEvent(event) {
27
27
  return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
28
28
  }
29
29
  function shouldProcessLinkClick(event, target) {
30
- return event.button === 0 && (!target || target === "_self") && !isModifiedEvent(event);
30
+ let element = event.currentTarget;
31
+ return event.button === 0 && (!target || target === "_self") && !isModifiedEvent(event) && !((element?.localName === "a" || element?.localName === "area") && element.hasAttribute("href") && element.hasAttribute("download"));
31
32
  }
32
33
  /**
33
34
  * Creates a URLSearchParams object using the given initializer.
@@ -86,12 +87,22 @@ const supportedFormEncTypes = new Set([
86
87
  "text/plain"
87
88
  ]);
88
89
  function getFormEncType(encType) {
90
+ encType = encType?.toLowerCase() ?? null;
89
91
  if (encType != null && !supportedFormEncTypes.has(encType)) {
90
92
  warning(false, `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`);
91
93
  return null;
92
94
  }
93
95
  return encType;
94
96
  }
97
+ function stripBasenameFromAction(action, basename) {
98
+ if (basename === "/") return action;
99
+ let path = parsePath(action);
100
+ let pathname = stripBasename(path.pathname || "", basename);
101
+ return pathname == null ? null : createPath({
102
+ ...path,
103
+ pathname
104
+ });
105
+ }
95
106
  function getFormSubmissionInfo(target, basename) {
96
107
  let method;
97
108
  let action;
@@ -100,7 +111,7 @@ function getFormSubmissionInfo(target, basename) {
100
111
  let body;
101
112
  if (isFormElement(target)) {
102
113
  let attr = target.getAttribute("action");
103
- action = attr ? stripBasename(attr, basename) : null;
114
+ action = attr ? stripBasenameFromAction(attr, basename) : null;
104
115
  method = target.getAttribute("method") || "get";
105
116
  encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
106
117
  formData = new FormData(target);
@@ -108,7 +119,7 @@ function getFormSubmissionInfo(target, basename) {
108
119
  let form = target.form;
109
120
  if (form == null) throw new Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);
110
121
  let attr = target.getAttribute("formaction") || form.getAttribute("action");
111
- action = attr ? stripBasename(attr, basename) : null;
122
+ action = attr ? stripBasenameFromAction(attr, basename) : null;
112
123
  method = target.getAttribute("formmethod") || form.getAttribute("method") || "get";
113
124
  encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
114
125
  formData = new FormData(form, target);
@@ -69,7 +69,7 @@ interface DOMRouterOpts {
69
69
  *
70
70
  * You will almost always include a complete set of `loaderData` to hydrate a
71
71
  * server-rendered app. But in advanced use-cases (such as Framework Mode's
72
- * [`clientLoader`](../../start/framework/route-module#clientLoader)), you may
72
+ * [`clientLoader`](../../start/framework/route-module#clientloader)), you may
73
73
  * want to include `loaderData` for only some routes that were loaded/rendered
74
74
  * on the server. This allows you to hydrate _some_ of the routes (such as the
75
75
  * app layout/shell) while showing a `HydrateFallback` component and running
@@ -208,7 +208,7 @@ interface DOMRouterOpts {
208
208
  * To combat this, we introduced [`route.lazy`](../../start/data/route-object#lazy)
209
209
  * in [v6.9.0](https://github.com/remix-run/react-router/blob/main/CHANGELOG.md#v690)
210
210
  * which lets you lazily load the route _implementation_ ([`loader`](../../start/data/route-object#loader),
211
- * [`Component`](../../start/data/route-object#Component), etc.) while still
211
+ * [`Component`](../../start/data/route-object#component), etc.) while still
212
212
  * providing the route _definition_ aspects up front (`path`, `index`, etc.).
213
213
  * This is a good middle ground. React Router still knows about your route
214
214
  * definitions (the lightweight part) up front and can perform synchronous
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { ABSOLUTE_URL_REGEX } from "../router/url.js";
12
12
  import { createBrowserHistory, createHashHistory, createPath, invariant, warning } from "../router/history.js";
13
+ import { validateDocumentNavigationTarget } from "../router/navigation.js";
13
14
  import { ErrorResponseImpl, SUPPORTED_ERROR_TYPES, defaultMapRouteProperties, joinPaths, matchPath, parseToInfo, resolveTo, stripBasename } from "../router/utils.js";
14
15
  import { IDLE_FETCHER, createRouter } from "../router/router.js";
15
16
  import { DataRouterNavigationContext, NavigationContext, RouteContext, ViewTransitionContext } from "../context.js";
@@ -314,10 +315,12 @@ const Link = React$1.forwardRef(function LinkWithRef({ onClick, discover = "rend
314
315
  if (!event.defaultPrevented) internalOnClick(event);
315
316
  }
316
317
  let isSpaLink = !(parsed.isExternal || reloadDocument);
318
+ let renderedHref = (isSpaLink ? maskedHref : void 0) || parsed.absoluteURL || href;
319
+ validateDocumentNavigationTarget(renderedHref);
317
320
  let link = /* @__PURE__ */ React$1.createElement("a", {
318
321
  ...rest,
319
322
  ...prefetchHandlers,
320
- href: (isSpaLink ? maskedHref : void 0) || parsed.absoluteURL || href,
323
+ href: renderedHref,
321
324
  onClick: isSpaLink ? handleClick : onClick,
322
325
  ref: mergeRefs(forwardedRef, prefetchRef),
323
326
  target,
@@ -326,6 +329,8 @@ const Link = React$1.forwardRef(function LinkWithRef({ onClick, discover = "rend
326
329
  return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, link, /* @__PURE__ */ React$1.createElement(PrefetchPageLinks, { page: href })) : link;
327
330
  });
328
331
  Link.displayName = "Link";
332
+ const subscribeToNothing = () => () => {};
333
+ const getClientSpaFallback = () => false;
329
334
  /**
330
335
  * Wraps {@link Link | `<Link>`} with additional props for styling active and
331
336
  * pending states.
@@ -374,7 +379,9 @@ const NavLink = React$1.forwardRef(function NavLinkWithRef({ "aria-current": ari
374
379
  let location = useLocation();
375
380
  let routerNavigation = React$1.useContext(DataRouterNavigationContext);
376
381
  let { navigator, basename } = React$1.useContext(NavigationContext);
377
- let isTransitioning = routerNavigation != null && useViewTransitionState(path) && viewTransition === true;
382
+ let isSpaMode = React$1.useContext(FrameworkContext)?.isSpaMode === true;
383
+ let isSpaFallback = React$1.useSyncExternalStore(subscribeToNothing, getClientSpaFallback, () => isSpaMode);
384
+ let isTransitioning = routerNavigation != null && useViewTransitionState(path) && viewTransition === true && !isSpaFallback;
378
385
  let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
379
386
  let locationPathname = location.pathname;
380
387
  let nextLocationPathname = routerNavigation?.navigation.location ? routerNavigation.navigation.location.pathname : null;
@@ -385,8 +392,8 @@ const NavLink = React$1.forwardRef(function NavLinkWithRef({ "aria-current": ari
385
392
  }
386
393
  if (nextLocationPathname && basename) nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
387
394
  const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
388
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
389
- let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(endSlashPosition) === "/");
395
+ let isActive = !isSpaFallback && (locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/");
396
+ let isPending = !isSpaFallback && nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(endSlashPosition) === "/");
390
397
  let renderProps = {
391
398
  isActive,
392
399
  isPending,
@@ -562,7 +569,9 @@ function ScrollRestoration({ getKey, storageKey, ...props }) {
562
569
  if (typeof storedY === "number") window.scrollTo(0, storedY);
563
570
  } catch (error) {
564
571
  console.error(error);
565
- sessionStorage.removeItem(storageKey);
572
+ try {
573
+ sessionStorage.removeItem(storageKey);
574
+ } catch {}
566
575
  }
567
576
  }).toString();
568
577
  if (props.nonce == null && remixContext?.nonce) props.nonce = remixContext.nonce;
@@ -872,7 +881,9 @@ function useFormAction(action, { relative } = {}) {
872
881
  }
873
882
  if ((!action || action === ".") && match.route.index) path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
874
883
  if (basename !== "/") path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
875
- return createPath(path);
884
+ let formAction = createPath(path);
885
+ validateDocumentNavigationTarget(formAction);
886
+ return formAction;
876
887
  }
877
888
  /**
878
889
  * Useful for creating complex, dynamic user interfaces that require multiple,
@@ -1101,7 +1112,10 @@ function useScrollRestoration({ getKey, storageKey } = {}) {
1101
1112
  React$1.useLayoutEffect(() => {
1102
1113
  try {
1103
1114
  let sessionPositions = sessionStorage.getItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY);
1104
- if (sessionPositions) savedScrollPositions = JSON.parse(sessionPositions);
1115
+ if (sessionPositions) {
1116
+ let parsedPositions = JSON.parse(sessionPositions);
1117
+ savedScrollPositions = parsedPositions && typeof parsedPositions === "object" && !Array.isArray(parsedPositions) ? parsedPositions : {};
1118
+ }
1105
1119
  } catch {}
1106
1120
  }, [storageKey]);
1107
1121
  React$1.useLayoutEffect(() => {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { ABSOLUTE_URL_REGEX } from "../router/url.js";
11
+ import { PROTOCOL_RELATIVE_URL_REGEX } from "../router/url.js";
12
12
  import { createPath, invariant, parsePath, warning } from "../router/history.js";
13
13
  import { convertRoutesToDataRoutes, isRouteErrorResponse } from "../router/utils.js";
14
14
  import { IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION } from "../router/router.js";
@@ -314,9 +314,11 @@ function createHref(to) {
314
314
  return typeof to === "string" ? to : createPath(to);
315
315
  }
316
316
  function encodeLocation(to) {
317
+ let base = "http://localhost";
317
318
  let href = typeof to === "string" ? to : createPath(to);
318
319
  href = href.replace(/ $/, "%20");
319
- let encoded = ABSOLUTE_URL_REGEX.test(href) ? new URL(href) : new URL(href, "http://localhost");
320
+ if (PROTOCOL_RELATIVE_URL_REGEX.test(href)) href = base + href;
321
+ let encoded = new URL(href, base);
320
322
  return {
321
323
  pathname: encoded.pathname,
322
324
  search: encoded.search,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -143,12 +143,14 @@ function Links({ nonce, crossOrigin }) {
143
143
  return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, typeof criticalCss === "string" ? /* @__PURE__ */ React$1.createElement("style", {
144
144
  [CRITICAL_CSS_DATA_ATTRIBUTE]: "",
145
145
  nonce,
146
+ suppressHydrationWarning: true,
146
147
  dangerouslySetInnerHTML: { __html: criticalCss }
147
148
  }) : null, typeof criticalCss === "object" ? /* @__PURE__ */ React$1.createElement("link", {
148
149
  [CRITICAL_CSS_DATA_ATTRIBUTE]: "",
149
150
  rel: "stylesheet",
150
151
  href: criticalCss.href,
151
152
  nonce,
153
+ suppressHydrationWarning: true,
152
154
  crossOrigin
153
155
  }) : null, keyedLinks.map(({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React$1.createElement(PrefetchPageLinks, {
154
156
  key,
@@ -158,6 +160,7 @@ function Links({ nonce, crossOrigin }) {
158
160
  }) : /* @__PURE__ */ React$1.createElement("link", {
159
161
  key,
160
162
  nonce,
163
+ suppressHydrationWarning: true,
161
164
  ...link,
162
165
  crossOrigin: link.crossOrigin ?? crossOrigin
163
166
  })));
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -49,6 +49,7 @@ function RemixRootDefaultErrorBoundary({ error, isOutsideRemixApp }) {
49
49
  console.error(error);
50
50
  let heyDeveloper = /* @__PURE__ */ React$1.createElement("script", {
51
51
  nonce,
52
+ suppressHydrationWarning: true,
52
53
  dangerouslySetInnerHTML: { __html: `
53
54
  console.log(
54
55
  "💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -19,6 +19,7 @@ function RemixRootDefaultHydrateFallback() {
19
19
  renderScripts: true
20
20
  }, /* @__PURE__ */ React$1.createElement("script", {
21
21
  nonce,
22
+ suppressHydrationWarning: true,
22
23
  dangerouslySetInnerHTML: { __html: `
23
24
  console.log(
24
25
  "💿 Hey developer 👋. You can provide a way better UX than this " +
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -22,6 +22,7 @@ declare function getHydrationData({
22
22
  routes: DataRouteObject[];
23
23
  getRouteInfo: (routeId: string) => {
24
24
  clientLoader: ClientLoaderFunction | undefined;
25
+ clientMiddleware?: DataRouteObject["middleware"];
25
26
  hasLoader: boolean;
26
27
  hasHydrateFallback: boolean;
27
28
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *