react-router 8.5.0 → 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 (214) hide show
  1. package/CHANGELOG.md +70 -1
  2. package/dist/development/dom-export.js +1 -1
  3. package/dist/development/index-react-server-client.js +1 -1
  4. package/dist/development/index-react-server.d.ts +75 -415
  5. package/dist/development/index-react-server.js +106 -20
  6. package/dist/development/index.js +1 -1
  7. package/dist/development/lib/actions.js +1 -1
  8. package/dist/development/lib/await.js +58 -0
  9. package/dist/development/lib/components.d.ts +65 -25
  10. package/dist/development/lib/components.js +69 -15
  11. package/dist/development/lib/context.d.ts +2 -2
  12. package/dist/development/lib/context.js +1 -1
  13. package/dist/development/lib/dom/dom.js +13 -4
  14. package/dist/development/lib/dom/lib.d.ts +2 -2
  15. package/dist/development/lib/dom/lib.js +11 -4
  16. package/dist/development/lib/dom/server.js +1 -1
  17. package/dist/development/lib/dom/ssr/components.js +1 -1
  18. package/dist/development/lib/dom/ssr/data.js +1 -1
  19. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  20. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  21. package/dist/development/lib/dom/ssr/fog-of-war.js +12 -3
  22. package/dist/development/lib/dom/ssr/hydration.d.ts +1 -0
  23. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  24. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  25. package/dist/development/lib/dom/ssr/links.js +1 -1
  26. package/dist/development/lib/dom/ssr/markup.js +1 -1
  27. package/dist/development/lib/dom/ssr/route-discovery.d.ts +2 -2
  28. package/dist/development/lib/dom/ssr/route-discovery.js +3 -3
  29. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  30. package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
  31. package/dist/development/lib/dom/ssr/routes.js +1 -1
  32. package/dist/development/lib/dom/ssr/server.js +1 -1
  33. package/dist/development/lib/dom/ssr/single-fetch.d.ts +1 -1
  34. package/dist/development/lib/dom/ssr/single-fetch.js +7 -7
  35. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  36. package/dist/development/lib/dom-export/hydrated-router.d.ts +1 -1
  37. package/dist/development/lib/dom-export/hydrated-router.js +5 -3
  38. package/dist/development/lib/errors.js +1 -1
  39. package/dist/development/lib/hooks.d.ts +0 -3
  40. package/dist/development/lib/hooks.js +13 -9
  41. package/dist/development/lib/href.js +4 -4
  42. package/dist/development/lib/router/history.js +1 -1
  43. package/dist/development/lib/router/instrumentation.js +1 -1
  44. package/dist/development/lib/router/matcher-route-pattern.js +1 -1
  45. package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
  46. package/dist/development/lib/router/matcher.js +6 -1
  47. package/dist/development/lib/router/navigation.js +17 -2
  48. package/dist/development/lib/router/router.d.ts +2 -0
  49. package/dist/development/lib/router/router.js +62 -29
  50. package/dist/development/lib/router/url.js +1 -1
  51. package/dist/development/lib/router/utils.d.ts +13 -5
  52. package/dist/development/lib/router/utils.js +17 -8
  53. package/dist/development/lib/rsc/browser.js +28 -5
  54. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  55. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  56. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  57. package/dist/development/lib/rsc/route-modules.js +1 -1
  58. package/dist/development/lib/rsc/server.rsc.d.ts +2 -0
  59. package/dist/development/lib/rsc/server.ssr.js +1 -1
  60. package/dist/development/lib/server-runtime/cookies.js +1 -1
  61. package/dist/development/lib/server-runtime/crypto.js +1 -1
  62. package/dist/development/lib/server-runtime/data.js +1 -1
  63. package/dist/development/lib/server-runtime/dev.js +1 -1
  64. package/dist/development/lib/server-runtime/entry.js +1 -1
  65. package/dist/development/lib/server-runtime/errors.js +1 -1
  66. package/dist/development/lib/server-runtime/headers.js +1 -1
  67. package/dist/development/lib/server-runtime/invariant.js +1 -1
  68. package/dist/development/lib/server-runtime/mode.js +1 -1
  69. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  70. package/dist/development/lib/server-runtime/routes.js +1 -1
  71. package/dist/development/lib/server-runtime/server.js +21 -10
  72. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  73. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  74. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  75. package/dist/development/lib/server-runtime/sessions.js +2 -2
  76. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  77. package/dist/development/lib/server-runtime/urls.js +1 -1
  78. package/dist/development/lib/server-runtime/warnings.js +1 -1
  79. package/dist/development/lib/types/internal.js +1 -1
  80. package/dist/development/lib/types/route-module-annotations.d.ts +1 -1
  81. package/dist/development/route-pattern.js +1 -1
  82. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  83. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +75 -66
  84. package/dist/development/vendor/turbo-stream-v2/unflatten.js +23 -3
  85. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  86. package/dist/production/dom-export.js +1 -1
  87. package/dist/production/index-react-server-client.js +1 -1
  88. package/dist/production/index-react-server.d.ts +75 -415
  89. package/dist/production/index-react-server.js +106 -20
  90. package/dist/production/index.js +1 -1
  91. package/dist/production/lib/actions.js +1 -1
  92. package/dist/production/lib/await.js +58 -0
  93. package/dist/production/lib/components.d.ts +65 -25
  94. package/dist/production/lib/components.js +69 -15
  95. package/dist/production/lib/context.d.ts +2 -2
  96. package/dist/production/lib/context.js +1 -1
  97. package/dist/production/lib/dom/dom.js +13 -4
  98. package/dist/production/lib/dom/lib.d.ts +2 -2
  99. package/dist/production/lib/dom/lib.js +11 -4
  100. package/dist/production/lib/dom/server.js +1 -1
  101. package/dist/production/lib/dom/ssr/components.js +1 -1
  102. package/dist/production/lib/dom/ssr/data.js +1 -1
  103. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  104. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  105. package/dist/production/lib/dom/ssr/fog-of-war.js +12 -3
  106. package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
  107. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  108. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  109. package/dist/production/lib/dom/ssr/links.js +1 -1
  110. package/dist/production/lib/dom/ssr/markup.js +1 -1
  111. package/dist/production/lib/dom/ssr/route-discovery.d.ts +2 -2
  112. package/dist/production/lib/dom/ssr/route-discovery.js +3 -3
  113. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  114. package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
  115. package/dist/production/lib/dom/ssr/routes.js +1 -1
  116. package/dist/production/lib/dom/ssr/server.js +1 -1
  117. package/dist/production/lib/dom/ssr/single-fetch.d.ts +1 -1
  118. package/dist/production/lib/dom/ssr/single-fetch.js +7 -7
  119. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  120. package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
  121. package/dist/production/lib/dom-export/hydrated-router.js +5 -3
  122. package/dist/production/lib/errors.js +1 -1
  123. package/dist/production/lib/hooks.d.ts +0 -3
  124. package/dist/production/lib/hooks.js +13 -9
  125. package/dist/production/lib/href.js +4 -4
  126. package/dist/production/lib/router/history.js +1 -1
  127. package/dist/production/lib/router/instrumentation.js +1 -1
  128. package/dist/production/lib/router/matcher-route-pattern.js +1 -1
  129. package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
  130. package/dist/production/lib/router/matcher.js +6 -1
  131. package/dist/production/lib/router/navigation.js +17 -2
  132. package/dist/production/lib/router/router.d.ts +2 -0
  133. package/dist/production/lib/router/router.js +62 -29
  134. package/dist/production/lib/router/url.js +1 -1
  135. package/dist/production/lib/router/utils.d.ts +13 -5
  136. package/dist/production/lib/router/utils.js +17 -8
  137. package/dist/production/lib/rsc/browser.js +28 -5
  138. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  139. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  140. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  141. package/dist/production/lib/rsc/route-modules.js +1 -1
  142. package/dist/production/lib/rsc/server.rsc.d.ts +2 -0
  143. package/dist/production/lib/rsc/server.ssr.js +1 -1
  144. package/dist/production/lib/server-runtime/cookies.js +1 -1
  145. package/dist/production/lib/server-runtime/crypto.js +1 -1
  146. package/dist/production/lib/server-runtime/data.js +1 -1
  147. package/dist/production/lib/server-runtime/dev.js +1 -1
  148. package/dist/production/lib/server-runtime/entry.js +1 -1
  149. package/dist/production/lib/server-runtime/errors.js +1 -1
  150. package/dist/production/lib/server-runtime/headers.js +1 -1
  151. package/dist/production/lib/server-runtime/invariant.js +1 -1
  152. package/dist/production/lib/server-runtime/mode.js +1 -1
  153. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  154. package/dist/production/lib/server-runtime/routes.js +1 -1
  155. package/dist/production/lib/server-runtime/server.js +21 -10
  156. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  157. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  158. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  159. package/dist/production/lib/server-runtime/sessions.js +2 -2
  160. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  161. package/dist/production/lib/server-runtime/urls.js +1 -1
  162. package/dist/production/lib/server-runtime/warnings.js +1 -1
  163. package/dist/production/lib/types/internal.js +1 -1
  164. package/dist/production/lib/types/route-module-annotations.d.ts +1 -1
  165. package/dist/production/route-pattern.js +1 -1
  166. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  167. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +75 -66
  168. package/dist/production/vendor/turbo-stream-v2/unflatten.js +23 -3
  169. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  170. package/docs/explanation/backend-for-frontend.md +0 -3
  171. package/docs/explanation/code-splitting.md +0 -3
  172. package/docs/explanation/concurrency.md +0 -3
  173. package/docs/explanation/hot-module-replacement.md +0 -3
  174. package/docs/explanation/lazy-route-discovery.md +0 -3
  175. package/docs/explanation/progressive-enhancement.md +0 -3
  176. package/docs/explanation/race-conditions.md +0 -3
  177. package/docs/explanation/react-transitions.md +0 -3
  178. package/docs/explanation/sessions-and-cookies.md +1 -1
  179. package/docs/explanation/state-management.md +0 -3
  180. package/docs/explanation/styling.md +0 -3
  181. package/docs/explanation/type-safety.md +0 -3
  182. package/docs/how-to/accessibility.md +0 -6
  183. package/docs/how-to/client-data.md +0 -3
  184. package/docs/how-to/data-strategy.md +0 -3
  185. package/docs/how-to/error-boundary.md +0 -3
  186. package/docs/how-to/error-reporting.md +0 -3
  187. package/docs/how-to/fetchers.md +0 -3
  188. package/docs/how-to/file-route-conventions.md +0 -3
  189. package/docs/how-to/file-uploads.md +0 -3
  190. package/docs/how-to/form-validation.md +0 -3
  191. package/docs/how-to/headers.md +0 -3
  192. package/docs/how-to/instrumentation.md +0 -3
  193. package/docs/how-to/middleware.md +6 -3
  194. package/docs/how-to/navigation-blocking.md +0 -3
  195. package/docs/how-to/optimize-revalidation.md +0 -3
  196. package/docs/how-to/pre-rendering.md +0 -3
  197. package/docs/how-to/presets.md +0 -3
  198. package/docs/how-to/react-server-components.md +0 -3
  199. package/docs/how-to/resource-routes.md +0 -3
  200. package/docs/how-to/route-discovery.md +4 -2
  201. package/docs/how-to/route-module-type-safety.md +0 -3
  202. package/docs/how-to/security.md +0 -3
  203. package/docs/how-to/server-bundles.md +0 -3
  204. package/docs/how-to/spa.md +0 -3
  205. package/docs/how-to/status.md +0 -3
  206. package/docs/how-to/suspense.md +22 -6
  207. package/docs/how-to/using-handle.md +0 -3
  208. package/docs/how-to/view-transitions.md +0 -3
  209. package/docs/start/framework/data-loading.md +9 -0
  210. package/docs/upgrading/future.md +0 -12
  211. package/docs/upgrading/v7.md +14 -33
  212. package/package.json +1 -1
  213. package/dist/development/lib/dom/global.d.ts +0 -35
  214. package/dist/production/lib/dom/global.d.ts +0 -35
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
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 };
@@ -353,6 +353,8 @@ interface StaticHandler {
353
353
  * The set of data routes managed by this handler
354
354
  */
355
355
  dataRoutes: DataRouteObject[];
356
+ /** @private Estimated route metadata visits per regex match. */
357
+ readonly _matchCost?: number;
356
358
  /**
357
359
  * @private
358
360
  * PRIVATE - DO NOT USE
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
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",
@@ -408,7 +408,7 @@ function createRouter(init) {
408
408
  pendingPreventScrollReset = false;
409
409
  pendingViewTransitionEnabled = false;
410
410
  isUninterruptedRevalidation = false;
411
- isRevalidationRequired = false;
411
+ isRevalidationRequired = fetchReloadIds.size > 0;
412
412
  }
413
413
  async function navigate(to, opts) {
414
414
  if (pendingDiscoveryCancellation) await pendingDiscoveryCancellation;
@@ -446,8 +446,9 @@ function createRouter(init) {
446
446
  validateNavigationTarget(to == null ? init.history.createHref(state.location) : typeof to === "string" ? to : createPath(to), init.history.createHref(nextLocation.mask || nextLocation), init.history.createURL("/"), "reject");
447
447
  let userReplace = opts && opts.replace != null ? opts.replace : void 0;
448
448
  let historyAction = "PUSH";
449
+ let currentPath = state.location.pathname + state.location.search;
449
450
  if (userReplace === true) historyAction = "REPLACE";
450
- else if (userReplace === false) {} else if (submission != null && isMutationMethod(submission.formMethod) && submission.formAction === state.location.pathname + state.location.search) historyAction = "REPLACE";
451
+ else if (userReplace === false) {} else if (submission != null && isMutationMethod(submission.formMethod) && (submission.formAction === currentPath || nextLocation.pathname + nextLocation.search === currentPath)) historyAction = "REPLACE";
451
452
  let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : void 0;
452
453
  let flushSync = (opts && opts.flushSync) === true;
453
454
  let blockerKey = shouldBlockNavigation({
@@ -572,6 +573,7 @@ function createRouter(init) {
572
573
  }
573
574
  matches = actionResult.matches || matches;
574
575
  pendingActionResult = actionResult.pendingActionResult;
576
+ historyAction = pendingAction;
575
577
  loadingNavigation = getLoadingNavigation(location, matches, historyAction, opts.submission);
576
578
  flushSync = false;
577
579
  fogOfWar.active = false;
@@ -789,12 +791,16 @@ function createRouter(init) {
789
791
  abortFetcher(rf.key);
790
792
  if (rf.controller) fetchControllers.set(rf.key, rf.controller);
791
793
  });
792
- let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((f) => abortFetcher(f.key));
794
+ let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((rf) => {
795
+ if (fetchControllers.get(rf.key) === rf.controller) abortFetcher(rf.key);
796
+ });
793
797
  if (pendingNavigationController) pendingNavigationController.signal.addEventListener("abort", abortPendingFetchRevalidations);
794
798
  let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(dsMatches, revalidatingFetchers, request, location, scopedContext, dataStrategyInitiator, historyAction);
795
799
  if (request.signal.aborted) return { shortCircuited: true };
796
800
  if (pendingNavigationController) pendingNavigationController.signal.removeEventListener("abort", abortPendingFetchRevalidations);
797
- revalidatingFetchers.forEach((rf) => fetchControllers.delete(rf.key));
801
+ revalidatingFetchers.forEach((rf) => {
802
+ if (fetchControllers.get(rf.key) === rf.controller) fetchControllers.delete(rf.key);
803
+ });
798
804
  let redirect = findRedirect(loaderResults);
799
805
  if (redirect) {
800
806
  await startRedirectNavigation(request, redirect.result, true, dataStrategyInitiator, { replace });
@@ -846,6 +852,7 @@ function createRouter(init) {
846
852
  let flushSync = (opts && opts.flushSync) === true;
847
853
  let instrumentationResultMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
848
854
  let normalizedPath = normalizeTo(state.location, state.matches, basename, href, routeId, opts?.relative);
855
+ validateNavigationTarget(null, normalizedPath, init.history.createURL("/"), "reject");
849
856
  let matches = dataRouteMatcher.match(normalizedPath);
850
857
  let fogOfWar = checkFogOfWar(matches, normalizedPath);
851
858
  if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
@@ -923,30 +930,39 @@ function createRouter(init) {
923
930
  return;
924
931
  }
925
932
  if (fetchersQueuedForDeletion.has(key)) {
926
- if (isRedirectResult(actionResult) || isErrorResult(actionResult)) {
933
+ if (isErrorResult(actionResult)) {
927
934
  updateFetcherState(key, getDoneFetcher(void 0));
928
935
  return;
929
936
  }
930
- } else {
931
937
  if (isRedirectResult(actionResult)) {
938
+ isRevalidationRequired = true;
939
+ actionResult = {
940
+ type: "data",
941
+ data: void 0
942
+ };
943
+ }
944
+ } else {
945
+ if (isRedirectResult(actionResult)) if (pendingNavigationLoadId > originatingLoadId) {
946
+ isRevalidationRequired = true;
947
+ actionResult = {
948
+ type: "data",
949
+ data: void 0
950
+ };
951
+ } else {
932
952
  fetchControllers.delete(key);
933
- if (pendingNavigationLoadId > originatingLoadId) {
934
- updateFetcherState(key, getDoneFetcher(void 0));
935
- return;
936
- } else {
937
- fetchRedirectIds.add(key);
938
- updateFetcherState(key, getLoadingFetcher(submission));
939
- return startRedirectNavigation(fetchRequest, actionResult, false, "fetcher", {
940
- fetcherSubmission: submission,
941
- preventScrollReset
942
- });
943
- }
953
+ fetchRedirectIds.add(key);
954
+ updateFetcherState(key, getLoadingFetcher(submission));
955
+ return startRedirectNavigation(fetchRequest, actionResult, false, "fetcher", {
956
+ fetcherSubmission: submission,
957
+ preventScrollReset
958
+ });
944
959
  }
945
960
  if (isErrorResult(actionResult)) {
946
961
  setFetcherError(key, routeId, actionResult.error);
947
962
  return;
948
963
  }
949
964
  }
965
+ isRevalidationRequired = true;
950
966
  let nextLocation = state.navigation.location || state.location;
951
967
  let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal);
952
968
  let matches = state.navigation.state !== "idle" ? dataRouteMatcher.match(state.navigation.location) : state.matches;
@@ -966,7 +982,9 @@ function createRouter(init) {
966
982
  if (rf.controller) fetchControllers.set(staleKey, rf.controller);
967
983
  });
968
984
  updateState({ fetchers: workingFetchers });
969
- let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((rf) => abortFetcher(rf.key));
985
+ let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((rf) => {
986
+ if (fetchControllers.get(rf.key) === rf.controller) abortFetcher(rf.key);
987
+ });
970
988
  abortController.signal.addEventListener("abort", abortPendingFetchRevalidations);
971
989
  let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(dsMatches, revalidatingFetchers, revalidationRequest, nextLocation, scopedContext, "fetcher");
972
990
  if (abortController.signal.aborted) {
@@ -976,7 +994,9 @@ function createRouter(init) {
976
994
  abortController.signal.removeEventListener("abort", abortPendingFetchRevalidations);
977
995
  fetchReloadIds.delete(key);
978
996
  fetchControllers.delete(key);
979
- revalidatingFetchers.forEach((r) => fetchControllers.delete(r.key));
997
+ revalidatingFetchers.forEach((r) => {
998
+ if (fetchControllers.get(r.key) === r.controller) fetchControllers.delete(r.key);
999
+ });
980
1000
  let fetcherIsMounted = state.fetchers.has(key);
981
1001
  let getRedirectStateWithDoneFetcher = (s) => {
982
1002
  if (!fetcherIsMounted) return s;
@@ -1005,6 +1025,7 @@ function createRouter(init) {
1005
1025
  if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
1006
1026
  invariant(pendingAction, "Expected pending action");
1007
1027
  pendingNavigationController && pendingNavigationController.abort();
1028
+ markFetchRedirectsDone(finalFetchers);
1008
1029
  completeNavigation(state.navigation.location, {
1009
1030
  matches,
1010
1031
  loaderData,
@@ -1017,7 +1038,7 @@ function createRouter(init) {
1017
1038
  loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
1018
1039
  fetchers: finalFetchers
1019
1040
  });
1020
- isRevalidationRequired = false;
1041
+ isRevalidationRequired = fetchReloadIds.size > 0;
1021
1042
  }
1022
1043
  }
1023
1044
  async function handleFetcherLoader(key, loadMatch, matches, scopedContext, flushSync, preventScrollReset, submission) {
@@ -1877,6 +1898,9 @@ function createStaticHandler(routes, opts) {
1877
1898
  }
1878
1899
  return {
1879
1900
  dataRoutes,
1901
+ get _matchCost() {
1902
+ return dataRouteMatcher instanceof V6RegExMatcher ? dataRouteMatcher.matchCost : void 0;
1903
+ },
1880
1904
  match,
1881
1905
  query,
1882
1906
  queryRoute
@@ -2262,6 +2286,9 @@ const loadLazyRouteProperty = ({ key, route, manifest, mapRouteProperties }) =>
2262
2286
  }
2263
2287
  })();
2264
2288
  cache[key] = propertyPromise;
2289
+ propertyPromise.catch(() => {
2290
+ if (cache[key] === propertyPromise) delete cache[key];
2291
+ });
2265
2292
  return propertyPromise;
2266
2293
  };
2267
2294
  const lazyRouteFunctionCache = /* @__PURE__ */ new WeakMap();
@@ -2303,7 +2330,9 @@ function loadLazyRoute(route, type, manifest, mapRouteProperties, lazyRoutePrope
2303
2330
  });
2304
2331
  })();
2305
2332
  lazyRouteFunctionCache.set(routeToUpdate, lazyRoutePromise);
2306
- lazyRoutePromise.catch(() => {});
2333
+ lazyRoutePromise.catch(() => {
2334
+ if (lazyRouteFunctionCache.get(routeToUpdate) === lazyRoutePromise) lazyRouteFunctionCache.delete(routeToUpdate);
2335
+ });
2307
2336
  return {
2308
2337
  lazyRoutePromise,
2309
2338
  lazyHandlerPromise: lazyRoutePromise
@@ -2595,10 +2624,13 @@ async function callLoaderOrAction({ request, path, pattern, match, lazyHandlerPr
2595
2624
  pathname,
2596
2625
  routeId: match.route.id
2597
2626
  });
2598
- } else return {
2599
- type: "data",
2600
- result: void 0
2601
- };
2627
+ } else {
2628
+ await lazyRoutePromise;
2629
+ return {
2630
+ type: "data",
2631
+ result: void 0
2632
+ };
2633
+ }
2602
2634
  }
2603
2635
  else if (!handler) {
2604
2636
  let url = new URL(request.url);
@@ -2679,6 +2711,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
2679
2711
  function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
2680
2712
  let location = response.headers.get("Location");
2681
2713
  invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
2714
+ validateNavigationTarget(location, location, new URL(request.url), "allow-explicit");
2682
2715
  if (!isAbsoluteUrl(location)) {
2683
2716
  let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
2684
2717
  location = normalizeTo(new URL(request.url), trimmedMatches, basename, location);
@@ -2793,12 +2826,12 @@ function processRouteLoaderData(matches, results, pendingActionResult, isStaticH
2793
2826
  function processLoaderData(state, matches, results, pendingActionResult, revalidatingFetchers, fetcherResults, workingFetchers) {
2794
2827
  let { loaderData, errors } = processRouteLoaderData(matches, results, pendingActionResult);
2795
2828
  revalidatingFetchers.filter((f) => !f.matches || f.matches.some((m) => m.shouldLoad)).forEach((rf) => {
2796
- let { key, match, controller } = rf;
2829
+ let { key, routeId, controller } = rf;
2797
2830
  if (controller && controller.signal.aborted) return;
2798
2831
  let result = fetcherResults[key];
2799
2832
  invariant(result, "Did not find corresponding fetcher result");
2800
2833
  if (isErrorResult(result)) {
2801
- let boundaryMatch = findNearestBoundary(state.matches, match?.route.id);
2834
+ let boundaryMatch = findNearestBoundary(state.matches, routeId);
2802
2835
  if (!(errors && errors[boundaryMatch.route.id])) errors = {
2803
2836
  ...errors,
2804
2837
  [boundaryMatch.route.id]: result.error
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
2
+ * react-router v8.5.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -185,6 +185,13 @@ interface DataFunctionArgs<Context> {
185
185
  * In Framework mode, this is a normalized URL with React-Router-specific
186
186
  * implementation details removed (`.data` suffixes, `index`/`_routes` search
187
187
  * params). For the raw incoming URL, use `request.url`.
188
+ *
189
+ * This normalization preserves standard URL pathname encoding and casing.
190
+ * For example, a request to `/%61dmin.data` produces a `url.pathname` of
191
+ * `/%61dmin`. This is not a canonical representation of the matched route.
192
+ * For authorization, attach {@link https://reactrouter.com/how-to/middleware#authentication server middleware}
193
+ * to the protected route or a common ancestor instead of relying on literal
194
+ * pathname-prefix comparisons.
188
195
  */
189
196
  url: URL;
190
197
  /**
@@ -505,7 +512,7 @@ type BaseRouteObject = {
505
512
  action?: ActionFunction | boolean;
506
513
  /**
507
514
  * The route shouldRevalidate function.
508
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
515
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
509
516
  */
510
517
  shouldRevalidate?: ShouldRevalidateFunction;
511
518
  /**
@@ -711,13 +718,14 @@ interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
711
718
  /**
712
719
  * Returns a path with params interpolated.
713
720
  *
714
- * Param values are percent-encoded for use in a path segment: characters that
715
- * 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)
716
723
  * are escaped, while characters that RFC 3986 allows literally in a path
717
724
  * segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
718
725
  * encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
719
- * delimiters and must be escaped. Splat (`*`) values are encoded per segment,
720
- * 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.
721
729
  *
722
730
  * See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
723
731
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
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
  /**
@@ -413,13 +414,14 @@ function encodePathParam(value) {
413
414
  /**
414
415
  * Returns a path with params interpolated.
415
416
  *
416
- * Param values are percent-encoded for use in a path segment: characters that
417
- * would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
417
+ * Named param values are percent-encoded for use in a path segment: characters
418
+ * that would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
418
419
  * are escaped, while characters that RFC 3986 allows literally in a path
419
420
  * segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
420
421
  * encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
421
- * delimiters and must be escaped. Splat (`*`) values are encoded per segment,
422
- * preserving `/` separators.
422
+ * delimiters and must be escaped. Splat (`*`) values are interpolated without
423
+ * per-segment encoding. Leading URL separators and schemes are handled so
424
+ * interpolated values remain paths.
423
425
  *
424
426
  * See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
425
427
  *
@@ -444,7 +446,7 @@ function generatePath(originalPath, params = {}) {
444
446
  }
445
447
  const prefix = path.startsWith("/") ? "/" : "";
446
448
  const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
447
- return prefix + path.split(/\/+/).map((segment, index, array) => {
449
+ let result = (prefix + path.split(/\/+/).map((segment, index, array) => {
448
450
  if (index === array.length - 1 && segment === "*") return stringify(params["*"]);
449
451
  const keyMatch = segment.match(/^:([\w-]+)(\??)(.*)/);
450
452
  if (keyMatch) {
@@ -454,7 +456,10 @@ function generatePath(originalPath, params = {}) {
454
456
  return encodePathParam(stringify(param)) + suffix;
455
457
  }
456
458
  return segment.replace(/\?$/g, "");
457
- }).filter((segment) => !!segment).join("/");
459
+ }).filter((segment) => !!segment).join("/")).replace(/^[\\/]{2,}/, "/");
460
+ if (!prefix && (path.startsWith(":") || path === "*")) result = result.replace(/^([a-z][a-z0-9+.-]*):/i, "$1%3A");
461
+ validateDocumentNavigationTarget(result);
462
+ return result;
458
463
  }
459
464
  /**
460
465
  * Performs pattern matching on a URL pathname and returns information about
@@ -696,11 +701,15 @@ function data(data, init) {
696
701
  * header.
697
702
  */
698
703
  const redirect = (url, init = 302) => {
704
+ validateDocumentNavigationTarget(url);
699
705
  let responseInit = init;
700
706
  if (typeof responseInit === "number") responseInit = { status: responseInit };
701
- else if (typeof responseInit.status === "undefined") responseInit.status = 302;
702
707
  let headers = new Headers(responseInit.headers);
703
708
  headers.set("Location", url);
709
+ if (typeof responseInit.status === "undefined") responseInit = {
710
+ ...responseInit,
711
+ status: 302
712
+ };
704
713
  return new Response(null, {
705
714
  ...responseInit,
706
715
  headers
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
2
+ * react-router v8.5.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,14 +10,14 @@
10
10
  */
11
11
  import { PROTOCOL_RELATIVE_URL_REGEX } from "../router/url.js";
12
12
  import { createBrowserHistory, createPath, invariant } from "../router/history.js";
13
- import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
14
13
  import { validateNavigationTarget } from "../router/navigation.js";
14
+ import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
15
15
  import { createRouter, hasInvalidProtocol, isMutationMethod } from "../router/router.js";
16
16
  import { RSCRouterContext } from "../context.js";
17
17
  import { createRequestInit } from "../dom/ssr/data.js";
18
18
  import { getSingleFetchDataStrategyImpl, singleFetchUrl, stripIndexParam } from "../dom/ssr/single-fetch.js";
19
19
  import { noActionDefinedError, shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
20
- import { getPathsWithAncestors, handleClientVersionMismatch } from "../dom/ssr/fog-of-war.js";
20
+ import { getManifestPathsParam, getPathsWithAncestors, handleClientVersionMismatch } from "../dom/ssr/fog-of-war.js";
21
21
  import { FrameworkContext, setIsHydrated } from "../dom/ssr/components.js";
22
22
  import { RouterProvider } from "../components.js";
23
23
  import { RSCRouterGlobalErrorBoundary } from "./errorBoundaries.js";
@@ -163,6 +163,7 @@ function createRouterFromPayload({ fetchImplementation, createFromReadableStream
163
163
  invariant(match, "Route not found in payload");
164
164
  return {
165
165
  clientLoader: match.clientLoader,
166
+ clientMiddleware: match.clientMiddleware,
166
167
  hasLoader: match.hasLoader,
167
168
  hasHydrateFallback: match.hydrateFallbackElement != null
168
169
  };
@@ -207,10 +208,11 @@ function createRouterFromPayload({ fetchImplementation, createFromReadableStream
207
208
  return routes.map((route) => {
208
209
  const routeUpdate = routeUpdateByRouteId.get(route.id);
209
210
  if (routeUpdate) {
210
- const { routeModule, hasAction, hasComponent, hasLoader } = routeUpdate;
211
+ const { routeModule, hasAction, hasComponent, hasLoader, hasClientMiddleware } = routeUpdate;
211
212
  const newRoute = createRouteFromServerManifest({
212
213
  clientAction: routeModule.clientAction,
213
214
  clientLoader: routeModule.clientLoader,
215
+ clientMiddleware: hasClientMiddleware ? routeModule.clientMiddleware ?? route.middleware : void 0,
214
216
  element: route.element,
215
217
  errorElement: route.errorElement,
216
218
  handle: route.handle,
@@ -389,6 +391,26 @@ function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementatio
389
391
  routes,
390
392
  router
391
393
  ]);
394
+ React$1.useLayoutEffect(() => {
395
+ if (state.initialized) return;
396
+ let unsubscribe = () => {};
397
+ unsubscribe = router.subscribe((newState) => {
398
+ if (newState.initialized) {
399
+ unsubscribe();
400
+ React$1.startTransition(() => {
401
+ setState((current) => current.state.initialized ? current : {
402
+ ...current,
403
+ state: newState
404
+ });
405
+ });
406
+ }
407
+ });
408
+ return unsubscribe;
409
+ }, [
410
+ router.subscribe,
411
+ router,
412
+ state.initialized
413
+ ]);
392
414
  const transitionEnabledRouter = React$1.useMemo(() => ({
393
415
  ...router,
394
416
  state,
@@ -508,6 +530,7 @@ function createRouteFromServerManifest(match, payload) {
508
530
  throw noActionDefinedError("action", match.id);
509
531
  },
510
532
  path: match.path,
533
+ middleware: match.clientMiddleware,
511
534
  shouldRevalidate: match.shouldRevalidate,
512
535
  hasLoader: true,
513
536
  hasClientLoader: match.clientLoader != null,
@@ -539,7 +562,7 @@ function getManifestUrl(paths, clientVersion) {
539
562
  else {
540
563
  let basename = (window.__reactRouterDataRouter.basename ?? "").replace(/^\/|\/$/g, "");
541
564
  url = new URL(`${basename}/.manifest`, window.location.origin);
542
- url.searchParams.set("paths", paths.sort().join(","));
565
+ url.searchParams.set("paths", getManifestPathsParam(paths));
543
566
  }
544
567
  if (clientVersion !== void 0) url.searchParams.set("version", clientVersion);
545
568
  return url;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
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.0
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.0
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.0
2
+ * react-router v8.5.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -11,6 +11,7 @@ type RSCRouteConfigEntryBase = {
11
11
  action?: ActionFunction;
12
12
  clientAction?: ClientActionFunction;
13
13
  clientLoader?: ClientLoaderFunction;
14
+ clientMiddleware?: MiddlewareFunction<any>[];
14
15
  ErrorBoundary?: React$1.ComponentType<any>;
15
16
  handle?: any;
16
17
  headers?: HeadersFunction;
@@ -42,6 +43,7 @@ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
42
43
  type RSCRouteManifest = {
43
44
  clientAction?: ClientActionFunction;
44
45
  clientLoader?: ClientLoaderFunction;
46
+ clientMiddleware?: MiddlewareFunction<any>[];
45
47
  element?: React$1.ReactElement | false;
46
48
  errorElement?: React$1.ReactElement;
47
49
  handle?: any;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.0
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.0
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.0
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.0
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.0
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.0
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.0
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.0
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.0
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.0
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.0
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.0
2
+ * react-router v8.5.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *