From cccea3ec3ea799d3df51a2eb2dcd945a149e4508 Mon Sep 17 00:00:00 2001 From: EYHN Date: Thu, 14 Mar 2024 13:14:03 +0800 Subject: [PATCH] fix(workspace): avoid data loss (hot-fix) (#6114) --- packages/common/infra/src/blocksuite/migration/fixing.ts | 3 +++ packages/frontend/workspace-impl/src/local/sync-sqlite.ts | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/packages/common/infra/src/blocksuite/migration/fixing.ts b/packages/common/infra/src/blocksuite/migration/fixing.ts index 5813da65da..840cb5a623 100644 --- a/packages/common/infra/src/blocksuite/migration/fixing.ts +++ b/packages/common/infra/src/blocksuite/migration/fixing.ts @@ -13,6 +13,9 @@ export function fixWorkspaceVersion(rootDoc: YDoc) { * Blocksuite just set the value, do nothing else. */ function doFix() { + if (meta.size === 0) { + return; + } const workspaceVersion = meta.get('workspaceVersion'); if (typeof workspaceVersion !== 'number' || workspaceVersion < 2) { transact( diff --git a/packages/frontend/workspace-impl/src/local/sync-sqlite.ts b/packages/frontend/workspace-impl/src/local/sync-sqlite.ts index a0f3b99c93..c2ea474482 100644 --- a/packages/frontend/workspace-impl/src/local/sync-sqlite.ts +++ b/packages/frontend/workspace-impl/src/local/sync-sqlite.ts @@ -19,6 +19,13 @@ export function createSQLiteStorage(workspaceId: string): SyncStorage { ); if (update) { + if ( + update.byteLength === 0 || + (update.byteLength === 2 && update[0] === 0 && update[1] === 0) + ) { + return null; + } + return { data: update, state: encodeStateVectorFromUpdate(update),