diff --git a/spx-gui/src/models/project/index.ts b/spx-gui/src/models/project/index.ts index 8ec026724..e1b787b7b 100644 --- a/spx-gui/src/models/project/index.ts +++ b/spx-gui/src/models/project/index.ts @@ -430,25 +430,27 @@ export class Project extends Disposable { try { if (this.hasUnsyncedChanges) await this.saveToCloud() this.autoSaveToCloudState = AutoSaveToCloudState.Saved - if (this.hasUnsyncedChanges) autoSaveToCloud() - else await localHelper.clear(localCacheKey) } catch (e) { - await this.saveToLocalCache(localCacheKey) // prevent data loss this.autoSaveToCloudState = AutoSaveToCloudState.Failed startRetry() + await this.saveToLocalCache(localCacheKey) // prevent data loss throw e } + + if (this.hasUnsyncedChanges) autoSaveToCloud() + else await localHelper.clear(localCacheKey) }, 1500) let retryTimeoutId: ReturnType const startRetry = () => { stopRetry() - retryTimeoutId = setTimeout(() => { - if ( - this.autoSaveToCloudState === AutoSaveToCloudState.Failed && - this.hasUnsyncedChanges - ) { + retryTimeoutId = setTimeout(async () => { + if (this.autoSaveToCloudState !== AutoSaveToCloudState.Failed) return + if (this.hasUnsyncedChanges) { autoSaveToCloud() + } else { + this.autoSaveToCloudState = AutoSaveToCloudState.Saved + await localHelper.clear(localCacheKey) } }, 5000) }