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,138 @@
1
+
2
+ import { Location } from "../router/history.js";
3
+ import { DataRouteObject, RouteBranch, RouteObject } from "../router/utils.js";
4
+ import { FutureConfig, Router, StaticHandlerContext } from "../router/router.js";
5
+ import * as React$1 from "react";
6
+
7
+ //#region lib/dom/server.d.ts
8
+ /**
9
+ * @category Types
10
+ */
11
+ interface StaticRouterProps {
12
+ /**
13
+ * The base URL for the static router (default: `/`)
14
+ */
15
+ basename?: string;
16
+ /**
17
+ * The child elements to render inside the static router
18
+ */
19
+ children?: React$1.ReactNode;
20
+ /**
21
+ * The {@link Location} to render the static router at (default: `/`)
22
+ */
23
+ location: Partial<Location> | string;
24
+ }
25
+ /**
26
+ * A {@link Router | `<Router>`} that may not navigate to any other {@link Location}.
27
+ * This is useful on the server where there is no stateful UI.
28
+ *
29
+ * @public
30
+ * @category Declarative Routers
31
+ * @mode declarative
32
+ * @param props Props
33
+ * @param {StaticRouterProps.basename} props.basename n/a
34
+ * @param {StaticRouterProps.children} props.children n/a
35
+ * @param {StaticRouterProps.location} props.location n/a
36
+ * @returns A React element that renders the static {@link Router | `<Router>`}
37
+ */
38
+ declare function StaticRouter({
39
+ basename,
40
+ children,
41
+ location: locationProp
42
+ }: StaticRouterProps): React$1.JSX.Element;
43
+ /**
44
+ * @category Types
45
+ */
46
+ interface StaticRouterProviderProps {
47
+ /**
48
+ * The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
49
+ * `query`
50
+ */
51
+ context: StaticHandlerContext;
52
+ /**
53
+ * The static {@link DataRouter} from {@link createStaticRouter}
54
+ */
55
+ router: Router;
56
+ /**
57
+ * Whether to hydrate the router on the client (default `true`)
58
+ */
59
+ hydrate?: boolean;
60
+ /**
61
+ * The [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
62
+ * to use for the hydration [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
63
+ * tag
64
+ */
65
+ nonce?: string;
66
+ }
67
+ /**
68
+ * A {@link DataRouter} that may not navigate to any other {@link Location}.
69
+ * This is useful on the server where there is no stateful UI.
70
+ *
71
+ * @example
72
+ * export async function handleRequest(request: Request) {
73
+ * let { query, dataRoutes } = createStaticHandler(routes);
74
+ * let context = await query(request));
75
+ *
76
+ * if (context instanceof Response) {
77
+ * return context;
78
+ * }
79
+ *
80
+ * let router = createStaticRouter(dataRoutes, context);
81
+ * return new Response(
82
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
83
+ * { headers: { "Content-Type": "text/html" } }
84
+ * );
85
+ * }
86
+ *
87
+ * @public
88
+ * @category Data Routers
89
+ * @mode data
90
+ * @param props Props
91
+ * @param {StaticRouterProviderProps.context} props.context n/a
92
+ * @param {StaticRouterProviderProps.hydrate} props.hydrate n/a
93
+ * @param {StaticRouterProviderProps.nonce} props.nonce n/a
94
+ * @param {StaticRouterProviderProps.router} props.router n/a
95
+ * @returns A React element that renders the static router provider
96
+ */
97
+ declare function StaticRouterProvider({
98
+ context,
99
+ router,
100
+ hydrate,
101
+ nonce
102
+ }: StaticRouterProviderProps): React$1.JSX.Element;
103
+ /**
104
+ * Create a static {@link DataRouter} for server-side rendering
105
+ *
106
+ * @example
107
+ * export async function handleRequest(request: Request) {
108
+ * let { query, dataRoutes } = createStaticHandler(routes);
109
+ * let context = await query(request);
110
+ *
111
+ * if (context instanceof Response) {
112
+ * return context;
113
+ * }
114
+ *
115
+ * let router = createStaticRouter(dataRoutes, context);
116
+ * return new Response(
117
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
118
+ * { headers: { "Content-Type": "text/html" } }
119
+ * );
120
+ * }
121
+ *
122
+ * @public
123
+ * @category Data Routers
124
+ * @mode data
125
+ * @param routes The route objects to create a static {@link DataRouter} for
126
+ * @param context The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
127
+ * `query`
128
+ * @param opts Options
129
+ * @param opts.future Future flags for the static {@link DataRouter}
130
+ * @param opts.branches Optional pre-computed route branches
131
+ * @returns A static {@link DataRouter} that can be used to render the provided routes
132
+ */
133
+ declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext, opts?: {
134
+ branches?: RouteBranch<DataRouteObject>[];
135
+ future?: Partial<FutureConfig>;
136
+ }): Router;
137
+ //#endregion
138
+ export { StaticRouter, StaticRouterProps, StaticRouterProvider, StaticRouterProviderProps, createStaticRouter };
@@ -0,0 +1,301 @@
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 { ABSOLUTE_URL_REGEX } from "../router/url.js";
12
+ import { createPath, invariant, parsePath } from "../router/history.js";
13
+ import { convertRoutesToDataRoutes, isRouteErrorResponse } from "../router/utils.js";
14
+ import { IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION } from "../router/router.js";
15
+ import { DataRouterContext, DataRouterStateContext, FetchersContext, ViewTransitionContext } from "../context.js";
16
+ import { DataRoutes, Router } from "../components.js";
17
+ import { escapeHtml } from "./ssr/markup.js";
18
+ import * as React$1 from "react";
19
+ //#region lib/dom/server.tsx
20
+ /**
21
+ * A {@link Router | `<Router>`} that may not navigate to any other {@link Location}.
22
+ * This is useful on the server where there is no stateful UI.
23
+ *
24
+ * @public
25
+ * @category Declarative Routers
26
+ * @mode declarative
27
+ * @param props Props
28
+ * @param {StaticRouterProps.basename} props.basename n/a
29
+ * @param {StaticRouterProps.children} props.children n/a
30
+ * @param {StaticRouterProps.location} props.location n/a
31
+ * @returns A React element that renders the static {@link Router | `<Router>`}
32
+ */
33
+ function StaticRouter({ basename, children, location: locationProp = "/" }) {
34
+ if (typeof locationProp === "string") locationProp = parsePath(locationProp);
35
+ let action = "POP";
36
+ let location = {
37
+ pathname: locationProp.pathname || "/",
38
+ search: locationProp.search || "",
39
+ hash: locationProp.hash || "",
40
+ state: locationProp.state != null ? locationProp.state : null,
41
+ key: locationProp.key || "default",
42
+ mask: void 0
43
+ };
44
+ let staticNavigator = getStatelessNavigator();
45
+ return /* @__PURE__ */ React$1.createElement(Router, {
46
+ basename,
47
+ children,
48
+ location,
49
+ navigationType: action,
50
+ navigator: staticNavigator,
51
+ static: true,
52
+ useTransitions: false
53
+ });
54
+ }
55
+ /**
56
+ * A {@link DataRouter} that may not navigate to any other {@link Location}.
57
+ * This is useful on the server where there is no stateful UI.
58
+ *
59
+ * @example
60
+ * export async function handleRequest(request: Request) {
61
+ * let { query, dataRoutes } = createStaticHandler(routes);
62
+ * let context = await query(request));
63
+ *
64
+ * if (context instanceof Response) {
65
+ * return context;
66
+ * }
67
+ *
68
+ * let router = createStaticRouter(dataRoutes, context);
69
+ * return new Response(
70
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
71
+ * { headers: { "Content-Type": "text/html" } }
72
+ * );
73
+ * }
74
+ *
75
+ * @public
76
+ * @category Data Routers
77
+ * @mode data
78
+ * @param props Props
79
+ * @param {StaticRouterProviderProps.context} props.context n/a
80
+ * @param {StaticRouterProviderProps.hydrate} props.hydrate n/a
81
+ * @param {StaticRouterProviderProps.nonce} props.nonce n/a
82
+ * @param {StaticRouterProviderProps.router} props.router n/a
83
+ * @returns A React element that renders the static router provider
84
+ */
85
+ function StaticRouterProvider({ context, router, hydrate = true, nonce }) {
86
+ invariant(router && context, "You must provide `router` and `context` to <StaticRouterProvider>");
87
+ let dataRouterContext = {
88
+ router,
89
+ navigator: getStatelessNavigator(),
90
+ static: true,
91
+ staticContext: context,
92
+ basename: context.basename || "/"
93
+ };
94
+ let fetchersContext = /* @__PURE__ */ new Map();
95
+ let hydrateScript = "";
96
+ if (hydrate !== false) {
97
+ let data = {
98
+ loaderData: context.loaderData,
99
+ actionData: context.actionData,
100
+ errors: serializeErrors(context.errors)
101
+ };
102
+ hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${escapeHtml(JSON.stringify(JSON.stringify(data)))});`;
103
+ }
104
+ let { state } = dataRouterContext.router;
105
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement(DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React$1.createElement(DataRouterStateContext.Provider, { value: state }, /* @__PURE__ */ React$1.createElement(FetchersContext.Provider, { value: fetchersContext }, /* @__PURE__ */ React$1.createElement(ViewTransitionContext.Provider, { value: { isTransitioning: false } }, /* @__PURE__ */ React$1.createElement(Router, {
106
+ basename: dataRouterContext.basename,
107
+ location: state.location,
108
+ navigationType: state.historyAction,
109
+ navigator: dataRouterContext.navigator,
110
+ static: dataRouterContext.static,
111
+ useTransitions: false
112
+ }, /* @__PURE__ */ React$1.createElement(DataRoutes, {
113
+ manifest: router.manifest,
114
+ routes: router.routes,
115
+ future: router.future,
116
+ state,
117
+ isStatic: true
118
+ })))))), hydrateScript ? /* @__PURE__ */ React$1.createElement("script", {
119
+ suppressHydrationWarning: true,
120
+ nonce,
121
+ dangerouslySetInnerHTML: { __html: hydrateScript }
122
+ }) : null);
123
+ }
124
+ function serializeErrors(errors) {
125
+ if (!errors) return null;
126
+ let entries = Object.entries(errors);
127
+ let serialized = {};
128
+ for (let [key, val] of entries) if (isRouteErrorResponse(val)) serialized[key] = {
129
+ ...val,
130
+ __type: "RouteErrorResponse"
131
+ };
132
+ else if (val instanceof Error) serialized[key] = {
133
+ message: val.message,
134
+ __type: "Error",
135
+ ...val.name !== "Error" ? { __subType: val.name } : {}
136
+ };
137
+ else serialized[key] = val;
138
+ return serialized;
139
+ }
140
+ function getStatelessNavigator() {
141
+ return {
142
+ createHref,
143
+ encodeLocation,
144
+ push(to) {
145
+ throw new Error(`You cannot use navigator.push() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${JSON.stringify(to)})\` somewhere in your app.`);
146
+ },
147
+ replace(to) {
148
+ throw new Error(`You cannot use navigator.replace() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere in your app.`);
149
+ },
150
+ go(delta) {
151
+ throw new Error(`You cannot use navigator.go() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${delta})\` somewhere in your app.`);
152
+ },
153
+ back() {
154
+ throw new Error("You cannot use navigator.back() on the server because it is a stateless environment.");
155
+ },
156
+ forward() {
157
+ throw new Error("You cannot use navigator.forward() on the server because it is a stateless environment.");
158
+ }
159
+ };
160
+ }
161
+ /**
162
+ * Create a static {@link DataRouter} for server-side rendering
163
+ *
164
+ * @example
165
+ * export async function handleRequest(request: Request) {
166
+ * let { query, dataRoutes } = createStaticHandler(routes);
167
+ * let context = await query(request);
168
+ *
169
+ * if (context instanceof Response) {
170
+ * return context;
171
+ * }
172
+ *
173
+ * let router = createStaticRouter(dataRoutes, context);
174
+ * return new Response(
175
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
176
+ * { headers: { "Content-Type": "text/html" } }
177
+ * );
178
+ * }
179
+ *
180
+ * @public
181
+ * @category Data Routers
182
+ * @mode data
183
+ * @param routes The route objects to create a static {@link DataRouter} for
184
+ * @param context The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
185
+ * `query`
186
+ * @param opts Options
187
+ * @param opts.future Future flags for the static {@link DataRouter}
188
+ * @param opts.branches Optional pre-computed route branches
189
+ * @returns A static {@link DataRouter} that can be used to render the provided routes
190
+ */
191
+ function createStaticRouter(routes, context, opts = {}) {
192
+ let manifest = {};
193
+ let dataRoutes = convertRoutesToDataRoutes(routes, void 0, void 0, manifest);
194
+ let matches = context.matches.map((match) => {
195
+ let route = manifest[match.route.id] || match.route;
196
+ return {
197
+ ...match,
198
+ route
199
+ };
200
+ });
201
+ let msg = (method) => `You cannot use router.${method}() on the server because it is a stateless environment`;
202
+ return {
203
+ get basename() {
204
+ return context.basename;
205
+ },
206
+ get future() {
207
+ return { ...opts?.future };
208
+ },
209
+ get state() {
210
+ return {
211
+ historyAction: "POP",
212
+ location: context.location,
213
+ matches,
214
+ loaderData: context.loaderData,
215
+ actionData: context.actionData,
216
+ errors: context.errors,
217
+ initialized: true,
218
+ renderFallback: false,
219
+ navigation: IDLE_NAVIGATION,
220
+ restoreScrollPosition: null,
221
+ preventScrollReset: false,
222
+ revalidation: "idle",
223
+ fetchers: /* @__PURE__ */ new Map(),
224
+ blockers: /* @__PURE__ */ new Map()
225
+ };
226
+ },
227
+ get routes() {
228
+ return dataRoutes;
229
+ },
230
+ get branches() {
231
+ return opts.branches;
232
+ },
233
+ get manifest() {
234
+ return manifest;
235
+ },
236
+ get window() {},
237
+ initialize() {
238
+ throw msg("initialize");
239
+ },
240
+ subscribe() {
241
+ throw msg("subscribe");
242
+ },
243
+ enableScrollRestoration() {
244
+ throw msg("enableScrollRestoration");
245
+ },
246
+ navigate() {
247
+ throw msg("navigate");
248
+ },
249
+ fetch() {
250
+ throw msg("fetch");
251
+ },
252
+ revalidate() {
253
+ throw msg("revalidate");
254
+ },
255
+ createHref,
256
+ encodeLocation,
257
+ getFetcher() {
258
+ return IDLE_FETCHER;
259
+ },
260
+ deleteFetcher() {
261
+ throw msg("deleteFetcher");
262
+ },
263
+ resetFetcher() {
264
+ throw msg("resetFetcher");
265
+ },
266
+ dispose() {
267
+ throw msg("dispose");
268
+ },
269
+ getBlocker() {
270
+ return IDLE_BLOCKER;
271
+ },
272
+ deleteBlocker() {
273
+ throw msg("deleteBlocker");
274
+ },
275
+ patchRoutes() {
276
+ throw msg("patchRoutes");
277
+ },
278
+ _internalFetchControllers: /* @__PURE__ */ new Map(),
279
+ _internalSetRoutes() {
280
+ throw msg("_internalSetRoutes");
281
+ },
282
+ _internalSetStateDoNotUseOrYouWillBreakYourApp() {
283
+ throw msg("_internalSetStateDoNotUseOrYouWillBreakYourApp");
284
+ }
285
+ };
286
+ }
287
+ function createHref(to) {
288
+ return typeof to === "string" ? to : createPath(to);
289
+ }
290
+ function encodeLocation(to) {
291
+ let href = typeof to === "string" ? to : createPath(to);
292
+ href = href.replace(/ $/, "%20");
293
+ let encoded = ABSOLUTE_URL_REGEX.test(href) ? new URL(href) : new URL(href, "http://localhost");
294
+ return {
295
+ pathname: encoded.pathname,
296
+ search: encoded.search,
297
+ hash: encoded.hash
298
+ };
299
+ }
300
+ //#endregion
301
+ export { StaticRouter, StaticRouterProvider, createStaticRouter };
@@ -0,0 +1,198 @@
1
+
2
+ import { PageLinkDescriptor } from "../../router/links.js";
3
+ import { FrameworkContextObject } from "./entry.js";
4
+ import * as React$1 from "react";
5
+
6
+ //#region lib/dom/ssr/components.d.ts
7
+ declare const FrameworkContext: React$1.Context<FrameworkContextObject | undefined>;
8
+ /**
9
+ * Defines the [lazy route discovery](../../explanation/lazy-route-discovery)
10
+ * behavior of the link/form:
11
+ *
12
+ * - "render" - default, discover the route when the link renders
13
+ * - "none" - don't eagerly discover, only discover if the link is clicked
14
+ */
15
+ type DiscoverBehavior = "render" | "none";
16
+ /**
17
+ * Defines the prefetching behavior of the link:
18
+ *
19
+ * - "none": Never fetched
20
+ * - "intent": Fetched when the user focuses or hovers the link
21
+ * - "render": Fetched when the link is rendered
22
+ * - "viewport": Fetched when the link is in the viewport
23
+ */
24
+ type PrefetchBehavior = "intent" | "render" | "none" | "viewport";
25
+ /**
26
+ * Props for the {@link Links} component.
27
+ *
28
+ * @category Types
29
+ */
30
+ interface LinksProps {
31
+ /**
32
+ * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
33
+ * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
34
+ * element. If not provided in Framework Mode, it will default to any
35
+ * {@link ServerRouter | `<ServerRouter nonce>`} prop.
36
+ */
37
+ nonce?: string | undefined;
38
+ /**
39
+ * A [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)
40
+ * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
41
+ * element
42
+ */
43
+ crossOrigin?: "anonymous" | "use-credentials";
44
+ }
45
+ /**
46
+ * Renders all the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
47
+ * tags created by the route module's [`links`](../../start/framework/route-module#links)
48
+ * export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
49
+ * of your document.
50
+ *
51
+ * @example
52
+ * import { Links } from "react-router";
53
+ *
54
+ * export default function Root() {
55
+ * return (
56
+ * <html>
57
+ * <head>
58
+ * <Links />
59
+ * </head>
60
+ * <body></body>
61
+ * </html>
62
+ * );
63
+ * }
64
+ *
65
+ * @public
66
+ * @category Components
67
+ * @mode framework
68
+ * @param props Props
69
+ * @param {LinksProps.nonce} props.nonce n/a
70
+ * @param {LinksProps.crossOrigin} props.crossOrigin n/a
71
+ * @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
72
+ * tags
73
+ */
74
+ declare function Links({
75
+ nonce,
76
+ crossOrigin
77
+ }: LinksProps): React$1.JSX.Element;
78
+ /**
79
+ * Renders [`<link rel=prefetch|modulepreload>`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel)
80
+ * tags for modules and data of another page to enable an instant navigation to
81
+ * that page. [`<Link prefetch>`](./Link#prefetch) uses this internally, but you
82
+ * can render it to prefetch a page for any other reason.
83
+ *
84
+ * For example, you may render one of this as the user types into a search field
85
+ * to prefetch search results before they click through to their selection.
86
+ *
87
+ * @example
88
+ * import { PrefetchPageLinks } from "react-router";
89
+ *
90
+ * <PrefetchPageLinks page="/absolute/path" />
91
+ *
92
+ * @public
93
+ * @category Components
94
+ * @mode framework
95
+ * @param props Props
96
+ * @param {PageLinkDescriptor.page} props.page n/a
97
+ * @param props.linkProps Additional props to spread onto the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
98
+ * tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/crossOrigin),
99
+ * [`integrity`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/integrity),
100
+ * [`rel`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel),
101
+ * etc.
102
+ * @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
103
+ * tags
104
+ */
105
+ declare function PrefetchPageLinks({
106
+ page,
107
+ ...linkProps
108
+ }: PageLinkDescriptor): React$1.JSX.Element | null;
109
+ /**
110
+ * Renders all the [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
111
+ * tags created by the route module's [`meta`](../../start/framework/route-module#meta)
112
+ * export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
113
+ * of your document.
114
+ *
115
+ * @example
116
+ * import { Meta } from "react-router";
117
+ *
118
+ * export default function Root() {
119
+ * return (
120
+ * <html>
121
+ * <head>
122
+ * <Meta />
123
+ * </head>
124
+ * </html>
125
+ * );
126
+ * }
127
+ *
128
+ * @public
129
+ * @category Components
130
+ * @mode framework
131
+ * @returns A collection of React elements for [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
132
+ * tags
133
+ */
134
+ declare function Meta(): React$1.JSX.Element;
135
+ /**
136
+ * A couple common attributes:
137
+ *
138
+ * - `<Scripts crossOrigin>` for hosting your static assets on a different
139
+ * server than your app.
140
+ * - `<Scripts nonce>` to support a [content security policy for scripts](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src)
141
+ * with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources)
142
+ * for your [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
143
+ * tags.
144
+ *
145
+ * You cannot pass through attributes such as [`async`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/async),
146
+ * [`defer`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/defer),
147
+ * [`noModule`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/noModule),
148
+ * [`src`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/src),
149
+ * or [`type`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type),
150
+ * because they are managed by React Router internally.
151
+ *
152
+ * @category Types
153
+ */
154
+ type ScriptsProps = Omit<React$1.HTMLProps<HTMLScriptElement>, "async" | "children" | "dangerouslySetInnerHTML" | "defer" | "noModule" | "src" | "suppressHydrationWarning" | "type"> & {
155
+ /**
156
+ * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
157
+ * attribute to render on the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
158
+ * element. If not provided in Framework Mode, it will default to any
159
+ * {@link ServerRouter | `<ServerRouter nonce>`} prop.
160
+ */
161
+ nonce?: string | undefined;
162
+ };
163
+ /**
164
+ * Renders the client runtime of your app. It should be rendered inside the
165
+ * [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body)
166
+ * of the document.
167
+ *
168
+ * If server rendering, you can omit `<Scripts/>` and the app will work as a
169
+ * traditional web app without JavaScript, relying solely on HTML and browser
170
+ * behaviors.
171
+ *
172
+ * @example
173
+ * import { Scripts } from "react-router";
174
+ *
175
+ * export default function Root() {
176
+ * return (
177
+ * <html>
178
+ * <head />
179
+ * <body>
180
+ * <Scripts />
181
+ * </body>
182
+ * </html>
183
+ * );
184
+ * }
185
+ *
186
+ * @public
187
+ * @category Components
188
+ * @mode framework
189
+ * @param scriptProps Additional props to spread onto the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
190
+ * tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin),
191
+ * [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce),
192
+ * etc.
193
+ * @returns A collection of React elements for [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
194
+ * tags
195
+ */
196
+ declare function Scripts(scriptProps: ScriptsProps): React$1.JSX.Element | null;
197
+ //#endregion
198
+ export { DiscoverBehavior, FrameworkContext, Links, LinksProps, Meta, PrefetchBehavior, PrefetchPageLinks, Scripts, ScriptsProps };