Serious lag in dismissing custom toasts
See original GitHub issueWhen I use toast.custom()
, there’s significant lag between firing the toast.dismiss()
and the toast actually being dismissed in the DOM. See this video below:
https://user-images.githubusercontent.com/7105182/142970722-cbccb01b-91a7-4e1a-8079-9fffab205aef.mp4
Code
test.tsx
import React from "react";
import toast from "react-hot-toast";
import SuccessToast from "../components/toasts/SuccessToast";
const Test: React.FC = () => {
const notify = () =>
toast.custom(
(t) => <SuccessToast toast={t} onDismiss={() => toast.dismiss(t.id)} />,
{
duration: 3000,
position: "top-right",
}
);
return (
<div className="flex flex-col space-y-4">
<button onClick={notify}>Custom toast</button>
<button
onClick={() =>
toast((t) => (
<span>
Custom and <b>bold</b>
<button onClick={() => toast.dismiss(t.id)}>Dismiss</button>
</span>
))
}
>
Regular Notify
</button>
</div>
);
};
successToast.tsx
import { Toast } from "react-hot-toast";
interface SuccessToastProps {
toast: Toast;
onDismiss: () => void;
}
const SuccessToast: React.FC<SuccessToastProps> = ({ toast: t, onDismiss }) => {
return (
<div
className={`${
t.visible ? "animate-enter" : "animate-leave"
} max-w-md w-full bg-white shadow-lg rounded-lg pointer-events-auto flex ring-1 ring-black ring-opacity-5`}
>
<div className="flex-1 w-0 p-4">
<div className="flex items-start">
<div className="flex-shrink-0 pt-0.5">
<img
className="h-10 w-10 rounded-full"
src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixqx=6GHAjsWpt9&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2.2&w=160&h=160&q=80"
alt=""
/>
</div>
<div className="ml-3 flex-1">
<p className="text-sm font-medium text-gray-900">Emilia Gates</p>
<p className="mt-1 text-sm text-gray-500">
Sure! 8:30pm works great!
</p>
</div>
</div>
</div>
<div className="flex border-l border-gray-200">
<button
onClick={onDismiss}
className="w-full border border-transparent rounded-none rounded-r-lg p-4 flex items-center justify-center text-sm font-medium text-indigo-600 hover:text-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500"
>
Close
</button>
</div>
</div>
);
};
_app.tsx
import type { AppProps } from "next/app";
import React from "react";
import { Toaster } from "react-hot-toast";
import { QueryClient, QueryClientProvider } from "react-query";
import { Provider } from "react-redux";
import "tailwindcss/tailwind.css";
import ModalWrapper from "../components/layout/ModalWrapper";
import ProtectedWrapper from "../components/ProtectedWrapper";
import SessionWrapper from "../components/SessionWrapper";
import { store } from "../store/root";
const queryClient = new QueryClient();
function MyApp({ Component, pageProps }: AppProps) {
const child = pageProps.protected ? (
<ProtectedWrapper>
<Component {...pageProps} />
</ProtectedWrapper>
) : (
<Component {...pageProps} />
);
return (
<Provider store={store}>
<QueryClientProvider client={queryClient}>
<ModalWrapper>
<SessionWrapper>{child}</SessionWrapper>
<Toaster />
</ModalWrapper>
</QueryClientProvider>
</Provider>
);
}
export default MyApp;
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Dismiss and duration don't work on a custom toast #199 - GitHub
Is it possible that it works, but is delayed for 1 second? This is because toast.dismiss() doesn't remove the toast instantly. It waits...
Read more >Windows 10 Toast Notification Script - imab.dk
The toast notifications are native to Windows. Similar to any other notification made in Windows, clicking the notification itself is equal to dismissing...
Read more >toast() API
Dismiss toast programmatically Be aware that it triggers the exit animation and does not remove the Toast instantly. Toasts will auto-remove after 1...
Read more >Lag between switching tab fragment in Android - Stack Overflow
Used cardviews and recyclerviews instead , and the lag was gone. ... takes time and causes lag. Other reason could be bad layout...
Read more >iOS 14 .onAppear() is called on DI… | Apple Developer Forums
I have the same problem with my custom toast view. The App is basically unusable. Although I have figured that this bug is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is due to the fact that
toast.custom()
has no animations per default, but leaves the element in the DOM for 1s to play your own.I can see you are using
animate-enter
&animate-leave
from the example page, which are not part of Tailwind by default. You can find the definition here: https://github.com/timolins/react-hot-toast/blob/main/site/tailwind.config.js#L21-L39The issue should be fixed by adding these animation, or by providing your own.
Issue #116 talks about adding default animations to
toast.custom()
. Feel free to voice your opinion there.I have the same issue. I’m not using tailwind… just custom divs. is it possible to just hide the toast.custom() on close without any animation or waiting for 1s before closing? it’s really frustrating…