react-router 7.18.0 → 8.0.0-pre.1

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 (285) hide show
  1. package/dist/development/dom-export.d.ts +6 -172
  2. package/dist/development/dom-export.js +12 -1009
  3. package/dist/development/index-react-server-client.d.ts +7 -4
  4. package/dist/development/index-react-server-client.js +8 -52
  5. package/dist/development/index-react-server.d.ts +1650 -1641
  6. package/dist/development/index-react-server.js +2882 -3664
  7. package/dist/development/index.d.ts +42 -1476
  8. package/dist/development/index.js +36 -2553
  9. package/dist/development/lib/actions.js +50 -0
  10. package/dist/development/lib/components.d.ts +1030 -0
  11. package/dist/development/lib/components.js +841 -0
  12. package/dist/development/lib/context.d.ts +83 -0
  13. package/dist/development/lib/context.js +41 -0
  14. package/dist/development/lib/dom/dom.d.ts +119 -0
  15. package/dist/development/lib/dom/dom.js +143 -0
  16. package/dist/development/lib/dom/lib.d.ts +2053 -0
  17. package/dist/development/lib/dom/lib.js +1271 -0
  18. package/dist/development/lib/dom/server.d.ts +138 -0
  19. package/dist/development/lib/dom/server.js +301 -0
  20. package/dist/development/lib/dom/ssr/components.d.ts +198 -0
  21. package/dist/development/lib/dom/ssr/components.js +589 -0
  22. package/dist/development/lib/dom/ssr/data.js +29 -0
  23. package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
  24. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
  26. package/dist/development/lib/dom/ssr/fallback.js +33 -0
  27. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  28. package/dist/development/lib/dom/ssr/fog-of-war.js +180 -0
  29. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  30. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  31. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  32. package/dist/development/lib/dom/ssr/links.js +170 -0
  33. package/dist/development/lib/dom/ssr/markup.js +24 -0
  34. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  35. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  36. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  37. package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
  38. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  39. package/dist/development/lib/dom/ssr/routes.js +303 -0
  40. package/dist/development/lib/dom/ssr/server.d.ts +48 -0
  41. package/dist/development/lib/dom/ssr/server.js +69 -0
  42. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  43. package/dist/development/lib/dom/ssr/single-fetch.js +345 -0
  44. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  45. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  46. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  47. package/dist/development/lib/dom-export/hydrated-router.js +150 -0
  48. package/dist/development/lib/errors.js +29 -0
  49. package/dist/development/lib/hooks.d.ts +947 -0
  50. package/dist/development/lib/hooks.js +1388 -0
  51. package/dist/development/lib/href.d.ts +20 -0
  52. package/dist/development/lib/href.js +50 -0
  53. package/dist/development/lib/router/history.d.ts +258 -0
  54. package/dist/development/lib/router/history.js +372 -0
  55. package/dist/development/lib/router/instrumentation.d.ts +86 -0
  56. package/dist/development/lib/router/instrumentation.js +213 -0
  57. package/dist/development/lib/router/links.d.ts +114 -0
  58. package/dist/development/lib/router/router.d.ts +663 -0
  59. package/dist/development/lib/router/router.js +2988 -0
  60. package/dist/development/lib/router/url.js +18 -0
  61. package/dist/development/lib/router/utils.d.ts +948 -0
  62. package/dist/development/lib/router/utils.js +810 -0
  63. package/dist/development/lib/rsc/browser.d.ts +137 -0
  64. package/dist/development/lib/rsc/browser.js +603 -0
  65. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  66. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  67. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  68. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  69. package/dist/development/lib/rsc/html-stream/server.js +78 -0
  70. package/dist/development/lib/rsc/route-modules.js +27 -0
  71. package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
  72. package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
  73. package/dist/development/lib/rsc/server.ssr.js +404 -0
  74. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  75. package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
  76. package/dist/development/lib/server-runtime/cookies.js +139 -0
  77. package/dist/development/lib/server-runtime/crypto.js +43 -0
  78. package/dist/development/lib/server-runtime/data.d.ts +13 -0
  79. package/dist/development/lib/server-runtime/data.js +25 -0
  80. package/dist/development/lib/server-runtime/dev.d.ts +9 -0
  81. package/dist/development/lib/server-runtime/dev.js +26 -0
  82. package/dist/development/lib/server-runtime/entry.js +20 -0
  83. package/dist/development/lib/server-runtime/errors.js +75 -0
  84. package/dist/development/lib/server-runtime/headers.js +73 -0
  85. package/dist/development/lib/server-runtime/invariant.js +19 -0
  86. package/dist/development/lib/server-runtime/mode.d.ts +12 -0
  87. package/dist/development/lib/server-runtime/mode.js +25 -0
  88. package/dist/development/lib/server-runtime/routeMatching.js +28 -0
  89. package/dist/development/lib/server-runtime/routes.d.ts +13 -0
  90. package/dist/development/lib/server-runtime/routes.js +74 -0
  91. package/dist/development/lib/server-runtime/server.d.ts +10 -0
  92. package/dist/development/lib/server-runtime/server.js +345 -0
  93. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  94. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  95. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
  96. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  97. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
  98. package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
  99. package/dist/development/lib/server-runtime/sessions.js +98 -0
  100. package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
  101. package/dist/development/lib/server-runtime/single-fetch.js +215 -0
  102. package/dist/development/lib/server-runtime/urls.js +28 -0
  103. package/dist/development/lib/server-runtime/warnings.js +20 -0
  104. package/dist/development/lib/types/future.d.ts +9 -0
  105. package/dist/development/lib/types/internal.d.ts +26 -177
  106. package/dist/development/lib/types/internal.js +3 -2
  107. package/dist/development/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  108. package/dist/development/lib/types/route-data.d.ts +113 -0
  109. package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
  110. package/dist/development/lib/types/route-module.d.ts +19 -0
  111. package/dist/development/lib/types/serializes-to.d.ts +13 -0
  112. package/dist/development/lib/types/utils.d.ts +11 -0
  113. package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
  114. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  115. package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
  116. package/dist/development/vendor/turbo-stream-v2/utils.js +39 -0
  117. package/dist/production/dom-export.d.ts +6 -172
  118. package/dist/production/dom-export.js +12 -1009
  119. package/dist/production/index-react-server-client.d.ts +7 -4
  120. package/dist/production/index-react-server-client.js +8 -52
  121. package/dist/production/index-react-server.d.ts +1650 -1641
  122. package/dist/production/index-react-server.js +2873 -3664
  123. package/dist/production/index.d.ts +42 -1476
  124. package/dist/production/index.js +36 -2553
  125. package/dist/production/lib/actions.js +50 -0
  126. package/dist/production/lib/components.d.ts +1030 -0
  127. package/dist/production/lib/components.js +841 -0
  128. package/dist/production/lib/context.d.ts +83 -0
  129. package/dist/production/lib/context.js +41 -0
  130. package/dist/production/lib/dom/dom.d.ts +119 -0
  131. package/dist/production/lib/dom/dom.js +143 -0
  132. package/dist/production/lib/dom/lib.d.ts +2053 -0
  133. package/dist/production/lib/dom/lib.js +1271 -0
  134. package/dist/production/lib/dom/server.d.ts +138 -0
  135. package/dist/production/lib/dom/server.js +301 -0
  136. package/dist/production/lib/dom/ssr/components.d.ts +198 -0
  137. package/dist/production/lib/dom/ssr/components.js +589 -0
  138. package/dist/production/lib/dom/ssr/data.js +29 -0
  139. package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
  140. package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  141. package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
  142. package/dist/production/lib/dom/ssr/fallback.js +23 -0
  143. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
  144. package/dist/production/lib/dom/ssr/fog-of-war.js +180 -0
  145. package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
  146. package/dist/production/lib/dom/ssr/hydration.js +29 -0
  147. package/dist/production/lib/dom/ssr/invariant.js +16 -0
  148. package/dist/production/lib/dom/ssr/links.js +170 -0
  149. package/dist/production/lib/dom/ssr/markup.js +24 -0
  150. package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
  151. package/dist/production/lib/dom/ssr/routeModules.js +31 -0
  152. package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  153. package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
  154. package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
  155. package/dist/production/lib/dom/ssr/routes.js +303 -0
  156. package/dist/production/lib/dom/ssr/server.d.ts +48 -0
  157. package/dist/production/lib/dom/ssr/server.js +69 -0
  158. package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
  159. package/dist/production/lib/dom/ssr/single-fetch.js +345 -0
  160. package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
  161. package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
  162. package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
  163. package/dist/production/lib/dom-export/hydrated-router.js +150 -0
  164. package/dist/production/lib/errors.js +29 -0
  165. package/dist/production/lib/hooks.d.ts +947 -0
  166. package/dist/production/lib/hooks.js +1373 -0
  167. package/dist/production/lib/href.d.ts +20 -0
  168. package/dist/production/lib/href.js +50 -0
  169. package/dist/production/lib/router/history.d.ts +258 -0
  170. package/dist/production/lib/router/history.js +372 -0
  171. package/dist/production/lib/router/instrumentation.d.ts +86 -0
  172. package/dist/production/lib/router/instrumentation.js +213 -0
  173. package/dist/production/lib/router/links.d.ts +114 -0
  174. package/dist/production/lib/router/router.d.ts +663 -0
  175. package/dist/production/lib/router/router.js +2988 -0
  176. package/dist/production/lib/router/url.js +18 -0
  177. package/dist/production/lib/router/utils.d.ts +948 -0
  178. package/dist/production/lib/router/utils.js +801 -0
  179. package/dist/production/lib/rsc/browser.d.ts +137 -0
  180. package/dist/production/lib/rsc/browser.js +603 -0
  181. package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
  182. package/dist/production/lib/rsc/errorBoundaries.js +90 -0
  183. package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
  184. package/dist/production/lib/rsc/html-stream/browser.js +74 -0
  185. package/dist/production/lib/rsc/html-stream/server.js +78 -0
  186. package/dist/production/lib/rsc/route-modules.js +27 -0
  187. package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
  188. package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
  189. package/dist/production/lib/rsc/server.ssr.js +404 -0
  190. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  191. package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
  192. package/dist/production/lib/server-runtime/cookies.js +139 -0
  193. package/dist/production/lib/server-runtime/crypto.js +43 -0
  194. package/dist/production/lib/server-runtime/data.d.ts +13 -0
  195. package/dist/production/lib/server-runtime/data.js +25 -0
  196. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  197. package/dist/production/lib/server-runtime/dev.js +26 -0
  198. package/dist/production/lib/server-runtime/entry.js +20 -0
  199. package/dist/production/lib/server-runtime/errors.js +75 -0
  200. package/dist/production/lib/server-runtime/headers.js +73 -0
  201. package/dist/production/lib/server-runtime/invariant.js +19 -0
  202. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  203. package/dist/production/lib/server-runtime/mode.js +25 -0
  204. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  205. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  206. package/dist/production/lib/server-runtime/routes.js +74 -0
  207. package/dist/production/lib/server-runtime/server.d.ts +10 -0
  208. package/dist/production/lib/server-runtime/server.js +345 -0
  209. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  210. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  211. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
  212. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  213. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
  214. package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
  215. package/dist/production/lib/server-runtime/sessions.js +98 -0
  216. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  217. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  218. package/dist/production/lib/server-runtime/urls.js +28 -0
  219. package/dist/production/lib/server-runtime/warnings.js +20 -0
  220. package/dist/production/lib/types/future.d.ts +9 -0
  221. package/dist/production/lib/types/internal.d.ts +26 -177
  222. package/dist/production/lib/types/internal.js +3 -2
  223. package/dist/production/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  224. package/dist/production/lib/types/route-data.d.ts +113 -0
  225. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  226. package/dist/production/lib/types/route-module.d.ts +19 -0
  227. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  228. package/dist/production/lib/types/utils.d.ts +11 -0
  229. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  230. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  231. package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
  232. package/dist/production/vendor/turbo-stream-v2/utils.js +39 -0
  233. package/docs/explanation/code-splitting.md +16 -0
  234. package/docs/how-to/middleware.md +6 -41
  235. package/docs/how-to/react-server-components.md +1 -1
  236. package/docs/upgrading/future.md +0 -249
  237. package/package.json +43 -87
  238. package/dist/development/browser-B2PdsXXH.d.ts +0 -318
  239. package/dist/development/browser-DBmQ1yAR.d.mts +0 -318
  240. package/dist/development/chunk-4ZMWKKQ3.mjs +0 -11606
  241. package/dist/development/chunk-E4MTK73K.mjs +0 -2517
  242. package/dist/development/chunk-U7ORXROY.js +0 -10307
  243. package/dist/development/chunk-WW7PN6QI.js +0 -188
  244. package/dist/development/chunk-YL5M26XI.js +0 -1366
  245. package/dist/development/context-CeD5LmaF.d.mts +0 -1779
  246. package/dist/development/data-CjO11-hU.d.ts +0 -1740
  247. package/dist/development/data-DEjBmEfD.d.mts +0 -1740
  248. package/dist/development/dom-export.d.mts +0 -172
  249. package/dist/development/dom-export.mjs +0 -1010
  250. package/dist/development/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  251. package/dist/development/index-react-server-client-CACgcj2J.d.mts +0 -2614
  252. package/dist/development/index-react-server-client.d.mts +0 -4
  253. package/dist/development/index-react-server-client.mjs +0 -59
  254. package/dist/development/index-react-server.d.mts +0 -2711
  255. package/dist/development/index-react-server.mjs +0 -3803
  256. package/dist/development/index.d.mts +0 -1479
  257. package/dist/development/index.mjs +0 -275
  258. package/dist/development/instrumentation-Dkmpzd13.d.ts +0 -715
  259. package/dist/development/lib/types/internal.d.mts +0 -184
  260. package/dist/development/lib/types/internal.mjs +0 -10
  261. package/dist/development/register-CmkRspdl.d.mts +0 -30
  262. package/dist/production/browser-B2PdsXXH.d.ts +0 -318
  263. package/dist/production/browser-DBmQ1yAR.d.mts +0 -318
  264. package/dist/production/chunk-3Z6WS2WZ.js +0 -188
  265. package/dist/production/chunk-BIP66BKV.js +0 -1366
  266. package/dist/production/chunk-EGOTSXNH.mjs +0 -2517
  267. package/dist/production/chunk-IUPBOWYO.js +0 -10307
  268. package/dist/production/chunk-M7NGGUU6.mjs +0 -11606
  269. package/dist/production/context-CeD5LmaF.d.mts +0 -1779
  270. package/dist/production/data-CjO11-hU.d.ts +0 -1740
  271. package/dist/production/data-DEjBmEfD.d.mts +0 -1740
  272. package/dist/production/dom-export.d.mts +0 -172
  273. package/dist/production/dom-export.mjs +0 -1010
  274. package/dist/production/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  275. package/dist/production/index-react-server-client-CACgcj2J.d.mts +0 -2614
  276. package/dist/production/index-react-server-client.d.mts +0 -4
  277. package/dist/production/index-react-server-client.mjs +0 -59
  278. package/dist/production/index-react-server.d.mts +0 -2711
  279. package/dist/production/index-react-server.mjs +0 -3803
  280. package/dist/production/index.d.mts +0 -1479
  281. package/dist/production/index.mjs +0 -275
  282. package/dist/production/instrumentation-Dkmpzd13.d.ts +0 -715
  283. package/dist/production/lib/types/internal.d.mts +0 -184
  284. package/dist/production/lib/types/internal.mjs +0 -10
  285. package/dist/production/register-CmkRspdl.d.mts +0 -30
@@ -0,0 +1,345 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { ErrorResponseImpl, SUPPORTED_ERROR_TYPES, data, isRouteErrorResponse, redirect } from "../../router/utils.js";
12
+ import { isDataWithResponseInit, isResponse } from "../../router/router.js";
13
+ import invariant from "./invariant.js";
14
+ import { escapeHtml } from "./markup.js";
15
+ import { decode } from "../../../vendor/turbo-stream-v2/turbo-stream.js";
16
+ import { createRequestInit } from "./data.js";
17
+ import * as React$1 from "react";
18
+ //#region lib/dom/ssr/single-fetch.tsx
19
+ const SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
20
+ var SingleFetchNoResultError = class extends Error {};
21
+ const NO_BODY_STATUS_CODES = new Set([
22
+ 100,
23
+ 101,
24
+ 204,
25
+ 205
26
+ ]);
27
+ function StreamTransfer({ context, identifier, reader, textDecoder, nonce }) {
28
+ if (!context.renderMeta || !context.renderMeta.didRenderScripts) return null;
29
+ if (!context.renderMeta.streamCache) context.renderMeta.streamCache = {};
30
+ let { streamCache } = context.renderMeta;
31
+ let promise = streamCache[identifier];
32
+ if (!promise) promise = streamCache[identifier] = reader.read().then((result) => {
33
+ streamCache[identifier].result = {
34
+ done: result.done,
35
+ value: textDecoder.decode(result.value, { stream: true })
36
+ };
37
+ }).catch((e) => {
38
+ streamCache[identifier].error = e;
39
+ });
40
+ if (promise.error) throw promise.error;
41
+ if (promise.result === void 0) throw promise;
42
+ let { done, value } = promise.result;
43
+ let scriptTag = value ? /* @__PURE__ */ React$1.createElement("script", {
44
+ nonce,
45
+ dangerouslySetInnerHTML: { __html: `window.__reactRouterContext.streamController.enqueue(${escapeHtml(JSON.stringify(value))});` }
46
+ }) : null;
47
+ if (done) return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, scriptTag, /* @__PURE__ */ React$1.createElement("script", {
48
+ nonce,
49
+ dangerouslySetInnerHTML: { __html: `window.__reactRouterContext.streamController.close();` }
50
+ }));
51
+ else return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, scriptTag, /* @__PURE__ */ React$1.createElement(React$1.Suspense, null, /* @__PURE__ */ React$1.createElement(StreamTransfer, {
52
+ context,
53
+ identifier: identifier + 1,
54
+ reader,
55
+ textDecoder,
56
+ nonce
57
+ })));
58
+ }
59
+ function getTurboStreamSingleFetchDataStrategy(getRouter, manifest, routeModules, ssr) {
60
+ let dataStrategy = getSingleFetchDataStrategyImpl(getRouter, (match) => {
61
+ let manifestRoute = manifest.routes[match.route.id];
62
+ invariant(manifestRoute, "Route not found in manifest");
63
+ return {
64
+ hasLoader: manifestRoute.hasLoader,
65
+ hasClientLoader: manifestRoute.hasClientLoader
66
+ };
67
+ }, fetchAndDecodeViaTurboStream, ssr);
68
+ return async (args) => args.runClientMiddleware(dataStrategy);
69
+ }
70
+ function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, shouldAllowOptOut = () => true) {
71
+ return async (args) => {
72
+ let { request, matches, fetcherKey } = args;
73
+ let router = getRouter();
74
+ if (request.method !== "GET") return singleFetchActionStrategy(args, fetchAndDecode);
75
+ let foundRevalidatingServerLoader = matches.some((m) => {
76
+ let { hasLoader, hasClientLoader } = getRouteInfo(m);
77
+ return m.shouldCallHandler() && hasLoader && !hasClientLoader;
78
+ });
79
+ if (!ssr && !foundRevalidatingServerLoader) return nonSsrStrategy(args, getRouteInfo, fetchAndDecode);
80
+ if (fetcherKey) return singleFetchLoaderFetcherStrategy(args, fetchAndDecode);
81
+ return singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, fetchAndDecode, ssr, shouldAllowOptOut);
82
+ };
83
+ }
84
+ async function singleFetchActionStrategy(args, fetchAndDecode) {
85
+ let actionMatch = args.matches.find((m) => m.shouldCallHandler());
86
+ invariant(actionMatch, "No action match found");
87
+ let actionStatus = void 0;
88
+ let result = await actionMatch.resolve(async (handler) => {
89
+ return await handler(async () => {
90
+ let { data, status } = await fetchAndDecode(args, [actionMatch.route.id]);
91
+ actionStatus = status;
92
+ return unwrapSingleFetchResult(data, actionMatch.route.id);
93
+ });
94
+ });
95
+ if (isResponse(result.result) || isRouteErrorResponse(result.result) || isDataWithResponseInit(result.result)) return { [actionMatch.route.id]: result };
96
+ return { [actionMatch.route.id]: {
97
+ type: result.type,
98
+ result: data(result.result, actionStatus)
99
+ } };
100
+ }
101
+ async function nonSsrStrategy(args, getRouteInfo, fetchAndDecode) {
102
+ let matchesToLoad = args.matches.filter((m) => m.shouldCallHandler());
103
+ let results = {};
104
+ await Promise.all(matchesToLoad.map((m) => m.resolve(async (handler) => {
105
+ try {
106
+ let { hasClientLoader } = getRouteInfo(m);
107
+ let routeId = m.route.id;
108
+ let result = hasClientLoader ? await handler(async () => {
109
+ let { data } = await fetchAndDecode(args, [routeId]);
110
+ return unwrapSingleFetchResult(data, routeId);
111
+ }) : await handler();
112
+ results[m.route.id] = {
113
+ type: "data",
114
+ result
115
+ };
116
+ } catch (e) {
117
+ results[m.route.id] = {
118
+ type: "error",
119
+ result: e
120
+ };
121
+ }
122
+ })));
123
+ return results;
124
+ }
125
+ async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, fetchAndDecode, ssr, shouldAllowOptOut = () => true) {
126
+ let routesParams = /* @__PURE__ */ new Set();
127
+ let foundOptOutRoute = false;
128
+ let routeDfds = args.matches.map(() => createDeferred());
129
+ let singleFetchDfd = createDeferred();
130
+ let results = {};
131
+ let resolvePromise = Promise.all(args.matches.map(async (m, i) => m.resolve(async (handler) => {
132
+ routeDfds[i].resolve();
133
+ let routeId = m.route.id;
134
+ let { hasLoader, hasClientLoader } = getRouteInfo(m);
135
+ let defaultShouldRevalidate = !m.shouldRevalidateArgs || m.shouldRevalidateArgs.actionStatus == null || m.shouldRevalidateArgs.actionStatus < 400;
136
+ if (!m.shouldCallHandler(defaultShouldRevalidate)) {
137
+ foundOptOutRoute ||= m.shouldRevalidateArgs != null && hasLoader;
138
+ return;
139
+ }
140
+ if (shouldAllowOptOut(m) && hasClientLoader) {
141
+ if (hasLoader) foundOptOutRoute = true;
142
+ try {
143
+ results[routeId] = {
144
+ type: "data",
145
+ result: await handler(async () => {
146
+ let { data } = await fetchAndDecode(args, [routeId]);
147
+ return unwrapSingleFetchResult(data, routeId);
148
+ })
149
+ };
150
+ } catch (e) {
151
+ results[routeId] = {
152
+ type: "error",
153
+ result: e
154
+ };
155
+ }
156
+ return;
157
+ }
158
+ if (hasLoader) routesParams.add(routeId);
159
+ try {
160
+ results[routeId] = {
161
+ type: "data",
162
+ result: await handler(async () => {
163
+ return unwrapSingleFetchResult(await singleFetchDfd.promise, routeId);
164
+ })
165
+ };
166
+ } catch (e) {
167
+ results[routeId] = {
168
+ type: "error",
169
+ result: e
170
+ };
171
+ }
172
+ })));
173
+ await Promise.all(routeDfds.map((d) => d.promise));
174
+ if ((!router.state.initialized && router.state.navigation.state === "idle" || routesParams.size === 0) && !window.__reactRouterHdrActive) singleFetchDfd.resolve({ routes: {} });
175
+ else {
176
+ let targetRoutes = ssr && foundOptOutRoute && routesParams.size > 0 ? [...routesParams.keys()] : void 0;
177
+ try {
178
+ let data = await fetchAndDecode(args, targetRoutes);
179
+ singleFetchDfd.resolve(data.data);
180
+ } catch (e) {
181
+ singleFetchDfd.reject(e);
182
+ }
183
+ }
184
+ await resolvePromise;
185
+ await bubbleMiddlewareErrors(singleFetchDfd.promise, args.matches, routesParams, results);
186
+ return results;
187
+ }
188
+ async function bubbleMiddlewareErrors(singleFetchPromise, matches, routesParams, results) {
189
+ try {
190
+ let middlewareError;
191
+ let fetchedData = await singleFetchPromise;
192
+ if ("routes" in fetchedData) {
193
+ for (let match of matches) if (match.route.id in fetchedData.routes) {
194
+ let routeResult = fetchedData.routes[match.route.id];
195
+ if ("error" in routeResult) {
196
+ middlewareError = routeResult.error;
197
+ if (results[match.route.id]?.result == null) results[match.route.id] = {
198
+ type: "error",
199
+ result: middlewareError
200
+ };
201
+ break;
202
+ }
203
+ }
204
+ }
205
+ if (middlewareError !== void 0) Array.from(routesParams.values()).forEach((routeId) => {
206
+ if (results[routeId].result instanceof SingleFetchNoResultError) results[routeId].result = middlewareError;
207
+ });
208
+ } catch (e) {}
209
+ }
210
+ async function singleFetchLoaderFetcherStrategy(args, fetchAndDecode) {
211
+ let fetcherMatch = args.matches.find((m) => m.shouldCallHandler());
212
+ invariant(fetcherMatch, "No fetcher match found");
213
+ let routeId = fetcherMatch.route.id;
214
+ let result = await fetcherMatch.resolve(async (handler) => handler(async () => {
215
+ let { data } = await fetchAndDecode(args, [routeId]);
216
+ return unwrapSingleFetchResult(data, routeId);
217
+ }));
218
+ return { [fetcherMatch.route.id]: result };
219
+ }
220
+ function stripIndexParam(url) {
221
+ let indexValues = url.searchParams.getAll("index");
222
+ url.searchParams.delete("index");
223
+ let indexValuesToKeep = [];
224
+ for (let indexValue of indexValues) if (indexValue) indexValuesToKeep.push(indexValue);
225
+ for (let toKeep of indexValuesToKeep) url.searchParams.append("index", toKeep);
226
+ return url;
227
+ }
228
+ function singleFetchUrl(reqUrl, extension) {
229
+ let url = typeof reqUrl === "string" ? new URL(reqUrl, typeof window === "undefined" ? "server://singlefetch/" : window.location.origin) : reqUrl;
230
+ if (url.pathname.endsWith("/")) url.pathname = `${url.pathname}_.${extension}`;
231
+ else url.pathname = `${url.pathname}.${extension}`;
232
+ return url;
233
+ }
234
+ async function fetchAndDecodeViaTurboStream(args, targetRoutes) {
235
+ let { request } = args;
236
+ let url = singleFetchUrl(request.url, "data");
237
+ if (request.method === "GET") {
238
+ url = stripIndexParam(url);
239
+ if (targetRoutes) url.searchParams.set("_routes", targetRoutes.join(","));
240
+ }
241
+ let res = await fetch(url, await createRequestInit(request));
242
+ if (res.status >= 400 && !res.headers.has("X-Remix-Response")) throw new ErrorResponseImpl(res.status, res.statusText, await res.text());
243
+ if (res.status === 204 && res.headers.has("X-Remix-Redirect")) return {
244
+ status: 202,
245
+ data: { redirect: {
246
+ redirect: res.headers.get("X-Remix-Redirect"),
247
+ status: Number(res.headers.get("X-Remix-Status") || "302"),
248
+ revalidate: res.headers.get("X-Remix-Revalidate") === "true",
249
+ reload: res.headers.get("X-Remix-Reload-Document") === "true",
250
+ replace: res.headers.get("X-Remix-Replace") === "true"
251
+ } }
252
+ };
253
+ if (NO_BODY_STATUS_CODES.has(res.status)) {
254
+ let routes = {};
255
+ if (targetRoutes && request.method !== "GET") routes[targetRoutes[0]] = { data: void 0 };
256
+ return {
257
+ status: res.status,
258
+ data: { routes }
259
+ };
260
+ }
261
+ invariant(res.body, "No response body to decode");
262
+ try {
263
+ let decoded = await decodeViaTurboStream(res.body, window);
264
+ let data;
265
+ if (request.method === "GET") {
266
+ let typed = decoded.value;
267
+ if (SingleFetchRedirectSymbol in typed) data = { redirect: typed[SingleFetchRedirectSymbol] };
268
+ else data = { routes: typed };
269
+ } else {
270
+ let typed = decoded.value;
271
+ let routeId = targetRoutes?.[0];
272
+ invariant(routeId, "No routeId found for single fetch call decoding");
273
+ if ("redirect" in typed) data = { redirect: typed };
274
+ else data = { routes: { [routeId]: typed } };
275
+ }
276
+ return {
277
+ status: res.status,
278
+ data
279
+ };
280
+ } catch (e) {
281
+ throw new Error("Unable to decode turbo-stream response");
282
+ }
283
+ }
284
+ function decodeViaTurboStream(body, global) {
285
+ return decode(body, { plugins: [(type, ...rest) => {
286
+ if (type === "SanitizedError") {
287
+ let [name, message, stack] = rest;
288
+ let Constructor = Error;
289
+ if (name && SUPPORTED_ERROR_TYPES.includes(name) && name in global && typeof global[name] === "function") Constructor = global[name];
290
+ let error = new Constructor(message);
291
+ error.stack = stack;
292
+ return { value: error };
293
+ }
294
+ if (type === "ErrorResponse") {
295
+ let [data, status, statusText] = rest;
296
+ return { value: new ErrorResponseImpl(status, statusText, data) };
297
+ }
298
+ if (type === "SingleFetchRedirect") return { value: { [SingleFetchRedirectSymbol]: rest[0] } };
299
+ if (type === "SingleFetchClassInstance") return { value: rest[0] };
300
+ if (type === "SingleFetchFallback") return { value: void 0 };
301
+ }] });
302
+ }
303
+ function unwrapSingleFetchResult(result, routeId) {
304
+ if ("redirect" in result) {
305
+ let { redirect: location, revalidate, reload, replace, status } = result.redirect;
306
+ throw redirect(location, {
307
+ status,
308
+ headers: {
309
+ ...revalidate ? { "X-Remix-Revalidate": "yes" } : null,
310
+ ...reload ? { "X-Remix-Reload-Document": "yes" } : null,
311
+ ...replace ? { "X-Remix-Replace": "yes" } : null
312
+ }
313
+ });
314
+ }
315
+ let routeResult = result.routes[routeId];
316
+ if (routeResult == null) throw new SingleFetchNoResultError(`No result found for routeId "${routeId}"`);
317
+ else if ("error" in routeResult) throw routeResult.error;
318
+ else if ("data" in routeResult) return routeResult.data;
319
+ else throw new Error(`Invalid response found for routeId "${routeId}"`);
320
+ }
321
+ function createDeferred() {
322
+ let resolve;
323
+ let reject;
324
+ let promise = new Promise((res, rej) => {
325
+ resolve = async (val) => {
326
+ res(val);
327
+ try {
328
+ await promise;
329
+ } catch (e) {}
330
+ };
331
+ reject = async (error) => {
332
+ rej(error);
333
+ try {
334
+ await promise;
335
+ } catch (e) {}
336
+ };
337
+ });
338
+ return {
339
+ promise,
340
+ resolve,
341
+ reject
342
+ };
343
+ }
344
+ //#endregion
345
+ export { NO_BODY_STATUS_CODES, SingleFetchRedirectSymbol, StreamTransfer, decodeViaTurboStream, getSingleFetchDataStrategyImpl, getTurboStreamSingleFetchDataStrategy, singleFetchUrl, stripIndexParam };
@@ -0,0 +1,9 @@
1
+
2
+ import * as React$1 from "react";
3
+ import { RouterProviderProps } from "react-router";
4
+
5
+ //#region lib/dom-export/dom-router-provider.d.ts
6
+ type RouterProviderProps$1 = Omit<RouterProviderProps, "flushSync">;
7
+ declare function RouterProvider$1(props: RouterProviderProps$1): React$1.JSX.Element;
8
+ //#endregion
9
+ export { RouterProvider$1 as RouterProvider, RouterProviderProps$1 as RouterProviderProps };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import * as React$1 from "react";
12
+ import * as ReactDOM from "react-dom";
13
+ import { RouterProvider } from "react-router";
14
+ //#region lib/dom-export/dom-router-provider.tsx
15
+ function RouterProvider$1(props) {
16
+ return /* @__PURE__ */ React$1.createElement(RouterProvider, {
17
+ flushSync: ReactDOM.flushSync,
18
+ ...props
19
+ });
20
+ }
21
+ //#endregion
22
+ export { RouterProvider$1 as RouterProvider };
@@ -0,0 +1,125 @@
1
+
2
+ import { ClientInstrumentation } from "../router/instrumentation.js";
3
+ import * as React$1 from "react";
4
+ import { ClientOnErrorFunction, RouterInit } from "react-router";
5
+
6
+ //#region lib/dom-export/hydrated-router.d.ts
7
+ /**
8
+ * Props for the {@link dom.HydratedRouter} component.
9
+ *
10
+ * @category Types
11
+ */
12
+ interface HydratedRouterProps {
13
+ /**
14
+ * Context factory function to be passed through to {@link createBrowserRouter}.
15
+ * This function will be called to create a fresh `context` instance on each
16
+ * navigation/fetch and made available to
17
+ * [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
18
+ * functions.
19
+ */
20
+ getContext?: RouterInit["getContext"];
21
+ /**
22
+ * Array of instrumentation objects allowing you to instrument the router and
23
+ * individual routes prior to router initialization (and on any subsequently
24
+ * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
25
+ * mostly useful for observability such as wrapping navigations, fetches,
26
+ * as well as route loaders/actions/middlewares with logging and/or performance
27
+ * tracing. See the [docs](../../how-to/instrumentation) for more information.
28
+ *
29
+ * ```tsx
30
+ * const logging = {
31
+ * router({ instrument }) {
32
+ * instrument({
33
+ * navigate: (impl, { to }) => logExecution(`navigate ${to}`, impl),
34
+ * fetch: (impl, { to }) => logExecution(`fetch ${to}`, impl)
35
+ * });
36
+ * },
37
+ * route({ instrument, id }) {
38
+ * instrument({
39
+ * middleware: (impl, { request }) => logExecution(
40
+ * `middleware ${request.url} (route ${id})`,
41
+ * impl
42
+ * ),
43
+ * loader: (impl, { request }) => logExecution(
44
+ * `loader ${request.url} (route ${id})`,
45
+ * impl
46
+ * ),
47
+ * action: (impl, { request }) => logExecution(
48
+ * `action ${request.url} (route ${id})`,
49
+ * impl
50
+ * ),
51
+ * })
52
+ * }
53
+ * };
54
+ *
55
+ * async function logExecution(label: string, impl: () => Promise<void>) {
56
+ * let start = performance.now();
57
+ * console.log(`start ${label}`);
58
+ * await impl();
59
+ * let duration = Math.round(performance.now() - start);
60
+ * console.log(`end ${label} (${duration}ms)`);
61
+ * }
62
+ *
63
+ * startTransition(() => {
64
+ * hydrateRoot(
65
+ * document,
66
+ * <HydratedRouter instrumentations={[logging]} />
67
+ * );
68
+ * });
69
+ * ```
70
+ */
71
+ instrumentations?: ClientInstrumentation[];
72
+ /**
73
+ * An error handler function that will be called for any middleware, loader, action,
74
+ * or render errors that are encountered in your application. This is useful for
75
+ * logging or reporting errors instead of in the {@link ErrorBoundary} because it's not
76
+ * subject to re-rendering and will only run one time per error.
77
+ *
78
+ * The `errorInfo` parameter is passed along from
79
+ * [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
80
+ * and is only present for render errors.
81
+ *
82
+ * ```tsx
83
+ * <HydratedRouter onError={(error, info) => {
84
+ * let { location, params, pattern, errorInfo } = info;
85
+ * console.error(error, location, errorInfo);
86
+ * reportToErrorService(error, location, errorInfo);
87
+ * }} />
88
+ * ```
89
+ */
90
+ onError?: ClientOnErrorFunction;
91
+ /**
92
+ * Control whether router state updates are internally wrapped in
93
+ * [`React.startTransition`](https://react.dev/reference/react/startTransition).
94
+ *
95
+ * - When left `undefined`, all state updates are wrapped in
96
+ * `React.startTransition`
97
+ * - This can lead to buggy behaviors if you are wrapping your own
98
+ * navigations/fetchers in `startTransition`.
99
+ * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
100
+ * in `React.startTransition` and router state changes will be wrapped in
101
+ * `React.startTransition` and also sent through
102
+ * [`useOptimistic`](https://react.dev/reference/react/useOptimistic) to
103
+ * surface mid-navigation router state changes to the UI.
104
+ * - When set to `false`, the router will not leverage `React.startTransition` or
105
+ * `React.useOptimistic` on any navigations or state changes.
106
+ *
107
+ * For more information, please see the [docs](../../explanation/react-transitions).
108
+ */
109
+ useTransitions?: boolean;
110
+ }
111
+ /**
112
+ * Framework-mode router component to be used to hydrate a router from a
113
+ * {@link ServerRouter}. See [`entry.client.tsx`](../framework-conventions/entry.client.tsx).
114
+ *
115
+ * @public
116
+ * @category Framework Routers
117
+ * @mode framework
118
+ * @param props Props
119
+ * @param {dom.HydratedRouterProps.getContext} props.getContext n/a
120
+ * @param {dom.HydratedRouterProps.onError} props.onError n/a
121
+ * @returns A React element that represents the hydrated application.
122
+ */
123
+ declare function HydratedRouter(props: HydratedRouterProps): React$1.JSX.Element;
124
+ //#endregion
125
+ export { HydratedRouter, HydratedRouterProps };
@@ -0,0 +1,150 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { CRITICAL_CSS_DATA_ATTRIBUTE } from "../dom/ssr/components.js";
12
+ import { RouterProvider as RouterProvider$1 } from "./dom-router-provider.js";
13
+ import * as React$1 from "react";
14
+ import { UNSAFE_FrameworkContext, UNSAFE_RemixErrorBoundary, UNSAFE_createBrowserHistory, UNSAFE_createClientRoutes, UNSAFE_createClientRoutesWithHMRRevalidationOptOut, UNSAFE_createRouter, UNSAFE_decodeViaTurboStream, UNSAFE_defaultMapRouteProperties, UNSAFE_getHydrationData, UNSAFE_getPatchRoutesOnNavigationFunction, UNSAFE_getTurboStreamSingleFetchDataStrategy, UNSAFE_hydrationRouteProperties, UNSAFE_invariant, UNSAFE_useFogOFWarDiscovery } from "react-router";
15
+ //#region lib/dom-export/hydrated-router.tsx
16
+ let ssrInfo = null;
17
+ let router = null;
18
+ function initSsrInfo() {
19
+ if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
20
+ if (window.__reactRouterManifest.sri === true) {
21
+ const importMap = document.querySelector("script[rr-importmap]");
22
+ if (importMap?.textContent) try {
23
+ window.__reactRouterManifest.sri = JSON.parse(importMap.textContent).integrity;
24
+ } catch (err) {
25
+ console.error("Failed to parse import map", err);
26
+ }
27
+ }
28
+ ssrInfo = {
29
+ context: window.__reactRouterContext,
30
+ manifest: window.__reactRouterManifest,
31
+ routeModules: window.__reactRouterRouteModules,
32
+ stateDecodingPromise: void 0,
33
+ router: void 0,
34
+ routerInitialized: false
35
+ };
36
+ }
37
+ }
38
+ function createHydratedRouter({ getContext, instrumentations }) {
39
+ initSsrInfo();
40
+ if (!ssrInfo) throw new Error("You must be using the SSR features of React Router in order to skip passing a `router` prop to `<RouterProvider>`");
41
+ let localSsrInfo = ssrInfo;
42
+ if (!ssrInfo.stateDecodingPromise) {
43
+ let stream = ssrInfo.context.stream;
44
+ UNSAFE_invariant(stream, "No stream found for single fetch decoding");
45
+ ssrInfo.context.stream = void 0;
46
+ ssrInfo.stateDecodingPromise = UNSAFE_decodeViaTurboStream(stream, window).then((value) => {
47
+ ssrInfo.context.state = value.value;
48
+ localSsrInfo.stateDecodingPromise.value = true;
49
+ }).catch((e) => {
50
+ localSsrInfo.stateDecodingPromise.error = e;
51
+ });
52
+ }
53
+ if (ssrInfo.stateDecodingPromise.error) throw ssrInfo.stateDecodingPromise.error;
54
+ if (!ssrInfo.stateDecodingPromise.value) throw ssrInfo.stateDecodingPromise;
55
+ let routes = UNSAFE_createClientRoutes(ssrInfo.manifest.routes, ssrInfo.routeModules, ssrInfo.context.state, ssrInfo.context.ssr, ssrInfo.context.isSpaMode);
56
+ let hydrationData = void 0;
57
+ if (ssrInfo.context.isSpaMode) {
58
+ let { loaderData } = ssrInfo.context.state;
59
+ if (ssrInfo.manifest.routes.root?.hasLoader && loaderData && "root" in loaderData) hydrationData = { loaderData: { root: loaderData.root } };
60
+ } else hydrationData = UNSAFE_getHydrationData({
61
+ state: ssrInfo.context.state,
62
+ routes,
63
+ getRouteInfo: (routeId) => ({
64
+ clientLoader: ssrInfo.routeModules[routeId]?.clientLoader,
65
+ hasLoader: ssrInfo.manifest.routes[routeId]?.hasLoader === true,
66
+ hasHydrateFallback: ssrInfo.routeModules[routeId]?.HydrateFallback != null
67
+ }),
68
+ location: window.location,
69
+ basename: window.__reactRouterContext?.basename,
70
+ isSpaMode: ssrInfo.context.isSpaMode
71
+ });
72
+ if (window.history.state && window.history.state.masked) window.history.replaceState({
73
+ ...window.history.state,
74
+ masked: void 0
75
+ }, "");
76
+ let router = UNSAFE_createRouter({
77
+ routes,
78
+ history: UNSAFE_createBrowserHistory(),
79
+ basename: ssrInfo.context.basename,
80
+ getContext,
81
+ hydrationData,
82
+ mapRouteProperties: UNSAFE_defaultMapRouteProperties,
83
+ hydrationRouteProperties: UNSAFE_hydrationRouteProperties,
84
+ instrumentations,
85
+ dataStrategy: UNSAFE_getTurboStreamSingleFetchDataStrategy(() => router, ssrInfo.manifest, ssrInfo.routeModules, ssrInfo.context.ssr),
86
+ patchRoutesOnNavigation: UNSAFE_getPatchRoutesOnNavigationFunction(() => router, ssrInfo.manifest, ssrInfo.routeModules, ssrInfo.context.ssr, ssrInfo.context.routeDiscovery, ssrInfo.context.isSpaMode, ssrInfo.context.basename)
87
+ });
88
+ ssrInfo.router = router;
89
+ if (router.state.initialized) {
90
+ ssrInfo.routerInitialized = true;
91
+ router.initialize();
92
+ }
93
+ router.createRoutesForHMR = UNSAFE_createClientRoutesWithHMRRevalidationOptOut;
94
+ window.__reactRouterDataRouter = router;
95
+ return router;
96
+ }
97
+ /**
98
+ * Framework-mode router component to be used to hydrate a router from a
99
+ * {@link ServerRouter}. See [`entry.client.tsx`](../framework-conventions/entry.client.tsx).
100
+ *
101
+ * @public
102
+ * @category Framework Routers
103
+ * @mode framework
104
+ * @param props Props
105
+ * @param {dom.HydratedRouterProps.getContext} props.getContext n/a
106
+ * @param {dom.HydratedRouterProps.onError} props.onError n/a
107
+ * @returns A React element that represents the hydrated application.
108
+ */
109
+ function HydratedRouter(props) {
110
+ if (!router) router = createHydratedRouter({
111
+ getContext: props.getContext,
112
+ instrumentations: props.instrumentations
113
+ });
114
+ let [criticalCss, setCriticalCss] = React$1.useState(process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0);
115
+ React$1.useEffect(() => {
116
+ if (process.env.NODE_ENV === "development") setCriticalCss(void 0);
117
+ }, []);
118
+ React$1.useEffect(() => {
119
+ if (process.env.NODE_ENV === "development" && criticalCss === void 0) document.querySelectorAll(`[${CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
120
+ }, [criticalCss]);
121
+ let [location, setLocation] = React$1.useState(router.state.location);
122
+ React$1.useLayoutEffect(() => {
123
+ if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
124
+ ssrInfo.routerInitialized = true;
125
+ ssrInfo.router.initialize();
126
+ }
127
+ }, []);
128
+ React$1.useLayoutEffect(() => {
129
+ if (ssrInfo && ssrInfo.router) return ssrInfo.router.subscribe((newState) => {
130
+ if (newState.location !== location) setLocation(newState.location);
131
+ });
132
+ }, [location]);
133
+ UNSAFE_invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
134
+ UNSAFE_useFogOFWarDiscovery(router, ssrInfo.manifest, ssrInfo.routeModules, ssrInfo.context.ssr, ssrInfo.context.routeDiscovery, ssrInfo.context.isSpaMode);
135
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement(UNSAFE_FrameworkContext.Provider, { value: {
136
+ manifest: ssrInfo.manifest,
137
+ routeModules: ssrInfo.routeModules,
138
+ future: ssrInfo.context.future,
139
+ criticalCss,
140
+ ssr: ssrInfo.context.ssr,
141
+ isSpaMode: ssrInfo.context.isSpaMode,
142
+ routeDiscovery: ssrInfo.context.routeDiscovery
143
+ } }, /* @__PURE__ */ React$1.createElement(UNSAFE_RemixErrorBoundary, { location }, /* @__PURE__ */ React$1.createElement(RouterProvider$1, {
144
+ router,
145
+ useTransitions: props.useTransitions,
146
+ onError: props.onError
147
+ }))), /* @__PURE__ */ React$1.createElement(React$1.Fragment, null));
148
+ }
149
+ //#endregion
150
+ export { HydratedRouter };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { ErrorResponseImpl } from "./router/utils.js";
12
+ //#region lib/errors.ts
13
+ const ERROR_DIGEST_BASE = "REACT_ROUTER_ERROR";
14
+ const ERROR_DIGEST_REDIRECT = "REDIRECT";
15
+ const ERROR_DIGEST_ROUTE_ERROR_RESPONSE = "ROUTE_ERROR_RESPONSE";
16
+ function decodeRedirectErrorDigest(digest) {
17
+ if (digest.startsWith(`${ERROR_DIGEST_BASE}:${ERROR_DIGEST_REDIRECT}:{`)) try {
18
+ let parsed = JSON.parse(digest.slice(28));
19
+ if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string" && typeof parsed.location === "string" && typeof parsed.reloadDocument === "boolean" && typeof parsed.replace === "boolean") return parsed;
20
+ } catch {}
21
+ }
22
+ function decodeRouteErrorResponseDigest(digest) {
23
+ if (digest.startsWith(`${ERROR_DIGEST_BASE}:${ERROR_DIGEST_ROUTE_ERROR_RESPONSE}:{`)) try {
24
+ let parsed = JSON.parse(digest.slice(40));
25
+ if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string") return new ErrorResponseImpl(parsed.status, parsed.statusText, parsed.data);
26
+ } catch {}
27
+ }
28
+ //#endregion
29
+ export { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest };