fkhadra / react-toastify

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

[bug] 'format.replace is not a function' when generating toastId #530

Closed freezepl closed 3 years ago

freezepl commented 3 years ago

Do you want to request a feature or report a bug? BUG What is the current behavior? Toasts are not working. Error is displayed in the console:

application-db3a52d1d5b71b55aa2e77ebf69a742adc8e5f2bc68e97029c4d4a1ea315897d.js:20410 Uncaught TypeError: format.replace is not a function
    at Date.toString 
    at generateToastId (react-toastify.esm.js?146c:607)
    at getToastId (react-toastify.esm.js?146c:619)
    at mergeOptions (react-toastify.esm.js?146c:656)
    at toast (react-toastify.esm.js?146c:661)
    at notify (index.js?002b:19)
    at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:188)
    at HTMLUnknownElement.fn.___hb (honeybadger.js?4072:767)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:237)
    at invokeGuardedCallback (react-dom.development.js?61bb:292)

How to reproduce? Paste the code of the method in the console:

(Math.random().toString(36) + Date.now().toString(36)).substr(2, 10);

application-db3a52d1d5b71b55aa2e77ebf69a742adc8e5f2bc68e97029c4d4a1ea315897d.js:20410 Uncaught TypeError: format.replace is not a function
    at Date.toString 
    at <anonymous>:1:42

I tried to change toString to toISOString and it worked:

(Math.random().toString(36) + Date.now().toISOString()).substr(2, 10);
"bv7a4q6eyc"

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: I used code from https://fkhadra.github.io/react-toastify/the-gist-of-react-toastify What is the expected behavior? It should display the toast Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? React 16.11.0 Chrome Version 85.0.4183.121 (Official Build) (64-bit)

fkhadra commented 3 years ago

Hello @freezepl,

Could you reproduce the bug and share a codesanbox thanks.