mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-24 04:27:27 +08:00
fix: potential race condition on app load when migration (#2977)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -129,16 +129,10 @@ if (environment.isBrowser) {
|
|||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
window.dispatchEvent(new CustomEvent('migration-done'));
|
window.dispatchEvent(new CustomEvent('migration-done'));
|
||||||
|
window.$migrationDone = true;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('error when migrating data', e);
|
console.error('error when migrating data', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
// global Events
|
|
||||||
interface WindowEventMap {
|
|
||||||
'migration-done': CustomEvent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Vendored
+6
@@ -35,6 +35,12 @@ declare global {
|
|||||||
events: any;
|
events: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface WindowEventMap {
|
||||||
|
'migration-done': CustomEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
|
var $migrationDone: boolean;
|
||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
var platform: Platform | undefined;
|
var platform: Platform | undefined;
|
||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
|
|||||||
@@ -118,7 +118,10 @@ const rootWorkspacesMetadataPromiseAtom = atom<
|
|||||||
}
|
}
|
||||||
|
|
||||||
// migration step, only data in `METADATA_STORAGE_KEY` will be migrated
|
// migration step, only data in `METADATA_STORAGE_KEY` will be migrated
|
||||||
if (metadata.some(meta => !('version' in meta))) {
|
if (
|
||||||
|
metadata.some(meta => !('version' in meta)) &&
|
||||||
|
!globalThis.$migrationDone
|
||||||
|
) {
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
signal.addEventListener('abort', () => reject(), { once: true });
|
signal.addEventListener('abort', () => reject(), { once: true });
|
||||||
window.addEventListener('migration-done', () => resolve(), {
|
window.addEventListener('migration-done', () => resolve(), {
|
||||||
|
|||||||
Reference in New Issue
Block a user