There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(core): migration (#3322)
Alex Yangcac609d36fe0
diff --git a/packages/workspace/src/atom.ts b/packages/workspace/src/atom.tsindex 4cee86bc62..fc826a3562 100644--- a/packages/workspace/src/atom.ts+++ b/packages/workspace/src/atom.ts@@ -81,9 +81,30 @@ const rootWorkspacesMetadataPromiseAtom = atom<// fixme(himself65): we might not need step 1// step 1: try load metadata from localStorage{+ const loadFromLocalStorage = (): RootWorkspaceMetadata[] => {+ // don't change this key,+ // otherwise it will cause the data loss in the production+ const primitiveMetadata = localStorage.getItem(METADATA_STORAGE_KEY);+ if (primitiveMetadata) {+ try {+ const items = JSON.parse(primitiveMetadata) as z.infer<+ typeof rootWorkspaceMetadataArraySchema+ >;+ rootWorkspaceMetadataArraySchema.parse(items);+ return [...items];+ } catch (e) {+ console.error('cannot parse worksapce', e);+ }+ return [];+ }+ return [];+ };++ const maybeMetadata = loadFromLocalStorage();+// migration step, only data in `METADATA_STORAGE_KEY` will be migratedif (- metadata.some(meta => !('version' in meta)) &&+ maybeMetadata.some(meta => !('version' in meta)) &&!globalThis.$migrationDone) {await new Promise<void>((resolve, reject) => {@@ -94,20 +115,7 @@ const rootWorkspacesMetadataPromiseAtom = atom<});}- // don't change this key,- // otherwise it will cause the data loss in the production- const primitiveMetadata = localStorage.getItem(METADATA_STORAGE_KEY);- if (primitiveMetadata) {- try {- const items = JSON.parse(primitiveMetadata) as z.infer<- typeof rootWorkspaceMetadataArraySchema- >;- rootWorkspaceMetadataArraySchema.parse(items);- metadata.push(...items);- } catch (e) {- console.error('cannot parse worksapce', e);- }- }+ metadata.push(...loadFromLocalStorage());}// step 2: fetch from adapters{diff --git a/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts b/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.tsindex 1a4896f40e..1e13ddd386 100644--- a/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts+++ b/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts@@ -84,8 +84,6 @@ test('init page', async ({ page, context }) => {await switchToNext();await page.waitForTimeout(1000);await page.goto('http://localhost:8081/');- await page.waitForTimeout(1000);- await page.goto('http://localhost:8081/');await page.waitForSelector('v-line', {timeout: 10000,});