From b83e8d6d92065c14cf39d5a561a42ef29f80469f Mon Sep 17 00:00:00 2001 From: Till JS Date: Thu, 9 Apr 2026 13:25:06 +0200 Subject: [PATCH] fix(mana/web): seed pending-changes badge count on mount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OfflineIndicator badge shows networkStore.pendingCount, which is only refreshed inside unifiedSync.onStatusChange. That callback fires on transitions only — so on a fresh tab where sync stays idle, the badge sticks at the last persisted value (or 0). Observed live as "13 pending" while _pendingChanges actually held 27 rows. Extract refreshPendingCount as a local helper and call it once right after startAll() to seed the badge. The transition-driven refresh inside onStatusChange now reuses the same helper. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/mana/apps/web/src/routes/(app)/+layout.svelte | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/mana/apps/web/src/routes/(app)/+layout.svelte b/apps/mana/apps/web/src/routes/(app)/+layout.svelte index f3132e585..cf5762ad8 100644 --- a/apps/mana/apps/web/src/routes/(app)/+layout.svelte +++ b/apps/mana/apps/web/src/routes/(app)/+layout.svelte @@ -372,17 +372,24 @@ trackReturnVisit(); const getToken = () => authStore.getValidToken(); unifiedSync = createUnifiedSync(SYNC_SERVER_URL, getToken); - unifiedSync.onStatusChange(async (s) => { - networkStore.setSyncStatus(s); - // Update pending count when sync status changes + const refreshPendingCount = async () => { try { const count = await db.table('_pendingChanges').count(); networkStore.setPendingCount(count); } catch { // DB not ready yet } + }; + unifiedSync.onStatusChange(async (s) => { + networkStore.setSyncStatus(s); + // Update pending count when sync status changes + await refreshPendingCount(); }); unifiedSync.startAll(); + // Seed the badge count on mount: onStatusChange only fires on + // transitions, so without this the badge stays at its last known + // value (0 on a fresh tab) until a sync actually runs. + refreshPendingCount(); userSettings.load().catch(() => {});