fix: the summary panel's first paint no longer freezes or claims the sources are gone

Two halves of the same first paint. The panel showed «Source unavailable»
in every row until the lazy metrics chunk arrived, because value() could
not tell "not loaded yet" from "source is dead"; and metrics() ran inside
render, walking the HA registry and unioning the clean floor of every
space synchronously — 11 s on the large-house fixture.

- totalCleanFloorAreaM2 computes the space's masonry and junction
  topology once per SPACE and hands them to innerContourForRoom, which
  otherwise unions the whole space again for every room: 11 045 → 1 488 ms
  on that fixture, same 306.3 m². The card has always done this through
  its own _innerContour cache; the panel now does the same.
- Aggregates leave the render path: the first frame paints skeletons and
  the work starts right after the frame is shown (timeout → rAF →
  timeout, never requestIdleCallback, which under load would leave the
  skeleton up for seconds). Stale memo keeps the previous number on
  screen instead of flashing back to a skeleton.
- valueState() separates pending from unavailable; a pending row keeps
  the same plate, grid and height and carries a pulsing rectangle the
  height of the line, replaced by the value with a short fade. Reduced
  motion keeps the rectangle and drops the pulse.
- Panel enter/exit animation (#505, 190 ms) is now actually visible —
  the main thread is free — and the smoke witnesses it.

Mutants: summary-first-paint-shows-unavailable, summary-metrics-block-first-frame,
summary-area-recomputes-walls-per-room, summary-stale-metric-falls-back-to-skeleton.

Issue: #509
User-Visible: yes
This commit is contained in:
Codex
2026-09-10 11:24:10 +03:00
parent 9d375dcb40
commit 398281a93f
54 changed files with 951 additions and 463 deletions
+43
View File
@@ -222,3 +222,46 @@ test('#493 late reload and confirmation completions stay outside a new lifecycle
browser.restore();
}
});
test('#509 AC1/AC2/AC9: значение показывает скелет до готовности, ошибку — только для недоступного источника', () => {
const browser = installBrowserGlobals();
try {
const host = hostFixture();
host._cfgEpoch = 1;
const runtime = new LoadedSummaryPanelRuntime(host);
const state = (value) => runtime.valueState(value);
const deviceCount = { id: 'v1', label: 'Devices', source: { type: 'system', key: 'device_count' } };
const entity = { id: 'v2', label: 'Lamp', source: { type: 'entity', entity_id: 'light.a' } };
// AC1: ленивый чанк ещё не пришёл — скелет, а не «источник недоступен».
assert.deepEqual(state(deviceCount), { kind: 'pending' });
assert.deepEqual(state(entity), { kind: 'pending' });
// Модуль пришёл, агрегат ещё не посчитан — по-прежнему скелет.
runtime.metricsModule = {
summaryEntityValue: (hass, id) => (id === 'light.a' ? 'On' : null),
summarySystemValue: (source, values) => (source.key === 'device_count'
? (values.deviceCount === null ? null : String(values.deviceCount)) : null),
representedHaDeviceIds: () => new Set(['d1', 'd2']),
totalCleanFloorAreaM2: () => 12.5,
};
assert.deepEqual(state(deviceCount), { kind: 'pending' });
// AC2: живая сущность отвечает сразу; отсутствующая — честная ошибка.
assert.deepEqual(state(entity), { kind: 'ready', text: 'On' });
assert.deepEqual(state({ ...entity, source: { type: 'entity', entity_id: 'light.gone' } }), { kind: 'unavailable' });
// Расчёт после кадра: имитируем его завершение.
runtime.computeMetrics();
assert.deepEqual(state(deviceCount), { kind: 'ready', text: '2' });
// AC9: конфигурация изменилась — мемо устарело, но на экране остаётся
// прежнее число, а не скелет; пересчёт запланирован.
host._cfgEpoch = 2;
assert.equal(runtime.metricsFresh(), false);
assert.deepEqual(state(deviceCount), { kind: 'ready', text: '2' });
runtime.computeMetrics();
assert.equal(runtime.metricsFresh(), true);
} finally {
browser.restore();
}
});