Skip to content

Commit 935fb25

Browse files
authored
fix(react-router/router): remove unused client side middleware future flag (#14213)
1 parent bebb46c commit 935fb25

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

.changeset/brown-ladybugs-yawn.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
[UNSTABLE] Remove Data Mode `future.unstable_middleware` flag from `createBrowserRouter`
6+
7+
- This is only needed as a Framework Mode flag because of the route modules and the `getLoadContext` type behavior change
8+
- In Data Mode, it's an opt-in feature because it's just a new property on a route object, so there's no behavior changes that necessitate a flag

docs/how-to/middleware.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,9 @@ function getLoadContext(req, res) {
133133

134134
## Quick Start (Data Mode)
135135

136-
### 1. Enable the middleware flag
136+
<docs-info>Note there is no future flag in Data Mode because you can opt-into middleware by adding it to your routes, no breaking changes exist that require a future flag.</docs-info>
137137

138-
```tsx
139-
const router = createBrowserRouter(routes, {
140-
future: {
141-
unstable_middleware: true,
142-
},
143-
});
144-
```
145-
146-
### 2. Create a context
138+
### 1. Create a context
147139

148140
Middleware uses a `context` provider instance to provide data down the middleware chain.
149141
You can create type-safe context objects using [`unstable_createContext`][createContext]:
@@ -156,7 +148,7 @@ export const userContext =
156148
unstable_createContext<User | null>(null);
157149
```
158150

159-
### 3. Add middleware to your routes
151+
### 2. Add middleware to your routes
160152

161153
```tsx
162154
import { redirect } from "react-router";
@@ -216,17 +208,14 @@ export default function Profile() {
216208
}
217209
```
218210

219-
### 4. Add an `unstable_getContext` function (optional)
211+
### 3. Add an `unstable_getContext` function (optional)
220212

221213
If you wish to include a base context on all navigations/fetches, you can add an [`unstable_getContext`][getContext] function to your router. This will be called to populate a fresh context on every navigation/fetch.
222214

223215
```tsx
224216
let sessionContext = unstable_createContext();
225217

226218
const router = createBrowserRouter(routes, {
227-
future: {
228-
unstable_middleware: true,
229-
},
230219
unstable_getContext() {
231220
let context = new unstable_RouterContextProvider();
232221
context.set(sessionContext, getSession());

packages/react-router/lib/router/router.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,7 @@ export type HydrationState = Partial<
384384
/**
385385
* Future flags to toggle new feature behavior
386386
*/
387-
export interface FutureConfig {
388-
unstable_middleware: boolean;
389-
}
387+
export interface FutureConfig {}
390388

391389
/**
392390
* Initialization options for createRouter
@@ -879,7 +877,6 @@ export function createRouter(init: RouterInit): Router {
879877

880878
// Config driven behavior flags
881879
let future: FutureConfig = {
882-
unstable_middleware: false,
883880
...init.future,
884881
};
885882
// Cleanup function for history

0 commit comments

Comments
 (0)