gor181 / react-notification-system-redux

Redux wrapper for react-notification-system
MIT License
324 stars 59 forks source link

notifications state not clearing with autoDismiss #57

Open denen99 opened 7 years ago

denen99 commented 7 years ago

Hi -

I have a situation where i call a Notifications.success() and the notifications state in redux (using autoDismiss) does not auto remove. This causes a double notification to show up when the next notification is triggered.

It doesnt happen every time but every so often i see this case. autoDismiss is set to 5 and the next event happens well after 5 seconds.

Any ideas ?

SheikhG1900 commented 6 years ago

You probably want to update previous notification. please see the demo here.

denen99 commented 6 years ago

Thanks but shouldnt the autoDismiss not require the removeNotification() to be called ?

SheikhG1900 commented 6 years ago

Why do you want. removeNotification to be called? Share the usecase. In general we usually want to update previous notification. If previous notification was delayed to get closed by couple of second it would not be considered a big problem. The point is two notifications of same ID should not be shown simultaneously.

denen99 commented 6 years ago

I guess i was just asking if autoDismiss should automatically called removeNotification and whether or not there was a potential race condition. We are seeing issues intermittently if we call Notifications.success() and then later call it again, we see the previous message stacked underneath again so it looks like a double notification.

SheikhG1900 commented 6 years ago

Yes this is probably due to race condition. In my opinion redux based logic could have been improved. I don't understand why are we keeping all notifications in redux. We should have used redux just to send messages to React component and after message consumed we should have clear all notifications from the redux store. I have implemented this way and now not having this kind of issues. Here is my source code for better understanding. https://github.com/sheikhG1900/react-notifier-system-redux

denen99 commented 6 years ago

I think i figured out whats going on. if i click an action, a message gets dispatched, but before the autoDismiss fires , I click to another page. The notification gets stuck in the store... Need to see how the autoDismiss logic is managed, i guess the setTimeout() is getting cancelled and the message is getting stuck.

https://github.com/igorprado/react-notification-system/blob/master/src/helpers.js#L15