fix: close previous EventSource before starting new sync job
All checks were successful
Deploy / deploy (push) Successful in 12s

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 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 20:19:41 +01:00
parent 7bbb459c6c
commit ce9051c348

View File

@@ -385,7 +385,9 @@ async function refreshStats() {
} catch(e) {} } catch(e) {}
} }
let _activeSrc = null;
async function doSync(endpoint, label) { async function doSync(endpoint, label) {
if (_activeSrc) { _activeSrc.close(); _activeSrc = null; }
const btn = event.currentTarget; const btn = event.currentTarget;
btn.disabled = true; btn.disabled = true;
const r = await fetch(endpoint, {method:'POST'}); const r = await fetch(endpoint, {method:'POST'});
@@ -400,6 +402,7 @@ async function doSync(endpoint, label) {
panel.style.display = 'block'; panel.style.display = 'block';
panel.innerHTML = '<div class="ln">' + label + '…</div>'; panel.innerHTML = '<div class="ln">' + label + '…</div>';
const src = new EventSource('/stream/' + d.job_id); const src = new EventSource('/stream/' + d.job_id);
_activeSrc = src;
src.onmessage = e => { src.onmessage = e => {
const ev = JSON.parse(e.data); const ev = JSON.parse(e.data);
if (ev.type === 'done') { if (ev.type === 'done') {
@@ -409,6 +412,7 @@ async function doSync(endpoint, label) {
panel.appendChild(div); panel.appendChild(div);
panel.scrollTop = panel.scrollHeight; panel.scrollTop = panel.scrollHeight;
src.close(); src.close();
_activeSrc = null;
btn.disabled = false; btn.disabled = false;
refreshStats(); refreshStats();
return; return;