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
@@ -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
  *
@@ -69,6 +69,7 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
69
69
  id: route.id,
70
70
  path: route.path,
71
71
  index: route.index,
72
+ caseSensitive: route.caseSensitive,
72
73
  Component: route.Component ? withComponentProps(route.Component) : void 0,
73
74
  HydrateFallback: route.HydrateFallback ? withHydrateFallbackProps(route.HydrateFallback) : void 0,
74
75
  ErrorBoundary: route.ErrorBoundary ? withErrorBoundaryProps(route.ErrorBoundary) : void 0,
@@ -91,6 +92,7 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
91
92
  id: route.id,
92
93
  path: route.path,
93
94
  index: route.index,
95
+ caseSensitive: route.caseSensitive,
94
96
  parentId,
95
97
  hasAction: route.action != null,
96
98
  hasLoader: route.loader != null,
@@ -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
  *
@@ -114,6 +114,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
114
114
  }
115
115
  }
116
116
  let dataRoute = {
117
+ caseSensitive: route.caseSensitive,
117
118
  id: route.id,
118
119
  index: route.index,
119
120
  path: route.path
@@ -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
  *
@@ -15,7 +15,7 @@ interface HydratedRouterProps {
15
15
  * Context factory function to be passed through to {@link createBrowserRouter}.
16
16
  * This function will be called to create a fresh `context` instance on each
17
17
  * navigation/fetch and made available to
18
- * [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
18
+ * [`clientAction`](../../start/framework/route-module#clientaction)/[`clientLoader`](../../start/framework/route-module#clientloader)
19
19
  * functions.
20
20
  */
21
21
  getContext?: RouterInit["getContext"];
@@ -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
  *
@@ -126,7 +126,9 @@ function HydratedRouter(props) {
126
126
  }
127
127
  let [criticalCss, setCriticalCss] = React$1.useState(process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0);
128
128
  React$1.useEffect(() => {
129
- if (process.env.NODE_ENV === "development") setCriticalCss(void 0);
129
+ if (process.env.NODE_ENV === "development") React$1.startTransition(() => {
130
+ setCriticalCss(void 0);
131
+ });
130
132
  }, []);
131
133
  React$1.useEffect(() => {
132
134
  if (process.env.NODE_ENV === "development" && criticalCss === void 0) document.querySelectorAll(`[${CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
@@ -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
  *
@@ -884,6 +884,36 @@ type UseRoute<RouteId extends keyof RouteModules | unknown> = {
884
884
  loaderData: RouteId extends keyof RouteModules ? GetLoaderData<RouteModules[RouteId]> | undefined : unknown;
885
885
  actionData: RouteId extends keyof RouteModules ? GetActionData<RouteModules[RouteId]> | undefined : unknown;
886
886
  };
887
+ /**
888
+ * Returns the current route's `handle`, `loaderData`, and `actionData`, or
889
+ * those of a matched route identified by `routeId`.
890
+ *
891
+ * Omit `routeId` to read the current route. Pass a route ID to infer the
892
+ * fields from registered route module types. Without an ID, the fields
893
+ * are typed as `unknown`.
894
+ *
895
+ * @example
896
+ * import { unstable_useRoute as useRoute } from "react-router";
897
+ *
898
+ * let currentRoute = useRoute();
899
+ * let rootRoute = useRoute("root");
900
+ *
901
+ * // A registered non-root route may not currently be matched:
902
+ * let dashboard = useRoute("routes/dashboard");
903
+ * if (dashboard) {
904
+ * console.log(dashboard.handle, dashboard.loaderData);
905
+ * }
906
+ *
907
+ * @name unstable_useRoute
908
+ * @public
909
+ * @category Hooks
910
+ * @mode framework
911
+ * @mode data
912
+ * @param args An optional route ID. Omit it to read the current route.
913
+ * @returns An object with the route's `handle`, `loaderData`, and
914
+ * `actionData`, or `undefined` if the specified route is not matched.
915
+ * Individual fields can be `undefined` when the handle or data is unavailable.
916
+ */
887
917
  declare function useRoute<Args extends UseRouteArgs>(...args: Args): UseRouteResult<Args>;
888
918
  /**
889
919
  * A single route match returned from {@link unstable_useRouterState}. Mirrors
@@ -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,10 +9,10 @@
9
9
  * @license MIT
10
10
  */
11
11
  import { createPath, invariant, parsePath, warning } from "./router/history.js";
12
- import { convertRouteMatchToUiMatch, decodePath, getResolveToMatches, getRoutePattern, isBrowser, isRouteErrorResponse, joinPaths, matchPath, matchRoutes, parseToInfo, resolveTo, stripBasename } from "./router/utils.js";
13
12
  import { getNavigatorCurrentUrl, validateNavigationTarget } from "./router/navigation.js";
13
+ import { convertRouteMatchToUiMatch, decodePath, getResolveToMatches, getRoutePattern, isBrowser, isRouteErrorResponse, joinPaths, matchPath, matchRoutes, parseToInfo, resolveTo, stripBasename } from "./router/utils.js";
14
14
  import { IDLE_BLOCKER, hasInvalidProtocol } from "./router/router.js";
15
- import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
15
+ import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCErrorAlreadyReportedContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
16
16
  import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "./errors.js";
17
17
  import * as React$1 from "react";
18
18
  //#region lib/hooks.tsx
@@ -626,6 +626,7 @@ function useRoutesImpl(routes, locationArg, dataRouterOpts) {
626
626
  }
627
627
  function DefaultErrorComponent() {
628
628
  let error = useRouteError();
629
+ let alreadyReported = React$1.useContext(RSCErrorAlreadyReportedContext);
629
630
  let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
630
631
  let stack = error instanceof Error ? error.stack : null;
631
632
  let lightgrey = "rgba(200,200,200, 0.5)";
@@ -638,7 +639,7 @@ function DefaultErrorComponent() {
638
639
  backgroundColor: lightgrey
639
640
  };
640
641
  let devInfo = null;
641
- console.error("Error handled by React Router default ErrorBoundary:", error);
642
+ if (!alreadyReported) console.error("Error handled by React Router default ErrorBoundary:", error);
642
643
  devInfo = /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ React$1.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React$1.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React$1.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
643
644
  return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React$1.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React$1.createElement("pre", { style: preStyles }, stack) : null, devInfo);
644
645
  }
@@ -1269,13 +1270,21 @@ function useBlocker(shouldBlock) {
1269
1270
  historyAction
1270
1271
  });
1271
1272
  }, [basename, shouldBlock]);
1273
+ let activeBlockerKey = React$1.useRef("");
1274
+ let activeBlockerRouter = React$1.useRef(null);
1272
1275
  React$1.useEffect(() => {
1273
1276
  let key = String(++blockerId);
1277
+ activeBlockerKey.current = key;
1278
+ activeBlockerRouter.current = router;
1274
1279
  setBlockerKey(key);
1275
- return () => router.deleteBlocker(key);
1280
+ return () => {
1281
+ activeBlockerKey.current = "";
1282
+ activeBlockerRouter.current = null;
1283
+ router.deleteBlocker(key);
1284
+ };
1276
1285
  }, [router]);
1277
- React$1.useEffect(() => {
1278
- if (blockerKey !== "") router.getBlocker(blockerKey, blockerFunction);
1286
+ React$1.useLayoutEffect(() => {
1287
+ if (blockerKey !== "" && blockerKey === activeBlockerKey.current && router === activeBlockerRouter.current) router.getBlocker(blockerKey, blockerFunction);
1279
1288
  }, [
1280
1289
  router,
1281
1290
  blockerKey,
@@ -1307,6 +1316,36 @@ function warningOnce(key, cond, message) {
1307
1316
  warning(false, message);
1308
1317
  }
1309
1318
  }
1319
+ /**
1320
+ * Returns the current route's `handle`, `loaderData`, and `actionData`, or
1321
+ * those of a matched route identified by `routeId`.
1322
+ *
1323
+ * Omit `routeId` to read the current route. Pass a route ID to infer the
1324
+ * fields from registered route module types. Without an ID, the fields
1325
+ * are typed as `unknown`.
1326
+ *
1327
+ * @example
1328
+ * import { unstable_useRoute as useRoute } from "react-router";
1329
+ *
1330
+ * let currentRoute = useRoute();
1331
+ * let rootRoute = useRoute("root");
1332
+ *
1333
+ * // A registered non-root route may not currently be matched:
1334
+ * let dashboard = useRoute("routes/dashboard");
1335
+ * if (dashboard) {
1336
+ * console.log(dashboard.handle, dashboard.loaderData);
1337
+ * }
1338
+ *
1339
+ * @name unstable_useRoute
1340
+ * @public
1341
+ * @category Hooks
1342
+ * @mode framework
1343
+ * @mode data
1344
+ * @param args An optional route ID. Omit it to read the current route.
1345
+ * @returns An object with the route's `handle`, `loaderData`, and
1346
+ * `actionData`, or `undefined` if the specified route is not matched.
1347
+ * Individual fields can be `undefined` when the handle or data is unavailable.
1348
+ */
1310
1349
  function useRoute(...args) {
1311
1350
  const currentRouteId = useCurrentRouteId("useRoute");
1312
1351
  const id = args[0] ?? currentRouteId;
@@ -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
  *
@@ -44,14 +44,14 @@ function href(path, ...args) {
44
44
  let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
45
45
  const isRequired = questionMark === void 0;
46
46
  const value = params?.[param];
47
- if (isRequired && value === void 0) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
47
+ if (isRequired && value == null) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
48
48
  return value == null ? "" : "/" + encodePathParam(stringify(value));
49
49
  });
50
50
  if (path.endsWith("*")) {
51
51
  const value = params?.["*"];
52
- if (value !== void 0) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
52
+ if (value != null) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
53
53
  }
54
- return result || "/";
54
+ return result.replace(/^\/{2,}/, "/") || "/";
55
55
  }
56
56
  /**
57
57
  * Removes a trailing splat and any number of slashes from the end of the path.
@@ -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
  *
@@ -111,11 +111,12 @@ function createMemoryHistory(options = {}) {
111
111
  action = "POP";
112
112
  let nextIndex = clampIndex(index + delta);
113
113
  let nextLocation = entries[nextIndex];
114
+ let actualDelta = nextIndex - index;
114
115
  index = nextIndex;
115
116
  if (listener) listener({
116
117
  action,
117
118
  location: nextLocation,
118
- delta
119
+ delta: actualDelta
119
120
  });
120
121
  },
121
122
  listen(fn) {
@@ -164,11 +165,16 @@ function createHashHistory(options = {}) {
164
165
  function createHashLocation(window, globalHistory) {
165
166
  let { pathname = "/", search = "", hash = "" } = parsePath(window.location.hash.substring(1));
166
167
  if (!pathname.startsWith("/") && !pathname.startsWith(".")) pathname = "/" + pathname;
167
- return createLocation("", {
168
+ let maskedLocation = globalHistory.state?.masked;
169
+ return createLocation("", maskedLocation || {
168
170
  pathname,
169
171
  search,
170
172
  hash
171
- }, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default");
173
+ }, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default", maskedLocation ? {
174
+ pathname,
175
+ search,
176
+ hash
177
+ } : void 0);
172
178
  }
173
179
  function createHashHref(window, to) {
174
180
  let base = window.document.querySelector("base");
@@ -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
  *
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
+ import { ABSOLUTE_URL_REGEX } from "./url.js";
11
12
  //#region lib/router/navigation.ts
12
13
  const DEFAULT_NAVIGATION_URL = new URL("http://localhost");
13
14
  function getNavigatorCurrentUrl(navigator) {
@@ -27,6 +28,20 @@ function isExplicitUrl(destination, target) {
27
28
  if (!destination.toLowerCase().startsWith(protocol)) return false;
28
29
  return target.host === "" || destination.slice(protocol.length).startsWith("//");
29
30
  }
31
+ function validateDocumentNavigationTarget(destination) {
32
+ let normalized = destination.replace(/[\t\n\r]/g, "");
33
+ let start = 0;
34
+ while (normalized.charCodeAt(start) <= 32) start++;
35
+ normalized = normalized.slice(start);
36
+ if (!ABSOLUTE_URL_REGEX.test(normalized)) return;
37
+ let target;
38
+ try {
39
+ target = new URL(destination, DEFAULT_NAVIGATION_URL);
40
+ } catch {
41
+ return;
42
+ }
43
+ if (!isExplicitUrl(destination, target)) throw new Error("External navigation is not allowed");
44
+ }
30
45
  function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
31
46
  let originalUrl = null;
32
47
  try {
@@ -42,4 +57,4 @@ function validateNavigationTarget(original, resolved, currentUrl, externalPolicy
42
57
  }
43
58
  }
44
59
  //#endregion
45
- export { getNavigatorCurrentUrl, validateNavigationTarget };
60
+ export { getNavigatorCurrentUrl, validateDocumentNavigationTarget, validateNavigationTarget };
@@ -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,11 +10,11 @@
10
10
  */
11
11
  import { PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
12
12
  import { createBrowserURLImpl, createLocation, createPath, invariant, parsePath, warning } from "./history.js";
13
+ import { validateNavigationTarget } from "./navigation.js";
13
14
  import { DiscoveryCancelledError, ErrorResponseImpl, RouterContextProvider, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createDataFunctionUrl, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, prependBasename, removeDoubleSlashes, resolveTo, stripBasename } from "./utils.js";
14
15
  import { consumeInstrumentationClientResultMetaReceiver, getRouteInstrumentationUpdates, instrumentClientSideRouter } from "./instrumentation.js";
15
16
  import { V6RegExMatcher } from "./matcher.js";
16
17
  import { getRoutePatternMatcher } from "./matcher-route-pattern.preload.js";
17
- import { validateNavigationTarget } from "./navigation.js";
18
18
  //#region lib/router/router.ts
19
19
  const validMutationMethodsArr = [
20
20
  "POST",
@@ -213,6 +213,7 @@ function createRouter(init) {
213
213
  blockers: /* @__PURE__ */ new Map()
214
214
  };
215
215
  let pendingAction = "POP";
216
+ let pendingActionData;
216
217
  let pendingPopstateDelta = 0;
217
218
  let pendingDiscoveryCancellation;
218
219
  let pendingPopstateNavigationDfd = null;
@@ -227,6 +228,7 @@ function createRouter(init) {
227
228
  let fetchControllers = /* @__PURE__ */ new Map();
228
229
  let incrementingLoadId = 0;
229
230
  let pendingNavigationLoadId = -1;
231
+ let pendingNavigationDiscoverySignal = null;
230
232
  let fetchReloadIds = /* @__PURE__ */ new Map();
231
233
  let fetchRedirectIds = /* @__PURE__ */ new Set();
232
234
  let fetchLoadMatches = /* @__PURE__ */ new Map();
@@ -340,10 +342,10 @@ function createRouter(init) {
340
342
  }
341
343
  function completeNavigation(location, newState, { flushSync } = {}) {
342
344
  let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && location.state?._isRedirect !== true;
345
+ let actionDataForCommit = newState.actionData || (isActionReload ? pendingActionData : void 0);
343
346
  let actionData;
344
- if (newState.actionData) if (Object.keys(newState.actionData).length > 0) actionData = newState.actionData;
347
+ if (actionDataForCommit) if (Object.keys(actionDataForCommit).length > 0) actionData = actionDataForCommit;
345
348
  else actionData = null;
346
- else if (isActionReload) actionData = state.actionData;
347
349
  else actionData = null;
348
350
  let loaderData = newState.loaderData ? mergeLoaderData(state.loaderData, newState.loaderData, newState.matches || [], newState.errors) : state.loaderData;
349
351
  let blockers = state.blockers;
@@ -405,6 +407,7 @@ function createRouter(init) {
405
407
  function resetPendingNavigation() {
406
408
  pendingPopstateDelta = 0;
407
409
  pendingAction = "POP";
410
+ pendingActionData = void 0;
408
411
  pendingPreventScrollReset = false;
409
412
  pendingViewTransitionEnabled = false;
410
413
  isUninterruptedRevalidation = false;
@@ -514,6 +517,7 @@ function createRouter(init) {
514
517
  pendingNavigationController && pendingNavigationController.abort();
515
518
  pendingNavigationController = null;
516
519
  pendingAction = historyAction;
520
+ if (!opts?.overrideNavigation) pendingActionData = void 0;
517
521
  isUninterruptedRevalidation = (opts && opts.startUninterruptedRevalidation) === true;
518
522
  saveScrollPosition(state.location, state.matches);
519
523
  pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
@@ -573,11 +577,13 @@ function createRouter(init) {
573
577
  }
574
578
  matches = actionResult.matches || matches;
575
579
  pendingActionResult = actionResult.pendingActionResult;
580
+ historyAction = pendingAction;
576
581
  loadingNavigation = getLoadingNavigation(location, matches, historyAction, opts.submission);
577
582
  flushSync = false;
578
583
  fogOfWar.active = false;
579
584
  request = createClientSideRequest(init.history, request.url, request.signal);
580
585
  }
586
+ if (pendingActionResult) pendingActionData = getActionDataForCommit(pendingActionResult).actionData;
581
587
  let { shortCircuited, matches: updatedMatches, loaderData, errors, workingFetchers } = await handleLoaders(request, dataStrategyInitiator, location, matches, historyAction, scopedContext, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult, opts && opts.callSiteDefaultShouldRevalidate);
582
588
  if (shortCircuited) return;
583
589
  pendingNavigationController = null;
@@ -723,6 +729,7 @@ function createRouter(init) {
723
729
  let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
724
730
  let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
725
731
  if (isFogOfWar) {
732
+ pendingNavigationDiscoverySignal = request.signal;
726
733
  if (shouldUpdateNavigationState) {
727
734
  let actionData = getUpdatedActionData(pendingActionResult);
728
735
  updateState({
@@ -731,6 +738,7 @@ function createRouter(init) {
731
738
  }, { flushSync });
732
739
  }
733
740
  let discoverResult = await discoverRoutes(matches, location.pathname, request.signal);
741
+ if (pendingNavigationDiscoverySignal === request.signal) pendingNavigationDiscoverySignal = null;
734
742
  if (future.unstable_customRouteDiscovery && request.signal.aborted || discoverResult.type === "aborted") return { shortCircuited: true };
735
743
  else if (discoverResult.type === "cancelled") {
736
744
  await cancelDiscoveryNavigation();
@@ -832,7 +840,10 @@ function createRouter(init) {
832
840
  };
833
841
  }
834
842
  function getUpdatedActionData(pendingActionResult) {
835
- if (pendingActionResult && !isErrorResult(pendingActionResult[1])) return { [pendingActionResult[0]]: pendingActionResult[1].data };
843
+ if (pendingActionResult && !isErrorResult(pendingActionResult[1])) return {
844
+ ...state.actionData,
845
+ [pendingActionResult[0]]: pendingActionResult[1].data
846
+ };
836
847
  else if (state.actionData) if (Object.keys(state.actionData).length === 0) return null;
837
848
  else return state.actionData;
838
849
  }
@@ -851,6 +862,7 @@ function createRouter(init) {
851
862
  let flushSync = (opts && opts.flushSync) === true;
852
863
  let instrumentationResultMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
853
864
  let normalizedPath = normalizeTo(state.location, state.matches, basename, href, routeId, opts?.relative);
865
+ validateNavigationTarget(null, normalizedPath, init.history.createURL("/"), "reject");
854
866
  let matches = dataRouteMatcher.match(normalizedPath);
855
867
  let fogOfWar = checkFogOfWar(matches, normalizedPath);
856
868
  if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
@@ -878,6 +890,9 @@ function createRouter(init) {
878
890
  fetchLoadMatches.set(key, loadMatch);
879
891
  await handleFetcherLoader(key, loadMatch, matches, scopedContext, flushSync, preventScrollReset, submission);
880
892
  }
893
+ function isNavigationAwaitingDiscovery() {
894
+ return pendingNavigationDiscoverySignal?.aborted === false;
895
+ }
881
896
  async function handleFetcherAction(key, routeId, path, requestMatches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission, callSiteDefaultShouldRevalidate) {
882
897
  if (!future.unstable_customRouteDiscovery) interruptActiveLoads();
883
898
  fetchLoadMatches.delete(key);
@@ -961,9 +976,10 @@ function createRouter(init) {
961
976
  }
962
977
  }
963
978
  isRevalidationRequired = true;
964
- let nextLocation = state.navigation.location || state.location;
979
+ let revalidationLocation = !isNavigationAwaitingDiscovery() ? state.navigation.location : void 0;
980
+ let nextLocation = revalidationLocation || state.location;
965
981
  let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal);
966
- let matches = state.navigation.state !== "idle" ? dataRouteMatcher.match(state.navigation.location) : state.matches;
982
+ let matches = revalidationLocation ? dataRouteMatcher.match(revalidationLocation) : state.matches;
967
983
  invariant(matches, "Didn't find any matches after fetcher action");
968
984
  let loadId = ++incrementingLoadId;
969
985
  fetchReloadIds.set(key, loadId);
@@ -1020,7 +1036,7 @@ function createRouter(init) {
1020
1036
  if (fetcherIsMounted) finalFetchers.set(key, getDoneFetcher(actionResult.data));
1021
1037
  let { loaderData, errors } = processLoaderData(state, matches, loaderResults, void 0, revalidatingFetchers, fetcherResults, finalFetchers);
1022
1038
  abortStaleFetchLoads(loadId, finalFetchers);
1023
- if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
1039
+ if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId && !isNavigationAwaitingDiscovery()) {
1024
1040
  invariant(pendingAction, "Expected pending action");
1025
1041
  pendingNavigationController && pendingNavigationController.abort();
1026
1042
  markFetchRedirectsDone(finalFetchers);
@@ -1033,7 +1049,7 @@ function createRouter(init) {
1033
1049
  } else {
1034
1050
  updateState({
1035
1051
  errors,
1036
- loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
1052
+ loaderData: mergeLoaderData(state.loaderData, loaderData, state.matches, errors),
1037
1053
  fetchers: finalFetchers
1038
1054
  });
1039
1055
  isRevalidationRequired = fetchReloadIds.size > 0;
@@ -2709,6 +2725,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
2709
2725
  function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
2710
2726
  let location = response.headers.get("Location");
2711
2727
  invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
2728
+ validateNavigationTarget(location, location, new URL(request.url), "allow-explicit");
2712
2729
  if (!isAbsoluteUrl(location)) {
2713
2730
  let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
2714
2731
  location = normalizeTo(new URL(request.url), trimmedMatches, basename, location);
@@ -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
  *
@@ -512,7 +512,7 @@ type BaseRouteObject = {
512
512
  action?: ActionFunction | boolean;
513
513
  /**
514
514
  * The route shouldRevalidate function.
515
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
515
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
516
516
  */
517
517
  shouldRevalidate?: ShouldRevalidateFunction;
518
518
  /**
@@ -718,13 +718,14 @@ interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
718
718
  /**
719
719
  * Returns a path with params interpolated.
720
720
  *
721
- * Param values are percent-encoded for use in a path segment: characters that
722
- * would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
721
+ * Named param values are percent-encoded for use in a path segment: characters
722
+ * that would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
723
723
  * are escaped, while characters that RFC 3986 allows literally in a path
724
724
  * segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
725
725
  * encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
726
- * delimiters and must be escaped. Splat (`*`) values are encoded per segment,
727
- * preserving `/` separators.
726
+ * delimiters and must be escaped. Splat (`*`) values are interpolated without
727
+ * per-segment encoding. Leading URL separators and schemes are handled so
728
+ * interpolated values remain paths.
728
729
  *
729
730
  * See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
730
731
  *
@@ -787,6 +788,8 @@ interface PathMatch<ParamKey extends string = string> {
787
788
  * Performs pattern matching on a URL pathname and returns information about
788
789
  * the match.
789
790
  *
791
+ * Throws if the pattern contains more than 12 optional (`?`) markers.
792
+ *
790
793
  * @public
791
794
  * @category Utils
792
795
  * @param pattern The pattern to match against the URL pathname. This can be a