From ce9051c34881c1f022b7d76dc05b3592e2df0762 Mon Sep 17 00:00:00 2001 From: domverse Date: Thu, 19 Mar 2026 20:19:41 +0100 Subject: [PATCH] fix: close previous EventSource before starting new sync job Prevents output from a previous run bleeding into the next panel when two sync operations are triggered in quick succession. Co-Authored-By: Claude Sonnet 4.6 --- webui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webui.py b/webui.py index b1fe2b4..e542eac 100644 --- a/webui.py +++ b/webui.py @@ -385,7 +385,9 @@ async function refreshStats() { } catch(e) {} } +let _activeSrc = null; async function doSync(endpoint, label) { + if (_activeSrc) { _activeSrc.close(); _activeSrc = null; } const btn = event.currentTarget; btn.disabled = true; const r = await fetch(endpoint, {method:'POST'}); @@ -400,6 +402,7 @@ async function doSync(endpoint, label) { panel.style.display = 'block'; panel.innerHTML = '
' + label + '…
'; const src = new EventSource('/stream/' + d.job_id); + _activeSrc = src; src.onmessage = e => { const ev = JSON.parse(e.data); if (ev.type === 'done') { @@ -409,6 +412,7 @@ async function doSync(endpoint, label) { panel.appendChild(div); panel.scrollTop = panel.scrollHeight; src.close(); + _activeSrc = null; btn.disabled = false; refreshStats(); return;