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
@@ -679,7 +679,7 @@ type BaseRouteObject = {
679
679
  action?: ActionFunction | boolean;
680
680
  /**
681
681
  * The route shouldRevalidate function.
682
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
682
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
683
683
  */
684
684
  shouldRevalidate?: ShouldRevalidateFunction;
685
685
  /**
@@ -1014,7 +1014,25 @@ interface AwaitResolveRenderFunction<Resolve = any> {
1014
1014
  * @category Types
1015
1015
  */
1016
1016
  interface AwaitProps<Resolve> {
1017
- /** Use either `resolve` or `unstable_promise`, never both. */
1017
+ /**
1018
+ * <docs-warning>This prop is currently unstable and may change in minor or patch
1019
+ * releases.</docs-warning>
1020
+ *
1021
+ * A promise (or value) to read using React's `use()` API in client components.
1022
+ * Unlike `resolve` in client components, this accepts promise-like values
1023
+ * without modifying the source promise.
1024
+ *
1025
+ * `errorElement` handles promise rejections. Errors thrown while rendering
1026
+ * children bubble to the nearest React error boundary.
1027
+ *
1028
+ * ```tsx
1029
+ * <Await unstable_promise={reviewsPromise} errorElement={<ReviewsError />}>
1030
+ * {(reviews) => <Reviews items={reviews} />}
1031
+ * </Await>
1032
+ * ```
1033
+ *
1034
+ * Pass exactly one of `unstable_promise` or `resolve`.
1035
+ */
1018
1036
  unstable_promise?: never;
1019
1037
  /**
1020
1038
  * When using a function, the resolved value is provided as the parameter.
@@ -1041,14 +1059,17 @@ interface AwaitProps<Resolve> {
1041
1059
  */
1042
1060
  children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
1043
1061
  /**
1044
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1062
+ * The error element renders instead of the `children` when the
1063
+ * [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1045
1064
  * rejects.
1046
1065
  *
1066
+ * When using `resolve`, errors thrown while rendering `children` are
1067
+ * also caught and rendered here. With `unstable_promise`, only promise
1068
+ * rejections are handled; errors thrown while rendering `children` bubble to
1069
+ * the nearest React error boundary.
1070
+ *
1047
1071
  * ```tsx
1048
- * <Await
1049
- * errorElement={<div>Oops</div>}
1050
- * resolve={reviewsPromise}
1051
- * >
1072
+ * <Await resolve={reviewsPromise} errorElement={<div>Oops</div>}>
1052
1073
  * <Reviews />
1053
1074
  * </Await>
1054
1075
  * ```
@@ -1057,10 +1078,7 @@ interface AwaitProps<Resolve> {
1057
1078
  * child component
1058
1079
  *
1059
1080
  * ```tsx
1060
- * <Await
1061
- * errorElement={<ReviewsError />}
1062
- * resolve={reviewsPromise}
1063
- * >
1081
+ * <Await resolve={reviewsPromise} errorElement={<ReviewsError />}>
1064
1082
  * <Reviews />
1065
1083
  * </Await>
1066
1084
  *
@@ -1140,22 +1158,16 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
1140
1158
  /**
1141
1159
  * Used to render promise values with automatic error handling.
1142
1160
  *
1143
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
1161
+ * Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
1162
+ * it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
1163
+ * API.
1144
1164
  *
1145
- * Pass `unstable_promise` instead of `resolve` to opt into React's
1146
- * [`use()`](https://react.dev/reference/react/use) implementation. With
1147
- * `unstable_promise`, `errorElement` handles promise rejections, while errors
1148
- * thrown by children bubble to the nearest React error boundary.
1149
- *
1150
- * In React Server Components, `resolve` already has this error-handling behavior:
1151
- * `errorElement` handles only input rejections, while child render errors
1152
- * propagate to the surrounding error boundary. Both props accept promise-like
1153
- * values without modifying the source promise. Both props treat a falsy
1154
- * `errorElement` as absent and propagate the rejection. Pass an empty fragment
1155
- * to handle a rejection without rendering any content.
1165
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
1156
1166
  *
1157
- * <docs-warning>The `unstable_promise` prop is experimental and may change in
1158
- * minor or patch releases.</docs-warning>
1167
+ * <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
1168
+ * releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
1169
+ * drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
1170
+ * between the two approaches.</docs-warning>
1159
1171
  *
1160
1172
  * @example
1161
1173
  * import { Await, useLoaderData } from "react-router";
@@ -1175,15 +1187,9 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
1175
1187
  * <h1>{book.title}</h1>
1176
1188
  * <p>{book.description}</p>
1177
1189
  * <React.Suspense fallback={<ReviewsSkeleton />}>
1178
- * <Await
1179
- * resolve={reviews}
1180
- * errorElement={
1181
- * <div>Could not load reviews 😬</div>
1182
- * }
1183
- * children={(resolvedReviews) => (
1184
- * <Reviews items={resolvedReviews} />
1185
- * )}
1186
- * />
1190
+ * <Await resolve={reviews} errorElement={<BookError />}>
1191
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
1192
+ * </Await>
1187
1193
  * </React.Suspense>
1188
1194
  * </div>
1189
1195
  * );
@@ -1197,9 +1203,7 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
1197
1203
  * @param {AwaitProps.children} props.children n/a
1198
1204
  * @param {AwaitProps.errorElement} props.errorElement n/a
1199
1205
  * @param {AwaitProps.resolve} props.resolve n/a
1200
- * @param props.unstable_promise A promise (or value) to read using React's `use()`
1201
- * API in client components. Accepts promise-like values without modifying the
1202
- * source promise. Pass exactly one of `unstable_promise` or `resolve`.
1206
+ * @param {AwaitProps.unstable_promise} props.unstable_promise n/a
1203
1207
  * @returns React element for the rendered awaited value
1204
1208
  */
1205
1209
  declare function Await$1<Resolve>(props: AwaitProps<Resolve> | AwaitPromiseProps<Resolve>): React.JSX.Element;
@@ -2330,6 +2334,7 @@ type RSCRouteConfigEntryBase = {
2330
2334
  action?: ActionFunction;
2331
2335
  clientAction?: ClientActionFunction;
2332
2336
  clientLoader?: ClientLoaderFunction;
2337
+ clientMiddleware?: MiddlewareFunction<any>[];
2333
2338
  ErrorBoundary?: React.ComponentType<any>;
2334
2339
  handle?: any;
2335
2340
  headers?: HeadersFunction;
@@ -2361,6 +2366,7 @@ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
2361
2366
  type RSCRouteManifest = {
2362
2367
  clientAction?: ClientActionFunction;
2363
2368
  clientLoader?: ClientLoaderFunction;
2369
+ clientMiddleware?: MiddlewareFunction<any>[];
2364
2370
  element?: React.ReactElement | false;
2365
2371
  errorElement?: React.ReactElement;
2366
2372
  handle?: any;
@@ -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
  *
@@ -83,6 +83,46 @@ function parsePath(path) {
83
83
  return parsedPath;
84
84
  }
85
85
  //#endregion
86
+ //#region lib/router/navigation.ts
87
+ const DEFAULT_NAVIGATION_URL = new URL("http://localhost");
88
+ function isSameOrigin(a, b) {
89
+ return a.origin === b.origin && (a.origin !== "null" || a.protocol === b.protocol && a.host === b.host);
90
+ }
91
+ function isExplicitUrl(destination, target) {
92
+ if (destination.startsWith("//")) return true;
93
+ let protocol = target.protocol.toLowerCase();
94
+ if (!destination.toLowerCase().startsWith(protocol)) return false;
95
+ return target.host === "" || destination.slice(protocol.length).startsWith("//");
96
+ }
97
+ function validateDocumentNavigationTarget(destination) {
98
+ let normalized = destination.replace(/[\t\n\r]/g, "");
99
+ let start = 0;
100
+ while (normalized.charCodeAt(start) <= 32) start++;
101
+ normalized = normalized.slice(start);
102
+ if (!ABSOLUTE_URL_REGEX.test(normalized)) return;
103
+ let target;
104
+ try {
105
+ target = new URL(destination, DEFAULT_NAVIGATION_URL);
106
+ } catch {
107
+ return;
108
+ }
109
+ if (!isExplicitUrl(destination, target)) throw new Error("External navigation is not allowed");
110
+ }
111
+ function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
112
+ let originalUrl = null;
113
+ try {
114
+ originalUrl = original == null ? null : new URL(original, currentUrl);
115
+ } catch {}
116
+ let resolvedUrl = new URL(resolved, currentUrl);
117
+ let originalIsExternal = originalUrl != null && !isSameOrigin(originalUrl, currentUrl);
118
+ let resolvedIsExternal = !isSameOrigin(resolvedUrl, currentUrl);
119
+ if (externalPolicy === "reject") {
120
+ if (originalIsExternal || resolvedIsExternal) throw new Error("External navigation is not allowed");
121
+ } else if (resolvedIsExternal) {
122
+ if (originalUrl == null || !isExplicitUrl(original, originalUrl) || !isSameOrigin(originalUrl, resolvedUrl)) throw new Error("External navigation is not allowed");
123
+ }
124
+ }
125
+ //#endregion
86
126
  //#region lib/router/utils.ts
87
127
  /**
88
128
  * Creates a type-safe {@link RouterContext} object that can be used to
@@ -721,11 +761,15 @@ function data(data, init) {
721
761
  * header.
722
762
  */
723
763
  const redirect$1 = (url, init = 302) => {
764
+ validateDocumentNavigationTarget(url);
724
765
  let responseInit = init;
725
766
  if (typeof responseInit === "number") responseInit = { status: responseInit };
726
- else if (typeof responseInit.status === "undefined") responseInit.status = 302;
727
767
  let headers = new Headers(responseInit.headers);
728
768
  headers.set("Location", url);
769
+ if (typeof responseInit.status === "undefined") responseInit = {
770
+ ...responseInit,
771
+ status: 302
772
+ };
729
773
  return new Response(null, {
730
774
  ...responseInit,
731
775
  headers
@@ -2009,6 +2053,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
2009
2053
  function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
2010
2054
  let location = response.headers.get("Location");
2011
2055
  invariant$1(location, "Redirects returned/thrown from loaders/actions must have a Location header");
2056
+ validateNavigationTarget(location, location, new URL(request.url), "allow-explicit");
2012
2057
  if (!isAbsoluteUrl(location)) {
2013
2058
  let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
2014
2059
  location = normalizeTo(new URL(request.url), trimmedMatches, basename, location);
@@ -2491,9 +2536,20 @@ async function matchRSCServerRequest({ allowedActionOrigins, createTemporaryRefe
2491
2536
  let matches = staticHandler.match(url.pathname);
2492
2537
  if (matches) await Promise.all(matches.map((m) => explodeLazyRoute(m.route)));
2493
2538
  const leafMatch = matches?.[matches.length - 1];
2494
- if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return generateResourceResponse(routerRequest, staticHandler, leafMatch.route.id, requestContext, onError);
2539
+ if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return normalizeResourceResponse(request, await generateResourceResponse(routerRequest, staticHandler, leafMatch.route.id, requestContext, onError));
2495
2540
  let response = await generateRenderResponse(routerRequest, staticHandler, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences, allowedActionOrigins, routeDiscovery, clientVersion);
2496
2541
  response.headers.set("X-Remix-Response", "yes");
2542
+ return normalizeResourceResponse(request, response);
2543
+ }
2544
+ function normalizeResourceResponse(request, response) {
2545
+ if (request.method === "HEAD" && response.headers.get("React-Router-Resource") === "true") {
2546
+ response.body?.cancel().catch(() => {});
2547
+ return new Response(null, {
2548
+ status: response.status,
2549
+ statusText: response.statusText,
2550
+ headers: response.headers
2551
+ });
2552
+ }
2497
2553
  return response;
2498
2554
  }
2499
2555
  async function generateManifestResponse(routes, basename, request, generateResponse, temporaryReferences, routeDiscovery, clientVersion) {
@@ -2851,6 +2907,7 @@ async function getRSCRouteMatch({ staticContext, match, isBelowErrorBoundary, ro
2851
2907
  return {
2852
2908
  clientAction: route.clientAction,
2853
2909
  clientLoader: route.clientLoader,
2910
+ clientMiddleware: route.clientMiddleware,
2854
2911
  element,
2855
2912
  errorElement,
2856
2913
  handle: route.handle,
@@ -2878,6 +2935,7 @@ async function getManifestRoute(route) {
2878
2935
  return {
2879
2936
  clientAction: route.clientAction,
2880
2937
  clientLoader: route.clientLoader,
2938
+ clientMiddleware: route.clientMiddleware,
2881
2939
  handle: route.handle,
2882
2940
  hasAction: !!route.action,
2883
2941
  hasComponent: !!route.Component,
@@ -2987,14 +3045,14 @@ function href(path, ...args) {
2987
3045
  let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
2988
3046
  const isRequired = questionMark === void 0;
2989
3047
  const value = params?.[param];
2990
- if (isRequired && value === void 0) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
3048
+ if (isRequired && value == null) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
2991
3049
  return value == null ? "" : "/" + encodePathParam(stringify(value));
2992
3050
  });
2993
3051
  if (path.endsWith("*")) {
2994
3052
  const value = params?.["*"];
2995
- if (value !== void 0) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
3053
+ if (value != null) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
2996
3054
  }
2997
- return result || "/";
3055
+ return result.replace(/^\/{2,}/, "/") || "/";
2998
3056
  }
2999
3057
  /**
3000
3058
  * 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
  *
@@ -447,7 +447,7 @@ interface PathRouteProps {
447
447
  action?: NonIndexRouteObject["action"];
448
448
  /**
449
449
  * The route shouldRevalidate function.
450
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
450
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
451
451
  */
452
452
  shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
453
453
  /**
@@ -537,7 +537,7 @@ interface IndexRouteProps {
537
537
  action?: IndexRouteObject["action"];
538
538
  /**
539
539
  * The route shouldRevalidate function.
540
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
540
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
541
541
  */
542
542
  shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
543
543
  /**
@@ -768,7 +768,25 @@ interface AwaitResolveRenderFunction<Resolve = any> {
768
768
  * @category Types
769
769
  */
770
770
  interface AwaitProps<Resolve> {
771
- /** Use either `resolve` or `unstable_promise`, never both. */
771
+ /**
772
+ * <docs-warning>This prop is currently unstable and may change in minor or patch
773
+ * releases.</docs-warning>
774
+ *
775
+ * A promise (or value) to read using React's `use()` API in client components.
776
+ * Unlike `resolve` in client components, this accepts promise-like values
777
+ * without modifying the source promise.
778
+ *
779
+ * `errorElement` handles promise rejections. Errors thrown while rendering
780
+ * children bubble to the nearest React error boundary.
781
+ *
782
+ * ```tsx
783
+ * <Await unstable_promise={reviewsPromise} errorElement={<ReviewsError />}>
784
+ * {(reviews) => <Reviews items={reviews} />}
785
+ * </Await>
786
+ * ```
787
+ *
788
+ * Pass exactly one of `unstable_promise` or `resolve`.
789
+ */
772
790
  unstable_promise?: never;
773
791
  /**
774
792
  * When using a function, the resolved value is provided as the parameter.
@@ -795,14 +813,17 @@ interface AwaitProps<Resolve> {
795
813
  */
796
814
  children: React$1.ReactNode | AwaitResolveRenderFunction<Resolve>;
797
815
  /**
798
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
816
+ * The error element renders instead of the `children` when the
817
+ * [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
799
818
  * rejects.
800
819
  *
820
+ * When using `resolve`, errors thrown while rendering `children` are
821
+ * also caught and rendered here. With `unstable_promise`, only promise
822
+ * rejections are handled; errors thrown while rendering `children` bubble to
823
+ * the nearest React error boundary.
824
+ *
801
825
  * ```tsx
802
- * <Await
803
- * errorElement={<div>Oops</div>}
804
- * resolve={reviewsPromise}
805
- * >
826
+ * <Await resolve={reviewsPromise} errorElement={<div>Oops</div>}>
806
827
  * <Reviews />
807
828
  * </Await>
808
829
  * ```
@@ -811,10 +832,7 @@ interface AwaitProps<Resolve> {
811
832
  * child component
812
833
  *
813
834
  * ```tsx
814
- * <Await
815
- * errorElement={<ReviewsError />}
816
- * resolve={reviewsPromise}
817
- * >
835
+ * <Await resolve={reviewsPromise} errorElement={<ReviewsError />}>
818
836
  * <Reviews />
819
837
  * </Await>
820
838
  *
@@ -894,22 +912,16 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
894
912
  /**
895
913
  * Used to render promise values with automatic error handling.
896
914
  *
897
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
915
+ * Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
916
+ * it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
917
+ * API.
898
918
  *
899
- * Pass `unstable_promise` instead of `resolve` to opt into React's
900
- * [`use()`](https://react.dev/reference/react/use) implementation. With
901
- * `unstable_promise`, `errorElement` handles promise rejections, while errors
902
- * thrown by children bubble to the nearest React error boundary.
903
- *
904
- * In React Server Components, `resolve` already has this error-handling behavior:
905
- * `errorElement` handles only input rejections, while child render errors
906
- * propagate to the surrounding error boundary. Both props accept promise-like
907
- * values without modifying the source promise. Both props treat a falsy
908
- * `errorElement` as absent and propagate the rejection. Pass an empty fragment
909
- * to handle a rejection without rendering any content.
919
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
910
920
  *
911
- * <docs-warning>The `unstable_promise` prop is experimental and may change in
912
- * minor or patch releases.</docs-warning>
921
+ * <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
922
+ * releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
923
+ * drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
924
+ * between the two approaches.</docs-warning>
913
925
  *
914
926
  * @example
915
927
  * import { Await, useLoaderData } from "react-router";
@@ -929,15 +941,9 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
929
941
  * <h1>{book.title}</h1>
930
942
  * <p>{book.description}</p>
931
943
  * <React.Suspense fallback={<ReviewsSkeleton />}>
932
- * <Await
933
- * resolve={reviews}
934
- * errorElement={
935
- * <div>Could not load reviews 😬</div>
936
- * }
937
- * children={(resolvedReviews) => (
938
- * <Reviews items={resolvedReviews} />
939
- * )}
940
- * />
944
+ * <Await resolve={reviews} errorElement={<BookError />}>
945
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
946
+ * </Await>
941
947
  * </React.Suspense>
942
948
  * </div>
943
949
  * );
@@ -951,9 +957,7 @@ interface AwaitPromiseProps<Resolve> extends Omit<AwaitProps<Resolve>, "resolve"
951
957
  * @param {AwaitProps.children} props.children n/a
952
958
  * @param {AwaitProps.errorElement} props.errorElement n/a
953
959
  * @param {AwaitProps.resolve} props.resolve n/a
954
- * @param props.unstable_promise A promise (or value) to read using React's `use()`
955
- * API in client components. Accepts promise-like values without modifying the
956
- * source promise. Pass exactly one of `unstable_promise` or `resolve`.
960
+ * @param {AwaitProps.unstable_promise} props.unstable_promise n/a
957
961
  * @returns React element for the rendered awaited value
958
962
  */
959
963
  declare function Await<Resolve>(props: AwaitProps<Resolve> | AwaitPromiseProps<Resolve>): React$1.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.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 { createMemoryHistory, createPath, invariant, parsePath, warning } from "./router/history.js";
12
- import { defaultMapRouteProperties, getResolveToMatches, getRoutePattern, resolveTo, stripBasename } from "./router/utils.js";
13
12
  import { getNavigatorCurrentUrl, validateNavigationTarget } from "./router/navigation.js";
13
+ import { defaultMapRouteProperties, getResolveToMatches, getRoutePattern, resolveTo, stripBasename } from "./router/utils.js";
14
14
  import { clientErrors, createRouter } from "./router/router.js";
15
15
  import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, LocationContext, NavigationContext, RouteContext, ViewTransitionContext, useIsRSCRouterContext } from "./context.js";
16
16
  import { getAwaitPromise, getPromiseResult } from "./await.js";
@@ -649,22 +649,16 @@ function Routes({ children, location }) {
649
649
  /**
650
650
  * Used to render promise values with automatic error handling.
651
651
  *
652
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
653
- *
654
- * Pass `unstable_promise` instead of `resolve` to opt into React's
655
- * [`use()`](https://react.dev/reference/react/use) implementation. With
656
- * `unstable_promise`, `errorElement` handles promise rejections, while errors
657
- * thrown by children bubble to the nearest React error boundary.
652
+ * Passing the promise through `resolve` uses React Router-specific promise tracking, while passing
653
+ * it through `unstable_promise` uses React's built-in [`use()`](https://react.dev/reference/react/use)
654
+ * API.
658
655
  *
659
- * In React Server Components, `resolve` already has this error-handling behavior:
660
- * `errorElement` handles only input rejections, while child render errors
661
- * propagate to the surrounding error boundary. Both props accept promise-like
662
- * values without modifying the source promise. Both props treat a falsy
663
- * `errorElement` as absent and propagate the rejection. Pass an empty fragment
664
- * to handle a rejection without rendering any content.
656
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
665
657
  *
666
- * <docs-warning>The `unstable_promise` prop is experimental and may change in
667
- * minor or patch releases.</docs-warning>
658
+ * <docs-warning>The `unstable_promise` prop is currently unstable and may change in minor or patch
659
+ * releases. We plan to stabilize `<Await promise>` and deprecate `<Await resolve>` during v8, and then
660
+ * drop `<Await resolve>` in v9. Please see below for minor `errorElement` behavioral differences
661
+ * between the two approaches.</docs-warning>
668
662
  *
669
663
  * @example
670
664
  * import { Await, useLoaderData } from "react-router";
@@ -684,15 +678,9 @@ function Routes({ children, location }) {
684
678
  * <h1>{book.title}</h1>
685
679
  * <p>{book.description}</p>
686
680
  * <React.Suspense fallback={<ReviewsSkeleton />}>
687
- * <Await
688
- * resolve={reviews}
689
- * errorElement={
690
- * <div>Could not load reviews 😬</div>
691
- * }
692
- * children={(resolvedReviews) => (
693
- * <Reviews items={resolvedReviews} />
694
- * )}
695
- * />
681
+ * <Await resolve={reviews} errorElement={<BookError />}>
682
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
683
+ * </Await>
696
684
  * </React.Suspense>
697
685
  * </div>
698
686
  * );
@@ -706,9 +694,7 @@ function Routes({ children, location }) {
706
694
  * @param {AwaitProps.children} props.children n/a
707
695
  * @param {AwaitProps.errorElement} props.errorElement n/a
708
696
  * @param {AwaitProps.resolve} props.resolve n/a
709
- * @param props.unstable_promise A promise (or value) to read using React's `use()`
710
- * API in client components. Accepts promise-like values without modifying the
711
- * source promise. Pass exactly one of `unstable_promise` or `resolve`.
697
+ * @param {AwaitProps.unstable_promise} props.unstable_promise n/a
712
698
  * @returns React element for the rendered awaited value
713
699
  */
714
700
  function Await(props) {
@@ -746,11 +732,21 @@ function AwaitPromise({ value, children, errorElement, onError }) {
746
732
  var AwaitErrorBoundary = class extends React$1.Component {
747
733
  constructor(props) {
748
734
  super(props);
749
- this.state = { error: null };
735
+ this.state = {
736
+ error: null,
737
+ resolve: props.resolve
738
+ };
750
739
  }
751
740
  static getDerivedStateFromError(error) {
752
741
  return { error };
753
742
  }
743
+ static getDerivedStateFromProps(props, state) {
744
+ if (props.resolve !== state.resolve) return {
745
+ error: null,
746
+ resolve: props.resolve
747
+ };
748
+ return null;
749
+ }
754
750
  componentDidCatch(error, errorInfo) {
755
751
  if (this.props.onError) this.props.onError(error, errorInfo);
756
752
  else console.error("<Await> caught the following error during render", error, errorInfo);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.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,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