react-router 7.16.0 → 7.17.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 (137) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/development/{browser-nIQ4Nsyi.d.mts → browser-CGcs-0pD.d.mts} +1 -1
  3. package/dist/development/{chunk-QUQL4437.mjs → chunk-6CSD65Y2.mjs} +2 -2
  4. package/dist/{production/chunk-NALGHHKE.mjs → development/chunk-ASILSGTR.mjs} +2 -2
  5. package/dist/development/{chunk-SRID2YZ2.js → chunk-KFNXW4AL.js} +1 -1
  6. package/dist/development/{chunk-XEJDWL2B.js → chunk-PBLBZ3QU.js} +7 -7
  7. package/dist/{production/chunk-SKEDDLRM.js → development/chunk-PULC7NLK.js} +99 -99
  8. package/dist/development/{context-m8rizgnE.d.mts → context-CmHpk1Ws.d.mts} +1 -1
  9. package/dist/development/dom-export.d.mts +3 -3
  10. package/dist/development/dom-export.d.ts +1 -1
  11. package/dist/development/dom-export.js +28 -28
  12. package/dist/development/dom-export.mjs +3 -3
  13. package/dist/development/{index-react-server-client-BLiUx67a.d.ts → index-react-server-client-CwU9bE5R.d.ts} +1 -1
  14. package/dist/development/{index-react-server-client-CdKROblb.d.mts → index-react-server-client-DPrDrCew.d.mts} +1 -1
  15. package/dist/development/index-react-server-client.d.mts +2 -2
  16. package/dist/development/index-react-server-client.d.ts +1 -1
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.js +1 -1
  20. package/dist/development/index-react-server.mjs +1 -1
  21. package/dist/development/index.d.mts +6 -6
  22. package/dist/development/index.d.ts +2 -2
  23. package/dist/development/index.js +85 -85
  24. package/dist/development/index.mjs +3 -3
  25. package/dist/development/lib/types/internal.js +1 -1
  26. package/dist/development/lib/types/internal.mjs +1 -1
  27. package/dist/production/{browser-nIQ4Nsyi.d.mts → browser-CGcs-0pD.d.mts} +1 -1
  28. package/dist/{development/chunk-S54KXAEJ.mjs → production/chunk-5TQZEVD5.mjs} +2 -2
  29. package/dist/production/{chunk-EAQNHM3N.js → chunk-CTIXC7EV.js} +7 -7
  30. package/dist/{development/chunk-IBI7OMNB.js → production/chunk-EN242BO4.js} +99 -99
  31. package/dist/production/{chunk-Q65P7S7Y.mjs → chunk-OSYEOCBT.mjs} +2 -2
  32. package/dist/production/{chunk-Y7DNFQZP.js → chunk-RTRY3JFT.js} +1 -1
  33. package/dist/production/{context-m8rizgnE.d.mts → context-CmHpk1Ws.d.mts} +1 -1
  34. package/dist/production/dom-export.d.mts +3 -3
  35. package/dist/production/dom-export.d.ts +1 -1
  36. package/dist/production/dom-export.js +28 -28
  37. package/dist/production/dom-export.mjs +3 -3
  38. package/dist/production/{index-react-server-client-BLiUx67a.d.ts → index-react-server-client-CwU9bE5R.d.ts} +1 -1
  39. package/dist/production/{index-react-server-client-CdKROblb.d.mts → index-react-server-client-DPrDrCew.d.mts} +1 -1
  40. package/dist/production/index-react-server-client.d.mts +2 -2
  41. package/dist/production/index-react-server-client.d.ts +1 -1
  42. package/dist/production/index-react-server-client.js +4 -4
  43. package/dist/production/index-react-server-client.mjs +2 -2
  44. package/dist/production/index-react-server.js +1 -1
  45. package/dist/production/index-react-server.mjs +1 -1
  46. package/dist/production/index.d.mts +6 -6
  47. package/dist/production/index.d.ts +2 -2
  48. package/dist/production/index.js +85 -85
  49. package/dist/production/index.mjs +3 -3
  50. package/dist/production/lib/types/internal.js +1 -1
  51. package/dist/production/lib/types/internal.mjs +1 -1
  52. package/docs/explanation/backend-for-frontend.md +50 -0
  53. package/docs/explanation/code-splitting.md +61 -0
  54. package/docs/explanation/concurrency.md +135 -0
  55. package/docs/explanation/form-vs-fetcher.md +292 -0
  56. package/docs/explanation/hot-module-replacement.md +137 -0
  57. package/docs/explanation/hydration.md +14 -0
  58. package/docs/explanation/index-query-param.md +86 -0
  59. package/docs/explanation/index.md +4 -0
  60. package/docs/explanation/lazy-route-discovery.md +78 -0
  61. package/docs/explanation/location.md +6 -0
  62. package/docs/explanation/progressive-enhancement.md +150 -0
  63. package/docs/explanation/race-conditions.md +88 -0
  64. package/docs/explanation/react-transitions.md +160 -0
  65. package/docs/explanation/route-matching.md +7 -0
  66. package/docs/explanation/server-client-execution.md +4 -0
  67. package/docs/explanation/sessions-and-cookies.md +465 -0
  68. package/docs/explanation/special-files.md +16 -0
  69. package/docs/explanation/state-management.md +524 -0
  70. package/docs/explanation/styling.md +87 -0
  71. package/docs/explanation/type-safety.md +82 -0
  72. package/docs/how-to/accessibility.md +44 -0
  73. package/docs/how-to/client-data.md +199 -0
  74. package/docs/how-to/data-strategy.md +317 -0
  75. package/docs/how-to/error-boundary.md +231 -0
  76. package/docs/how-to/error-reporting.md +142 -0
  77. package/docs/how-to/fetchers.md +307 -0
  78. package/docs/how-to/file-route-conventions.md +410 -0
  79. package/docs/how-to/file-uploads.md +217 -0
  80. package/docs/how-to/form-validation.md +120 -0
  81. package/docs/how-to/headers.md +164 -0
  82. package/docs/how-to/index.md +4 -0
  83. package/docs/how-to/instrumentation.md +556 -0
  84. package/docs/how-to/meta.md +40 -0
  85. package/docs/how-to/middleware.md +763 -0
  86. package/docs/how-to/navigation-blocking.md +233 -0
  87. package/docs/how-to/optimize-revalidation.md +12 -0
  88. package/docs/how-to/pre-rendering.md +225 -0
  89. package/docs/how-to/presets.md +103 -0
  90. package/docs/how-to/react-server-components.md +899 -0
  91. package/docs/how-to/resource-routes.md +126 -0
  92. package/docs/how-to/route-module-type-safety.md +100 -0
  93. package/docs/how-to/search-params.md +4 -0
  94. package/docs/how-to/security.md +30 -0
  95. package/docs/how-to/server-bundles.md +66 -0
  96. package/docs/how-to/spa.md +120 -0
  97. package/docs/how-to/status.md +63 -0
  98. package/docs/how-to/suspense.md +132 -0
  99. package/docs/how-to/using-handle.md +117 -0
  100. package/docs/how-to/view-transitions.md +237 -0
  101. package/docs/how-to/webhook.md +50 -0
  102. package/docs/index.md +39 -0
  103. package/docs/start/data/actions.md +138 -0
  104. package/docs/start/data/custom.md +198 -0
  105. package/docs/start/data/data-loading.md +44 -0
  106. package/docs/start/data/index.md +4 -0
  107. package/docs/start/data/installation.md +52 -0
  108. package/docs/start/data/navigating.md +12 -0
  109. package/docs/start/data/pending-ui.md +12 -0
  110. package/docs/start/data/route-object.md +268 -0
  111. package/docs/start/data/routing.md +281 -0
  112. package/docs/start/data/testing.md +8 -0
  113. package/docs/start/declarative/index.md +4 -0
  114. package/docs/start/declarative/installation.md +43 -0
  115. package/docs/start/declarative/navigating.md +133 -0
  116. package/docs/start/declarative/routing.md +237 -0
  117. package/docs/start/declarative/url-values.md +65 -0
  118. package/docs/start/framework/actions.md +174 -0
  119. package/docs/start/framework/data-loading.md +201 -0
  120. package/docs/start/framework/deploying.md +96 -0
  121. package/docs/start/framework/index.md +4 -0
  122. package/docs/start/framework/installation.md +41 -0
  123. package/docs/start/framework/navigating.md +182 -0
  124. package/docs/start/framework/pending-ui.md +142 -0
  125. package/docs/start/framework/rendering.md +59 -0
  126. package/docs/start/framework/route-module.md +527 -0
  127. package/docs/start/framework/routing.md +362 -0
  128. package/docs/start/framework/testing.md +133 -0
  129. package/docs/start/index.md +4 -0
  130. package/docs/start/modes.md +201 -0
  131. package/docs/upgrading/component-routes.md +363 -0
  132. package/docs/upgrading/future.md +280 -0
  133. package/docs/upgrading/index.md +4 -0
  134. package/docs/upgrading/remix.md +403 -0
  135. package/docs/upgrading/router-provider.md +442 -0
  136. package/docs/upgrading/v6.md +382 -0
  137. package/package.json +2 -1
@@ -0,0 +1,363 @@
1
+ ---
2
+ title: Framework Adoption from Component Routes
3
+ order: 4
4
+ ---
5
+
6
+ # Framework Adoption from Component Routes
7
+
8
+ If you are using `<RouterProvider>` please see [Framework Adoption from RouterProvider][upgrade-router-provider] instead.
9
+
10
+ If you are using `<Routes>` this is the right place.
11
+
12
+ The React Router Vite plugin adds framework features to React Router. This guide will help you adopt the plugin in your app. If you run into any issues, please reach out for help on [Twitter](https://x.com/remix_run) or [Discord](https://rmx.as/discord).
13
+
14
+ ## Features
15
+
16
+ The Vite plugin adds:
17
+
18
+ - Route loaders, actions, and automatic data revalidation
19
+ - Type-safe Routes Modules
20
+ - Automatic route code-splitting
21
+ - Automatic scroll restoration across navigations
22
+ - Optional Static pre-rendering
23
+ - Optional Server rendering
24
+
25
+ The initial setup requires the most work. However, once complete, you can adopt new features incrementally, one route at a time.
26
+
27
+ ## Prerequisites
28
+
29
+ To use the Vite plugin, your project requires:
30
+
31
+ - Node.js 20+ (if using Node as your runtime)
32
+ - Vite 5+
33
+
34
+ ## 1. Install the Vite plugin
35
+
36
+ **👉 Install the React Router Vite plugin**
37
+
38
+ ```shellscript nonumber
39
+ npm install -D @react-router/dev
40
+ ```
41
+
42
+ **👉 Install a runtime adapter**
43
+
44
+ We will assume you are using Node as your runtime.
45
+
46
+ ```shellscript nonumber
47
+ npm install @react-router/node
48
+ ```
49
+
50
+ **👉 Swap out the React plugin for React Router.**
51
+
52
+ ```diff filename=vite.config.ts
53
+ -import react from '@vitejs/plugin-react'
54
+ +import { reactRouter } from "@react-router/dev/vite";
55
+ import { defineConfig } from "vite";
56
+
57
+
58
+ export default defineConfig({
59
+ plugins: [
60
+ - react()
61
+ + reactRouter()
62
+ ],
63
+ });
64
+ ```
65
+
66
+ ## 2. Add the React Router config
67
+
68
+ **👉 Create a `react-router.config.ts` file**
69
+
70
+ Add the following to the root of your project. In this config you can tell React Router about your project, like where to find the app directory and to not use SSR (server-side rendering) for now.
71
+
72
+ ```shellscript nonumber
73
+ touch react-router.config.ts
74
+ ```
75
+
76
+ ```ts filename=react-router.config.ts
77
+ import type { Config } from "@react-router/dev/config";
78
+
79
+ export default {
80
+ appDirectory: "src",
81
+ ssr: false,
82
+ } satisfies Config;
83
+ ```
84
+
85
+ ## 3. Add the Root entry point
86
+
87
+ In a typical Vite app, the `index.html` file is the entry point for bundling. The React Router Vite plugin moves the entry point to a `root.tsx` file so you can use React to render the shell of your app instead of static HTML, and eventually upgrade to Server Rendering if you want.
88
+
89
+ **👉 Move your existing `index.html` to `root.tsx`**
90
+
91
+ For example, if your current `index.html` looks like this:
92
+
93
+ ```html filename=index.html
94
+ <!DOCTYPE html>
95
+ <html lang="en">
96
+ <head>
97
+ <meta charset="UTF-8" />
98
+ <meta
99
+ name="viewport"
100
+ content="width=device-width, initial-scale=1.0"
101
+ />
102
+ <title>My App</title>
103
+ </head>
104
+ <body>
105
+ <div id="root"></div>
106
+ <script type="module" src="/src/main.tsx"></script>
107
+ </body>
108
+ </html>
109
+ ```
110
+
111
+ You would move that markup into `src/root.tsx` and delete `index.html`:
112
+
113
+ ```shellscript nonumber
114
+ touch src/root.tsx
115
+ ```
116
+
117
+ ```tsx filename=src/root.tsx
118
+ import {
119
+ Links,
120
+ Meta,
121
+ Outlet,
122
+ Scripts,
123
+ ScrollRestoration,
124
+ } from "react-router";
125
+
126
+ export function Layout({
127
+ children,
128
+ }: {
129
+ children: React.ReactNode;
130
+ }) {
131
+ return (
132
+ <html lang="en">
133
+ <head>
134
+ <meta charSet="UTF-8" />
135
+ <meta
136
+ name="viewport"
137
+ content="width=device-width, initial-scale=1.0"
138
+ />
139
+ <title>My App</title>
140
+ <Meta />
141
+ <Links />
142
+ </head>
143
+ <body>
144
+ {children}
145
+ <ScrollRestoration />
146
+ <Scripts />
147
+ </body>
148
+ </html>
149
+ );
150
+ }
151
+
152
+ export default function Root() {
153
+ return <Outlet />;
154
+ }
155
+ ```
156
+
157
+ ## 4. Add client entry module
158
+
159
+ In the typical Vite app the `index.html` file points to `src/main.tsx` as the client entry point. React Router uses a file named `src/entry.client.tsx` instead.
160
+
161
+ **👉 Make `src/entry.client.tsx` your entry point**
162
+
163
+ If your current `src/main.tsx` looks like this:
164
+
165
+ ```tsx filename=src/main.tsx
166
+ import React from "react";
167
+ import ReactDOM from "react-dom/client";
168
+ import { BrowserRouter } from "react-router";
169
+ import "./index.css";
170
+ import App from "./App";
171
+
172
+ ReactDOM.createRoot(
173
+ document.getElementById("root")!,
174
+ ).render(
175
+ <React.StrictMode>
176
+ <BrowserRouter>
177
+ <App />
178
+ </BrowserRouter>
179
+ </React.StrictMode>,
180
+ );
181
+ ```
182
+
183
+ You would rename it to `entry.client.tsx` and change it to this:
184
+
185
+ ```tsx filename=src/entry.client.tsx
186
+ import React from "react";
187
+ import ReactDOM from "react-dom/client";
188
+ import { HydratedRouter } from "react-router/dom";
189
+ import "./index.css";
190
+
191
+ ReactDOM.hydrateRoot(
192
+ document,
193
+ <React.StrictMode>
194
+ <HydratedRouter />
195
+ </React.StrictMode>,
196
+ );
197
+ ```
198
+
199
+ - Use `hydrateRoot` instead of `createRoot`
200
+ - Render a `<HydratedRouter>` instead of your `<App/>` component
201
+ - Note: we stopped rendering the `<App/>` component. We'll bring it back in a later step, but first we want to get the app to boot with the new entry point.
202
+
203
+ ## 5. Shuffle stuff around
204
+
205
+ Between `root.tsx` and `entry.client.tsx`, you may want to shuffle some stuff around between them.
206
+
207
+ In general:
208
+
209
+ - `root.tsx` contains any rendering things like context providers, layouts, styles, etc.
210
+ - `entry.client.tsx` should be as minimal as possible
211
+ - Remember to _not_ try to render your existing `<App/>` component yet, we'll do that in a later step
212
+
213
+ Note that your `root.tsx` file will be statically generated and served as the entry point of your app, so just that module will need to be compatible with server rendering. This is where most of your trouble will come.
214
+
215
+ ## 6. Set up your routes
216
+
217
+ The React Router Vite plugin uses a `routes.ts` file to configure your routes. For now we'll add a simple catchall route to get things going.
218
+
219
+ **👉 Set up a `catchall.tsx` route**
220
+
221
+ ```shellscript nonumber
222
+ touch src/routes.ts src/catchall.tsx
223
+ ```
224
+
225
+ ```ts filename=src/routes.ts
226
+ import {
227
+ type RouteConfig,
228
+ route,
229
+ } from "@react-router/dev/routes";
230
+
231
+ export default [
232
+ // * matches all URLs, the ? makes it optional so it will match / as well
233
+ route("*?", "catchall.tsx"),
234
+ ] satisfies RouteConfig;
235
+ ```
236
+
237
+ **👉 Render a placeholder route**
238
+
239
+ Eventually we'll replace this with our original `App` component, but for now we'll just render something simple to make sure we can boot the app.
240
+
241
+ ```tsx filename=src/catchall.tsx
242
+ export default function Component() {
243
+ return <div>Hello, world!</div>;
244
+ }
245
+ ```
246
+
247
+ [View our guide on configuring routes][configuring-routes] to learn more about the `routes.ts` file.
248
+
249
+ ## 7. Boot the app
250
+
251
+ At this point you should be able to boot the app and see the root layout.
252
+
253
+ **👉 Add `dev` script and run the app**
254
+
255
+ ```json filename=package.json
256
+ "scripts": {
257
+ "dev": "react-router dev"
258
+ }
259
+ ```
260
+
261
+ Now make sure you can boot your app at this point before moving on:
262
+
263
+ ```shellscript
264
+ npm run dev
265
+ ```
266
+
267
+ You will probably want to add `.react-router/` to your `.gitignore` file to avoid tracking unnecessary files in your repository.
268
+
269
+ ```txt
270
+ .react-router/
271
+ ```
272
+
273
+ You can check out [Type Safety][type-safety] to learn how to fully set up and use autogenerated type safety for params, loader data, and more.
274
+
275
+ ## 8. Render your app
276
+
277
+ To get back to rendering your app, we'll update the "catchall" route we set up earlier that matches all URLs so that your existing `<Routes>` get a chance to render.
278
+
279
+ **👉 Update the catchall route to render your app**
280
+
281
+ ```tsx filename=src/catchall.tsx
282
+ import App from "./App";
283
+
284
+ export default function Component() {
285
+ return <App />;
286
+ }
287
+ ```
288
+
289
+ Your app should be back on the screen and working as usual!
290
+
291
+ ## 9. Migrate a route to a Route Module
292
+
293
+ You can now incrementally migrate your routes to route modules.
294
+
295
+ Given an existing route like this:
296
+
297
+ ```tsx filename=src/App.tsx
298
+ // ...
299
+ import About from "./containers/About";
300
+
301
+ export default function App() {
302
+ return (
303
+ <Routes>
304
+ <Route path="/about" element={<About />} />
305
+ </Routes>
306
+ );
307
+ }
308
+ ```
309
+
310
+ **👉 Add the route definition to `routes.ts`**
311
+
312
+ ```tsx filename=src/routes.ts
313
+ import {
314
+ type RouteConfig,
315
+ route,
316
+ } from "@react-router/dev/routes";
317
+
318
+ export default [
319
+ route("/about", "./pages/about.tsx"),
320
+ route("*?", "catchall.tsx"),
321
+ ] satisfies RouteConfig;
322
+ ```
323
+
324
+ **👉 Add the route module**
325
+
326
+ Edit the route module to use the [Route Module API][route-modules]:
327
+
328
+ ```tsx filename=src/pages/about.tsx
329
+ export async function clientLoader() {
330
+ // you can now fetch data here
331
+ return {
332
+ title: "About page",
333
+ };
334
+ }
335
+
336
+ export default function Component({ loaderData }) {
337
+ return <h1>{loaderData.title}</h1>;
338
+ }
339
+ ```
340
+
341
+ See [Type Safety][type-safety] to set up autogenerated type safety for params, loader data, and more.
342
+
343
+ The first few routes you migrate are the hardest because you often have to access various abstractions a bit differently than before (like in a loader instead of from a hook or context). But once the trickiest bits get dealt with, you get into an incremental groove.
344
+
345
+ ## Enable SSR and/or Pre-rendering
346
+
347
+ If you want to enable server rendering and static pre-rendering, you can do so with the `ssr` and `prerender` options in the bundler plugin. For SSR you'll need to also deploy the server build to a server.
348
+
349
+ ```ts filename=react-router.config.ts
350
+ import type { Config } from "@react-router/dev/config";
351
+
352
+ export default {
353
+ ssr: true,
354
+ async prerender() {
355
+ return ["/", "/about", "/contact"];
356
+ },
357
+ } satisfies Config;
358
+ ```
359
+
360
+ [upgrade-router-provider]: ./router-provider
361
+ [configuring-routes]: ../start/framework/routing
362
+ [route-modules]: ../start/framework/route-module
363
+ [type-safety]: ../how-to/route-module-type-safety
@@ -0,0 +1,280 @@
1
+ ---
2
+ title: Future Flags
3
+ order: 1
4
+ ---
5
+
6
+ # Future Flags and Deprecations
7
+
8
+ This guide walks you through the process of adopting future flags in your React Router app. By following this strategy, you will be able to upgrade to the next major version of React Router with minimal changes. To read more about future flags see [API Development Strategy][api-development-strategy].
9
+
10
+ We highly recommend you make a commit after each step and ship it instead of doing everything all at once. Most flags can be adopted in any order, with exceptions noted below.
11
+
12
+ ## Update to latest v7.x
13
+
14
+ First update to the latest minor version of v7.x to have the latest future flags. You may see a number of deprecation warnings as you upgrade, which we'll cover below.
15
+
16
+ 👉 Update to latest v7
17
+
18
+ ```sh
19
+ npm install react-router@7 @react-router/{dev,node,etc.}@7
20
+ ```
21
+
22
+ ## `future.v8_middleware`
23
+
24
+ [MODES: framework, data]
25
+
26
+ <br/>
27
+ <br/>
28
+
29
+ **Background**
30
+
31
+ Middleware allows you to run code before and after the [`Response`][Response] generation for the matched path. This enables common patterns like authentication, logging, error handling, and data preprocessing in a reusable way. Please see the [docs](../how-to/middleware) for more information.
32
+
33
+ 👉 **Enable the Flag**
34
+
35
+ In Framework mode:
36
+
37
+ ```ts filename=react-router.config.ts
38
+ import type { Config } from "@react-router/dev/config";
39
+
40
+ export default {
41
+ future: {
42
+ v8_middleware: true,
43
+ },
44
+ } satisfies Config;
45
+ ```
46
+
47
+ In Data mode:
48
+
49
+ ```ts
50
+ import { createBrowserRouter } from "react-router/dom";
51
+
52
+ const router = createBrowserRouter(routes, {
53
+ future: {
54
+ v8_middleware: true,
55
+ },
56
+ });
57
+ ```
58
+
59
+ **Update your Code**
60
+
61
+ If you're using the `context` parameter in `loader` and `action` functions, you may need to update your code:
62
+
63
+ - In Framework mode, if you're using `react-router-serve`, you should not need to make any updates. Otherwise, this only applies if you have a custom server with a `getLoadContext` function. Please see the docs on the middleware [`getLoadContext` changes](../how-to/middleware#changes-to-getloadcontextapploadcontext) and the instructions to [migrate to the new API](../how-to/middleware#migration-from-apploadcontext).
64
+ - In Data mode, add the `Future` module augmentation described in the [middleware docs](../how-to/middleware#1-typescript-augment-future-for-loaderaction-context) so `context` is typed correctly.
65
+
66
+ ## `future.v8_splitRouteModules`
67
+
68
+ [MODES: framework]
69
+
70
+ <br/>
71
+ <br/>
72
+
73
+ **Background**
74
+
75
+ This feature enables splitting client-side route exports (`clientLoader`, `clientAction`, `clientMiddleware`, `HydrateFallback`) into separate chunks that can be loaded independently from the route component. This allows these exports to be fetched and executed while the component code is still downloading, improving performance for client-side data loading.
76
+
77
+ This can be set to `true` for opt-in behavior, or `"enforce"` to require all routes to be splittable (which will cause build failures for routes that cannot be split due to shared code).
78
+
79
+ 👉 **Enable the Flag**
80
+
81
+ ```ts filename=react-router.config.ts
82
+ import type { Config } from "@react-router/dev/config";
83
+
84
+ export default {
85
+ future: {
86
+ v8_splitRouteModules: true,
87
+ },
88
+ } satisfies Config;
89
+ ```
90
+
91
+ **Update your Code**
92
+
93
+ No code changes are required. This is an optimization feature that works automatically once enabled.
94
+
95
+ ## `future.v8_viteEnvironmentApi`
96
+
97
+ [MODES: framework]
98
+
99
+ <br/>
100
+ <br/>
101
+
102
+ **Background**
103
+
104
+ This enables support for the experimental Vite Environment API, which provides a more flexible and powerful way to configure Vite environments. This is only available when using Vite 6+.
105
+
106
+ 👉 **Enable the Flag**
107
+
108
+ ```ts filename=react-router.config.ts
109
+ import type { Config } from "@react-router/dev/config";
110
+
111
+ export default {
112
+ future: {
113
+ v8_viteEnvironmentApi: true,
114
+ },
115
+ } satisfies Config;
116
+ ```
117
+
118
+ **Update your Code**
119
+
120
+ Most users won't need to make any changes. However, if you have custom Vite configuration that previously relied on the `isSsrBuild` flag — such as a custom server build that sets `build.rollupOptions.input` — you'll need to move that configuration under the per-environment [Environment API][vite-environment] config instead.
121
+
122
+ For example, a custom server build should move its SSR `rollupOptions` from the top-level `build` config into `environments.ssr.build`:
123
+
124
+ ```diff filename=vite.config.ts
125
+ import { reactRouter } from "@react-router/dev/vite";
126
+ import { defineConfig } from "vite";
127
+
128
+ -export default defineConfig(({ isSsrBuild }) => ({
129
+ - build: {
130
+ - rollupOptions: isSsrBuild
131
+ - ? {
132
+ - input: "./server/app.ts",
133
+ - }
134
+ - : undefined,
135
+ - },
136
+ +export default defineConfig({
137
+ + environments: {
138
+ + ssr: {
139
+ + build: {
140
+ + rollupOptions: {
141
+ + input: "./server/app.ts",
142
+ + },
143
+ + },
144
+ + },
145
+ + },
146
+ plugins: [reactRouter()],
147
+ -}));
148
+ +});
149
+ ```
150
+
151
+ See the [`node-custom-server` template][node-custom-server-template] for a complete example.
152
+
153
+ ## `future.v8_passThroughRequests`
154
+
155
+ [MODES: framework]
156
+
157
+ <br/>
158
+ <br/>
159
+
160
+ **Background**
161
+
162
+ By default, React Router normalizes the `request.url` passed to your `loader`, `action`, and `middleware` functions by removing React Router's internal implementation details. Specifically, it removes `.data` suffixes and internal search parameters like `?index` and `?_routes`.
163
+
164
+ This flag eliminates that normalization and passes the raw HTTP `request` instance to your handlers. This provides a few benefits:
165
+
166
+ - Reduces server-side overhead by eliminating multiple `new Request()` calls on the critical path
167
+ - Allows you to distinguish document from data requests in your handlers based on the presence of a `.data` suffix (useful for [observability] purposes)
168
+
169
+ If you were previously relying on the normalization of `request.url`, you can switch to use the new sibling `url` parameter which contains a `URL` instance representing the normalized location.
170
+
171
+ 👉 **Enable the Flag**
172
+
173
+ ```ts filename=react-router.config.ts
174
+ import type { Config } from "@react-router/dev/config";
175
+
176
+ export default {
177
+ future: {
178
+ v8_passThroughRequests: true,
179
+ },
180
+ } satisfies Config;
181
+ ```
182
+
183
+ **Update your Code**
184
+
185
+ If your code relies on inspecting the request URL, you should review it for any assumptions about the URL format:
186
+
187
+ ```tsx
188
+ // ❌ Before: assuming no `.data` suffix in `request.url` pathname
189
+ export async function loader({
190
+ request,
191
+ }: Route.LoaderArgs) {
192
+ let url = new URL(request.url);
193
+ if (url.pathname === "/path") {
194
+ // This check might now behave differently because the request pathname will
195
+ // contain the `.data` suffix on data requests
196
+ }
197
+ }
198
+
199
+ // ✅ After: use `url` for normalized routing logic and `request.url`
200
+ // for raw routing logic
201
+ export async function loader({
202
+ request,
203
+ url,
204
+ }: Route.LoaderArgs) {
205
+ if (url.pathname === "/path") {
206
+ // This will always have the `.data` suffix stripped
207
+ }
208
+
209
+ // And now you can distinguish between document versus data requests
210
+ let isDataRequest = new URL(
211
+ request.url,
212
+ ).pathname.endsWith(".data");
213
+ }
214
+ ```
215
+
216
+ ## `future.v8_trailingSlashAwareDataRequests`
217
+
218
+ [MODES: framework]
219
+
220
+ <br/>
221
+ <br/>
222
+
223
+ **Background**
224
+
225
+ React Router serves Framework mode data requests from `.data` URLs. Previously, data requests for routes with and without trailing slashes could map to the same `.data` URL because trailing slashes were not considered during URL generation. This flag preserves trailing slash semantics for data request URLs to avoid ambiguity when your app distinguishes between trailing-slash and non-trailing-slash URLs.
226
+
227
+ Currently, your HTTP and `request` pathnames would be as follows for `/a/b/c` and `/a/b/c/`
228
+
229
+ | URL `/a/b/c` | **HTTP pathname** | **`request` pathname`** |
230
+ | ------------ | ----------------- | ----------------------- |
231
+ | **Document** | `/a/b/c` | `/a/b/c` ✅ |
232
+ | **Data** | `/a/b/c.data` | `/a/b/c` ✅ |
233
+
234
+ | URL `/a/b/c/` | **HTTP pathname** | **`request` pathname`** |
235
+ | ------------- | ----------------- | ----------------------- |
236
+ | **Document** | `/a/b/c/` | `/a/b/c/` ✅ |
237
+ | **Data** | `/a/b/c.data` | `/a/b/c` ⚠️ |
238
+
239
+ With this flag enabled, these pathnames will be made consistent though a new `_.data` format for client-side `.data` requests:
240
+
241
+ | URL `/a/b/c` | **HTTP pathname** | **`request` pathname`** |
242
+ | ------------ | ----------------- | ----------------------- |
243
+ | **Document** | `/a/b/c` | `/a/b/c` ✅ |
244
+ | **Data** | `/a/b/c.data` | `/a/b/c` ✅ |
245
+
246
+ | URL `/a/b/c/` | **HTTP pathname** | **`request` pathname`** |
247
+ | ------------- | ------------------ | ----------------------- |
248
+ | **Document** | `/a/b/c/` | `/a/b/c/` ✅ |
249
+ | **Data** | `/a/b/c/_.data` ⬅️ | `/a/b/c/` ✅ |
250
+
251
+ This flag also aligns the root data request to match this behavior by changing it from `/_root.data` to `/_.data`.
252
+
253
+ 👉 **Enable the Flag**
254
+
255
+ ```ts filename=react-router.config.ts
256
+ import type { Config } from "@react-router/dev/config";
257
+
258
+ export default {
259
+ future: {
260
+ v8_trailingSlashAwareDataRequests: true,
261
+ },
262
+ } satisfies Config;
263
+ ```
264
+
265
+ **Update your Code**
266
+
267
+ If you have custom app, CDN, cache, or rewrite logic that matches `.data` request URLs, update it to handle the new trailing-slash-aware `/_.data` format.
268
+
269
+ ## Unstable Future Flags (Optional)
270
+
271
+ We document some [unstable] flags here as a reference for folks contributing to the project via beta testing, but they are not generally recommended for production use and may having breaking changes patch/minor releases - adopt with caution!
272
+
273
+ _No current unstable flags to document_
274
+
275
+ [api-development-strategy]: ../community/api-development-strategy
276
+ [unstable]: ../community/api-development-strategy#unstable-flags
277
+ [observability]: ../how-to/instrumentation
278
+ [Response]: https://developer.mozilla.org/en-US/docs/Web/API/Response
279
+ [vite-environment]: https://vite.dev/guide/api-environment
280
+ [node-custom-server-template]: https://github.com/remix-run/react-router-templates/blob/7c617a435510bc3add3a5395c07bc65328b65e9e/node-custom-server/vite.config.ts
@@ -0,0 +1,4 @@
1
+ ---
2
+ title: Upgrading
3
+ order: 2
4
+ ---