mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user