react-router 8.4.0 → 8.5.0

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 (198) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/dist/development/dom-export.d.ts +2 -1
  3. package/dist/development/dom-export.js +1 -1
  4. package/dist/development/index-react-server-client.js +2 -2
  5. package/dist/development/index-react-server.d.ts +583 -165
  6. package/dist/development/index-react-server.js +27 -19
  7. package/dist/development/index.d.ts +9 -8
  8. package/dist/development/index.js +5 -4
  9. package/dist/development/lib/actions.js +1 -1
  10. package/dist/development/lib/components.js +22 -3
  11. package/dist/development/lib/context.d.ts +6 -1
  12. package/dist/development/lib/context.js +1 -1
  13. package/dist/development/lib/dom/dom.d.ts +3 -0
  14. package/dist/development/lib/dom/dom.js +1 -1
  15. package/dist/development/lib/dom/global.d.ts +35 -0
  16. package/dist/development/lib/dom/lib.d.ts +34 -9
  17. package/dist/development/lib/dom/lib.js +17 -6
  18. package/dist/development/lib/dom/server.js +2 -2
  19. package/dist/development/lib/dom/ssr/components.js +12 -9
  20. package/dist/development/lib/dom/ssr/data.js +1 -1
  21. package/dist/development/lib/dom/ssr/entry.d.ts +9 -2
  22. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  23. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  24. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +3 -2
  25. package/dist/development/lib/dom/ssr/fog-of-war.js +14 -11
  26. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  27. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  28. package/dist/development/lib/dom/ssr/links.js +1 -1
  29. package/dist/development/lib/dom/ssr/markup.js +1 -1
  30. package/dist/development/lib/dom/ssr/route-discovery.d.ts +120 -0
  31. package/dist/development/lib/dom/ssr/route-discovery.js +415 -0
  32. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  33. package/dist/development/lib/dom/ssr/routes-test-stub.js +2 -2
  34. package/dist/development/lib/dom/ssr/routes.d.ts +2 -2
  35. package/dist/development/lib/dom/ssr/routes.js +8 -8
  36. package/dist/development/lib/dom/ssr/server.js +3 -1
  37. package/dist/development/lib/dom/ssr/single-fetch.d.ts +28 -2
  38. package/dist/development/lib/dom/ssr/single-fetch.js +73 -55
  39. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  40. package/dist/development/lib/dom-export/hydrated-router.d.ts +28 -0
  41. package/dist/development/lib/dom-export/hydrated-router.js +32 -12
  42. package/dist/development/lib/errors.js +1 -1
  43. package/dist/development/lib/hooks.d.ts +3 -3
  44. package/dist/development/lib/hooks.js +4 -4
  45. package/dist/development/lib/href.js +1 -1
  46. package/dist/development/lib/router/history.js +1 -1
  47. package/dist/development/lib/router/instrumentation.js +1 -1
  48. package/dist/development/lib/router/matcher-route-pattern.js +1 -1
  49. package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
  50. package/dist/development/lib/router/matcher.js +1 -1
  51. package/dist/development/lib/router/navigation.js +1 -1
  52. package/dist/development/lib/router/router.d.ts +6 -0
  53. package/dist/development/lib/router/router.js +157 -65
  54. package/dist/development/lib/router/url.js +1 -1
  55. package/dist/development/lib/router/utils.d.ts +24 -4
  56. package/dist/development/lib/router/utils.js +4 -3
  57. package/dist/development/lib/rsc/browser.js +2 -2
  58. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  59. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  60. package/dist/development/lib/rsc/html-stream/server.js +24 -12
  61. package/dist/development/lib/rsc/route-modules.js +1 -1
  62. package/dist/development/lib/rsc/server.rsc.d.ts +3 -2
  63. package/dist/development/lib/rsc/server.ssr.js +1 -1
  64. package/dist/development/lib/server-runtime/build.d.ts +14 -0
  65. package/dist/development/lib/server-runtime/cookies.js +1 -1
  66. package/dist/development/lib/server-runtime/crypto.js +1 -1
  67. package/dist/development/lib/server-runtime/data.js +1 -1
  68. package/dist/development/lib/server-runtime/dev.js +1 -1
  69. package/dist/development/lib/server-runtime/entry.js +1 -1
  70. package/dist/development/lib/server-runtime/errors.js +1 -1
  71. package/dist/development/lib/server-runtime/headers.js +1 -1
  72. package/dist/development/lib/server-runtime/invariant.js +1 -1
  73. package/dist/development/lib/server-runtime/mode.js +1 -1
  74. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  75. package/dist/development/lib/server-runtime/routes.d.ts +1 -1
  76. package/dist/development/lib/server-runtime/routes.js +1 -1
  77. package/dist/development/lib/server-runtime/server.js +12 -4
  78. package/dist/development/lib/server-runtime/serverHandoff.d.ts +17 -0
  79. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  80. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  81. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  82. package/dist/development/lib/server-runtime/sessions.js +1 -1
  83. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  84. package/dist/development/lib/server-runtime/urls.js +1 -1
  85. package/dist/development/lib/server-runtime/warnings.js +1 -1
  86. package/dist/development/lib/types/internal.js +1 -1
  87. package/dist/development/lib/types/route-data.d.ts +2 -2
  88. package/dist/development/lib/types/route-module-annotations.d.ts +1 -1
  89. package/dist/development/route-pattern.js +1 -1
  90. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  91. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  92. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  93. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  94. package/dist/production/dom-export.d.ts +2 -1
  95. package/dist/production/dom-export.js +1 -1
  96. package/dist/production/index-react-server-client.js +2 -2
  97. package/dist/production/index-react-server.d.ts +583 -165
  98. package/dist/production/index-react-server.js +27 -19
  99. package/dist/production/index.d.ts +9 -8
  100. package/dist/production/index.js +5 -4
  101. package/dist/production/lib/actions.js +1 -1
  102. package/dist/production/lib/components.js +22 -3
  103. package/dist/production/lib/context.d.ts +6 -1
  104. package/dist/production/lib/context.js +1 -1
  105. package/dist/production/lib/dom/dom.d.ts +3 -0
  106. package/dist/production/lib/dom/dom.js +1 -1
  107. package/dist/production/lib/dom/global.d.ts +35 -0
  108. package/dist/production/lib/dom/lib.d.ts +34 -9
  109. package/dist/production/lib/dom/lib.js +17 -6
  110. package/dist/production/lib/dom/server.js +2 -2
  111. package/dist/production/lib/dom/ssr/components.js +12 -9
  112. package/dist/production/lib/dom/ssr/data.js +1 -1
  113. package/dist/production/lib/dom/ssr/entry.d.ts +9 -2
  114. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  115. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  116. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +3 -2
  117. package/dist/production/lib/dom/ssr/fog-of-war.js +14 -11
  118. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  119. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  120. package/dist/production/lib/dom/ssr/links.js +1 -1
  121. package/dist/production/lib/dom/ssr/markup.js +1 -1
  122. package/dist/production/lib/dom/ssr/route-discovery.d.ts +120 -0
  123. package/dist/production/lib/dom/ssr/route-discovery.js +415 -0
  124. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  125. package/dist/production/lib/dom/ssr/routes-test-stub.js +2 -2
  126. package/dist/production/lib/dom/ssr/routes.d.ts +2 -2
  127. package/dist/production/lib/dom/ssr/routes.js +8 -8
  128. package/dist/production/lib/dom/ssr/server.js +3 -1
  129. package/dist/production/lib/dom/ssr/single-fetch.d.ts +28 -2
  130. package/dist/production/lib/dom/ssr/single-fetch.js +73 -55
  131. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  132. package/dist/production/lib/dom-export/hydrated-router.d.ts +28 -0
  133. package/dist/production/lib/dom-export/hydrated-router.js +32 -12
  134. package/dist/production/lib/errors.js +1 -1
  135. package/dist/production/lib/hooks.d.ts +3 -3
  136. package/dist/production/lib/hooks.js +3 -3
  137. package/dist/production/lib/href.js +1 -1
  138. package/dist/production/lib/router/history.js +1 -1
  139. package/dist/production/lib/router/instrumentation.js +1 -1
  140. package/dist/production/lib/router/matcher-route-pattern.js +1 -1
  141. package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
  142. package/dist/production/lib/router/matcher.js +1 -1
  143. package/dist/production/lib/router/navigation.js +1 -1
  144. package/dist/production/lib/router/router.d.ts +6 -0
  145. package/dist/production/lib/router/router.js +157 -65
  146. package/dist/production/lib/router/url.js +1 -1
  147. package/dist/production/lib/router/utils.d.ts +24 -4
  148. package/dist/production/lib/router/utils.js +4 -3
  149. package/dist/production/lib/rsc/browser.js +2 -2
  150. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  151. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  152. package/dist/production/lib/rsc/html-stream/server.js +24 -12
  153. package/dist/production/lib/rsc/route-modules.js +1 -1
  154. package/dist/production/lib/rsc/server.rsc.d.ts +3 -2
  155. package/dist/production/lib/rsc/server.ssr.js +1 -1
  156. package/dist/production/lib/server-runtime/build.d.ts +14 -0
  157. package/dist/production/lib/server-runtime/cookies.js +1 -1
  158. package/dist/production/lib/server-runtime/crypto.js +1 -1
  159. package/dist/production/lib/server-runtime/data.js +1 -1
  160. package/dist/production/lib/server-runtime/dev.js +1 -1
  161. package/dist/production/lib/server-runtime/entry.js +1 -1
  162. package/dist/production/lib/server-runtime/errors.js +1 -1
  163. package/dist/production/lib/server-runtime/headers.js +1 -1
  164. package/dist/production/lib/server-runtime/invariant.js +1 -1
  165. package/dist/production/lib/server-runtime/mode.js +1 -1
  166. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  167. package/dist/production/lib/server-runtime/routes.d.ts +1 -1
  168. package/dist/production/lib/server-runtime/routes.js +1 -1
  169. package/dist/production/lib/server-runtime/server.js +12 -4
  170. package/dist/production/lib/server-runtime/serverHandoff.d.ts +17 -0
  171. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  172. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  173. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  174. package/dist/production/lib/server-runtime/sessions.js +1 -1
  175. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  176. package/dist/production/lib/server-runtime/urls.js +1 -1
  177. package/dist/production/lib/server-runtime/warnings.js +1 -1
  178. package/dist/production/lib/types/internal.js +1 -1
  179. package/dist/production/lib/types/route-data.d.ts +2 -2
  180. package/dist/production/lib/types/route-module-annotations.d.ts +1 -1
  181. package/dist/production/route-pattern.js +1 -1
  182. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  183. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  184. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  185. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  186. package/docs/explanation/lazy-route-discovery.md +4 -0
  187. package/docs/explanation/sessions-and-cookies.md +108 -4
  188. package/docs/how-to/custom-fetch.md +218 -0
  189. package/docs/how-to/data-strategy.md +23 -1
  190. package/docs/how-to/middleware.md +1 -0
  191. package/docs/how-to/optimize-revalidation.md +2 -2
  192. package/docs/how-to/pre-rendering.md +23 -1
  193. package/docs/how-to/route-discovery.md +145 -0
  194. package/docs/how-to/spa.md +2 -0
  195. package/docs/how-to/view-transitions.md +80 -13
  196. package/docs/start/framework/navigating.md +5 -9
  197. package/docs/start/framework/rendering.md +37 -0
  198. package/package.json +9 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,11 +10,11 @@
10
10
  */
11
11
  import { useIsRSCRouterContext } from "../../context.js";
12
12
  import { useDataRouterContext, useDataRouterData, useDataRouterState, useLocation } from "../../hooks.js";
13
- import { warnOnce } from "../../server-runtime/warnings.js";
14
13
  import invariant from "./invariant.js";
15
14
  import { getKeyedLinksForMatches, getKeyedPrefetchLinks, getModuleLinkHrefs, getNewMatchesForLinks, isPageLinkDescriptor } from "./links.js";
16
15
  import { escapeHtml } from "./markup.js";
17
16
  import { singleFetchUrl } from "./single-fetch.js";
17
+ import { warnOnce } from "../../server-runtime/warnings.js";
18
18
  import { getPartialManifest, isFogOfWarEnabled } from "./fog-of-war.js";
19
19
  import * as React$1 from "react";
20
20
  //#region lib/dom/ssr/components.tsx
@@ -234,19 +234,21 @@ function useKeyedPrefetchLinks(matches) {
234
234
  }
235
235
  function RSCPrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
236
236
  let location = useLocation();
237
+ let { unstable_apiServerOrigin } = useFrameworkContext();
237
238
  let dataHrefs = React$1.useMemo(() => {
238
239
  if (page === location.pathname + location.search + location.hash) return [];
239
- let url = singleFetchUrl(page, "rsc");
240
+ let url = singleFetchUrl(page, "rsc", unstable_apiServerOrigin);
240
241
  let hasSomeRoutesWithShouldRevalidate = false;
241
242
  let targetRoutes = [];
242
243
  for (let match of nextMatches) if (typeof match.route.shouldRevalidate === "function") hasSomeRoutesWithShouldRevalidate = true;
243
244
  else targetRoutes.push(match.route.id);
244
245
  if (hasSomeRoutesWithShouldRevalidate && targetRoutes.length > 0) url.searchParams.set("_routes", targetRoutes.join(","));
245
- return [url.pathname + url.search];
246
+ return [unstable_apiServerOrigin ? url.toString() : url.pathname + url.search];
246
247
  }, [
247
248
  page,
248
249
  location,
249
- nextMatches
250
+ nextMatches,
251
+ unstable_apiServerOrigin
250
252
  ]);
251
253
  return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
252
254
  key: href,
@@ -258,7 +260,7 @@ function RSCPrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps })
258
260
  }
259
261
  function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
260
262
  let location = useLocation();
261
- let { manifest, routeModules } = useFrameworkContext();
263
+ let { manifest, routeModules, unstable_apiServerOrigin } = useFrameworkContext();
262
264
  let { matches } = useDataRouterState("PrefetchPageLinks");
263
265
  let { loaderData } = useDataRouterData("PrefetchPageLinks");
264
266
  let newMatchesForData = React$1.useMemo(() => getNewMatchesForLinks(page, nextMatches, matches, manifest, location, "data"), [
@@ -287,9 +289,9 @@ function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
287
289
  else routesParams.add(m.route.id);
288
290
  });
289
291
  if (routesParams.size === 0) return [];
290
- let url = singleFetchUrl(page, "data");
292
+ let url = singleFetchUrl(page, "data", unstable_apiServerOrigin);
291
293
  if (foundOptOutRoute && routesParams.size > 0) url.searchParams.set("_routes", nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(","));
292
- return [url.pathname + url.search];
294
+ return [unstable_apiServerOrigin ? url.toString() : url.pathname + url.search];
293
295
  }, [
294
296
  loaderData,
295
297
  location,
@@ -297,7 +299,8 @@ function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
297
299
  newMatchesForData,
298
300
  nextMatches,
299
301
  page,
300
- routeModules
302
+ routeModules,
303
+ unstable_apiServerOrigin
301
304
  ]);
302
305
  let moduleHrefs = React$1.useMemo(() => getModuleLinkHrefs(newMatchesForAssets, manifest), [newMatchesForAssets, manifest]);
303
306
  let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,8 +1,9 @@
1
1
 
2
2
  import { DataRouteObject, RouteBranch, RouteManifest } from "../../router/utils.js";
3
3
  import { StaticHandlerContext } from "../../router/router.js";
4
- import { RouteModules } from "./routeModules.js";
5
4
  import { EntryRoute } from "./routes.js";
5
+ import { RouteModules } from "./routeModules.js";
6
+ import { DiscoveryState, RouteDiscoveryRuntime } from "./route-discovery.js";
6
7
  import { ServerBuild } from "../../server-runtime/build.js";
7
8
 
8
9
  //#region lib/dom/ssr/entry.d.ts
@@ -11,6 +12,8 @@ type SerializedError = {
11
12
  stack?: string;
12
13
  };
13
14
  interface FrameworkContextObject {
15
+ routeDiscoveryRuntime?: RouteDiscoveryRuntime;
16
+ routeDiscoveryState?: DiscoveryState;
14
17
  manifest: AssetsManifest;
15
18
  routeModules: RouteModules;
16
19
  criticalCss?: CriticalCss;
@@ -18,6 +21,8 @@ interface FrameworkContextObject {
18
21
  future: FutureConfig;
19
22
  ssr: boolean;
20
23
  isSpaMode: boolean;
24
+ unstable_apiOnly?: boolean;
25
+ unstable_apiServerOrigin?: string;
21
26
  routeDiscovery: ServerBuild["routeDiscovery"];
22
27
  nonce?: string;
23
28
  serializeError?(error: Error): SerializedError;
@@ -41,7 +46,9 @@ interface EntryContext extends FrameworkContextObject {
41
46
  staticHandlerContext: StaticHandlerContext;
42
47
  serverHandoffStream?: ReadableStream<Uint8Array>;
43
48
  }
44
- type FutureConfig = Record<string, never>;
49
+ interface FutureConfig {
50
+ unstable_customRouteDiscovery?: boolean;
51
+ }
45
52
  type CriticalCss = string | {
46
53
  rel: "stylesheet";
47
54
  href: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -2,11 +2,12 @@
2
2
  import { PatchRoutesOnNavigationFunction } from "../../router/utils.js";
3
3
  import { Router } from "../../router/router.js";
4
4
  import { RouteModules } from "./routeModules.js";
5
+ import { RouterFetch } from "./single-fetch.js";
5
6
  import { AssetsManifest } from "./entry.js";
6
7
  import { ServerBuild } from "../../server-runtime/build.js";
7
8
 
8
9
  //#region lib/dom/ssr/fog-of-war.d.ts
9
- declare function getPatchRoutesOnNavigationFunction(getRouter: () => Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, routeDiscovery: ServerBuild["routeDiscovery"], isSpaMode: boolean, basename: string | undefined): PatchRoutesOnNavigationFunction | undefined;
10
- declare function useFogOFWarDiscovery(router: Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, routeDiscovery: ServerBuild["routeDiscovery"], isSpaMode: boolean): void;
10
+ declare function getPatchRoutesOnNavigationFunction(getRouter: () => Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, routeDiscovery: ServerBuild["routeDiscovery"], isSpaMode: boolean, basename: string | undefined, fetchImplementation?: RouterFetch, serverOrigin?: string, isApiOnly?: boolean): PatchRoutesOnNavigationFunction | undefined;
11
+ declare function useFogOFWarDiscovery(router: Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, routeDiscovery: ServerBuild["routeDiscovery"], isSpaMode: boolean, fetchImplementation?: RouterFetch, serverOrigin?: string, isApiOnly?: boolean): void;
11
12
  //#endregion
12
13
  export { getPatchRoutesOnNavigationFunction, useFogOFWarDiscovery };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -27,7 +27,7 @@ function getPathsWithAncestors(paths) {
27
27
  return Array.from(result);
28
28
  }
29
29
  function isFogOfWarEnabled(routeDiscovery, ssr) {
30
- return routeDiscovery.mode === "lazy" && ssr === true;
30
+ return routeDiscovery.mode === "lazy" && ssr;
31
31
  }
32
32
  function getPartialManifest({ sri, ...manifest }, router) {
33
33
  let routeIds = new Set(router.state.matches.map((m) => m.route.id));
@@ -49,15 +49,15 @@ function getPartialManifest({ sri, ...manifest }, router) {
49
49
  sri: sri ? true : void 0
50
50
  };
51
51
  }
52
- function getPatchRoutesOnNavigationFunction(getRouter, manifest, routeModules, ssr, routeDiscovery, isSpaMode, basename) {
52
+ function getPatchRoutesOnNavigationFunction(getRouter, manifest, routeModules, ssr, routeDiscovery, isSpaMode, basename, fetchImplementation = (request) => fetch(request), serverOrigin, isApiOnly = false) {
53
53
  if (!isFogOfWarEnabled(routeDiscovery, ssr)) return;
54
54
  return async ({ path, patch, signal, fetcherKey }) => {
55
55
  if (discoveredPaths.has(path)) return;
56
56
  let { state } = getRouter();
57
- await fetchAndApplyManifestPatches([path], fetcherKey ? window.location.href : createPath(state.navigation.location || state.location), manifest, routeModules, ssr, isSpaMode, basename, routeDiscovery.manifestPath, patch, signal);
57
+ await fetchAndApplyManifestPatches([path], fetcherKey ? window.location.href : createPath(state.navigation.location || state.location), manifest, routeModules, ssr, isSpaMode, basename, routeDiscovery.manifestPath, patch, signal, fetchImplementation, serverOrigin, isApiOnly);
58
58
  };
59
59
  }
60
- function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscovery, isSpaMode) {
60
+ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscovery, isSpaMode, fetchImplementation = (request) => fetch(request), serverOrigin, isApiOnly = false) {
61
61
  React$1.useEffect(() => {
62
62
  if (!isFogOfWarEnabled(routeDiscovery, ssr) || window.navigator?.connection?.saveData === true) return;
63
63
  function registerElement(el) {
@@ -77,7 +77,7 @@ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscover
77
77
  });
78
78
  if (lazyPaths.length === 0) return;
79
79
  try {
80
- await fetchAndApplyManifestPatches(lazyPaths, null, manifest, routeModules, ssr, isSpaMode, router.basename, routeDiscovery.manifestPath, router.patchRoutes);
80
+ await fetchAndApplyManifestPatches(lazyPaths, null, manifest, routeModules, ssr, isSpaMode, router.basename, routeDiscovery.manifestPath, router.patchRoutes, void 0, fetchImplementation, serverOrigin, isApiOnly);
81
81
  } catch (e) {
82
82
  console.error("Failed to fetch manifest patches", e);
83
83
  }
@@ -102,7 +102,10 @@ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscover
102
102
  manifest,
103
103
  routeModules,
104
104
  router,
105
- routeDiscovery
105
+ routeDiscovery,
106
+ fetchImplementation,
107
+ serverOrigin,
108
+ isApiOnly
106
109
  ]);
107
110
  }
108
111
  function getManifestPath(_manifestPath, basename) {
@@ -154,12 +157,12 @@ async function handleClientVersionMismatch(needsReload, version, errorReloadPath
154
157
  }
155
158
  return reloadPromise;
156
159
  }
157
- async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
160
+ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal, fetchImplementation = (request) => fetch(request), serverOrigin, isApiOnly = false) {
158
161
  paths = getPathsWithAncestors(paths);
159
162
  const searchParams = new URLSearchParams();
160
163
  searchParams.set("paths", paths.sort().join(","));
161
164
  searchParams.set("version", manifest.version);
162
- let url = new URL(getManifestPath(manifestPath, basename), window.location.origin);
165
+ let url = new URL(getManifestPath(manifestPath, basename), serverOrigin ?? window.location.origin);
163
166
  url.search = searchParams.toString();
164
167
  if (url.toString().length > 7680) {
165
168
  nextPaths.clear();
@@ -167,7 +170,7 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
167
170
  }
168
171
  let serverPatches;
169
172
  try {
170
- let res = await fetch(url, { signal });
173
+ let res = await fetchImplementation(new Request(url, { signal }), { type: "manifest" });
171
174
  if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
172
175
  if (await handleClientVersionMismatch(res.status === 204 && res.headers.has("X-Remix-Reload-Document"), manifest.version, errorReloadPath)) return;
173
176
  serverPatches = await res.json();
@@ -187,7 +190,7 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
187
190
  Object.values(patches).forEach((patch) => {
188
191
  if (patch && (!patch.parentId || !patches[patch.parentId])) parentIds.add(patch.parentId);
189
192
  });
190
- parentIds.forEach((parentId) => patchRoutes(parentId || null, createClientRoutes(patches, routeModules, null, ssr, isSpaMode, parentId)));
193
+ parentIds.forEach((parentId) => patchRoutes(parentId || null, createClientRoutes(patches, routeModules, null, ssr, isSpaMode, parentId, void 0, void 0, isApiOnly)));
191
194
  }
192
195
  function addToFifoQueue(path, queue) {
193
196
  if (queue.size >= discoveredPathsMaxSize) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.4.0
2
+ * react-router v8.5.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -0,0 +1,120 @@
1
+
2
+ import { PatchRoutesOnNavigationFunction, RouteObject } from "../../router/utils.js";
3
+ import { Router } from "../../router/router.js";
4
+ import { ClientOnErrorFunction } from "../../components.js";
5
+ import { RouteModules } from "./routeModules.js";
6
+ import { RouterFetch } from "./single-fetch.js";
7
+ import { WindowReactRouterContext } from "../global.js";
8
+ import { AssetsManifest } from "./entry.js";
9
+
10
+ //#region lib/dom/ssr/route-discovery.d.ts
11
+ /** A discovery response from a different build. */
12
+ type ManifestMismatchEvent = {
13
+ source: "eager" | "navigation" | "fetcher" | "imperative";
14
+ version: string;
15
+ reloadUrl: string | null;
16
+ loadAllRoutes(): Promise<void>;
17
+ stopPropagation(): void; /** Run built-in recovery for this source, at most once per mismatch event. */
18
+ defaultBehavior(): Promise<void>;
19
+ };
20
+ /** The result of imperative route discovery. */
21
+ type DiscoveryResult = {
22
+ type: "success";
23
+ } | {
24
+ type: "version-mismatch";
25
+ } | {
26
+ type: "aborted";
27
+ };
28
+ /** Options for {@link unstable_useRouteDiscovery}. */
29
+ type RouteDiscoveryOptions = {
30
+ onManifestMismatch?: (event: ManifestMismatchEvent) => void | Promise<void>;
31
+ };
32
+ type Registration = {
33
+ current: RouteDiscoveryOptions;
34
+ };
35
+ type DiscoveryState = "partial" | "loading" | "complete";
36
+ type RouteDiscoverySsrInfo = {
37
+ manifest: AssetsManifest;
38
+ routeModules: RouteModules;
39
+ router: Router | undefined;
40
+ context: Pick<WindowReactRouterContext, "ssr" | "routeDiscovery" | "isSpaMode" | "basename" | "unstable_apiServerOrigin" | "unstable_apiOnly">;
41
+ };
42
+ declare class RouteDiscoveryRuntime {
43
+ private ssrInfo;
44
+ readonly enabled: boolean;
45
+ readonly discoveredPaths: Set<string>;
46
+ readonly nextPaths: Set<string>;
47
+ state: DiscoveryState;
48
+ ready: boolean;
49
+ private registrations;
50
+ private listeners;
51
+ private fullLoadErrorListeners;
52
+ private fullLoad?;
53
+ private loadedManifest?;
54
+ private mismatch?;
55
+ private fetchImplementation;
56
+ private loadManifest;
57
+ onError?: ClientOnErrorFunction;
58
+ constructor(ssrInfo: RouteDiscoverySsrInfo, {
59
+ fetch: fetchImplementation,
60
+ loadManifest
61
+ }?: {
62
+ fetch?: RouterFetch;
63
+ loadManifest?: () => Promise<AssetsManifest>;
64
+ });
65
+ private get router();
66
+ private loadManifestAsset;
67
+ subscribe: (listener: () => void) => () => void;
68
+ private update;
69
+ markReady: () => void;
70
+ register(registration: Registration): () => void;
71
+ private isComplete;
72
+ loadAllRoutes: () => Promise<void>;
73
+ reportError(error: unknown): void;
74
+ private dispatchMismatch;
75
+ private requestUrl;
76
+ discoverRoutes: (paths: string[], options?: {
77
+ signal?: AbortSignal;
78
+ }) => Promise<DiscoveryResult>;
79
+ discover(paths: string[], source: ManifestMismatchEvent["source"], reloadUrl: string | null, signal?: AbortSignal, patch?: (routeId: string | null, children: RouteObject[], unstable_allowElementMutations?: boolean) => void): Promise<DiscoveryResult>;
80
+ }
81
+ /**
82
+ * Control lazy route discovery in Framework Mode with `future.unstable_customRouteDiscovery`
83
+ * enabled. This allows you to imperatively discover routes as well as add custom behavior
84
+ * when a manifest version mismatch is detected. Calling `loadAllRoutes` will load the entire
85
+ * route manifest for the current (potentially stale) client version - this requires that prior
86
+ * client artifacts are still available on your CDN _and_ you have not made breaking changes to
87
+ * the API contracts of your loaders and actions.
88
+ *
89
+ * See the [Route Discovery guide](../../how-to/route-discovery) for more information and examples.
90
+ *
91
+ * @example
92
+ * let { state, discoverRoutes, loadAllRoutes } = unstable_useRouteDiscovery({
93
+ * onManifestMismatch: async (event) => {
94
+ * // Eagerly load the complete route tree for this client without requiring a hard reload
95
+ * await event.loadAllRoutes();
96
+ * },
97
+ * });
98
+ *
99
+ * // Eagerly discover specific routes
100
+ * discoverRoutes(["/a", "/b"]);
101
+ *
102
+ * @name unstable_useRouteDiscovery
103
+ * @public
104
+ * @category Hooks
105
+ * @mode framework
106
+ * @param options An awaited manifest-mismatch handler.
107
+ * @returns The client version, full-manifest loading state, and discovery operations.
108
+ */
109
+ declare function useRouteDiscovery(options?: RouteDiscoveryOptions): {
110
+ version: string;
111
+ state: DiscoveryState;
112
+ loadAllRoutes: () => Promise<void>;
113
+ discoverRoutes: (paths: string[], options?: {
114
+ signal?: AbortSignal;
115
+ }) => Promise<DiscoveryResult>;
116
+ };
117
+ declare function getCustomPatchRoutesOnNavigationFunction(getRouter: () => Router, runtime: RouteDiscoveryRuntime): PatchRoutesOnNavigationFunction | undefined;
118
+ declare function useCustomRouteDiscovery(runtime: RouteDiscoveryRuntime, onError?: ClientOnErrorFunction): "partial" | "loading" | "complete";
119
+ //#endregion
120
+ export { DiscoveryResult, DiscoveryState, ManifestMismatchEvent, RouteDiscoveryOptions, RouteDiscoveryRuntime, getCustomPatchRoutesOnNavigationFunction, useCustomRouteDiscovery, useRouteDiscovery };