diff --git a/static/script.js b/static/script.js index 265ba76c..02fac38f 100644 --- a/static/script.js +++ b/static/script.js @@ -499,7 +499,7 @@ let imgW = 0, imgH = 0; let scale = 1, offX = 0, offY = 0, minScale = 1; let dragging = false, sx = 0, sy = 0; let selected = ""; -let pollID = null; +const pollIntervals = []; /* ---------- utility functions ----------------------------------- */ const hue = name => { @@ -1449,15 +1449,21 @@ function handleServerStatusUpdate(msg) { } function startPolling() { - if (pollID !== null) return; + // Clear any existing intervals first (prevents leak on re-init) + pollIntervals.forEach(id => clearInterval(id)); + pollIntervals.length = 0; + + // Initial fetches pollLive(); - pollTotalRares(); // Initial fetch - pollTotalKills(); // Initial fetch - pollServerHealth(); // Initial server health check - pollID = setInterval(pollLive, POLL_MS); - setInterval(pollTotalRares, POLL_RARES_MS); - setInterval(pollTotalKills, POLL_KILLS_MS); - setInterval(pollServerHealth, POLL_HEALTH_MS); + pollTotalRares(); + pollTotalKills(); + pollServerHealth(); + + // Set up recurring polls + pollIntervals.push(setInterval(pollLive, POLL_MS)); + pollIntervals.push(setInterval(pollTotalRares, POLL_RARES_MS)); + pollIntervals.push(setInterval(pollTotalKills, POLL_KILLS_MS)); + pollIntervals.push(setInterval(pollServerHealth, POLL_HEALTH_MS)); } img.onload = () => {