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,465 @@
1
+ ---
2
+ title: Sessions and Cookies
3
+ ---
4
+
5
+ # Sessions and Cookies
6
+
7
+ [MODES: framework, data]
8
+
9
+ ## Sessions
10
+
11
+ Sessions are an important part of websites that allow the server to identify requests coming from the same person, especially when it comes to server-side form validation or when JavaScript is not on the page. Sessions are a fundamental building block of many sites that let users "log in", including social, e-commerce, business, and educational websites.
12
+
13
+ When using React Router as your framework, sessions are managed on a per-route basis (rather than something like express middleware) in your `loader` and `action` methods using a "session storage" object (that implements the [`SessionStorage`][session-storage] interface). Session storage understands how to parse and generate cookies, and how to store session data in a database or filesystem.
14
+
15
+ ### Using Sessions
16
+
17
+ This is an example of a cookie session storage:
18
+
19
+ ```ts filename=app/sessions.server.ts
20
+ import { createCookieSessionStorage } from "react-router";
21
+
22
+ type SessionData = {
23
+ userId: string;
24
+ };
25
+
26
+ type SessionFlashData = {
27
+ error: string;
28
+ };
29
+
30
+ const { getSession, commitSession, destroySession } =
31
+ createCookieSessionStorage<SessionData, SessionFlashData>(
32
+ {
33
+ // a Cookie from `createCookie` or the CookieOptions to create one
34
+ cookie: {
35
+ name: "__session",
36
+
37
+ // all of these are optional
38
+ domain: "reactrouter.com",
39
+ // Expires can also be set (although maxAge overrides it when used in combination).
40
+ // Note that this method is NOT recommended as `new Date` creates only one date on each server deployment, not a dynamic date in the future!
41
+ //
42
+ // expires: new Date(Date.now() + 60_000),
43
+ httpOnly: true,
44
+ maxAge: 60,
45
+ path: "/",
46
+ sameSite: "lax",
47
+ secrets: ["s3cret1"],
48
+ secure: true,
49
+ },
50
+ },
51
+ );
52
+
53
+ export { getSession, commitSession, destroySession };
54
+ ```
55
+
56
+ We recommend setting up your session storage object in `app/sessions.server.ts` so all routes that need to access session data can import from the same spot.
57
+
58
+ The input/output to a session storage object are HTTP cookies. `getSession()` retrieves the current session from the incoming request's `Cookie` header, and `commitSession()`/`destroySession()` provide the `Set-Cookie` header for the outgoing response.
59
+
60
+ You'll use methods to get access to sessions in your `loader` and `action` functions.
61
+
62
+ After retrieving a session with `getSession`, the returned session object has a handful of methods and properties:
63
+
64
+ ```tsx
65
+ export async function action({
66
+ request,
67
+ }: ActionFunctionArgs) {
68
+ const session = await getSession(
69
+ request.headers.get("Cookie"),
70
+ );
71
+ session.get("foo");
72
+ session.has("bar");
73
+ // etc.
74
+ }
75
+ ```
76
+
77
+ See the [Session API][session-api] for all methods available on the session object.
78
+
79
+ ### Login form example
80
+
81
+ A login form might look something like this:
82
+
83
+ ```tsx filename=app/routes/login.tsx lines=[4-7,12-14,16,22,25,33-35,46,51,56,61]
84
+ import { data, redirect } from "react-router";
85
+ import type { Route } from "./+types/login";
86
+
87
+ import {
88
+ getSession,
89
+ commitSession,
90
+ } from "../sessions.server";
91
+
92
+ export async function loader({
93
+ request,
94
+ }: Route.LoaderArgs) {
95
+ const session = await getSession(
96
+ request.headers.get("Cookie"),
97
+ );
98
+
99
+ if (session.has("userId")) {
100
+ // Redirect to the home page if they are already signed in.
101
+ return redirect("/");
102
+ }
103
+
104
+ return data(
105
+ { error: session.get("error") },
106
+ {
107
+ headers: {
108
+ "Set-Cookie": await commitSession(session),
109
+ },
110
+ },
111
+ );
112
+ }
113
+
114
+ export async function action({
115
+ request,
116
+ }: Route.ActionArgs) {
117
+ const session = await getSession(
118
+ request.headers.get("Cookie"),
119
+ );
120
+ const form = await request.formData();
121
+ const username = form.get("username");
122
+ const password = form.get("password");
123
+
124
+ const userId = await validateCredentials(
125
+ username,
126
+ password,
127
+ );
128
+
129
+ if (userId == null) {
130
+ session.flash("error", "Invalid username/password");
131
+
132
+ // Redirect back to the login page with errors.
133
+ return redirect("/login", {
134
+ headers: {
135
+ "Set-Cookie": await commitSession(session),
136
+ },
137
+ });
138
+ }
139
+
140
+ session.set("userId", userId);
141
+
142
+ // Login succeeded, send them to the home page.
143
+ return redirect("/", {
144
+ headers: {
145
+ "Set-Cookie": await commitSession(session),
146
+ },
147
+ });
148
+ }
149
+
150
+ export default function Login({
151
+ loaderData,
152
+ }: Route.ComponentProps) {
153
+ const { error } = loaderData;
154
+
155
+ return (
156
+ <div>
157
+ {error ? <div className="error">{error}</div> : null}
158
+ <form method="POST">
159
+ <div>
160
+ <p>Please sign in</p>
161
+ </div>
162
+ <label>
163
+ Username: <input type="text" name="username" />
164
+ </label>
165
+ <label>
166
+ Password:{" "}
167
+ <input type="password" name="password" />
168
+ </label>
169
+ </form>
170
+ </div>
171
+ );
172
+ }
173
+ ```
174
+
175
+ And then a logout form might look something like this:
176
+
177
+ ```tsx filename=app/routes/logout.tsx
178
+ import {
179
+ getSession,
180
+ destroySession,
181
+ } from "../sessions.server";
182
+ import type { Route } from "./+types/logout";
183
+
184
+ export async function action({
185
+ request,
186
+ }: Route.ActionArgs) {
187
+ const session = await getSession(
188
+ request.headers.get("Cookie"),
189
+ );
190
+ return redirect("/login", {
191
+ headers: {
192
+ "Set-Cookie": await destroySession(session),
193
+ },
194
+ });
195
+ }
196
+
197
+ export default function LogoutRoute() {
198
+ return (
199
+ <>
200
+ <p>Are you sure you want to log out?</p>
201
+ <Form method="post">
202
+ <button>Logout</button>
203
+ </Form>
204
+ <Link to="/">Never mind</Link>
205
+ </>
206
+ );
207
+ }
208
+ ```
209
+
210
+ <docs-warning>It's important that you logout (or perform any mutation for that matter) in an `action` and not a `loader`. Otherwise you open your users to [Cross-Site Request Forgery][csrf] attacks.</docs-warning>
211
+
212
+ ### Session Gotchas
213
+
214
+ Because of nested routes, multiple loaders can be called to construct a single page. When using `session.flash()` or `session.unset()`, you need to be sure no other loaders in the request are going to want to read that, otherwise you'll get race conditions. Typically if you're using flash, you'll want to have a single loader read it, if another loader wants a flash message, use a different key for that loader.
215
+
216
+ ### Creating custom session storage
217
+
218
+ React Router makes it easy to store sessions in your own database if needed. The [`createSessionStorage()`][create-session-storage] API requires a `cookie` (for options for creating a cookie, see [cookies][cookies]) and a set of create, read, update, and delete (CRUD) methods for managing the session data. The cookie is used to persist the session ID.
219
+
220
+ - `createData` will be called from `commitSession` on the initial session creation when no session ID exists in the cookie
221
+ - `readData` will be called from `getSession` when a session ID exists in the cookie
222
+ - `updateData` will be called from `commitSession` when a session ID already exists in the cookie
223
+ - `deleteData` is called from `destroySession`
224
+
225
+ The following example shows how you could do this using a generic database client:
226
+
227
+ ```ts
228
+ import { createSessionStorage } from "react-router";
229
+
230
+ function createDatabaseSessionStorage({
231
+ cookie,
232
+ host,
233
+ port,
234
+ }) {
235
+ // Configure your database client...
236
+ const db = createDatabaseClient(host, port);
237
+
238
+ return createSessionStorage({
239
+ cookie,
240
+ async createData(data, expires) {
241
+ // `expires` is a Date after which the data should be considered
242
+ // invalid. You could use it to invalidate the data somehow or
243
+ // automatically purge this record from your database.
244
+ const id = await db.insert(data);
245
+ return id;
246
+ },
247
+ async readData(id) {
248
+ return (await db.select(id)) || null;
249
+ },
250
+ async updateData(id, data, expires) {
251
+ await db.update(id, data);
252
+ },
253
+ async deleteData(id) {
254
+ await db.delete(id);
255
+ },
256
+ });
257
+ }
258
+ ```
259
+
260
+ And then you can use it like this:
261
+
262
+ ```ts
263
+ const { getSession, commitSession, destroySession } =
264
+ createDatabaseSessionStorage({
265
+ host: "localhost",
266
+ port: 1234,
267
+ cookie: {
268
+ name: "__session",
269
+ sameSite: "lax",
270
+ },
271
+ });
272
+ ```
273
+
274
+ The `expires` argument to `createData` and `updateData` is the same `Date` at which the cookie itself expires and is no longer valid. You can use this information to automatically purge the session record from your database to save on space, or to ensure that you do not otherwise return any data for old, expired cookies.
275
+
276
+ ### Additional session utils
277
+
278
+ There are also several other session utilities available if you need them:
279
+
280
+ - [`isSession`][is-session]
281
+ - [`createMemorySessionStorage`][create-memory-session-storage] (local dev and testing)
282
+ - [`createSession`][create-session] (custom storage)
283
+ - [`createFileSessionStorage`][create-file-session-storage] (node)
284
+ - [`createWorkersKVSessionStorage`][create-workers-kv-session-storage] (Cloudflare Workers)
285
+ - [`createArcTableSessionStorage`][create-arc-table-session-storage] (architect, Amazon DynamoDB)
286
+
287
+ ## Cookies
288
+
289
+ A [cookie][cookie] is a small piece of information that your server sends someone in a HTTP response that their browser will send back on subsequent requests. This technique is a fundamental building block of many interactive websites that adds state so you can build authentication (see [sessions][sessions]), shopping carts, user preferences, and many other features that require remembering who is "logged in".
290
+
291
+ React Router's [`Cookie` interface][cookie-api] provides a logical, reusable container for cookie metadata.
292
+
293
+ ### Using cookies
294
+
295
+ While you may create these cookies manually, it is more common to use a [session storage][sessions].
296
+
297
+ In React Router, you will typically work with cookies in your `loader` and/or `action` functions, since those are the places where you need to read and write data.
298
+
299
+ Let's say you have a banner on your e-commerce site that prompts users to check out the items you currently have on sale. The banner spans the top of your homepage, and includes a button on the side that allows the user to dismiss the banner so they don't see it for at least another week.
300
+
301
+ First, create a cookie:
302
+
303
+ ```ts filename=app/cookies.server.ts
304
+ import { createCookie } from "react-router";
305
+
306
+ export const userPrefs = createCookie("user-prefs", {
307
+ maxAge: 604_800, // one week
308
+ });
309
+ ```
310
+
311
+ Then, you can `import` the cookie and use it in your `loader` and/or `action`. The `loader` in this case just checks the value of the user preference so you can use it in your component for deciding whether to render the banner. When the button is clicked, the `<form>` calls the `action` on the server and reloads the page without the banner.
312
+
313
+ ### User preferences example
314
+
315
+ ```tsx filename=app/routes/home.tsx lines=[4,9-11,18-20,29]
316
+ import { Link, Form, redirect } from "react-router";
317
+ import type { Route } from "./+types/home";
318
+
319
+ import { userPrefs } from "../cookies.server";
320
+
321
+ export async function loader({
322
+ request,
323
+ }: Route.LoaderArgs) {
324
+ const cookieHeader = request.headers.get("Cookie");
325
+ const cookie =
326
+ (await userPrefs.parse(cookieHeader)) || {};
327
+ return { showBanner: cookie.showBanner };
328
+ }
329
+
330
+ export async function action({
331
+ request,
332
+ }: Route.ActionArgs) {
333
+ const cookieHeader = request.headers.get("Cookie");
334
+ const cookie =
335
+ (await userPrefs.parse(cookieHeader)) || {};
336
+ const bodyParams = await request.formData();
337
+
338
+ if (bodyParams.get("bannerVisibility") === "hidden") {
339
+ cookie.showBanner = false;
340
+ }
341
+
342
+ return redirect("/", {
343
+ headers: {
344
+ "Set-Cookie": await userPrefs.serialize(cookie),
345
+ },
346
+ });
347
+ }
348
+
349
+ export default function Home({
350
+ loaderData,
351
+ }: Route.ComponentProps) {
352
+ return (
353
+ <div>
354
+ {loaderData.showBanner ? (
355
+ <div>
356
+ <Link to="/sale">Don't miss our sale!</Link>
357
+ <Form method="post">
358
+ <input
359
+ type="hidden"
360
+ name="bannerVisibility"
361
+ value="hidden"
362
+ />
363
+ <button type="submit">Hide</button>
364
+ </Form>
365
+ </div>
366
+ ) : null}
367
+ <h1>Welcome!</h1>
368
+ </div>
369
+ );
370
+ }
371
+ ```
372
+
373
+ ### Cookie attributes
374
+
375
+ Cookies have [several attributes][cookie-attrs] that control when they expire, how they are accessed, and where they are sent. Any of these attributes may be specified either in `createCookie(name, options)`, or during `serialize()` when the `Set-Cookie` header is generated.
376
+
377
+ ```ts
378
+ const cookie = createCookie("user-prefs", {
379
+ // These are defaults for this cookie.
380
+ path: "/",
381
+ sameSite: "lax",
382
+ httpOnly: true,
383
+ secure: true,
384
+ expires: new Date(Date.now() + 60_000),
385
+ maxAge: 60,
386
+ });
387
+
388
+ // You can either use the defaults:
389
+ cookie.serialize(userPrefs);
390
+
391
+ // Or override individual ones as needed:
392
+ cookie.serialize(userPrefs, { sameSite: "strict" });
393
+ ```
394
+
395
+ Please read [more info about these attributes][cookie-attrs] to get a better understanding of what they do.
396
+
397
+ ### Signing cookies
398
+
399
+ It is possible to sign a cookie to automatically verify its contents when it is received. Since it's relatively easy to spoof HTTP headers, this is a good idea for any information that you do not want someone to be able to fake, like authentication information (see [sessions][sessions]).
400
+
401
+ To sign a cookie, provide one or more `secrets` when you first create the cookie:
402
+
403
+ ```ts
404
+ const cookie = createCookie("user-prefs", {
405
+ secrets: ["s3cret1"],
406
+ });
407
+ ```
408
+
409
+ Cookies that have one or more `secrets` will be stored and verified in a way that ensures the cookie's integrity.
410
+
411
+ Secrets may be rotated by adding new secrets to the front of the `secrets` array. Cookies that have been signed with old secrets will still be decoded successfully in `cookie.parse()`, and the newest secret (the first one in the array) will always be used to sign outgoing cookies created in `cookie.serialize()`.
412
+
413
+ ```ts filename=app/cookies.server.ts
414
+ export const cookie = createCookie("user-prefs", {
415
+ secrets: ["n3wsecr3t", "olds3cret"],
416
+ });
417
+ ```
418
+
419
+ ```tsx filename=app/routes/my-route.tsx
420
+ import { data } from "react-router";
421
+ import { cookie } from "../cookies.server";
422
+ import type { Route } from "./+types/my-route";
423
+
424
+ export async function loader({
425
+ request,
426
+ }: Route.LoaderArgs) {
427
+ const oldCookie = request.headers.get("Cookie");
428
+ // oldCookie may have been signed with "olds3cret", but still parses ok
429
+ const value = await cookie.parse(oldCookie);
430
+
431
+ return data("...", {
432
+ headers: {
433
+ // Set-Cookie is signed with "n3wsecr3t"
434
+ "Set-Cookie": await cookie.serialize(value),
435
+ },
436
+ });
437
+ }
438
+ ```
439
+
440
+ ### Additional cookie utils
441
+
442
+ There are also several other cookie utilities available if you need them:
443
+
444
+ - [`isCookie`][is-cookie]
445
+ - [`createCookie`][create-cookie]
446
+
447
+ To learn more about each attribute, please see the [MDN Set-Cookie docs][cookie-attrs].
448
+
449
+ [csrf]: https://developer.mozilla.org/en-US/docs/Glossary/CSRF
450
+ [cookies]: #cookies
451
+ [sessions]: #sessions
452
+ [session-storage]: https://api.reactrouter.com/v8/interfaces/react-router.SessionStorage
453
+ [session-api]: https://api.reactrouter.com/v8/interfaces/react-router.Session
454
+ [is-session]: https://api.reactrouter.com/v8/variables/react-router.isSession.html
455
+ [cookie-api]: https://api.reactrouter.com/v8/interfaces/react-router.Cookie
456
+ [create-session-storage]: https://api.reactrouter.com/v8/functions/react-router.createSessionStorage
457
+ [create-session]: https://api.reactrouter.com/v8/variables/react-router.createSession.html
458
+ [create-memory-session-storage]: https://api.reactrouter.com/v8/functions/react-router.createMemorySessionStorage
459
+ [create-file-session-storage]: https://api.reactrouter.com/v8/functions/_react-router_node.createFileSessionStorage
460
+ [create-workers-kv-session-storage]: https://api.reactrouter.com/v8/functions/_react-router_cloudflare.createWorkersKVSessionStorage
461
+ [create-arc-table-session-storage]: https://api.reactrouter.com/v8/functions/_react-router_architect.createArcTableSessionStorage
462
+ [cookie]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
463
+ [cookie-attrs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
464
+ [is-cookie]: https://api.reactrouter.com/v8/variables/react-router.isCookie.html
465
+ [create-cookie]: https://api.reactrouter.com/v8/functions/react-router.createCookie
@@ -0,0 +1,16 @@
1
+ ---
2
+ title: Special Files
3
+ hidden: true
4
+ ---
5
+
6
+ # Special Files
7
+
8
+ The content of this page has been moved to the following:
9
+
10
+ - [`react-router.config.ts`](../api/framework-conventions/react-router.config.ts) - Optional configuration file for your app
11
+ - [`root.tsx`](../api/framework-conventions/root.tsx) - Required root route that renders the HTML document
12
+ - [`routes.ts`](../api/framework-conventions/routes.ts) - Required route configuration mapping URLs to components
13
+ - [`entry.client.tsx`](../api/framework-conventions/entry.client.tsx) - Optional client-side entry point for hydration
14
+ - [`entry.server.tsx`](../api/framework-conventions/entry.server.tsx) - Optional server-side entry point for rendering
15
+ - [`.server` modules](../api/framework-conventions/server-modules) - Server-only modules excluded from client bundles
16
+ - [`.client` modules](../api/framework-conventions/client-modules) - Client-only modules excluded from server bundles