From b66efae5b7e4ca3652004b5cc48c408d131cc46d Mon Sep 17 00:00:00 2001 From: DhanushSantosh Date: Sun, 18 Jan 2026 02:30:16 +0530 Subject: [PATCH] fix: sync projects immediately instead of debouncing Projects are critical data that must persist across mode switches (Electron/web). Previously, project changes were debounced by 1 second, which could cause data loss if: 1. User switched from Electron to web mode quickly 2. App closed before debounce timer fired 3. Network temporarily unavailable during debounce window This change makes project array changes sync immediately (syncNow) instead of using the 1-second debounce, ensuring projects are always persisted to the server right away and visible in both Electron and web modes. Fixes issue where projects opened in Electron didn't appear in web mode. Co-Authored-By: Claude Haiku 4.5 --- apps/ui/src/hooks/use-settings-sync.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/ui/src/hooks/use-settings-sync.ts b/apps/ui/src/hooks/use-settings-sync.ts index ea865566..80fd00a8 100644 --- a/apps/ui/src/hooks/use-settings-sync.ts +++ b/apps/ui/src/hooks/use-settings-sync.ts @@ -340,9 +340,22 @@ export function useSettingsSync(): SettingsSyncState { return; } - // Check if any synced field changed + // If projects array changed (by reference, meaning content changed), sync immediately + // This is critical - projects list changes must sync right away to prevent loss + // when switching between Electron and web modes or closing the app + if (newState.projects !== prevState.projects) { + logger.debug('Projects array changed, syncing immediately', { + prevCount: prevState.projects?.length ?? 0, + newCount: newState.projects?.length ?? 0, + }); + syncNow(); + return; + } + + // Check if any other synced field changed let changed = false; for (const field of SETTINGS_FIELDS_TO_SYNC) { + if (field === 'projects') continue; // Already handled above if (hasSettingsFieldChanged(field, newState, prevState)) { changed = true; break;