fix(nbstore): adjust doc sync logic (#10342)

This commit is contained in:
EYHN
2025-02-21 08:17:07 +00:00
parent f3218ab3bc
commit 244d683d83
2 changed files with 47 additions and 27 deletions

View File

@@ -399,23 +399,31 @@ export class DocFrontend {
this.statusUpdatedSubject$.next(job.docId);
}
/**
* skip listen doc update when apply update
*/
private skipDocUpdate = false;
applyUpdate(docId: string, update: Uint8Array) {
const doc = this.status.docs.get(docId);
if (doc && !isEmptyUpdate(update)) {
try {
this.skipDocUpdate = true;
applyUpdate(doc, update, NBSTORE_ORIGIN);
} catch (err) {
console.error('failed to apply update yjs doc', err);
} finally {
this.skipDocUpdate = false;
}
}
}
private readonly handleDocUpdate = (
update: Uint8Array,
origin: any,
_origin: any,
doc: YDoc
) => {
if (origin === NBSTORE_ORIGIN) {
if (this.skipDocUpdate) {
return;
}
if (!this.status.docs.has(doc.guid)) {