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,589 @@
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 { matchRoutes } from "../../router/utils.js";
12
+ import { DataRouterContext, DataRouterStateContext, useIsRSCRouterContext } from "../../context.js";
13
+ import { useLocation } from "../../hooks.js";
14
+ import { warnOnce } from "../../server-runtime/warnings.js";
15
+ import invariant from "./invariant.js";
16
+ import { getKeyedLinksForMatches, getKeyedPrefetchLinks, getModuleLinkHrefs, getNewMatchesForLinks, isPageLinkDescriptor } from "./links.js";
17
+ import { escapeHtml } from "./markup.js";
18
+ import { singleFetchUrl } from "./single-fetch.js";
19
+ import { getPartialManifest, isFogOfWarEnabled } from "./fog-of-war.js";
20
+ import * as React$1 from "react";
21
+ //#region lib/dom/ssr/components.tsx
22
+ function useDataRouterContext() {
23
+ let context = React$1.useContext(DataRouterContext);
24
+ invariant(context, "You must render this element inside a <DataRouterContext.Provider> element");
25
+ return context;
26
+ }
27
+ function useDataRouterStateContext() {
28
+ let context = React$1.useContext(DataRouterStateContext);
29
+ invariant(context, "You must render this element inside a <DataRouterStateContext.Provider> element");
30
+ return context;
31
+ }
32
+ const FrameworkContext = React$1.createContext(void 0);
33
+ FrameworkContext.displayName = "FrameworkContext";
34
+ function useFrameworkContext() {
35
+ let context = React$1.useContext(FrameworkContext);
36
+ invariant(context, "You must render this element inside a <HydratedRouter> element");
37
+ return context;
38
+ }
39
+ function usePrefetchBehavior(prefetch, theirElementProps) {
40
+ let frameworkContext = React$1.useContext(FrameworkContext);
41
+ let [maybePrefetch, setMaybePrefetch] = React$1.useState(false);
42
+ let [shouldPrefetch, setShouldPrefetch] = React$1.useState(false);
43
+ let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
44
+ let ref = React$1.useRef(null);
45
+ React$1.useEffect(() => {
46
+ if (prefetch === "render") setShouldPrefetch(true);
47
+ if (prefetch === "viewport") {
48
+ let callback = (entries) => {
49
+ entries.forEach((entry) => {
50
+ setShouldPrefetch(entry.isIntersecting);
51
+ });
52
+ };
53
+ let observer = new IntersectionObserver(callback, { threshold: .5 });
54
+ if (ref.current) observer.observe(ref.current);
55
+ return () => {
56
+ observer.disconnect();
57
+ };
58
+ }
59
+ }, [prefetch]);
60
+ React$1.useEffect(() => {
61
+ if (maybePrefetch) {
62
+ let id = setTimeout(() => {
63
+ setShouldPrefetch(true);
64
+ }, 100);
65
+ return () => {
66
+ clearTimeout(id);
67
+ };
68
+ }
69
+ }, [maybePrefetch]);
70
+ let setIntent = () => {
71
+ setMaybePrefetch(true);
72
+ };
73
+ let cancelIntent = () => {
74
+ setMaybePrefetch(false);
75
+ setShouldPrefetch(false);
76
+ };
77
+ if (!frameworkContext) return [
78
+ false,
79
+ ref,
80
+ {}
81
+ ];
82
+ if (prefetch !== "intent") return [
83
+ shouldPrefetch,
84
+ ref,
85
+ {}
86
+ ];
87
+ return [
88
+ shouldPrefetch,
89
+ ref,
90
+ {
91
+ onFocus: composeEventHandlers(onFocus, setIntent),
92
+ onBlur: composeEventHandlers(onBlur, cancelIntent),
93
+ onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
94
+ onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
95
+ onTouchStart: composeEventHandlers(onTouchStart, setIntent)
96
+ }
97
+ ];
98
+ }
99
+ function composeEventHandlers(theirHandler, ourHandler) {
100
+ return (event) => {
101
+ theirHandler && theirHandler(event);
102
+ if (!event.defaultPrevented) ourHandler(event);
103
+ };
104
+ }
105
+ function getActiveMatches(matches, errors, isSpaMode) {
106
+ if (isSpaMode && !isHydrated) return [matches[0]];
107
+ if (errors) {
108
+ let errorIdx = matches.findIndex((m) => errors[m.route.id] !== void 0);
109
+ return matches.slice(0, errorIdx + 1);
110
+ }
111
+ return matches;
112
+ }
113
+ const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
114
+ /**
115
+ * Renders all the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
116
+ * tags created by the route module's [`links`](../../start/framework/route-module#links)
117
+ * export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
118
+ * of your document.
119
+ *
120
+ * @example
121
+ * import { Links } from "react-router";
122
+ *
123
+ * export default function Root() {
124
+ * return (
125
+ * <html>
126
+ * <head>
127
+ * <Links />
128
+ * </head>
129
+ * <body></body>
130
+ * </html>
131
+ * );
132
+ * }
133
+ *
134
+ * @public
135
+ * @category Components
136
+ * @mode framework
137
+ * @param props Props
138
+ * @param {LinksProps.nonce} props.nonce n/a
139
+ * @param {LinksProps.crossOrigin} props.crossOrigin n/a
140
+ * @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
141
+ * tags
142
+ */
143
+ function Links({ nonce, crossOrigin }) {
144
+ let { isSpaMode, manifest, routeModules, criticalCss, nonce: contextNonce } = useFrameworkContext();
145
+ let { errors, matches: routerMatches } = useDataRouterStateContext();
146
+ let matches = getActiveMatches(routerMatches, errors, isSpaMode);
147
+ let keyedLinks = React$1.useMemo(() => getKeyedLinksForMatches(matches, routeModules, manifest), [
148
+ matches,
149
+ routeModules,
150
+ manifest
151
+ ]);
152
+ if (nonce == null && contextNonce) nonce = contextNonce;
153
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, typeof criticalCss === "string" ? /* @__PURE__ */ React$1.createElement("style", {
154
+ [CRITICAL_CSS_DATA_ATTRIBUTE]: "",
155
+ nonce,
156
+ dangerouslySetInnerHTML: { __html: criticalCss }
157
+ }) : null, typeof criticalCss === "object" ? /* @__PURE__ */ React$1.createElement("link", {
158
+ [CRITICAL_CSS_DATA_ATTRIBUTE]: "",
159
+ rel: "stylesheet",
160
+ href: criticalCss.href,
161
+ nonce,
162
+ crossOrigin
163
+ }) : null, keyedLinks.map(({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React$1.createElement(PrefetchPageLinks, {
164
+ key,
165
+ nonce,
166
+ ...link,
167
+ crossOrigin: link.crossOrigin ?? crossOrigin
168
+ }) : /* @__PURE__ */ React$1.createElement("link", {
169
+ key,
170
+ nonce,
171
+ ...link,
172
+ crossOrigin: link.crossOrigin ?? crossOrigin
173
+ })));
174
+ }
175
+ /**
176
+ * Renders [`<link rel=prefetch|modulepreload>`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel)
177
+ * tags for modules and data of another page to enable an instant navigation to
178
+ * that page. [`<Link prefetch>`](./Link#prefetch) uses this internally, but you
179
+ * can render it to prefetch a page for any other reason.
180
+ *
181
+ * For example, you may render one of this as the user types into a search field
182
+ * to prefetch search results before they click through to their selection.
183
+ *
184
+ * @example
185
+ * import { PrefetchPageLinks } from "react-router";
186
+ *
187
+ * <PrefetchPageLinks page="/absolute/path" />
188
+ *
189
+ * @public
190
+ * @category Components
191
+ * @mode framework
192
+ * @param props Props
193
+ * @param {PageLinkDescriptor.page} props.page n/a
194
+ * @param props.linkProps Additional props to spread onto the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
195
+ * tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/crossOrigin),
196
+ * [`integrity`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/integrity),
197
+ * [`rel`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel),
198
+ * etc.
199
+ * @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
200
+ * tags
201
+ */
202
+ function PrefetchPageLinks({ page, ...linkProps }) {
203
+ let rsc = useIsRSCRouterContext();
204
+ let { nonce: contextNonce } = useFrameworkContext();
205
+ let { router } = useDataRouterContext();
206
+ let matches = React$1.useMemo(() => matchRoutes(router.routes, page, router.basename), [
207
+ router.routes,
208
+ page,
209
+ router.basename
210
+ ]);
211
+ if (!matches) return null;
212
+ if (linkProps.nonce == null && contextNonce) linkProps = {
213
+ ...linkProps,
214
+ nonce: contextNonce
215
+ };
216
+ if (rsc) return /* @__PURE__ */ React$1.createElement(RSCPrefetchPageLinksImpl, {
217
+ page,
218
+ matches,
219
+ ...linkProps
220
+ });
221
+ return /* @__PURE__ */ React$1.createElement(PrefetchPageLinksImpl, {
222
+ page,
223
+ matches,
224
+ ...linkProps
225
+ });
226
+ }
227
+ function useKeyedPrefetchLinks(matches) {
228
+ let { manifest, routeModules } = useFrameworkContext();
229
+ let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React$1.useState([]);
230
+ React$1.useEffect(() => {
231
+ let interrupted = false;
232
+ getKeyedPrefetchLinks(matches, manifest, routeModules).then((links) => {
233
+ if (!interrupted) setKeyedPrefetchLinks(links);
234
+ });
235
+ return () => {
236
+ interrupted = true;
237
+ };
238
+ }, [
239
+ matches,
240
+ manifest,
241
+ routeModules
242
+ ]);
243
+ return keyedPrefetchLinks;
244
+ }
245
+ function RSCPrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
246
+ let location = useLocation();
247
+ let dataHrefs = React$1.useMemo(() => {
248
+ if (page === location.pathname + location.search + location.hash) return [];
249
+ let url = singleFetchUrl(page, "rsc");
250
+ let hasSomeRoutesWithShouldRevalidate = false;
251
+ let targetRoutes = [];
252
+ for (let match of nextMatches) if (typeof match.route.shouldRevalidate === "function") hasSomeRoutesWithShouldRevalidate = true;
253
+ else targetRoutes.push(match.route.id);
254
+ if (hasSomeRoutesWithShouldRevalidate && targetRoutes.length > 0) url.searchParams.set("_routes", targetRoutes.join(","));
255
+ return [url.pathname + url.search];
256
+ }, [
257
+ page,
258
+ location,
259
+ nextMatches
260
+ ]);
261
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
262
+ key: href,
263
+ rel: "prefetch",
264
+ as: "fetch",
265
+ href,
266
+ ...linkProps
267
+ })));
268
+ }
269
+ function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
270
+ let location = useLocation();
271
+ let { manifest, routeModules } = useFrameworkContext();
272
+ let { loaderData, matches } = useDataRouterStateContext();
273
+ let newMatchesForData = React$1.useMemo(() => getNewMatchesForLinks(page, nextMatches, matches, manifest, location, "data"), [
274
+ page,
275
+ nextMatches,
276
+ matches,
277
+ manifest,
278
+ location
279
+ ]);
280
+ let newMatchesForAssets = React$1.useMemo(() => getNewMatchesForLinks(page, nextMatches, matches, manifest, location, "assets"), [
281
+ page,
282
+ nextMatches,
283
+ matches,
284
+ manifest,
285
+ location
286
+ ]);
287
+ let dataHrefs = React$1.useMemo(() => {
288
+ if (page === location.pathname + location.search + location.hash) return [];
289
+ let routesParams = /* @__PURE__ */ new Set();
290
+ let foundOptOutRoute = false;
291
+ nextMatches.forEach((m) => {
292
+ let manifestRoute = manifest.routes[m.route.id];
293
+ if (!manifestRoute || !manifestRoute.hasLoader) return;
294
+ if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && routeModules[m.route.id]?.shouldRevalidate) foundOptOutRoute = true;
295
+ else if (manifestRoute.hasClientLoader) foundOptOutRoute = true;
296
+ else routesParams.add(m.route.id);
297
+ });
298
+ if (routesParams.size === 0) return [];
299
+ let url = singleFetchUrl(page, "data");
300
+ if (foundOptOutRoute && routesParams.size > 0) url.searchParams.set("_routes", nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(","));
301
+ return [url.pathname + url.search];
302
+ }, [
303
+ loaderData,
304
+ location,
305
+ manifest,
306
+ newMatchesForData,
307
+ nextMatches,
308
+ page,
309
+ routeModules
310
+ ]);
311
+ let moduleHrefs = React$1.useMemo(() => getModuleLinkHrefs(newMatchesForAssets, manifest), [newMatchesForAssets, manifest]);
312
+ let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
313
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
314
+ key: href,
315
+ rel: "prefetch",
316
+ as: "fetch",
317
+ href,
318
+ ...linkProps
319
+ })), moduleHrefs.map((href) => /* @__PURE__ */ React$1.createElement("link", {
320
+ key: href,
321
+ rel: "modulepreload",
322
+ href,
323
+ ...linkProps
324
+ })), keyedPrefetchLinks.map(({ key, link }) => /* @__PURE__ */ React$1.createElement("link", {
325
+ key,
326
+ nonce: linkProps.nonce,
327
+ ...link,
328
+ crossOrigin: link.crossOrigin ?? linkProps.crossOrigin
329
+ })));
330
+ }
331
+ /**
332
+ * Renders all the [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
333
+ * tags created by the route module's [`meta`](../../start/framework/route-module#meta)
334
+ * export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
335
+ * of your document.
336
+ *
337
+ * @example
338
+ * import { Meta } from "react-router";
339
+ *
340
+ * export default function Root() {
341
+ * return (
342
+ * <html>
343
+ * <head>
344
+ * <Meta />
345
+ * </head>
346
+ * </html>
347
+ * );
348
+ * }
349
+ *
350
+ * @public
351
+ * @category Components
352
+ * @mode framework
353
+ * @returns A collection of React elements for [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
354
+ * tags
355
+ */
356
+ function Meta() {
357
+ let { isSpaMode, routeModules } = useFrameworkContext();
358
+ let { errors, matches: routerMatches, loaderData } = useDataRouterStateContext();
359
+ let location = useLocation();
360
+ let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
361
+ let error = null;
362
+ if (errors) error = errors[_matches[_matches.length - 1].route.id];
363
+ let meta = [];
364
+ let leafMeta = null;
365
+ let matches = [];
366
+ for (let i = 0; i < _matches.length; i++) {
367
+ let _match = _matches[i];
368
+ let routeId = _match.route.id;
369
+ let data = loaderData[routeId];
370
+ let params = _match.params;
371
+ let routeModule = routeModules[routeId];
372
+ let routeMeta = [];
373
+ let match = {
374
+ id: routeId,
375
+ loaderData: data,
376
+ meta: [],
377
+ params: _match.params,
378
+ pathname: _match.pathname,
379
+ handle: _match.route.handle,
380
+ error
381
+ };
382
+ matches[i] = match;
383
+ if (routeModule?.meta) routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
384
+ loaderData: data,
385
+ params,
386
+ location,
387
+ matches,
388
+ error
389
+ }) : Array.isArray(routeModule.meta) ? [...routeModule.meta] : routeModule.meta;
390
+ else if (leafMeta) routeMeta = [...leafMeta];
391
+ routeMeta = routeMeta || [];
392
+ if (!Array.isArray(routeMeta)) throw new Error("The route at " + _match.route.path + " returns an invalid value. All route meta functions must return an array of meta objects.\n\nTo reference the meta function API, see https://reactrouter.com/start/framework/route-module#meta");
393
+ match.meta = routeMeta;
394
+ matches[i] = match;
395
+ meta = [...routeMeta];
396
+ leafMeta = meta;
397
+ }
398
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, meta.flat().map((metaProps) => {
399
+ if (!metaProps) return null;
400
+ if ("tagName" in metaProps) {
401
+ let { tagName, ...rest } = metaProps;
402
+ if (!isValidMetaTag(tagName)) {
403
+ console.warn(`A meta object uses an invalid tagName: ${tagName}. Expected either 'link' or 'meta'`);
404
+ return null;
405
+ }
406
+ let Comp = tagName;
407
+ return /* @__PURE__ */ React$1.createElement(Comp, {
408
+ key: JSON.stringify(rest),
409
+ ...rest
410
+ });
411
+ }
412
+ if ("title" in metaProps) return /* @__PURE__ */ React$1.createElement("title", { key: "title" }, String(metaProps.title));
413
+ if ("charset" in metaProps) {
414
+ metaProps.charSet ??= metaProps.charset;
415
+ delete metaProps.charset;
416
+ }
417
+ if ("charSet" in metaProps && metaProps.charSet != null) return typeof metaProps.charSet === "string" ? /* @__PURE__ */ React$1.createElement("meta", {
418
+ key: "charSet",
419
+ charSet: metaProps.charSet
420
+ }) : null;
421
+ if ("script:ld+json" in metaProps) try {
422
+ let json = JSON.stringify(metaProps["script:ld+json"]);
423
+ return /* @__PURE__ */ React$1.createElement("script", {
424
+ key: `script:ld+json:${json}`,
425
+ type: "application/ld+json",
426
+ dangerouslySetInnerHTML: { __html: escapeHtml(json) }
427
+ });
428
+ } catch (e) {
429
+ return null;
430
+ }
431
+ return /* @__PURE__ */ React$1.createElement("meta", {
432
+ key: JSON.stringify(metaProps),
433
+ ...metaProps
434
+ });
435
+ }));
436
+ }
437
+ function isValidMetaTag(tagName) {
438
+ return typeof tagName === "string" && /^(meta|link)$/.test(tagName);
439
+ }
440
+ /**
441
+ * Tracks whether hydration is finished, so scripts can be skipped
442
+ * during client-side updates.
443
+ */
444
+ let isHydrated = false;
445
+ function setIsHydrated() {
446
+ isHydrated = true;
447
+ }
448
+ /**
449
+ * Renders the client runtime of your app. It should be rendered inside the
450
+ * [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body)
451
+ * of the document.
452
+ *
453
+ * If server rendering, you can omit `<Scripts/>` and the app will work as a
454
+ * traditional web app without JavaScript, relying solely on HTML and browser
455
+ * behaviors.
456
+ *
457
+ * @example
458
+ * import { Scripts } from "react-router";
459
+ *
460
+ * export default function Root() {
461
+ * return (
462
+ * <html>
463
+ * <head />
464
+ * <body>
465
+ * <Scripts />
466
+ * </body>
467
+ * </html>
468
+ * );
469
+ * }
470
+ *
471
+ * @public
472
+ * @category Components
473
+ * @mode framework
474
+ * @param scriptProps Additional props to spread onto the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
475
+ * tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin),
476
+ * [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce),
477
+ * etc.
478
+ * @returns A collection of React elements for [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
479
+ * tags
480
+ */
481
+ function Scripts(scriptProps) {
482
+ let { manifest, serverHandoffString, isSpaMode, renderMeta, routeDiscovery, ssr, nonce: contextNonce } = useFrameworkContext();
483
+ let { router, static: isStatic, staticContext } = useDataRouterContext();
484
+ let { matches: routerMatches } = useDataRouterStateContext();
485
+ let isRSCRouterContext = useIsRSCRouterContext();
486
+ let enableFogOfWar = isFogOfWarEnabled(routeDiscovery, ssr);
487
+ if (scriptProps.nonce == null && contextNonce) scriptProps = {
488
+ ...scriptProps,
489
+ nonce: contextNonce
490
+ };
491
+ if (renderMeta) renderMeta.didRenderScripts = true;
492
+ let matches = getActiveMatches(routerMatches, null, isSpaMode);
493
+ React$1.useEffect(() => {
494
+ setIsHydrated();
495
+ }, []);
496
+ let initialScripts = React$1.useMemo(() => {
497
+ if (isRSCRouterContext) return null;
498
+ let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());` : " ";
499
+ let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
500
+ ${matches.map((match, routeIndex) => {
501
+ let routeVarName = `route${routeIndex}`;
502
+ let manifestEntry = manifest.routes[match.route.id];
503
+ invariant(manifestEntry, `Route ${match.route.id} not found in manifest`);
504
+ let { clientActionModule, clientLoaderModule, clientMiddlewareModule, hydrateFallbackModule, module } = manifestEntry;
505
+ let chunks = [
506
+ ...clientActionModule ? [{
507
+ module: clientActionModule,
508
+ varName: `${routeVarName}_clientAction`
509
+ }] : [],
510
+ ...clientLoaderModule ? [{
511
+ module: clientLoaderModule,
512
+ varName: `${routeVarName}_clientLoader`
513
+ }] : [],
514
+ ...clientMiddlewareModule ? [{
515
+ module: clientMiddlewareModule,
516
+ varName: `${routeVarName}_clientMiddleware`
517
+ }] : [],
518
+ ...hydrateFallbackModule ? [{
519
+ module: hydrateFallbackModule,
520
+ varName: `${routeVarName}_HydrateFallback`
521
+ }] : [],
522
+ {
523
+ module,
524
+ varName: `${routeVarName}_main`
525
+ }
526
+ ];
527
+ if (chunks.length === 1) return `import * as ${routeVarName} from ${JSON.stringify(module)};`;
528
+ return [chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n"), `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`].join("\n");
529
+ }).join("\n")}
530
+ ${enableFogOfWar ? `window.__reactRouterManifest = ${JSON.stringify(getPartialManifest(manifest, router), null, 2)};` : ""}
531
+ window.__reactRouterRouteModules = {${matches.map((match, index) => `${JSON.stringify(match.route.id)}:route${index}`).join(",")}};
532
+
533
+ import(${JSON.stringify(manifest.entry.module)});`;
534
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("script", {
535
+ ...scriptProps,
536
+ suppressHydrationWarning: true,
537
+ dangerouslySetInnerHTML: { __html: contextScript },
538
+ type: void 0
539
+ }), /* @__PURE__ */ React$1.createElement("script", {
540
+ ...scriptProps,
541
+ suppressHydrationWarning: true,
542
+ dangerouslySetInnerHTML: { __html: routeModulesScript },
543
+ type: "module",
544
+ async: true
545
+ }));
546
+ }, []);
547
+ let preloads = isHydrated || isRSCRouterContext ? [] : [...new Set(manifest.entry.imports.concat(getModuleLinkHrefs(matches, manifest, { includeHydrateFallback: true })))];
548
+ let sri = typeof manifest.sri === "object" ? manifest.sri : {};
549
+ warnOnce(!isRSCRouterContext, "The <Scripts /> element is a no-op when using RSC and can be safely removed.");
550
+ return isHydrated || isRSCRouterContext ? null : /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, typeof manifest.sri === "object" ? /* @__PURE__ */ React$1.createElement("script", {
551
+ ...scriptProps,
552
+ "rr-importmap": "",
553
+ type: "importmap",
554
+ suppressHydrationWarning: true,
555
+ dangerouslySetInnerHTML: { __html: JSON.stringify({ integrity: sri }) }
556
+ }) : null, !enableFogOfWar ? /* @__PURE__ */ React$1.createElement("link", {
557
+ rel: "modulepreload",
558
+ href: manifest.url,
559
+ crossOrigin: scriptProps.crossOrigin,
560
+ integrity: sri[manifest.url],
561
+ nonce: scriptProps.nonce,
562
+ suppressHydrationWarning: true
563
+ }) : null, /* @__PURE__ */ React$1.createElement("link", {
564
+ rel: "modulepreload",
565
+ href: manifest.entry.module,
566
+ crossOrigin: scriptProps.crossOrigin,
567
+ integrity: sri[manifest.entry.module],
568
+ nonce: scriptProps.nonce,
569
+ suppressHydrationWarning: true
570
+ }), preloads.map((path) => /* @__PURE__ */ React$1.createElement("link", {
571
+ key: path,
572
+ rel: "modulepreload",
573
+ href: path,
574
+ crossOrigin: scriptProps.crossOrigin,
575
+ integrity: sri[path],
576
+ nonce: scriptProps.nonce,
577
+ suppressHydrationWarning: true
578
+ })), initialScripts);
579
+ }
580
+ function mergeRefs(...refs) {
581
+ return (value) => {
582
+ refs.forEach((ref) => {
583
+ if (typeof ref === "function") ref(value);
584
+ else if (ref != null) ref.current = value;
585
+ });
586
+ };
587
+ }
588
+ //#endregion
589
+ export { CRITICAL_CSS_DATA_ATTRIBUTE, FrameworkContext, Links, Meta, PrefetchPageLinks, Scripts, mergeRefs, setIsHydrated, useFrameworkContext, usePrefetchBehavior };
@@ -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
+ //#region lib/dom/ssr/data.ts
12
+ async function createRequestInit(request) {
13
+ let init = { signal: request.signal };
14
+ if (request.method !== "GET") {
15
+ init.method = request.method;
16
+ let contentType = request.headers.get("Content-Type");
17
+ if (contentType && /\bapplication\/json\b/.test(contentType)) {
18
+ init.headers = { "Content-Type": contentType };
19
+ init.body = JSON.stringify(await request.json());
20
+ } else if (contentType && /\btext\/plain\b/.test(contentType)) {
21
+ init.headers = { "Content-Type": contentType };
22
+ init.body = await request.text();
23
+ } else if (contentType && /\bapplication\/x-www-form-urlencoded\b/.test(contentType)) init.body = new URLSearchParams(await request.text());
24
+ else init.body = await request.formData();
25
+ }
26
+ return init;
27
+ }
28
+ //#endregion
29
+ export { createRequestInit };
@@ -0,0 +1,60 @@
1
+
2
+ import { DataRouteObject, RouteBranch, RouteManifest } from "../../router/utils.js";
3
+ import { StaticHandlerContext } from "../../router/router.js";
4
+ import { RouteModules } from "./routeModules.js";
5
+ import { EntryRoute } from "./routes.js";
6
+ import { ServerBuild } from "../../server-runtime/build.js";
7
+
8
+ //#region lib/dom/ssr/entry.d.ts
9
+ type SerializedError = {
10
+ message: string;
11
+ stack?: string;
12
+ };
13
+ interface FrameworkContextObject {
14
+ manifest: AssetsManifest;
15
+ routeModules: RouteModules;
16
+ criticalCss?: CriticalCss;
17
+ serverHandoffString?: string;
18
+ future: FutureConfig;
19
+ ssr: boolean;
20
+ isSpaMode: boolean;
21
+ routeDiscovery: ServerBuild["routeDiscovery"];
22
+ nonce?: string;
23
+ serializeError?(error: Error): SerializedError;
24
+ renderMeta?: {
25
+ didRenderScripts?: boolean;
26
+ streamCache?: Record<number, Promise<void> & {
27
+ result?: {
28
+ done: boolean;
29
+ value: string;
30
+ };
31
+ error?: unknown;
32
+ }>;
33
+ };
34
+ }
35
+ interface EntryContext extends FrameworkContextObject {
36
+ branches: RouteBranch<DataRouteObject>[];
37
+ staticHandlerContext: StaticHandlerContext;
38
+ serverHandoffStream?: ReadableStream<Uint8Array>;
39
+ }
40
+ type FutureConfig = Record<string, never>;
41
+ type CriticalCss = string | {
42
+ rel: "stylesheet";
43
+ href: string;
44
+ };
45
+ interface AssetsManifest {
46
+ entry: {
47
+ imports: string[];
48
+ module: string;
49
+ };
50
+ routes: RouteManifest<EntryRoute>;
51
+ url: string;
52
+ version: string;
53
+ hmr?: {
54
+ timestamp?: number;
55
+ runtime: string;
56
+ };
57
+ sri?: Record<string, string> | true;
58
+ }
59
+ //#endregion
60
+ export { AssetsManifest, CriticalCss, EntryContext, FrameworkContextObject, FutureConfig };