Skip to content

Commit ef1fc10

Browse files
committed
Update to stable middleware (experimental release)
1 parent 19aa959 commit ef1fc10

8 files changed

Lines changed: 47 additions & 48 deletions

File tree

app/actions/menu-collapse/server.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2+
createContext,
23
createCookie,
3-
unstable_createContext,
4-
type unstable_MiddlewareFunction,
5-
type unstable_RouterContextProvider,
4+
type MiddlewareFunction,
5+
type RouterContextProvider,
66
} from "react-router";
77

88
let cookie = createCookie("menu-collapse", {
@@ -14,11 +14,9 @@ let cookie = createCookie("menu-collapse", {
1414
// Default behavior: missing categories are treated as "open" (true)
1515
type MenuCollapseState = Record<string, boolean>;
1616

17-
let menuCollapseStateContext = unstable_createContext<MenuCollapseState>({});
17+
let menuCollapseStateContext = createContext<MenuCollapseState>({});
1818

19-
export function menuCollapseContext(
20-
context: Readonly<unstable_RouterContextProvider>,
21-
) {
19+
export function menuCollapseContext(context: Readonly<RouterContextProvider>) {
2220
return {
2321
get: () => {
2422
return context.get(menuCollapseStateContext);
@@ -43,9 +41,10 @@ export function menuCollapseContext(
4341
*
4442
* This is used to persist the menu collapse state across page loads
4543
*/
46-
export let menuCollapseStateMiddleware: unstable_MiddlewareFunction<
47-
Response
48-
> = async ({ request, context }, next) => {
44+
export let menuCollapseStateMiddleware: MiddlewareFunction<Response> = async (
45+
{ request, context },
46+
next,
47+
) => {
4948
// Set the context to whatever is in the cookie
5049
let menuCollapseCookieState = await parseMenuCollapseState(request);
5150
let menuCollapse = menuCollapseContext(context);

app/modules/http-utils/ensure-secure.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { redirect, type unstable_MiddlewareFunction } from "react-router";
1+
import { redirect, type MiddlewareFunction } from "react-router";
22

3-
export const ensureSecure: unstable_MiddlewareFunction<
4-
void | Response
5-
> = async ({ request }) => {
3+
export const ensureSecure: MiddlewareFunction<void | Response> = async ({
4+
request,
5+
}) => {
66
let proto = request.headers.get("x-forwarded-proto");
77
// this indirectly allows `http://localhost` because there is no
88
// "x-forwarded-proto" in the local server headers

app/modules/http-utils/remove-slashes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { redirect, type unstable_MiddlewareFunction } from "react-router";
1+
import { redirect, type MiddlewareFunction } from "react-router";
22

3-
export const removeTrailingSlashes: unstable_MiddlewareFunction<
3+
export const removeTrailingSlashes: MiddlewareFunction<
44
void | Response
55
> = async ({ request }) => {
66
let url = new URL(request.url);

app/modules/redirects/.server/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type unstable_MiddlewareFunction } from "react-router";
1+
import { type MiddlewareFunction } from "react-router";
22
import { checkUrl } from "./check-url";
33
import { getRedirects } from "./get-redirects";
44

@@ -15,9 +15,9 @@ import { getRedirects } from "./get-redirects";
1515
*
1616
* @param request Web Fetch Request to possibly redirect
1717
*/
18-
export const handleRedirects: unstable_MiddlewareFunction<
19-
void | Response
20-
> = async ({ request }) => {
18+
export const handleRedirects: MiddlewareFunction<void | Response> = async ({
19+
request,
20+
}) => {
2121
let redirects = await getRedirects();
2222
let url = new URL(request.url);
2323
let response = await checkUrl(url.pathname, redirects);

app/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ensureSecure } from "~/modules/http-utils/ensure-secure";
2525
import { handleRedirects } from "~/modules/redirects/.server";
2626
import { removeTrailingSlashes } from "~/modules/http-utils/remove-slashes";
2727

28-
export const unstable_middleware: Route.unstable_MiddlewareFunction[] = [
28+
export const middleware: Route.MiddlewareFunction[] = [
2929
ensureSecure,
3030
removeTrailingSlashes,
3131
handleRedirects,

package-lock.json

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"dependencies": {
1818
"@docsearch/css": "^3.8.3",
1919
"@docsearch/react": "^3.8.3",
20-
"@react-router/express": "^7.8.1",
21-
"@react-router/node": "^7.8.1",
20+
"@react-router/express": "0.0.0-experimental-426e5caec",
21+
"@react-router/node": "0.0.0-experimental-426e5caec",
2222
"@types/express": "^5.0.0",
2323
"cheerio": "^1.0.0-rc.12",
2424
"classnames": "^2.3.2",
@@ -42,7 +42,7 @@
4242
"parse-numeric-range": "^1.3.0",
4343
"react": "^19.0.0",
4444
"react-dom": "^19.0.0",
45-
"react-router": "^7.8.1",
45+
"react-router": "0.0.0-experimental-426e5caec",
4646
"rehype-autolink-headings": "^7.1.0",
4747
"rehype-slug": "^6.0.0",
4848
"rehype-stringify": "^10.0.1",
@@ -59,7 +59,7 @@
5959
"unist-util-visit": "^5.0.0"
6060
},
6161
"devDependencies": {
62-
"@react-router/dev": "^7.8.1",
62+
"@react-router/dev": "0.0.0-experimental-426e5caec",
6363
"@testing-library/jest-dom": "^5.16.5",
6464
"@types/express-serve-static-core": "^5.0.6",
6565
"@types/follow-redirects": "^1.14.4",

react-router.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export default {
44
future: {
55
unstable_optimizeDeps: true,
66
unstable_splitRouteModules: "enforce",
7-
unstable_middleware: true,
7+
v8_middleware: true,
88
},
99
} satisfies Config;

0 commit comments

Comments
 (0)