Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep track of dismissed toasts #53

Merged
merged 1 commit into from
Mar 21, 2021
Merged

Keep track of dismissed toasts #53

merged 1 commit into from
Mar 21, 2021

Conversation

timolins
Copy link
Owner

@timolins timolins commented Mar 1, 2021

Store timeouts of dismissed toasts.
This should prevent toasts from beeing removed, after re-dispatched with the same ID.

Fixes #50

Store timeouts of dismissed toasts.
This should prevent toasts from beeing removed, after re-dispatched with the same ID.

Fixes #50
@vercel
Copy link

vercel bot commented Mar 1, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/timo/react-hot-toast/BUKuYopcMaGxmX839fARJB917HWa
✅ Preview: https://react-hot-toast-git-clear-timeouts-timo1.vercel.app

@github-actions
Copy link

github-actions bot commented Mar 1, 2021

size-limit report 📦

Path Size
dist/react-hot-toast.cjs.production.min.js 4.48 KB (+2.07% 🔺)
dist/react-hot-toast.esm.js 4.42 KB (+2.03% 🔺)

@gr-qft
Copy link
Contributor

gr-qft commented Mar 4, 2021

@timolins I checked and this fix worked for non-promise toasts. But I still don't understand your comment about same IDs, it seems to me the IDs are generated uniquely.

For promise toasts, if a toast is generated fast enough after the dismissal, the success notification still pops up again after. I think this is also a bug right?

@timolins
Copy link
Owner Author

timolins commented Mar 4, 2021

Thanks for checking!. You right, IDs are uniquely generated. But you can create/update a toast by providing a toast id as an option. This is used internally by toast.promise. I'm also using this for the toaster position example on the website, to prevent multiple toasts of the same kind: https://github.com/timolins/react-hot-toast/blob/main/site/components/sections/toaster-example.tsx#L79

You can replicate the problem on the current website:

  1. Trigger the position toast
  2. Wait for it to disappear (1s timeout starts)
  3. Trigger another position toast (has the same ID) → Toast becomes visible again
  4. New toasts is deleted prematurely since timeout from step 2 ends

With this PR, the removal timeout gets cleared when the toast is updated.

What exactly do you mean by the promise toast bug? Is there a reason why would create a promise toast and dismiss it instantly again?

@gr-qft
Copy link
Contributor

gr-qft commented Mar 5, 2021

I see, it also fixed the problem when the IDs are generated automatically.

No reason, it's just I would normally expect that whatever kind of toast it is, after I dismiss it, it should go away. But for promise toast, the toast is dismissed immediately, but the success (or failure) state comes back again briefly.

@timolins
Copy link
Owner Author

timolins commented Mar 5, 2021

Fair point. That's kinda tricky since it somewhat collides with this logic. As it clears the previously dismissed toast instead of preventing it from disappearing.

@timolins timolins merged commit 351e62a into main Mar 21, 2021
@timolins timolins deleted the clear-timeouts branch March 21, 2021 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

toast.dimiss
2 participants