You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because I'm using StrictMode, this function is called twice but WillMount is not properly cleaned because we call cancelEmit, which makes the cleanup function never be called since we call events using setTimeout:
If the toast is called very close to the last notification, react will join these two calls in a single batch (my guess), and then, the buildToast function cannot verify if the toast is duplicated because it was not added yet to the toastToRender by appendToast.
I'll close the issue given it can be solved using a custom id. In v10 it won't happen as the library internal implementation has switched to useSyncExternalStore
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I added just once the notification but it has been displayed twice.
From what I looked, the problem is with these lines:
react-toastify/src/hooks/useToastContainer.ts
Lines 68 to 81 in 97d9afc
Because I'm using
StrictMode
, this function is called twice butWillMount
is not properly cleaned because we callcancelEmit
, which makes the cleanup function never be called since we call events usingsetTimeout
:react-toastify/src/core/toast.ts
Lines 325 to 334 in 97d9afc
If the toast is called very close to the last notification, react will join these two calls in a single batch (my guess), and then, the
buildToast
function cannot verify if the toast is duplicated because it was not added yet to thetoastToRender
byappendToast
.react-toastify/src/hooks/useToastContainer.ts
Lines 218 to 233 in 97d9afc
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
https://codesandbox.io/s/amazing-cray-9f19y2
What is the expected behavior?
To not duplicate the notifications.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The text was updated successfully, but these errors were encountered: