refetchInterval and active queries when not on tab
We have an issue whereby we are requesting a presigned url of an image. This expires every minute. I've added a
refetchInterval of 1 minute to request the photo. THis all works well unless the user is not on the tab. Question, is this expected browser behavior as you aren;'t actually active on the tab anymore?5 Replies
fair-rose•3y ago
@trickydisco7250 Browsers that put inactive tabs to sleep are one case that I would expect that behavior.
graceful-beigeOP•3y ago
Indeed. That's what I was thinking. It's by design. Will go back to qa and maybe enable refetch on window focus
Looks like i can use
deep-jade•3y ago
yes, the option will work, but be aware that browsers might still throttle timers in inactive tabs: https://developer.chrome.com/blog/timer-throttling-in-chrome-88/
Chrome Developers
Heavy throttling of chained JS timers beginning in Chrome 88 - Chro...
Intensive throttling takes effect when the page has been hidden for more than 5 minutes, the page has been silent for at least 30 seconds, WebRTC is not in use, and the chain of timers is 100 or greater.
graceful-beigeOP•3y ago
oh interesting.I've just been trying to look into the source to work out if you somehow got round this. It makes sense that browser de prioritise inactive/hidden tabs
fair-rose•3y ago
Unless it was a mandatory specification, I personally would find a way to shut down fetching when the page document is in hidden state.
If you must keep fetching, you could try setInterval from a worker. The page visibility API can help in detecting when the document tab visibility state changes