react-router 8.5.1 → 8.5.2

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 (161) hide show
  1. package/CHANGELOG.md +29 -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 +43 -37
  5. package/dist/development/index-react-server.js +64 -6
  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 +25 -29
  11. package/dist/development/lib/context.js +1 -1
  12. package/dist/development/lib/dom/dom.js +13 -4
  13. package/dist/development/lib/dom/lib.d.ts +2 -2
  14. package/dist/development/lib/dom/lib.js +11 -4
  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 +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 +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.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.js +9 -4
  37. package/dist/development/lib/href.js +4 -4
  38. package/dist/development/lib/router/history.js +1 -1
  39. package/dist/development/lib/router/instrumentation.js +1 -1
  40. package/dist/development/lib/router/matcher-route-pattern.js +1 -1
  41. package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
  42. package/dist/development/lib/router/matcher.js +1 -1
  43. package/dist/development/lib/router/navigation.js +17 -2
  44. package/dist/development/lib/router/router.js +5 -2
  45. package/dist/development/lib/router/url.js +1 -1
  46. package/dist/development/lib/router/utils.d.ts +6 -5
  47. package/dist/development/lib/router/utils.js +17 -8
  48. package/dist/development/lib/rsc/browser.js +26 -3
  49. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  50. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  51. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  52. package/dist/development/lib/rsc/route-modules.js +1 -1
  53. package/dist/development/lib/rsc/server.rsc.d.ts +2 -0
  54. package/dist/development/lib/rsc/server.ssr.js +1 -1
  55. package/dist/development/lib/server-runtime/cookies.js +1 -1
  56. package/dist/development/lib/server-runtime/crypto.js +1 -1
  57. package/dist/development/lib/server-runtime/data.js +1 -1
  58. package/dist/development/lib/server-runtime/dev.js +1 -1
  59. package/dist/development/lib/server-runtime/entry.js +1 -1
  60. package/dist/development/lib/server-runtime/errors.js +1 -1
  61. package/dist/development/lib/server-runtime/headers.js +1 -1
  62. package/dist/development/lib/server-runtime/invariant.js +1 -1
  63. package/dist/development/lib/server-runtime/mode.js +1 -1
  64. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  65. package/dist/development/lib/server-runtime/routes.js +1 -1
  66. package/dist/development/lib/server-runtime/server.js +9 -6
  67. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  68. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  69. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  70. package/dist/development/lib/server-runtime/sessions.js +1 -1
  71. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  72. package/dist/development/lib/server-runtime/urls.js +1 -1
  73. package/dist/development/lib/server-runtime/warnings.js +1 -1
  74. package/dist/development/lib/types/internal.js +1 -1
  75. package/dist/development/lib/types/route-module-annotations.d.ts +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 +75 -66
  79. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  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 +43 -37
  84. package/dist/production/index-react-server.js +64 -6
  85. package/dist/production/index.js +1 -1
  86. package/dist/production/lib/actions.js +1 -1
  87. package/dist/production/lib/await.js +1 -1
  88. package/dist/production/lib/components.d.ts +42 -38
  89. package/dist/production/lib/components.js +25 -29
  90. package/dist/production/lib/context.js +1 -1
  91. package/dist/production/lib/dom/dom.js +13 -4
  92. package/dist/production/lib/dom/lib.d.ts +2 -2
  93. package/dist/production/lib/dom/lib.js +11 -4
  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 +1 -1
  100. package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
  101. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  102. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  103. package/dist/production/lib/dom/ssr/links.js +1 -1
  104. package/dist/production/lib/dom/ssr/markup.js +1 -1
  105. package/dist/production/lib/dom/ssr/route-discovery.js +1 -1
  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.js +1 -1
  111. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  112. package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
  113. package/dist/production/lib/dom-export/hydrated-router.js +4 -2
  114. package/dist/production/lib/errors.js +1 -1
  115. package/dist/production/lib/hooks.js +9 -4
  116. package/dist/production/lib/href.js +4 -4
  117. package/dist/production/lib/router/history.js +1 -1
  118. package/dist/production/lib/router/instrumentation.js +1 -1
  119. package/dist/production/lib/router/matcher-route-pattern.js +1 -1
  120. package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
  121. package/dist/production/lib/router/matcher.js +1 -1
  122. package/dist/production/lib/router/navigation.js +17 -2
  123. package/dist/production/lib/router/router.js +5 -2
  124. package/dist/production/lib/router/url.js +1 -1
  125. package/dist/production/lib/router/utils.d.ts +6 -5
  126. package/dist/production/lib/router/utils.js +17 -8
  127. package/dist/production/lib/rsc/browser.js +26 -3
  128. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  129. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  130. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  131. package/dist/production/lib/rsc/route-modules.js +1 -1
  132. package/dist/production/lib/rsc/server.rsc.d.ts +2 -0
  133. package/dist/production/lib/rsc/server.ssr.js +1 -1
  134. package/dist/production/lib/server-runtime/cookies.js +1 -1
  135. package/dist/production/lib/server-runtime/crypto.js +1 -1
  136. package/dist/production/lib/server-runtime/data.js +1 -1
  137. package/dist/production/lib/server-runtime/dev.js +1 -1
  138. package/dist/production/lib/server-runtime/entry.js +1 -1
  139. package/dist/production/lib/server-runtime/errors.js +1 -1
  140. package/dist/production/lib/server-runtime/headers.js +1 -1
  141. package/dist/production/lib/server-runtime/invariant.js +1 -1
  142. package/dist/production/lib/server-runtime/mode.js +1 -1
  143. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  144. package/dist/production/lib/server-runtime/routes.js +1 -1
  145. package/dist/production/lib/server-runtime/server.js +9 -6
  146. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  147. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  148. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  149. package/dist/production/lib/server-runtime/sessions.js +1 -1
  150. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  151. package/dist/production/lib/server-runtime/urls.js +1 -1
  152. package/dist/production/lib/server-runtime/warnings.js +1 -1
  153. package/dist/production/lib/types/internal.js +1 -1
  154. package/dist/production/lib/types/route-module-annotations.d.ts +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 +75 -66
  158. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  159. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  160. package/docs/upgrading/v7.md +11 -0
  161. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.2
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) {
@@ -92,6 +92,15 @@ function getFormEncType(encType) {
92
92
  }
93
93
  return encType;
94
94
  }
95
+ function stripBasenameFromAction(action, basename) {
96
+ if (basename === "/") return action;
97
+ let path = parsePath(action);
98
+ let pathname = stripBasename(path.pathname || "", basename);
99
+ return pathname == null ? null : createPath({
100
+ ...path,
101
+ pathname
102
+ });
103
+ }
95
104
  function getFormSubmissionInfo(target, basename) {
96
105
  let method;
97
106
  let action;
@@ -100,7 +109,7 @@ function getFormSubmissionInfo(target, basename) {
100
109
  let body;
101
110
  if (isFormElement(target)) {
102
111
  let attr = target.getAttribute("action");
103
- action = attr ? stripBasename(attr, basename) : null;
112
+ action = attr ? stripBasenameFromAction(attr, basename) : null;
104
113
  method = target.getAttribute("method") || "get";
105
114
  encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
106
115
  formData = new FormData(target);
@@ -108,7 +117,7 @@ function getFormSubmissionInfo(target, basename) {
108
117
  let form = target.form;
109
118
  if (form == null) throw new Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);
110
119
  let attr = target.getAttribute("formaction") || form.getAttribute("action");
111
- action = attr ? stripBasename(attr, basename) : null;
120
+ action = attr ? stripBasenameFromAction(attr, basename) : null;
112
121
  method = target.getAttribute("formmethod") || form.getAttribute("method") || "get";
113
122
  encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
114
123
  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.2
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,
@@ -562,7 +565,9 @@ function ScrollRestoration({ getKey, storageKey, ...props }) {
562
565
  if (typeof storedY === "number") window.scrollTo(0, storedY);
563
566
  } catch (error) {
564
567
  console.error(error);
565
- sessionStorage.removeItem(storageKey);
568
+ try {
569
+ sessionStorage.removeItem(storageKey);
570
+ } catch {}
566
571
  }
567
572
  }).toString();
568
573
  if (props.nonce == null && remixContext?.nonce) props.nonce = remixContext.nonce;
@@ -872,7 +877,9 @@ function useFormAction(action, { relative } = {}) {
872
877
  }
873
878
  if ((!action || action === ".") && match.route.index) path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
874
879
  if (basename !== "/") path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
875
- return createPath(path);
880
+ let formAction = createPath(path);
881
+ validateDocumentNavigationTarget(formAction);
882
+ return formAction;
876
883
  }
877
884
  /**
878
885
  * Useful for creating complex, dynamic user interfaces that require multiple,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,8 +9,8 @@
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
15
  import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
16
16
  import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "./errors.js";
@@ -1269,13 +1269,18 @@ function useBlocker(shouldBlock) {
1269
1269
  historyAction
1270
1270
  });
1271
1271
  }, [basename, shouldBlock]);
1272
+ let activeBlockerKey = React$1.useRef("");
1272
1273
  React$1.useEffect(() => {
1273
1274
  let key = String(++blockerId);
1275
+ activeBlockerKey.current = key;
1274
1276
  setBlockerKey(key);
1275
- return () => router.deleteBlocker(key);
1277
+ return () => {
1278
+ activeBlockerKey.current = "";
1279
+ router.deleteBlocker(key);
1280
+ };
1276
1281
  }, [router]);
1277
1282
  React$1.useEffect(() => {
1278
- if (blockerKey !== "") router.getBlocker(blockerKey, blockerFunction);
1283
+ if (blockerKey !== "" && blockerKey === activeBlockerKey.current) router.getBlocker(blockerKey, blockerFunction);
1279
1284
  }, [
1280
1285
  router,
1281
1286
  blockerKey,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.2
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.2
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.2
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.2
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.2
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.2
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.2
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.2
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",
@@ -573,6 +573,7 @@ function createRouter(init) {
573
573
  }
574
574
  matches = actionResult.matches || matches;
575
575
  pendingActionResult = actionResult.pendingActionResult;
576
+ historyAction = pendingAction;
576
577
  loadingNavigation = getLoadingNavigation(location, matches, historyAction, opts.submission);
577
578
  flushSync = false;
578
579
  fogOfWar.active = false;
@@ -851,6 +852,7 @@ function createRouter(init) {
851
852
  let flushSync = (opts && opts.flushSync) === true;
852
853
  let instrumentationResultMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
853
854
  let normalizedPath = normalizeTo(state.location, state.matches, basename, href, routeId, opts?.relative);
855
+ validateNavigationTarget(null, normalizedPath, init.history.createURL("/"), "reject");
854
856
  let matches = dataRouteMatcher.match(normalizedPath);
855
857
  let fogOfWar = checkFogOfWar(matches, normalizedPath);
856
858
  if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
@@ -2709,6 +2711,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
2709
2711
  function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
2710
2712
  let location = response.headers.get("Location");
2711
2713
  invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
2714
+ validateNavigationTarget(location, location, new URL(request.url), "allow-explicit");
2712
2715
  if (!isAbsoluteUrl(location)) {
2713
2716
  let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
2714
2717
  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.2
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
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { ABSOLUTE_URL_REGEX, PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
12
12
  import { invariant, parsePath, warning } from "./history.js";
13
+ import { validateDocumentNavigationTarget } from "./navigation.js";
13
14
  import * as React$1 from "react";
14
15
  //#region lib/router/utils.ts
15
16
  /**
@@ -422,13 +423,14 @@ function encodePathParam(value) {
422
423
  /**
423
424
  * Returns a path with params interpolated.
424
425
  *
425
- * Param values are percent-encoded for use in a path segment: characters that
426
- * would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
426
+ * Named param values are percent-encoded for use in a path segment: characters
427
+ * that would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
427
428
  * are escaped, while characters that RFC 3986 allows literally in a path
428
429
  * segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
429
430
  * encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
430
- * delimiters and must be escaped. Splat (`*`) values are encoded per segment,
431
- * preserving `/` separators.
431
+ * delimiters and must be escaped. Splat (`*`) values are interpolated without
432
+ * per-segment encoding. Leading URL separators and schemes are handled so
433
+ * interpolated values remain paths.
432
434
  *
433
435
  * See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
434
436
  *
@@ -453,7 +455,7 @@ function generatePath(originalPath, params = {}) {
453
455
  }
454
456
  const prefix = path.startsWith("/") ? "/" : "";
455
457
  const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
456
- return prefix + path.split(/\/+/).map((segment, index, array) => {
458
+ let result = (prefix + path.split(/\/+/).map((segment, index, array) => {
457
459
  if (index === array.length - 1 && segment === "*") return stringify(params["*"]);
458
460
  const keyMatch = segment.match(/^:([\w-]+)(\??)(.*)/);
459
461
  if (keyMatch) {
@@ -463,7 +465,10 @@ function generatePath(originalPath, params = {}) {
463
465
  return encodePathParam(stringify(param)) + suffix;
464
466
  }
465
467
  return segment.replace(/\?$/g, "");
466
- }).filter((segment) => !!segment).join("/");
468
+ }).filter((segment) => !!segment).join("/")).replace(/^[\\/]{2,}/, "/");
469
+ if (!prefix && (path.startsWith(":") || path === "*")) result = result.replace(/^([a-z][a-z0-9+.-]*):/i, "$1%3A");
470
+ validateDocumentNavigationTarget(result);
471
+ return result;
467
472
  }
468
473
  /**
469
474
  * Performs pattern matching on a URL pathname and returns information about
@@ -705,11 +710,15 @@ function data(data, init) {
705
710
  * header.
706
711
  */
707
712
  const redirect = (url, init = 302) => {
713
+ validateDocumentNavigationTarget(url);
708
714
  let responseInit = init;
709
715
  if (typeof responseInit === "number") responseInit = { status: responseInit };
710
- else if (typeof responseInit.status === "undefined") responseInit.status = 302;
711
716
  let headers = new Headers(responseInit.headers);
712
717
  headers.set("Location", url);
718
+ if (typeof responseInit.status === "undefined") responseInit = {
719
+ ...responseInit,
720
+ status: 302
721
+ };
713
722
  return new Response(null, {
714
723
  ...responseInit,
715
724
  headers