React-toastify: Prevent duplicate with custom toastId - buggy toast appears that does not auto-close.

Created on 10 Nov 2018  路  10Comments  路  Source: fkhadra/react-toastify

Hello!
I am trying to prevent showing duplicated toasts using custom toastId. I am using autoClose option (2000ms). After multiple calls to e.g. toast.error() with same toastId feature works perfectly - only the first toast is being displayed. However, when autoClose time is finished and toast is ready to be closed - calling the toast.error() function results with showing the same toast once again, but this time with no autoClose timer. I deducted from experiments, that this occurs precisely when toast function is called during closing animation of the previous toast. Here is CodeSandbox snippet - to reproduce just start hitting 'Toast' button near active toast timer finish.

Edit 7j5r23pykj

This bug does not appear when I am using isActive() function to prevent duplicates, however combining isActive() and setting custom toastId still causes above unwanted behaviour. For the design reasons it is important for me to be able to prevent duplicates using custom toastId, cause managing auto generated ids will quickly become quite a pain.

isActive() version:
Edit jp5wprpyz5

Thanks in advance!

bug

Most helpful comment

Hello everyone,

I think I know where the bug is coming from. I'll be able to work on it in 2 weeks.

All 10 comments

hey @JanuszBartosz,

I tried both pen, I need to investigate to figure out what is going on.

I see the same behaviour if the following is called in quick succession. The .dismiss(2) call is not working consistently. (I think it might be the same issue?) Here's a sandbox to demo: it works with a 2000ms timeout, but not 200ms:


Edit ox836j3pny

  notifyWarn(msg: string) {
    if (msg === "") {
      toast.dismiss(2);
    } else if (!toast.isActive(2)) {
      toast(msg, { toastId: 2, type: toast.TYPE.WARNING });
    } else {
      toast.update(2, { render: msg, type: toast.TYPE.WARNING });
    }
  }

Same issue here. After the toast disappears automatically and I try to show it again quickly after, then it won't show up with animation and autoClose doesn't work on it, and the progress bar doesn't show up. This only happens if I try to show the toast again quickly after the first one auto closes.

            if (!toast.isActive('designer_refresh')) {
                toast('test', {
                    toastId: 'designer_refresh',
                    position: 'top-right',
                    autoClose: 2000,
                    hideProgressBar: false,
                    closeOnClick: true,
                    // pauseOnHover: true,
                    draggable: true,
                    className: 'notificationToolTip',
                });
            }

Hello everyone,

I think I know where the bug is coming from. I'll be able to work on it in 2 weeks.

Hi. Any update on this? Thanks!

i have same problem, when i click more one time and consecutive, toast do not disappear although i'm using {autoClose:4000} ? thanks

i updated new version, problem fix. Thanks so much.

@JanuszBartosz did you try to upgrade to the latest version and see if the issue if fixed for you ?

Yes, it works alright now :slightly_smiling_face: Thank you for your support!

Thank you @fkhadra, much appreciated!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tobiasfriden picture tobiasfriden  路  3Comments

NoMercy235 picture NoMercy235  路  5Comments

billtlee picture billtlee  路  5Comments

JaLe29 picture JaLe29  路  5Comments

albert-olive picture albert-olive  路  5Comments