From be8c0482b7a001466ce773bd894ba7570b8ddbe7 Mon Sep 17 00:00:00 2001 From: Till JS Date: Thu, 9 Apr 2026 13:24:51 +0200 Subject: [PATCH] fix(mana/web/sync): drain leftover pending changes on startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit startAll() registered channels but never kicked a push for changes that survived across page reloads. schedulePush only fires from the Dexie hook on fresh writes, so any pending row from a previous session sat in _pendingChanges until the user happened to mutate the same table again — observed live as 27 pending across mana/memoro/places that never reached the server despite a healthy sync route. Add drainLeftoverPending() called once at the end of startAll(): scan _pendingChanges for distinct appIds and schedulePush each registered channel. Fire-and-forget; errors swallowed because the push retry path already handles failures. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/mana/apps/web/src/lib/data/sync.ts | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/mana/apps/web/src/lib/data/sync.ts b/apps/mana/apps/web/src/lib/data/sync.ts index 98df318a8..1cf435317 100644 --- a/apps/mana/apps/web/src/lib/data/sync.ts +++ b/apps/mana/apps/web/src/lib/data/sync.ts @@ -551,6 +551,13 @@ export function createUnifiedSync(serverUrl: string, getToken: () => Promise Promise { + try { + const leftoverAppIds = new Set(); + await db.table('_pendingChanges').each((change: { appId?: string }) => { + if (change.appId) leftoverAppIds.add(change.appId); + }); + for (const appId of leftoverAppIds) { + if (channels.has(appId)) schedulePush(appId); + } + } catch { + // DB not ready or query failed — next user write will trigger push anyway. + } + })(); + } + function stopAll(): void { for (const [, channel] of channels) { if (channel.pushTimer) clearTimeout(channel.pushTimer);