Skip to content

Commit 5bab6fa

Browse files
authored
Merge pull request #48 from kenn/stable
Stabilized middleware API for RR v7.9+
2 parents 78b5f7f + 719e823 commit 5bab6fa

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const action = () => {
5252
In order to be able to show toasts anywhere in the app you need to add the following code to your `root.tsx` file.
5353

5454
```tsx
55-
import { getToast, setToast, unstable_toastMiddleware } from "remix-toast/middleware";
55+
import { getToast, setToast, toastMiddleware } from "remix-toast/middleware";
5656

5757
export const loader = async ({ request, context }: Route.LoaderArgs) => {
5858
// Extracts the toast from the request
@@ -82,7 +82,7 @@ export default function App({ loaderData }: Route.ComponentArgs) {
8282
}
8383

8484
// Export the middleware to be used in the app
85-
export const unstable_middleware = [unstable_toastMiddleware()];
85+
export const middleware = [toastMiddleware()];
8686

8787
```
8888

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "remix-toast",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "Utility functions for server-side toast notifications",
55
"type": "module",
66
"main": "./dist/index.cjs",
@@ -61,7 +61,7 @@
6161
"format-code": "npm run prettier:fix & npm run lint:fix"
6262
},
6363
"peerDependencies": {
64-
"react-router": ">=7.8.0"
64+
"react-router": ">=7.9.0"
6565
},
6666
"repository": {
6767
"type": "git",

src/middleware/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import {
2-
type SessionStorage,
3-
type unstable_MiddlewareFunction,
4-
type unstable_RouterContextProvider,
5-
unstable_createContext,
6-
} from "react-router";
1+
import { type SessionStorage, type MiddlewareFunction, type RouterContextProvider, createContext } from "react-router";
72
import { type ToastMessage, getToast as getToastPrimitive } from "..";
83
import { FLASH_SESSION } from "../schema";
94
import { sessionStorage } from "../session";
105

11-
const toastContext = unstable_createContext<ToastMessage | null>(null);
12-
const sessionToastContext = unstable_createContext<ToastMessage | null>(null);
6+
const toastContext = createContext<ToastMessage | null>(null);
7+
const sessionToastContext = createContext<ToastMessage | null>(null);
138

14-
export function unstable_toastMiddleware(props?: { customSession?: SessionStorage }): unstable_MiddlewareFunction {
9+
export function toastMiddleware(props?: { customSession?: SessionStorage }): MiddlewareFunction {
1510
const { customSession } = props || {};
1611
const sessionToUse = customSession || sessionStorage;
1712
return async function toastMiddleware({ request, context }, next) {
@@ -37,11 +32,16 @@ export function unstable_toastMiddleware(props?: { customSession?: SessionStorag
3732
}
3833

3934
export const setToast = (
40-
context: unstable_RouterContextProvider | Readonly<unstable_RouterContextProvider>,
35+
context: RouterContextProvider | Readonly<RouterContextProvider>,
4136
toast: ToastMessage | null,
4237
) => {
4338
context.set(sessionToastContext, toast);
4439
};
4540

46-
export const getToast = (context: unstable_RouterContextProvider | Readonly<unstable_RouterContextProvider>) =>
41+
export const getToast = (context: RouterContextProvider | Readonly<RouterContextProvider>) =>
4742
context.get(toastContext);
43+
44+
/**
45+
* @deprecated Use `toastMiddleware` instead.
46+
*/
47+
export const unstable_toastMiddleware = toastMiddleware;

test-apps/react-router/app/root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type LinksFunction, type LoaderFunctionArgs, data } from "react-router"
33
import { Links, Meta, Outlet, Scripts, ScrollRestoration, useLoaderData } from "react-router";
44
import { ToastContainer, toast as notify } from "react-toastify";
55
import toastStyles from "react-toastify/ReactToastify.css?url";
6-
import { getToast, unstable_toastMiddleware } from "remix-toast/middleware";
6+
import { getToast, toastMiddleware } from "remix-toast/middleware";
77

88
export const links: LinksFunction = () => [{ rel: "stylesheet", href: toastStyles }];
99

@@ -39,4 +39,4 @@ export default function App() {
3939
);
4040
}
4141

42-
export const unstable_middleware = [unstable_toastMiddleware()];
42+
export const middleware = [toastMiddleware()];

test-apps/react-router/react-router.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { Config } from "@react-router/dev/config";
22

33
declare module "react-router" {
44
interface Future {
5-
unstable_middleware: true; // 👈 Enable middleware types
5+
v8_middleware: true; // 👈 Enable middleware types
66
}
77
}
88

99
export default {
1010
future: {
11-
unstable_middleware: true, // 👈 Enable middleware
11+
v8_middleware: true, // 👈 Enable middleware
1212
},
1313
} satisfies Config;

0 commit comments

Comments
 (0)