I'm having a page that getting refreshed every few seconds using router refresh
const router = useRouter()
...
useEffect(() => {
interval = setInterval(() => {
router.refresh()
}, REFRESH_RATE_MIL)
return () => {
clearInterval(interval)
}
}, []);
The problem is, when the machine is entering to hydration (sleep mode or closing the screen and wait a few minutes) The app crashes with net::ERR_NETWORK_IO_SUSPENDED, causing the whole application to crash.
I'm using Mac Ventura 13 and Chrome Version 127.0.6533.72 (arm64)
I tried few things to solve it:
** I want to use the router refresh because of the caching ability and the fact that it preserves the component's state
Any ideas of how to address this?
If I understand your question, I believe that a combination of document.visibilityState and navigator.onLine may be able to help you here.
if (navigator.onLine && document.visibilityState === 'visible')
Something similar to this around the router.refresh() will ensure that both possible things that could be causing the issues are checked for and the refresh hopefully does not cause a crash.