mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-17 16:37:43 +00:00
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:
parent
ecd5ec7077
commit
b3f7be0afc
1 changed files with 9 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue