fix(electron): guard sync-folder cache against stale-load clobber

If a folder pick (setSyncFolderPath) completes while the very first
getSyncFolderPath disk read is still in flight, the load's resolution
callback would overwrite the freshly-set cache with the now-stale disk
value (null), leaving sync wrongly not-ready until restart. Only seed
the cache from disk when it's still unset; the freshly-picked value wins.
This commit is contained in:
Johannes Millan 2026-06-10 20:35:00 +02:00
parent ecd5ec7077
commit b3f7be0afc

View file

@ -44,8 +44,15 @@ const getSyncFolderPath = async (): Promise<string | null> => {
if (_cachedSyncFolder !== undefined) return _cachedSyncFolder;
if (!_loadPromise) {
_loadPromise = _loadSyncFolderFromDisk().then((v) => {
_cachedSyncFolder = v;
return v;
// A pick (setSyncFolderPath) can complete while this first disk read is
// still in flight. Only seed the cache if it's still unset, so the now-
// stale disk value can't clobber the freshly-picked folder. The guard +
// assignment run in one synchronous tick, so setSyncFolderPath cannot
// interleave between them.
if (_cachedSyncFolder === undefined) {
_cachedSyncFolder = v;
}
return _cachedSyncFolder;
});
}
return _loadPromise;