fix: prevent polling leak when online event fires from connected state

Guard startPolling in handleOnline to only fire when transitioning from
offline state. Previously, a spurious browser online event while already
connected would start a polling interval that never gets cleared.
This commit is contained in:
ashim-hq
2026-04-21 09:24:10 +08:00
parent a145ffdc68
commit 1f9fa08002
+4 -1
View File
@@ -7,8 +7,11 @@ export function useConnectionMonitor() {
const handleOffline = () => store.getState().setOffline();
const handleOnline = () => {
const prev = store.getState().status;
store.getState().setOnline();
store.getState().startPolling();
if (prev === "offline") {
store.getState().startPolling();
}
};
window.addEventListener("offline", handleOffline);