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

Notifications are not auto dismissed when browser tab is inactive #149

Closed
pauliusg opened this issue Mar 25, 2022 · 3 comments
Closed

Notifications are not auto dismissed when browser tab is inactive #149

pauliusg opened this issue Mar 25, 2022 · 3 comments

Comments

@pauliusg
Copy link

pauliusg commented Mar 25, 2022

I can reproduce this with Chrome browser. For example, when browser tab is not active, code in that browser tab receives a message and calls:

Store.addNotification({
  ...notification,
  dismiss: {
    duration: 2000
  }
})

If I click on that browser tab after 2 seconds, I would expect not to see a notification because time, to display it, has elapsed.
But notification appears as soon as I activate browser tab.

You can quickly check this in your demo page: https://teodosii.github.io/react-notifications-component/
Open Chrome console and execute this:

setTimeout(() => document.getElementsByClassName('btn-outline-secondary')[0].click(), 2000)

Then quickly go to other browser tab and wait 10 seconds. Go back to demo page tab and you will see appeared notification.

@teodosii
Copy link
Owner

Right, that's because animations are paused when tab is inactive (or sort of paused). Maybe I'll change it in the future to calculate elapsed time from last active tab time, but for now no such thing.

@masbaehr
Copy link

This is unfortunately very annoying to the point which makes me want to change notification library. Note: I'm not ranting or "demanding" a fix but i'd really also like to see a solution for it in future, so i think closing the issue is wrong.

Especially if the Notification occur while the Tab is not in the foreground, they stack up and wait for the Tab to be active again, causing a tsunami of notifications which did not pass.

Maybe a quick solution would be to add a configuration flag to completely omit any notification which happens in the background and leave it to the developer to show missed notifications

@pauliusg
Copy link
Author

pauliusg commented May 25, 2022

@masbaehr I use this workaround:

if (document.visibilityState !== 'hidden') {
  Store.addNotification({
    ...notification,
    dismiss: {
      duration: 3000
    }
  })
}

Downside of this, is that, if for example tab was hidden for 1000ms, notification does not show up at all. With proper solution it would show up 3000 - 1000 = 2000ms (duration - hidden tab time).

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

No branches or pull requests

3 participants