Skip to content

Commit 462e947

Browse files
Update react-router and react, update middleware (#207)
1 parent 19e184f commit 462e947

File tree

9 files changed

+100
-175
lines changed

9 files changed

+100
-175
lines changed

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 {
22
createCookie,
3-
unstable_createContext,
4-
type unstable_MiddlewareFunction,
5-
type unstable_RouterContextProvider,
3+
createContext,
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/components/docs-header/data.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function getHeaderData(
3939
["dev", "nightly", "release-next", "local"].includes(githubRef);
4040

4141
// TODO: make this smarter before v8
42-
let apiDocsRef = githubRef === "dev" || githubRef === "local" ? "dev" : "v7";
42+
let apiDocsRef = "v7";
4343

4444
let latestV6Version = getLatestV6Version(tags);
4545

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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 = async ({ request }) => {
64
let proto = request.headers.get("x-forwarded-proto");
75
// this indirectly allows `http://localhost` because there is no
86
// "x-forwarded-proto" in the local server headers

app/modules/http-utils/remove-slashes.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 removeTrailingSlashes: unstable_MiddlewareFunction<
4-
void | Response
5-
> = async ({ request }) => {
3+
export const removeTrailingSlashes: MiddlewareFunction = async ({
4+
request,
5+
}) => {
66
let url = new URL(request.url);
77
if (url.pathname.endsWith("/") && url.pathname !== "/") {
88
url.pathname = url.pathname.slice(0, -1);

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

Lines changed: 2 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,7 @@ 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 = async ({ request }) => {
2119
let redirects = await getRedirects();
2220
let url = new URL(request.url);
2321
let response = await checkUrl(url.pathname, redirects);

app/root.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Outlet,
77
Scripts,
88
ScrollRestoration,
9+
type MiddlewareFunction,
910
} from "react-router";
1011
import { CACHE_CONTROL } from "./http";
1112

@@ -25,7 +26,7 @@ import { ensureSecure } from "~/modules/http-utils/ensure-secure";
2526
import { handleRedirects } from "~/modules/redirects/.server";
2627
import { removeTrailingSlashes } from "~/modules/http-utils/remove-slashes";
2728

28-
export const unstable_middleware: Route.unstable_MiddlewareFunction[] = [
29+
export const middleware: MiddlewareFunction[] = [
2930
ensureSecure,
3031
removeTrailingSlashes,
3132
handleRedirects,

0 commit comments

Comments
 (0)