From 9b631f23289ab098dca83a18bb9ac5fa3f11f2a8 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Wed, 15 Nov 2023 17:36:08 +0800 Subject: [PATCH] fix(infra): page id compat fix for page ids in workspace.meta (#4950) since we strip `page:` in keys of workspacedoc.spaces, we should also strip the prefix in meta.pages as well. --- packages/common/infra/src/blocksuite/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/common/infra/src/blocksuite/index.ts b/packages/common/infra/src/blocksuite/index.ts index ec281bad7d..383f8c3bee 100644 --- a/packages/common/infra/src/blocksuite/index.ts +++ b/packages/common/infra/src/blocksuite/index.ts @@ -670,8 +670,17 @@ async function upgradeV2ToV3(options: UpgradeOptions): Promise { export function guidCompatibilityFix(rootDoc: YDoc) { let changed = false; transact(rootDoc, () => { + const meta = rootDoc.getMap('meta') as YMap; + const pages = meta.get('pages') as YArray>; + pages?.forEach(page => { + const pageId = page.get('id') as string | undefined; + if (pageId?.includes(':')) { + // remove the prefix "space:" from page id + page.set('id', pageId.split(':').at(-1)); + } + }); const spaces = rootDoc.getMap('spaces') as YMap; - spaces.forEach((doc: YDoc, pageId: string) => { + spaces?.forEach((doc: YDoc, pageId: string) => { if (pageId.includes(':')) { const newPageId = pageId.split(':').at(-1) ?? pageId; const newDoc = new YDoc();