fix: merge two empty doc, no udpate event trigger

This commit is contained in:
alt0
2023-01-12 12:08:37 +08:00
parent 48d355ee72
commit 034e460701
4 changed files with 36 additions and 33 deletions

View File

@@ -45,3 +45,25 @@ export async function getDefaultHeadImgBlob(
}
});
}
export const applyUpdate = async (
blocksuiteWorkspace: BlocksuiteWorkspace,
updates: Uint8Array
) => {
if (updates && updates.byteLength) {
await new Promise(resolve => {
// FIXME: if we merge two empty doc, there will no update event.
// So we set a timer to cancel update listener.
const doc = blocksuiteWorkspace.doc;
const timer = setTimeout(() => {
doc.off('update', resolve);
resolve(undefined);
}, 1000);
doc.once('update', () => {
clearTimeout(timer);
setTimeout(resolve, 100);
});
BlocksuiteWorkspace.Y.applyUpdate(doc, new Uint8Array(updates));
});
}
};