fix: keep localStorage cache in sync with server settings

When switching between Electron and web modes or when the server temporarily
stops, web mode was falling back to stale localStorage data instead of fresh
server data.

This fix:
1. Updates localStorage cache whenever fresh server settings are fetched
2. Updates localStorage cache whenever settings are synced to server
3. Prioritizes fresh settings cache over old Zustand persisted storage

This ensures that:
- Web mode always sees the latest projects even after mode switches
- Switching from Electron to web mode immediately shows new projects
- Server restarts don't cause web mode to use stale cached data

Fixes issue where projects opened in Electron didn't appear in web mode
after stopping and restarting the server.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
DhanushSantosh
2026-01-18 02:46:31 +05:30
parent b66efae5b7
commit 9137f0e75f
2 changed files with 32 additions and 0 deletions

View File

@@ -215,6 +215,15 @@ export function useSettingsSync(): SettingsSyncState {
if (result.success) {
lastSyncedRef.current = updateHash;
logger.debug('Settings synced to server');
// Update localStorage cache with synced settings to keep it fresh
// This prevents stale data when switching between Electron and web modes
try {
setItem('automaker-settings-cache', JSON.stringify(updates));
logger.debug('Updated localStorage cache after sync');
} catch (storageError) {
logger.warn('Failed to update localStorage cache after sync:', storageError);
}
} else {
logger.error('Failed to sync settings:', result.error);
}