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

fix(toast): specific behavior if delay is provided in pending toast #729

Closed
wants to merge 7 commits into from

Conversation

git-angelo
Copy link

@git-angelo git-angelo commented Mar 28, 2022

If a delay is provided in "pending" toast and if the Promise is completed before it, we should not display the "pending" toast.

PS: I will clean this PR but I pushed a kind of "PoC" to eventually discuss about this feature.

PS 2: PR does not work as expected in real use case. It is waiting the end of the delay before returning the result if the promise ends quickly. Nevertheless, it can be used with a delay value of "500" to avoid seeing the pending toast in most of the cases without problem.

@git-angelo
Copy link
Author

git-angelo commented Mar 29, 2022

Commit ea54546 is fixing the problem described in first comment.

Now it seems that all is working as expected (from my point of view).

Edit: To test it you can change the code in example/components/App.tsx:

firePromise = () => { toast.promise( new Promise((resolve, reject) => { setTimeout(() => { this.resolvePromise ? resolve(null) : reject(null); this.resolvePromise = !this.resolvePromise; }, 1000); }), { pending: { render({ data }: any) { return 'Promise is pending'; }, delay: 5000 }, success: 'Promise1 resolved 👌', error: 'Promise1 rejected 🤯' } ); };

In this case, success/error toasts will be displayed after 1000ms without displaying the pending toast.

If you reverse the delays, pending toast will appear after 1000ms and success/error toasts will be displayed after 5000ms.

@git-angelo git-angelo marked this pull request as ready for review March 29, 2022 08:08
@git-angelo
Copy link
Author

I created 2 sandboxes:

  1. The current behavior, it works if the promise returns after de pending toast delay, otherwise the pending toast never disappears: https://codesandbox.io/s/intelligent-feynman-p1o7e5?file=/src/App.js

  2. With my fix: https://codesandbox.io/s/magical-galileo-zpm5df?file=/src/App.js

I created a npm package for myself but in case anyone wants it, here is the link: https://www.npmjs.com/package/potassium-react-toastify

@git-angelo
Copy link
Author

@fkhadra Please, could you tell me what would you need to take a look at this PR ? Some people are downloading my custom package so I think that this is an interesting thing to add. If you did not understand something or if you need more explanations, you can ask... thank you.

@fkhadra
Copy link
Owner

fkhadra commented May 3, 2022

Hey @git-angelo , I totally miss your PR, sorry for that. I've addressed this issue in v9.

@fkhadra fkhadra closed this May 29, 2022
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.

None yet

2 participants