dashboard: remove stale KPI box before re-inserting on each poll

Assign a stable id to the KPI element so the previous instance can be
found and removed before the fresh one is prepended to the TOC sidebar.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 13:33:23 +01:00
parent 715bc8f501
commit 173b82ceb8

View File

@@ -151,9 +151,12 @@ const _kpiBox = html`<div class="kpi-infobox">
withDocHelp(_kpiBox, "/docs/decisions-kpi");
// ── Inject into the TOC sidebar (right column, non-scrolling) ───────────────
_kpiBox.id = "decisions-kpi-box";
const _toc = document.querySelector("#observablehq-toc");
if (_toc) _toc.prepend(_kpiBox);
else display(html`<div style="float:right;width:215px;margin-left:1rem">${_kpiBox}</div>`);
if (_toc) {
document.getElementById("decisions-kpi-box")?.remove();
_toc.prepend(_kpiBox);
} else display(html`<div style="float:right;width:215px;margin-left:1rem">${_kpiBox}</div>`);
```
```js