From 933b5a75c0ba942a6a9cb702e9eb7824f3352593 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Mon, 23 Nov 2026 16:30:22 +0000 Subject: [PATCH] fix(ui): read nested stats from stats_update events The server sends stats_update as {stats, timestamp}, but the realtime store read the counters from the top level of the payload. About 30 seconds after load, the first broadcast replaced the polled stats with undefined values, and the dashboard tiles showed 0. The store now unwraps the nested stats object. --- frontend/src/stores/realtime.spec.ts | 16 ++++++++++++++++ frontend/src/stores/realtime.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/src/stores/realtime.spec.ts b/frontend/src/stores/realtime.spec.ts index 9a0a5c5..463e28e 100644 --- a/frontend/src/stores/realtime.spec.ts +++ b/frontend/src/stores/realtime.spec.ts @@ -53,6 +53,22 @@ describe('useRealtimeStore', () => { expect(store.lastStats).toMatchObject({ total_packages: 42, total_size: 1024 }) }) + it('unwraps the server stats_update shape {stats, timestamp}', () => { + const store = useRealtimeStore() + store.ingest( + makeEvent('stats_update', { + stats: { total_packages: 1454, total_size: 980870617, total_downloads: 5376, scanned_packages: 1451 }, + timestamp: '2026-11-23T16:00:00Z', + }), + ) + expect(store.lastStats).toMatchObject({ + total_packages: 1454, + total_size: 980870617, + total_downloads: 5376, + scanned_packages: 1451, + }) + }) + it('exposes filtered computed slices', () => { const store = useRealtimeStore() store.ingest(makeEvent('package_cached')) diff --git a/frontend/src/stores/realtime.ts b/frontend/src/stores/realtime.ts index d46940b..4539dde 100644 --- a/frontend/src/stores/realtime.ts +++ b/frontend/src/stores/realtime.ts @@ -55,7 +55,9 @@ export const useRealtimeStore = defineStore('realtime', () => { events.value.splice(0, events.value.length - EVENTS_CAP) } if (event.type === 'stats_update') { - lastStats.value = event.payload as RealtimeStats + // The server nests the counters under `stats`; reading the payload flat shows zeros. + const nested = event.payload.stats + lastStats.value = (nested && typeof nested === 'object' ? nested : event.payload) as RealtimeStats } }