fkhadra / react-toastify

React notification made easy 🚀 !
https://fkhadra.github.io/react-toastify/introduction
MIT License
12.58k stars 692 forks source link

Toast is undefined || Uncaught TypeError: Cannot read properties of undefined (reading 'content') #952

Closed PsyCowpathe closed 1 year ago

PsyCowpathe commented 1 year ago

Hi, thanks in advance for your time !

Do you want to request a feature or report a bug?

A bug

What is the current behavior?

When displaying notification, if the user change page when a notification is deleted (autoclose or toast.dismiss()) an error occur :

-On firefox : "Toast is undefined" or "T is undefined" folowing the version used.

-On chrome : "Uncaught TypeError: Cannot read properties of undefined (reading 'content')"

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your CodeSandbox (https://codesandbox.io/s/new) example below:

On a single page application, display lots of notification with autoclose enabled, wait for some of the oldest notification to close itself then change page.

What is the expected behavior?

The expected behavior is no error when user change from page to page.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React : 18.2.0

Toastify :

Os : Ubuntu

Browser : -Firefox -Google Chrome

Screenshot :

Firefox : Screenshot from 2023-05-04 17-30-19

Chrome : Screenshot from 2023-05-04 17-31-55

NuoWenLei commented 1 year ago

If you're using nextjs and/or some kind of auth provider, this error could be due to some unfinished promise that, when fulfilled, refreshes the entire container.

A temporary solution for me (if you're using nextjs) is to go to "next.config.js" and set "reactStrictMode" to false.

Hope this helps!

fkhadra commented 1 year ago

Hey @PsyCowpathe, it should be gone with the latest release. Can you confirm?

PsyCowpathe commented 1 year ago

Hey, I'm unable to test it right now. I'll tell you as soon as possible ! :)

Btw, my "solution" was to use version 9.0.5

OscarBC commented 1 year ago

Hey @PsyCowpathe, it should be gone with the latest release. Can you confirm?

@fkhadra I was having this exception (can't read content) while implementing some notifications in next.js, I upgraded to the latest version (9.1.3) and it seems that it is fixed since it's not coming up.

I also changed the moment the toast is present (after it finished navigating to a new page), so maybe that page change was also causing some issues.

Anyway, Thanks!