react-router 7.15.1 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/CHANGELOG.md +181 -2
  2. package/dist/development/dom-export.d.ts +6 -172
  3. package/dist/development/dom-export.js +12 -1007
  4. package/dist/development/index-react-server-client.d.ts +7 -4
  5. package/dist/development/index-react-server-client.js +8 -52
  6. package/dist/development/index-react-server.d.ts +1789 -1657
  7. package/dist/development/index-react-server.js +3074 -3674
  8. package/dist/development/index.d.ts +41 -1469
  9. package/dist/development/index.js +36 -2621
  10. package/dist/development/lib/actions.js +50 -0
  11. package/dist/development/lib/components.d.ts +1030 -0
  12. package/dist/development/lib/components.js +841 -0
  13. package/dist/development/lib/context.d.ts +83 -0
  14. package/dist/development/lib/context.js +41 -0
  15. package/dist/development/lib/dom/dom.d.ts +119 -0
  16. package/dist/development/lib/dom/dom.js +143 -0
  17. package/dist/development/lib/dom/lib.d.ts +2054 -0
  18. package/dist/development/lib/dom/lib.js +1272 -0
  19. package/dist/development/lib/dom/server.d.ts +138 -0
  20. package/dist/development/lib/dom/server.js +301 -0
  21. package/dist/development/lib/dom/ssr/components.d.ts +198 -0
  22. package/dist/development/lib/dom/ssr/components.js +589 -0
  23. package/dist/development/lib/dom/ssr/data.js +29 -0
  24. package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  26. package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
  27. package/dist/development/lib/dom/ssr/fallback.js +33 -0
  28. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  29. package/dist/development/lib/dom/ssr/fog-of-war.js +185 -0
  30. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  31. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  32. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  33. package/dist/development/lib/dom/ssr/links.js +170 -0
  34. package/dist/development/lib/dom/ssr/markup.js +24 -0
  35. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  36. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  37. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +75 -0
  38. package/dist/development/lib/dom/ssr/routes-test-stub.js +121 -0
  39. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  40. package/dist/development/lib/dom/ssr/routes.js +303 -0
  41. package/dist/development/lib/dom/ssr/server.d.ts +48 -0
  42. package/dist/development/lib/dom/ssr/server.js +69 -0
  43. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  44. package/dist/development/lib/dom/ssr/single-fetch.js +345 -0
  45. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  46. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  47. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  48. package/dist/development/lib/dom-export/hydrated-router.js +150 -0
  49. package/dist/development/lib/errors.js +29 -0
  50. package/dist/development/lib/hooks.d.ts +974 -0
  51. package/dist/development/lib/hooks.js +1415 -0
  52. package/dist/development/lib/href.d.ts +36 -0
  53. package/dist/development/lib/href.js +70 -0
  54. package/dist/development/lib/router/history.d.ts +264 -0
  55. package/dist/development/lib/router/history.js +378 -0
  56. package/dist/development/lib/router/instrumentation.d.ts +111 -0
  57. package/dist/development/lib/router/instrumentation.js +290 -0
  58. package/dist/development/lib/router/links.d.ts +114 -0
  59. package/dist/development/lib/router/router.d.ts +663 -0
  60. package/dist/development/lib/router/router.js +2988 -0
  61. package/dist/development/lib/router/url.js +18 -0
  62. package/dist/development/lib/router/utils.d.ts +960 -0
  63. package/dist/development/lib/router/utils.js +881 -0
  64. package/dist/development/lib/rsc/browser.d.ts +137 -0
  65. package/dist/development/lib/rsc/browser.js +612 -0
  66. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  67. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  68. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  69. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  70. package/dist/development/lib/rsc/html-stream/server.js +97 -0
  71. package/dist/development/lib/rsc/route-modules.js +27 -0
  72. package/dist/development/lib/rsc/server.rsc.d.ts +224 -0
  73. package/dist/development/lib/rsc/server.ssr.d.ts +152 -0
  74. package/dist/development/lib/rsc/server.ssr.js +419 -0
  75. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  76. package/dist/development/lib/server-runtime/cookies.d.ts +92 -0
  77. package/dist/development/lib/server-runtime/cookies.js +153 -0
  78. package/dist/development/lib/server-runtime/crypto.js +43 -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 +22 -0
  92. package/dist/development/lib/server-runtime/server.js +364 -0
  93. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  94. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +33 -0
  95. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +53 -0
  96. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +29 -0
  97. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +58 -0
  98. package/dist/development/lib/server-runtime/sessions.d.ts +174 -0
  99. package/dist/development/lib/server-runtime/sessions.js +115 -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/{production/register-Bsscfj79.d.ts → development/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 -1007
  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 +1789 -1657
  122. package/dist/production/index-react-server.js +3065 -3674
  123. package/dist/production/index.d.ts +41 -1469
  124. package/dist/production/index.js +36 -2621
  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 +2054 -0
  133. package/dist/production/lib/dom/lib.js +1272 -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 +185 -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 +75 -0
  153. package/dist/production/lib/dom/ssr/routes-test-stub.js +121 -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 +974 -0
  166. package/dist/production/lib/hooks.js +1400 -0
  167. package/dist/production/lib/href.d.ts +36 -0
  168. package/dist/production/lib/href.js +70 -0
  169. package/dist/production/lib/router/history.d.ts +264 -0
  170. package/dist/production/lib/router/history.js +378 -0
  171. package/dist/production/lib/router/instrumentation.d.ts +111 -0
  172. package/dist/production/lib/router/instrumentation.js +290 -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 +960 -0
  178. package/dist/production/lib/router/utils.js +872 -0
  179. package/dist/production/lib/rsc/browser.d.ts +137 -0
  180. package/dist/production/lib/rsc/browser.js +612 -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 +97 -0
  186. package/dist/production/lib/rsc/route-modules.js +27 -0
  187. package/dist/production/lib/rsc/server.rsc.d.ts +224 -0
  188. package/dist/production/lib/rsc/server.ssr.d.ts +152 -0
  189. package/dist/production/lib/rsc/server.ssr.js +419 -0
  190. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  191. package/dist/production/lib/server-runtime/cookies.d.ts +92 -0
  192. package/dist/production/lib/server-runtime/cookies.js +153 -0
  193. package/dist/production/lib/server-runtime/crypto.js +43 -0
  194. package/dist/production/lib/server-runtime/data.js +25 -0
  195. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  196. package/dist/production/lib/server-runtime/dev.js +26 -0
  197. package/dist/production/lib/server-runtime/entry.js +20 -0
  198. package/dist/production/lib/server-runtime/errors.js +75 -0
  199. package/dist/production/lib/server-runtime/headers.js +73 -0
  200. package/dist/production/lib/server-runtime/invariant.js +19 -0
  201. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  202. package/dist/production/lib/server-runtime/mode.js +25 -0
  203. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  204. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  205. package/dist/production/lib/server-runtime/routes.js +74 -0
  206. package/dist/production/lib/server-runtime/server.d.ts +22 -0
  207. package/dist/production/lib/server-runtime/server.js +364 -0
  208. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  209. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +33 -0
  210. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +53 -0
  211. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +29 -0
  212. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +58 -0
  213. package/dist/production/lib/server-runtime/sessions.d.ts +174 -0
  214. package/dist/production/lib/server-runtime/sessions.js +115 -0
  215. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  216. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  217. package/dist/production/lib/server-runtime/urls.js +28 -0
  218. package/dist/production/lib/server-runtime/warnings.js +20 -0
  219. package/dist/production/lib/types/future.d.ts +9 -0
  220. package/dist/production/lib/types/internal.d.ts +26 -177
  221. package/dist/production/lib/types/internal.js +3 -2
  222. package/dist/{development/register-Bsscfj79.d.ts → production/lib/types/register.d.ts} +9 -15
  223. package/dist/production/lib/types/route-data.d.ts +113 -0
  224. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  225. package/dist/production/lib/types/route-module.d.ts +19 -0
  226. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  227. package/dist/production/lib/types/utils.d.ts +11 -0
  228. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  229. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  230. package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
  231. package/dist/production/vendor/turbo-stream-v2/utils.js +39 -0
  232. package/docs/explanation/backend-for-frontend.md +50 -0
  233. package/docs/explanation/code-splitting.md +77 -0
  234. package/docs/explanation/concurrency.md +135 -0
  235. package/docs/explanation/form-vs-fetcher.md +292 -0
  236. package/docs/explanation/hot-module-replacement.md +137 -0
  237. package/docs/explanation/hydration.md +14 -0
  238. package/docs/explanation/index-query-param.md +86 -0
  239. package/docs/explanation/index.md +4 -0
  240. package/docs/explanation/lazy-route-discovery.md +78 -0
  241. package/docs/explanation/location.md +6 -0
  242. package/docs/explanation/progressive-enhancement.md +150 -0
  243. package/docs/explanation/race-conditions.md +88 -0
  244. package/docs/explanation/react-transitions.md +160 -0
  245. package/docs/explanation/route-matching.md +7 -0
  246. package/docs/explanation/server-client-execution.md +4 -0
  247. package/docs/explanation/sessions-and-cookies.md +465 -0
  248. package/docs/explanation/special-files.md +16 -0
  249. package/docs/explanation/state-management.md +524 -0
  250. package/docs/explanation/styling.md +87 -0
  251. package/docs/explanation/type-safety.md +82 -0
  252. package/docs/how-to/accessibility.md +44 -0
  253. package/docs/how-to/client-data.md +199 -0
  254. package/docs/how-to/data-strategy.md +317 -0
  255. package/docs/how-to/error-boundary.md +231 -0
  256. package/docs/how-to/error-reporting.md +142 -0
  257. package/docs/how-to/fetchers.md +307 -0
  258. package/docs/how-to/file-route-conventions.md +410 -0
  259. package/docs/how-to/file-uploads.md +217 -0
  260. package/docs/how-to/form-validation.md +120 -0
  261. package/docs/how-to/headers.md +165 -0
  262. package/docs/how-to/index.md +4 -0
  263. package/docs/how-to/instrumentation.md +661 -0
  264. package/docs/how-to/meta.md +40 -0
  265. package/docs/how-to/middleware.md +647 -0
  266. package/docs/how-to/navigation-blocking.md +233 -0
  267. package/docs/how-to/optimize-revalidation.md +12 -0
  268. package/docs/how-to/pre-rendering.md +225 -0
  269. package/docs/how-to/presets.md +103 -0
  270. package/docs/how-to/react-server-components.md +951 -0
  271. package/docs/how-to/resource-routes.md +126 -0
  272. package/docs/how-to/route-module-type-safety.md +85 -0
  273. package/docs/how-to/search-params.md +4 -0
  274. package/docs/how-to/security.md +39 -0
  275. package/docs/how-to/server-bundles.md +66 -0
  276. package/docs/how-to/spa.md +120 -0
  277. package/docs/how-to/status.md +63 -0
  278. package/docs/how-to/suspense.md +132 -0
  279. package/docs/how-to/using-handle.md +117 -0
  280. package/docs/how-to/view-transitions.md +237 -0
  281. package/docs/how-to/webhook.md +50 -0
  282. package/docs/index.md +36 -0
  283. package/docs/start/data/actions.md +138 -0
  284. package/docs/start/data/custom.md +198 -0
  285. package/docs/start/data/data-loading.md +44 -0
  286. package/docs/start/data/index.md +4 -0
  287. package/docs/start/data/installation.md +56 -0
  288. package/docs/start/data/navigating.md +12 -0
  289. package/docs/start/data/pending-ui.md +12 -0
  290. package/docs/start/data/route-object.md +268 -0
  291. package/docs/start/data/routing.md +281 -0
  292. package/docs/start/data/testing.md +8 -0
  293. package/docs/start/declarative/index.md +4 -0
  294. package/docs/start/declarative/installation.md +43 -0
  295. package/docs/start/declarative/navigating.md +133 -0
  296. package/docs/start/declarative/routing.md +237 -0
  297. package/docs/start/declarative/url-values.md +65 -0
  298. package/docs/start/framework/actions.md +174 -0
  299. package/docs/start/framework/data-loading.md +201 -0
  300. package/docs/start/framework/deploying.md +104 -0
  301. package/docs/start/framework/index.md +4 -0
  302. package/docs/start/framework/installation.md +41 -0
  303. package/docs/start/framework/navigating.md +182 -0
  304. package/docs/start/framework/pending-ui.md +142 -0
  305. package/docs/start/framework/rendering.md +59 -0
  306. package/docs/start/framework/route-module.md +527 -0
  307. package/docs/start/framework/routing.md +362 -0
  308. package/docs/start/framework/testing.md +133 -0
  309. package/docs/start/index.md +4 -0
  310. package/docs/start/modes.md +200 -0
  311. package/docs/upgrading/component-routes.md +363 -0
  312. package/docs/upgrading/future.md +111 -0
  313. package/docs/upgrading/index.md +4 -0
  314. package/docs/upgrading/router-provider.md +445 -0
  315. package/docs/upgrading/v7.md +460 -0
  316. package/package.json +44 -87
  317. package/dist/development/browser-3AnU12UI.d.mts +0 -318
  318. package/dist/development/browser-BOdXz9dK.d.ts +0 -318
  319. package/dist/development/chunk-4N6VE7H7.mjs +0 -11528
  320. package/dist/development/chunk-4YRVXM2U.js +0 -188
  321. package/dist/development/chunk-66UKHEGQ.js +0 -1362
  322. package/dist/development/chunk-D6LUOGOQ.js +0 -10229
  323. package/dist/development/chunk-RJYABSBD.mjs +0 -2585
  324. package/dist/development/context-ByvtofY2.d.mts +0 -1771
  325. package/dist/development/data-BVUf681J.d.mts +0 -1732
  326. package/dist/development/data-BqZ2x964.d.ts +0 -1732
  327. package/dist/development/dom-export.d.mts +0 -172
  328. package/dist/development/dom-export.mjs +0 -1008
  329. package/dist/development/index-react-server-client-BS5F89FR.d.ts +0 -3655
  330. package/dist/development/index-react-server-client-DY04-103.d.mts +0 -2600
  331. package/dist/development/index-react-server-client.d.mts +0 -4
  332. package/dist/development/index-react-server-client.mjs +0 -59
  333. package/dist/development/index-react-server.d.mts +0 -2703
  334. package/dist/development/index-react-server.mjs +0 -3780
  335. package/dist/development/index.d.mts +0 -1472
  336. package/dist/development/index.mjs +0 -277
  337. package/dist/development/instrumentation-cRWWLfsU.d.ts +0 -715
  338. package/dist/development/lib/types/internal.d.mts +0 -184
  339. package/dist/development/lib/types/internal.mjs +0 -10
  340. package/dist/development/register-Df8okEea.d.mts +0 -30
  341. package/dist/production/browser-3AnU12UI.d.mts +0 -318
  342. package/dist/production/browser-BOdXz9dK.d.ts +0 -318
  343. package/dist/production/chunk-6S4627ZB.mjs +0 -2585
  344. package/dist/production/chunk-HUBUW7R3.js +0 -10229
  345. package/dist/production/chunk-JAKZPQZC.mjs +0 -11528
  346. package/dist/production/chunk-PNZCCTKT.js +0 -1362
  347. package/dist/production/chunk-Y6IFXO7V.js +0 -188
  348. package/dist/production/context-ByvtofY2.d.mts +0 -1771
  349. package/dist/production/data-BVUf681J.d.mts +0 -1732
  350. package/dist/production/data-BqZ2x964.d.ts +0 -1732
  351. package/dist/production/dom-export.d.mts +0 -172
  352. package/dist/production/dom-export.mjs +0 -1008
  353. package/dist/production/index-react-server-client-BS5F89FR.d.ts +0 -3655
  354. package/dist/production/index-react-server-client-DY04-103.d.mts +0 -2600
  355. package/dist/production/index-react-server-client.d.mts +0 -4
  356. package/dist/production/index-react-server-client.mjs +0 -59
  357. package/dist/production/index-react-server.d.mts +0 -2703
  358. package/dist/production/index-react-server.mjs +0 -3780
  359. package/dist/production/index.d.mts +0 -1472
  360. package/dist/production/index.mjs +0 -277
  361. package/dist/production/instrumentation-cRWWLfsU.d.ts +0 -715
  362. package/dist/production/lib/types/internal.d.mts +0 -184
  363. package/dist/production/lib/types/internal.mjs +0 -10
  364. package/dist/production/register-Df8okEea.d.mts +0 -30
@@ -0,0 +1,159 @@
1
+ /**
2
+ * react-router v8.3.0
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 vendor/turbo-stream-v2/flatten.ts
12
+ const TIME_LIMIT_MS = 1;
13
+ const getNow = () => Date.now();
14
+ const yieldToMain = () => new Promise((resolve) => setTimeout(resolve, 0));
15
+ async function flatten(input) {
16
+ const { indices } = this;
17
+ const existing = indices.get(input);
18
+ if (existing) return [existing];
19
+ if (input === void 0) return -7;
20
+ if (input === null) return -5;
21
+ if (Number.isNaN(input)) return -2;
22
+ if (input === Number.POSITIVE_INFINITY) return -6;
23
+ if (input === Number.NEGATIVE_INFINITY) return -3;
24
+ if (input === 0 && 1 / input < 0) return -4;
25
+ const index = this.index++;
26
+ indices.set(input, index);
27
+ const stack = [[input, index]];
28
+ await stringify.call(this, stack);
29
+ return index;
30
+ }
31
+ async function stringify(stack) {
32
+ const { deferred, indices, plugins, postPlugins } = this;
33
+ const str = this.stringified;
34
+ let lastYieldTime = getNow();
35
+ const flattenValue = (value) => {
36
+ const existing = indices.get(value);
37
+ if (existing) return [existing];
38
+ if (value === void 0) return -7;
39
+ if (value === null) return -5;
40
+ if (Number.isNaN(value)) return -2;
41
+ if (value === Number.POSITIVE_INFINITY) return -6;
42
+ if (value === Number.NEGATIVE_INFINITY) return -3;
43
+ if (value === 0 && 1 / value < 0) return -4;
44
+ const index = this.index++;
45
+ indices.set(value, index);
46
+ stack.push([value, index]);
47
+ return index;
48
+ };
49
+ let i = 0;
50
+ while (stack.length > 0) {
51
+ const now = getNow();
52
+ if (++i % 6e3 === 0 && now - lastYieldTime >= TIME_LIMIT_MS) {
53
+ await yieldToMain();
54
+ lastYieldTime = getNow();
55
+ }
56
+ const [input, index] = stack.pop();
57
+ const partsForObj = (obj) => Object.keys(obj).map((k) => `"_${flattenValue(k)}":${flattenValue(obj[k])}`).join(",");
58
+ let error = null;
59
+ switch (typeof input) {
60
+ case "boolean":
61
+ case "number":
62
+ case "string":
63
+ str[index] = JSON.stringify(input);
64
+ break;
65
+ case "bigint":
66
+ str[index] = `["B","${input}"]`;
67
+ break;
68
+ case "symbol": {
69
+ const keyFor = Symbol.keyFor(input);
70
+ if (!keyFor) error = /* @__PURE__ */ new Error("Cannot encode symbol unless created with Symbol.for()");
71
+ else str[index] = `["Y",${JSON.stringify(keyFor)}]`;
72
+ break;
73
+ }
74
+ case "object": {
75
+ if (!input) {
76
+ str[index] = `-5`;
77
+ break;
78
+ }
79
+ const isArray = Array.isArray(input);
80
+ let pluginHandled = false;
81
+ if (!isArray && plugins) for (const plugin of plugins) {
82
+ const pluginResult = plugin(input);
83
+ if (Array.isArray(pluginResult)) {
84
+ pluginHandled = true;
85
+ const [pluginIdentifier, ...rest] = pluginResult;
86
+ str[index] = `[${JSON.stringify(pluginIdentifier)}`;
87
+ if (rest.length > 0) str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
88
+ str[index] += "]";
89
+ break;
90
+ }
91
+ }
92
+ if (!pluginHandled) {
93
+ let result = isArray ? "[" : "{";
94
+ if (isArray) {
95
+ for (let i = 0; i < input.length; i++) result += (i ? "," : "") + (i in input ? flattenValue(input[i]) : -1);
96
+ str[index] = `${result}]`;
97
+ } else if (input instanceof Date) {
98
+ const dateTime = input.getTime();
99
+ str[index] = `["D",${Number.isNaN(dateTime) ? JSON.stringify("invalid") : dateTime}]`;
100
+ } else if (input instanceof URL) str[index] = `["U",${JSON.stringify(input.href)}]`;
101
+ else if (input instanceof RegExp) str[index] = `["R",${JSON.stringify(input.source)},${JSON.stringify(input.flags)}]`;
102
+ else if (input instanceof Set) if (input.size > 0) str[index] = `["S",${[...input].map((val) => flattenValue(val)).join(",")}]`;
103
+ else str[index] = `["S"]`;
104
+ else if (input instanceof Map) if (input.size > 0) str[index] = `["M",${[...input].flatMap(([k, v]) => [flattenValue(k), flattenValue(v)]).join(",")}]`;
105
+ else str[index] = `["M"]`;
106
+ else if (input instanceof Promise) {
107
+ str[index] = `["P",${index}]`;
108
+ deferred[index] = input;
109
+ } else if (input instanceof Error) {
110
+ str[index] = `["E",${JSON.stringify(input.message)}`;
111
+ if (input.name !== "Error") str[index] += `,${JSON.stringify(input.name)}`;
112
+ str[index] += "]";
113
+ } else if (Object.getPrototypeOf(input) === null) str[index] = `["N",{${partsForObj(input)}}]`;
114
+ else if (isPlainObject(input)) str[index] = `{${partsForObj(input)}}`;
115
+ else error = /* @__PURE__ */ new Error("Cannot encode object with prototype");
116
+ }
117
+ break;
118
+ }
119
+ default: {
120
+ const isArray = Array.isArray(input);
121
+ let pluginHandled = false;
122
+ if (!isArray && plugins) for (const plugin of plugins) {
123
+ const pluginResult = plugin(input);
124
+ if (Array.isArray(pluginResult)) {
125
+ pluginHandled = true;
126
+ const [pluginIdentifier, ...rest] = pluginResult;
127
+ str[index] = `[${JSON.stringify(pluginIdentifier)}`;
128
+ if (rest.length > 0) str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
129
+ str[index] += "]";
130
+ break;
131
+ }
132
+ }
133
+ if (!pluginHandled) error = /* @__PURE__ */ new Error("Cannot encode function or unexpected type");
134
+ }
135
+ }
136
+ if (error) {
137
+ let pluginHandled = false;
138
+ if (postPlugins) for (const plugin of postPlugins) {
139
+ const pluginResult = plugin(input);
140
+ if (Array.isArray(pluginResult)) {
141
+ pluginHandled = true;
142
+ const [pluginIdentifier, ...rest] = pluginResult;
143
+ str[index] = `[${JSON.stringify(pluginIdentifier)}`;
144
+ if (rest.length > 0) str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
145
+ str[index] += "]";
146
+ break;
147
+ }
148
+ }
149
+ if (!pluginHandled) throw error;
150
+ }
151
+ }
152
+ }
153
+ const objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
154
+ function isPlainObject(thing) {
155
+ const proto = Object.getPrototypeOf(thing);
156
+ return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
157
+ }
158
+ //#endregion
159
+ export { flatten };
@@ -0,0 +1,179 @@
1
+ /**
2
+ * react-router v8.3.0
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 "../../lib/router/utils.js";
12
+ import { Deferred, createLineSplittingTransform } from "./utils.js";
13
+ import { flatten } from "./flatten.js";
14
+ import { unflatten } from "./unflatten.js";
15
+ //#region vendor/turbo-stream-v2/turbo-stream.ts
16
+ async function decode(readable, options) {
17
+ const { plugins } = options ?? {};
18
+ const done = new Deferred();
19
+ const reader = readable.pipeThrough(createLineSplittingTransform()).getReader();
20
+ const decoder = {
21
+ values: [],
22
+ hydrated: [],
23
+ deferred: {},
24
+ plugins
25
+ };
26
+ const decoded = await decodeInitial.call(decoder, reader);
27
+ let donePromise = done.promise;
28
+ if (decoded.done) done.resolve();
29
+ else donePromise = decodeDeferred.call(decoder, reader).then(done.resolve).catch((reason) => {
30
+ for (const deferred of Object.values(decoder.deferred)) deferred.reject(reason);
31
+ done.reject(reason);
32
+ });
33
+ return {
34
+ done: donePromise.then(() => reader.closed),
35
+ value: decoded.value
36
+ };
37
+ }
38
+ async function decodeInitial(reader) {
39
+ const read = await reader.read();
40
+ if (!read.value) throw new SyntaxError();
41
+ let line;
42
+ try {
43
+ line = JSON.parse(read.value);
44
+ } catch (reason) {
45
+ throw new SyntaxError();
46
+ }
47
+ return {
48
+ done: read.done,
49
+ value: unflatten.call(this, line)
50
+ };
51
+ }
52
+ async function decodeDeferred(reader) {
53
+ let read = await reader.read();
54
+ while (!read.done) {
55
+ if (!read.value) continue;
56
+ const line = read.value;
57
+ switch (line[0]) {
58
+ case "P": {
59
+ const colonIndex = line.indexOf(":");
60
+ const deferredId = Number(line.slice(1, colonIndex));
61
+ const deferred = this.deferred[deferredId];
62
+ if (!deferred) throw new Error(`Deferred ID ${deferredId} not found in stream`);
63
+ const lineData = line.slice(colonIndex + 1);
64
+ let jsonLine;
65
+ try {
66
+ jsonLine = JSON.parse(lineData);
67
+ } catch (reason) {
68
+ throw new SyntaxError();
69
+ }
70
+ const value = unflatten.call(this, jsonLine);
71
+ deferred.resolve(value);
72
+ break;
73
+ }
74
+ case "E": {
75
+ const colonIndex = line.indexOf(":");
76
+ const deferredId = Number(line.slice(1, colonIndex));
77
+ const deferred = this.deferred[deferredId];
78
+ if (!deferred) throw new Error(`Deferred ID ${deferredId} not found in stream`);
79
+ const lineData = line.slice(colonIndex + 1);
80
+ let jsonLine;
81
+ try {
82
+ jsonLine = JSON.parse(lineData);
83
+ } catch (reason) {
84
+ throw new SyntaxError();
85
+ }
86
+ const value = unflatten.call(this, jsonLine);
87
+ deferred.reject(value);
88
+ break;
89
+ }
90
+ default: throw new SyntaxError();
91
+ }
92
+ read = await reader.read();
93
+ }
94
+ }
95
+ function encode(input, options) {
96
+ const { onComplete, plugins, postPlugins, signal } = options ?? {};
97
+ const encoder = {
98
+ deferred: {},
99
+ index: 0,
100
+ indices: /* @__PURE__ */ new Map(),
101
+ stringified: [],
102
+ plugins,
103
+ postPlugins,
104
+ signal
105
+ };
106
+ const textEncoder = new TextEncoder();
107
+ let lastSentIndex = 0;
108
+ return new ReadableStream({ async start(controller) {
109
+ const id = await flatten.call(encoder, input);
110
+ if (Array.isArray(id)) throw new Error("This should never happen");
111
+ if (id < 0) controller.enqueue(textEncoder.encode(`${id}\n`));
112
+ else {
113
+ controller.enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]\n`));
114
+ lastSentIndex = encoder.stringified.length - 1;
115
+ }
116
+ const seenPromises = /* @__PURE__ */ new WeakSet();
117
+ let processingChain = Promise.resolve();
118
+ if (Object.keys(encoder.deferred).length) {
119
+ let raceDone;
120
+ const racePromise = new Promise((resolve, reject) => {
121
+ raceDone = resolve;
122
+ if (signal) {
123
+ const rejectPromise = () => reject(signal.reason || /* @__PURE__ */ new Error("Signal was aborted."));
124
+ if (signal.aborted) rejectPromise();
125
+ else signal.addEventListener("abort", (event) => {
126
+ rejectPromise();
127
+ });
128
+ }
129
+ });
130
+ while (Object.keys(encoder.deferred).length > 0) {
131
+ for (const [deferredId, deferred] of Object.entries(encoder.deferred)) {
132
+ if (seenPromises.has(deferred)) continue;
133
+ seenPromises.add(encoder.deferred[Number(deferredId)] = Promise.race([racePromise, deferred]).then((resolved) => {
134
+ processingChain = processingChain.then(async () => {
135
+ const id = await flatten.call(encoder, resolved);
136
+ if (Array.isArray(id)) {
137
+ controller.enqueue(textEncoder.encode(`P${deferredId}:[["Z",${id[0]}]]\n`));
138
+ encoder.index++;
139
+ lastSentIndex++;
140
+ } else if (id < 0) controller.enqueue(textEncoder.encode(`P${deferredId}:${id}\n`));
141
+ else {
142
+ const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
143
+ controller.enqueue(textEncoder.encode(`P${deferredId}:[${values}]\n`));
144
+ lastSentIndex = encoder.stringified.length - 1;
145
+ }
146
+ });
147
+ return processingChain;
148
+ }, (reason) => {
149
+ processingChain = processingChain.then(async () => {
150
+ if (!reason || typeof reason !== "object" || !(reason instanceof Error)) reason = /* @__PURE__ */ new Error("An unknown error occurred");
151
+ const id = await flatten.call(encoder, reason);
152
+ if (Array.isArray(id)) {
153
+ controller.enqueue(textEncoder.encode(`E${deferredId}:[["Z",${id[0]}]]\n`));
154
+ encoder.index++;
155
+ lastSentIndex++;
156
+ } else if (id < 0) controller.enqueue(textEncoder.encode(`E${deferredId}:${id}\n`));
157
+ else {
158
+ const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
159
+ controller.enqueue(textEncoder.encode(`E${deferredId}:[${values}]\n`));
160
+ lastSentIndex = encoder.stringified.length - 1;
161
+ }
162
+ });
163
+ return processingChain;
164
+ }).finally(() => {
165
+ delete encoder.deferred[Number(deferredId)];
166
+ }));
167
+ }
168
+ await Promise.race(Object.values(encoder.deferred));
169
+ }
170
+ raceDone();
171
+ }
172
+ await Promise.all(Object.values(encoder.deferred));
173
+ await processingChain;
174
+ controller.close();
175
+ onComplete?.();
176
+ } });
177
+ }
178
+ //#endregion
179
+ export { decode, encode };
@@ -0,0 +1,199 @@
1
+ /**
2
+ * react-router v8.3.0
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 { SUPPORTED_ERROR_TYPES } from "../../lib/router/utils.js";
12
+ import { Deferred } from "./utils.js";
13
+ //#region vendor/turbo-stream-v2/unflatten.ts
14
+ const globalObj = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
15
+ function unflatten(parsed) {
16
+ const { hydrated, values } = this;
17
+ if (typeof parsed === "number") return hydrate.call(this, parsed);
18
+ if (!Array.isArray(parsed) || !parsed.length) throw new SyntaxError();
19
+ const startIndex = values.length;
20
+ for (const value of parsed) values.push(value);
21
+ hydrated.length = values.length;
22
+ return hydrate.call(this, startIndex);
23
+ }
24
+ function hydrate(index) {
25
+ const { hydrated, values, deferred, plugins } = this;
26
+ let result;
27
+ const stack = [[index, (v) => {
28
+ result = v;
29
+ }]];
30
+ let postRun = [];
31
+ while (stack.length > 0) {
32
+ const [index, set] = stack.pop();
33
+ switch (index) {
34
+ case -7:
35
+ set(void 0);
36
+ continue;
37
+ case -5:
38
+ set(null);
39
+ continue;
40
+ case -2:
41
+ set(NaN);
42
+ continue;
43
+ case -6:
44
+ set(Infinity);
45
+ continue;
46
+ case -3:
47
+ set(-Infinity);
48
+ continue;
49
+ case -4:
50
+ set(-0);
51
+ continue;
52
+ }
53
+ if (hydrated[index]) {
54
+ set(hydrated[index]);
55
+ continue;
56
+ }
57
+ const value = values[index];
58
+ if (!value || typeof value !== "object") {
59
+ hydrated[index] = value;
60
+ set(value);
61
+ continue;
62
+ }
63
+ if (Array.isArray(value)) if (typeof value[0] === "string") {
64
+ const [type, b, c] = value;
65
+ switch (type) {
66
+ case "D":
67
+ set(hydrated[index] = new Date(b));
68
+ continue;
69
+ case "U":
70
+ set(hydrated[index] = new URL(b));
71
+ continue;
72
+ case "B":
73
+ set(hydrated[index] = BigInt(b));
74
+ continue;
75
+ case "R":
76
+ set(hydrated[index] = new RegExp(b, c));
77
+ continue;
78
+ case "Y":
79
+ set(hydrated[index] = Symbol.for(b));
80
+ continue;
81
+ case "S":
82
+ const newSet = /* @__PURE__ */ new Set();
83
+ hydrated[index] = newSet;
84
+ for (let i = value.length - 1; i > 0; i--) stack.push([value[i], (v) => {
85
+ newSet.add(v);
86
+ }]);
87
+ set(newSet);
88
+ continue;
89
+ case "M":
90
+ const map = /* @__PURE__ */ new Map();
91
+ hydrated[index] = map;
92
+ for (let i = value.length - 2; i > 0; i -= 2) {
93
+ const r = [];
94
+ stack.push([value[i + 1], (v) => {
95
+ r[1] = v;
96
+ }]);
97
+ stack.push([value[i], (k) => {
98
+ r[0] = k;
99
+ }]);
100
+ postRun.push(() => {
101
+ map.set(r[0], r[1]);
102
+ });
103
+ }
104
+ set(map);
105
+ continue;
106
+ case "N":
107
+ const obj = Object.create(null);
108
+ hydrated[index] = obj;
109
+ for (const key of Object.keys(b).reverse()) {
110
+ const r = [];
111
+ stack.push([b[key], (v) => {
112
+ r[1] = v;
113
+ }]);
114
+ stack.push([Number(key.slice(1)), (k) => {
115
+ r[0] = k;
116
+ }]);
117
+ postRun.push(() => {
118
+ obj[r[0]] = r[1];
119
+ });
120
+ }
121
+ set(obj);
122
+ continue;
123
+ case "P":
124
+ if (hydrated[b]) set(hydrated[index] = hydrated[b]);
125
+ else {
126
+ const d = new Deferred();
127
+ deferred[b] = d;
128
+ set(hydrated[index] = d.promise);
129
+ }
130
+ continue;
131
+ case "E":
132
+ const [, message, errorType] = value;
133
+ let error = errorType && globalObj && SUPPORTED_ERROR_TYPES.includes(errorType) && errorType in globalObj && typeof globalObj[errorType] === "function" ? new globalObj[errorType](message) : new Error(message);
134
+ hydrated[index] = error;
135
+ set(error);
136
+ continue;
137
+ case "Z":
138
+ set(hydrated[index] = hydrated[b]);
139
+ continue;
140
+ default:
141
+ if (Array.isArray(plugins)) {
142
+ const r = [];
143
+ const vals = value.slice(1);
144
+ for (let i = 0; i < vals.length; i++) {
145
+ const v = vals[i];
146
+ stack.push([v, (v) => {
147
+ r[i] = v;
148
+ }]);
149
+ }
150
+ postRun.push(() => {
151
+ for (const plugin of plugins) {
152
+ const result = plugin(value[0], ...r);
153
+ if (result) {
154
+ set(hydrated[index] = result.value);
155
+ return;
156
+ }
157
+ }
158
+ throw new SyntaxError();
159
+ });
160
+ continue;
161
+ }
162
+ throw new SyntaxError();
163
+ }
164
+ } else {
165
+ const array = [];
166
+ hydrated[index] = array;
167
+ for (let i = 0; i < value.length; i++) {
168
+ const n = value[i];
169
+ if (n !== -1) stack.push([n, (v) => {
170
+ array[i] = v;
171
+ }]);
172
+ }
173
+ set(array);
174
+ continue;
175
+ }
176
+ else {
177
+ const object = {};
178
+ hydrated[index] = object;
179
+ for (const key of Object.keys(value).reverse()) {
180
+ const r = [];
181
+ stack.push([value[key], (v) => {
182
+ r[1] = v;
183
+ }]);
184
+ stack.push([Number(key.slice(1)), (k) => {
185
+ r[0] = k;
186
+ }]);
187
+ postRun.push(() => {
188
+ object[r[0]] = r[1];
189
+ });
190
+ }
191
+ set(object);
192
+ continue;
193
+ }
194
+ }
195
+ while (postRun.length > 0) postRun.pop()();
196
+ return result;
197
+ }
198
+ //#endregion
199
+ export { unflatten };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * react-router v8.3.0
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 vendor/turbo-stream-v2/utils.ts
12
+ var Deferred = class {
13
+ promise;
14
+ resolve;
15
+ reject;
16
+ constructor() {
17
+ this.promise = new Promise((resolve, reject) => {
18
+ this.resolve = resolve;
19
+ this.reject = reject;
20
+ });
21
+ }
22
+ };
23
+ function createLineSplittingTransform() {
24
+ const decoder = new TextDecoder();
25
+ let leftover = "";
26
+ return new TransformStream({
27
+ transform(chunk, controller) {
28
+ const str = decoder.decode(chunk, { stream: true });
29
+ const parts = (leftover + str).split("\n");
30
+ leftover = parts.pop() || "";
31
+ for (const part of parts) controller.enqueue(part);
32
+ },
33
+ flush(controller) {
34
+ if (leftover) controller.enqueue(leftover);
35
+ }
36
+ });
37
+ }
38
+ //#endregion
39
+ export { Deferred, createLineSplittingTransform };
@@ -0,0 +1,50 @@
1
+ ---
2
+ title: Backend For Frontend
3
+ ---
4
+
5
+ # Backend For Frontend
6
+
7
+ [MODES: framework]
8
+
9
+ <br/>
10
+ <br/>
11
+
12
+ While React Router can serve as your fullstack application, it also fits perfectly into the "Backend for Frontend" architecture.
13
+
14
+ The BFF strategy employs a web server with a job scoped to serving the frontend web app and connecting it to the services it needs: your database, mailer, job queues, existing backend APIs (REST, GraphQL), etc. Instead of your UI integrating directly from the browser to these services, it connects to the BFF, and the BFF connects to your services.
15
+
16
+ Mature apps already have a lot of backend application code in Ruby, Elixir, PHP, etc., and there's no reason to justify migrating it all to a server-side JavaScript runtime just to get the benefits of React Router. Instead, you can use your React Router app as a backend for your frontend.
17
+
18
+ You can use `fetch` right from your loaders and actions to your backend.
19
+
20
+ ```tsx lines=[7,13,17]
21
+ import escapeHtml from "escape-html";
22
+
23
+ export async function loader() {
24
+ const apiUrl = "https://api.example.com/some-data.json";
25
+ const res = await fetch(apiUrl, {
26
+ headers: {
27
+ Authorization: `Bearer ${process.env.API_TOKEN}`,
28
+ },
29
+ });
30
+
31
+ const data = await res.json();
32
+
33
+ const prunedData = data.map((record) => {
34
+ return {
35
+ id: record.id,
36
+ title: record.title,
37
+ formattedBody: escapeHtml(record.content),
38
+ };
39
+ });
40
+ return { prunedData };
41
+ }
42
+ ```
43
+
44
+ There are several benefits of this approach vs. fetching directly from the browser. The highlighted lines above show how you can:
45
+
46
+ 1. Simplify third-party integrations and keep tokens and secrets out of client bundles
47
+ 2. Prune the data down to send less kB over the network, speeding up your app significantly
48
+ 3. Move a lot of code from browser bundles to the server, like `escapeHtml`, which speeds up your app. Additionally, moving code to the server usually makes your code easier to maintain since server-side code doesn't have to worry about UI states for async operations
49
+
50
+ Again, React Router can be used as your only server by talking directly to the database and other services with server-side JavaScript APIs, but it also works perfectly as a backend for your frontend. Go ahead and keep your existing API server for application logic and let React Router connect the UI to it.
@@ -0,0 +1,77 @@
1
+ ---
2
+ title: Automatic Code Splitting
3
+ ---
4
+
5
+ # Automatic Code Splitting
6
+
7
+ [MODES: framework]
8
+
9
+ <br/>
10
+ <br/>
11
+
12
+ When using React Router's framework features, your application is automatically code split to improve the performance of initial load times when users visit your application.
13
+
14
+ ## Code Splitting by Route
15
+
16
+ Consider this simple route config:
17
+
18
+ ```tsx filename=app/routes.ts
19
+ import {
20
+ type RouteConfig,
21
+ route,
22
+ } from "@react-router/dev/routes";
23
+
24
+ export default [
25
+ route("/contact", "./contact.tsx"),
26
+ route("/about", "./about.tsx"),
27
+ ] satisfies RouteConfig;
28
+ ```
29
+
30
+ Instead of bundling all routes into a single giant build, the modules referenced (`contact.tsx` and `about.tsx`) become entry points to the bundler.
31
+
32
+ Because these entry points are coupled to URL segments, React Router knows just from a URL which bundles are needed in the browser, and more importantly, which are not.
33
+
34
+ If the user visits `"/about"` then the bundles for `about.tsx` will be loaded but not `contact.tsx`. This drastically reduces the JavaScript footprint for initial page loads and speeds up your application.
35
+
36
+ ## Route Module Splitting
37
+
38
+ React Router can also split client-side route exports (`clientLoader`, `clientAction`, `clientMiddleware`, `HydrateFallback`) into separate chunks that can be loaded independently from the route component.
39
+
40
+ This allows these exports to be fetched and executed while the component code is still downloading, improving performance for client-side data loading.
41
+
42
+ This behavior is enabled by default. You can set `splitRouteModules` to `false` to opt out, or `"enforce"` to require all routes to be splittable. The `"enforce"` option will cause build failures for routes that cannot be split due to shared code.
43
+
44
+ ```ts filename=react-router.config.ts
45
+ import type { Config } from "@react-router/dev/config";
46
+
47
+ export default {
48
+ splitRouteModules: false,
49
+ } satisfies Config;
50
+ ```
51
+
52
+ ## Removal of Server Code
53
+
54
+ Any server-only [Route Module APIs][route-module] will be removed from the bundles. Consider this route module:
55
+
56
+ ```tsx
57
+ export async function loader() {
58
+ return { message: "hello" };
59
+ }
60
+
61
+ export async function action() {
62
+ console.log(Date.now());
63
+ return { ok: true };
64
+ }
65
+
66
+ export async function headers() {
67
+ return { "Cache-Control": "max-age=300" };
68
+ }
69
+
70
+ export default function Component({ loaderData }) {
71
+ return <div>{loaderData.message}</div>;
72
+ }
73
+ ```
74
+
75
+ After building for the browser, only the `Component` will still be in the bundle, so you can use server-only code in the other module exports.
76
+
77
+ [route-module]: ../start/framework/route-module