fix(workspace): avoid data loss (hot-fix) (#6114)

This commit is contained in:
EYHN
2024-03-14 13:14:03 +08:00
committed by GitHub
parent 39476d16ef
commit cccea3ec3e
2 changed files with 10 additions and 0 deletions
@@ -13,6 +13,9 @@ export function fixWorkspaceVersion(rootDoc: YDoc) {
* Blocksuite just set the value, do nothing else. * Blocksuite just set the value, do nothing else.
*/ */
function doFix() { function doFix() {
if (meta.size === 0) {
return;
}
const workspaceVersion = meta.get('workspaceVersion'); const workspaceVersion = meta.get('workspaceVersion');
if (typeof workspaceVersion !== 'number' || workspaceVersion < 2) { if (typeof workspaceVersion !== 'number' || workspaceVersion < 2) {
transact( transact(
@@ -19,6 +19,13 @@ export function createSQLiteStorage(workspaceId: string): SyncStorage {
); );
if (update) { if (update) {
if (
update.byteLength === 0 ||
(update.byteLength === 2 && update[0] === 0 && update[1] === 0)
) {
return null;
}
return { return {
data: update, data: update,
state: encodeStateVectorFromUpdate(update), state: encodeStateVectorFromUpdate(update),