fix: same broken metric-button line, plus a mangled location.reload()

The dashboard carried the identical inline-handler line inside PAGE_HTML — the
served JS was a syntax error from there on, so the page loaded and then did
nothing — and a second casualty of the same sloppy one-shot replace:
`location.reload()` had become `location.rebuildMetricButtons()\nload()` inside
loadGuests(). Both are fixed, and the same gate fix applies (the gate now reads
PAGE_HTML via ast.literal_eval, i.e. the string the app serves, not the source
text between the quotes).

Buttons are delegated data-metric clicks now, the harness proves the click
reaches setTrendMetric, and the stub gained stateful attributes plus
addEventListener/__fire to make that possible.
This commit is contained in:
inference-admin committed 2026-11-13 21:14:03 +00:00
1 parent 36d8ba6e35
commit e2a5018150
3 files changed
+64 -11

No files matched your search

+14 -4
View File
@@ -1055,8 +1055,7 @@ function fmtDay(s) {
async function loadGuests() {
try {
const r = await fetch('/api/guests');
if (r.status === 401) { location.rebuildMetricButtons();
load(); return; }
if (r.status === 401) { location.reload(); return; }
const d = await r.json().catch(() => ({}));
renderGuests(d);
} catch (e) {
@@ -1360,11 +1359,22 @@ function buildMetricButtons() {
let html = "";
for (const def of CHART_METRICS) {
if (!METRIC_SOURCE[def.id]) continue; // a metric this page cannot fetch
html += '<button class="mode-btn" id="tm-' + def.id + '"'
+ " onclick=\"setTrendMetric('" + def.id + "')\">" + escapeHtml(def.title) + "</button>";
html += '<button class="mode-btn" id="tm-' + def.id + '" data-metric="' + def.id + '">'
+ escapeHtml(def.title) + "</button>";
}
row.insertAdjacentHTML("beforeend", html);
row.setAttribute("data-built", "1");
// Delegated, not an inline handler: an inline onclick inside this
// Python triple-quoted string is exactly where a quote escape can
// silently break the whole page, and the escape that ships is not the
// one the raw source text shows.
if (!row.getAttribute("data-wired")) {
row.addEventListener("click", function (e) {
const b = e.target && e.target.closest ? e.target.closest("button[data-metric]") : null;
if (b) setTrendMetric(b.getAttribute("data-metric"));
});
row.setAttribute("data-wired", "1");
}
syncMetricButtons();
}