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
  *
@@ -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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { ABSOLUTE_URL_REGEX, 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,12 +456,18 @@ 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
  }
464
+ const MAX_OPTIONAL_PATH_SEGMENTS = 12;
459
465
  /**
460
466
  * Performs pattern matching on a URL pathname and returns information about
461
467
  * the match.
462
468
  *
469
+ * Throws if the pattern contains more than 12 optional (`?`) markers.
470
+ *
463
471
  * @public
464
472
  * @category Utils
465
473
  * @param pattern The pattern to match against the URL pathname. This can be a
@@ -476,7 +484,10 @@ function matchPath(pattern, pathname) {
476
484
  caseSensitive: false,
477
485
  end: true
478
486
  };
479
- let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end);
487
+ let { path } = pattern;
488
+ let optionalSegments = 0;
489
+ for (let index = path.indexOf("?"); index !== -1; index = path.indexOf("?", index + 1)) if (++optionalSegments > MAX_OPTIONAL_PATH_SEGMENTS) throw new Error(`Path pattern ${JSON.stringify(path)} exceeds the limit of ${MAX_OPTIONAL_PATH_SEGMENTS} optional segments.`);
490
+ let [matcher, compiledParams] = compilePath(path, pattern.caseSensitive, pattern.end);
480
491
  return matchPathImpl(pattern, pathname, matcher, compiledParams);
481
492
  }
482
493
  function matchPathImpl(pattern, pathname, matcher, compiledParams) {
@@ -696,11 +707,15 @@ function data(data, init) {
696
707
  * header.
697
708
  */
698
709
  const redirect = (url, init = 302) => {
710
+ validateDocumentNavigationTarget(url);
699
711
  let responseInit = init;
700
712
  if (typeof responseInit === "number") responseInit = { status: responseInit };
701
- else if (typeof responseInit.status === "undefined") responseInit.status = 302;
702
713
  let headers = new Headers(responseInit.headers);
703
714
  headers.set("Location", url);
715
+ if (typeof responseInit.status === "undefined") responseInit = {
716
+ ...responseInit,
717
+ status: 302
718
+ };
704
719
  return new Response(null, {
705
720
  ...responseInit,
706
721
  headers
@@ -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,8 +10,8 @@
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";
@@ -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,
@@ -560,13 +583,13 @@ async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fet
560
583
  if (!response.body || response.status < 200 || response.status >= 300) throw new Error("Unable to fetch new route matches from the server");
561
584
  let payload = await createFromReadableStream(response.body, { temporaryReferences: void 0 });
562
585
  if (payload.type !== "manifest") throw new Error("Failed to patch routes");
563
- paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
564
586
  let patches = await payload.patches;
565
587
  React$1.startTransition(() => {
566
588
  patches.forEach((p) => {
567
589
  window.__reactRouterDataRouter.patchRoutes(p.parentId ?? null, [createRouteFromServerManifest(p)]);
568
590
  });
569
591
  });
592
+ paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
570
593
  }
571
594
  function addToFifoQueue(path, queue) {
572
595
  if (queue.size >= discoveredPathsMaxSize) {
@@ -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,6 +9,7 @@
9
9
  * @license MIT
10
10
  */
11
11
  import { isRouteErrorResponse } from "../router/utils.js";
12
+ import { RSCErrorAlreadyReportedContext } from "../context.js";
12
13
  import { useRouteError } from "../hooks.js";
13
14
  import React from "react";
14
15
  //#region lib/rsc/errorBoundaries.tsx
@@ -52,7 +53,7 @@ function ErrorWrapper({ renderAppShell, title, children }) {
52
53
  } }, children)));
53
54
  }
54
55
  function RSCDefaultRootErrorBoundaryImpl({ error, renderAppShell }) {
55
- console.error(error);
56
+ if (!React.useContext(RSCErrorAlreadyReportedContext)) console.error(error);
56
57
  let heyDeveloper = /* @__PURE__ */ React.createElement("script", { dangerouslySetInnerHTML: { __html: `
57
58
  console.log(
58
59
  "💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -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
  *
@@ -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;
@@ -179,7 +181,8 @@ type RouteDiscovery = {
179
181
  * @param opts.clientVersion A version derived from the client build output used
180
182
  * to detect stale clients during lazy route discovery.
181
183
  * @param opts.onError An optional error handler that will be called with any
182
- * errors that occur during the request processing.
184
+ * errors that occur during the request processing. Defaults to logging errors
185
+ * with `console.error` unless the request was aborted.
183
186
  * @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
184
187
  * to match against.
185
188
  * @param opts.requestContext An instance of {@link RouterContextProvider}
@@ -5,6 +5,7 @@ import * as React$1 from "react";
5
5
  //#region lib/rsc/server.ssr.d.ts
6
6
  type DecodedPayload = Promise<RSCPayload> & {
7
7
  _deepestRenderedBoundaryId?: string | null;
8
+ _isErrorRender?: boolean;
8
9
  formState: Promise<any>;
9
10
  };
10
11
  type SSRCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>) => Promise<unknown>;
@@ -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,7 +10,7 @@
10
10
  */
11
11
  import { isRouteErrorResponse } from "../router/utils.js";
12
12
  import { createDataRouteMatcher, hasInvalidProtocol } from "../router/router.js";
13
- import { RSCRouterContext } from "../context.js";
13
+ import { RSCErrorAlreadyReportedContext, RSCRouterContext } from "../context.js";
14
14
  import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "../errors.js";
15
15
  import { escapeAttribute } from "../dom/ssr/markup.js";
16
16
  import { shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
@@ -214,6 +214,7 @@ async function routeRSCServerRequest({ request, serverResponse, createFromReadab
214
214
  errors: deepestRenderedBoundaryId ? { [deepestRenderedBoundaryId]: normalizedError } : {}
215
215
  }));
216
216
  return Object.defineProperties(payloadPromise, {
217
+ _isErrorRender: { value: true },
217
218
  _deepestRenderedBoundaryId: {
218
219
  get() {
219
220
  return deepestRenderedBoundaryId;
@@ -407,11 +408,11 @@ function RSCStaticRouter({ getPayload, nonce }) {
407
408
  routeModules: createRSCRouteModules(payload),
408
409
  nonce
409
410
  };
410
- return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
411
+ return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(RSCErrorAlreadyReportedContext.Provider, { value: payload.errors != null && !decoded._isErrorRender }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
411
412
  context,
412
413
  router,
413
414
  hydrate: false
414
- }))));
415
+ })))));
415
416
  }
416
417
  function isReactServerRequest(url) {
417
418
  return url.pathname.endsWith(".rsc");
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -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
  *