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.
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.
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.
๐ Update to latest v7
npm install react-router@7 @react-router/{dev,node,etc.}@7
future.v8_middlewareBackground
Middleware allows you to run code before and after the 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 for more information.
๐ Enable the Flag
In Framework mode:
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_middleware: true,
},
} satisfies Config;
In Data mode:
import { createBrowserRouter } from "react-router/dom";
const router = createBrowserRouter(routes, {
future: {
v8_middleware: true,
},
});
Update your Code
If you're using the context parameter in loader and action functions, you may need to update your code:
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 and the instructions to migrate to the new API.Future module augmentation described in the middleware docs so context is typed correctly.future.v8_splitRouteModulesBackground
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.
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).
๐ Enable the Flag
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_splitRouteModules: true,
},
} satisfies Config;
Update your Code
No code changes are required. This is an optimization feature that works automatically once enabled.
future.v8_viteEnvironmentApiBackground
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+.
๐ Enable the Flag
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_viteEnvironmentApi: true,
},
} satisfies Config;
Update your Code
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 config instead.
For example, a custom server build should move its SSR rollupOptions from the top-level build config into environments.ssr.build:
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
-export default defineConfig(({ isSsrBuild }) => ({
- build: {
- rollupOptions: isSsrBuild
- ? {
- input: "./server/app.ts",
- }
- : undefined,
- },
+export default defineConfig({
+ environments: {
+ ssr: {
+ build: {
+ rollupOptions: {
+ input: "./server/app.ts",
+ },
+ },
+ },
+ },
plugins: [reactRouter()],
-}));
+});
See the node-custom-server template for a complete example.
future.v8_passThroughRequestsBackground
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.
This flag eliminates that normalization and passes the raw HTTP request instance to your handlers. This provides a few benefits:
new Request() calls on the critical path.data suffix (useful for observability purposes)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.
๐ Enable the Flag
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_passThroughRequests: true,
},
} satisfies Config;
Update your Code
If your code relies on inspecting the request URL, you should review it for any assumptions about the URL format:
// โ Before: assuming no `.data` suffix in `request.url` pathname
export async function loader({
request,
}: Route.LoaderArgs) {
let url = new URL(request.url);
if (url.pathname === "/path") {
// This check might now behave differently because the request pathname will
// contain the `.data` suffix on data requests
}
}
// โ
After: use `url` for normalized routing logic and `request.url`
// for raw routing logic
export async function loader({
request,
url,
}: Route.LoaderArgs) {
if (url.pathname === "/path") {
// This will always have the `.data` suffix stripped
}
// And now you can distinguish between document versus data requests
let isDataRequest = new URL(
request.url,
).pathname.endsWith(".data");
}
future.v8_trailingSlashAwareDataRequestsBackground
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.
Currently, your HTTP and request pathnames would be as follows for /a/b/c and /a/b/c/
URL /a/b/c |
HTTP pathname | request pathname` |
|---|---|---|
| Document | /a/b/c |
/a/b/c โ
|
| Data | /a/b/c.data |
/a/b/c โ
|
URL /a/b/c/ |
HTTP pathname | request pathname` |
|---|---|---|
| Document | /a/b/c/ |
/a/b/c/ โ
|
| Data | /a/b/c.data |
/a/b/c โ ๏ธ |
With this flag enabled, these pathnames will be made consistent though a new _.data format for client-side .data requests:
URL /a/b/c |
HTTP pathname | request pathname` |
|---|---|---|
| Document | /a/b/c |
/a/b/c โ
|
| Data | /a/b/c.data |
/a/b/c โ
|
URL /a/b/c/ |
HTTP pathname | request pathname` |
|---|---|---|
| Document | /a/b/c/ |
/a/b/c/ โ
|
| Data | /a/b/c/_.data โฌ
๏ธ |
/a/b/c/ โ
|
This flag also aligns the root data request to match this behavior by changing it from /_root.data to /_.data.
๐ Enable the Flag
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_trailingSlashAwareDataRequests: true,
},
} satisfies Config;
Update your Code
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.
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!
No current unstable flags to document