fix(nbstore): local doc update lost (#10422)

This commit is contained in:
EYHN
2025-02-25 12:26:49 +08:00
committed by GitHub
parent 7e892b3a7e
commit c644a46b8d
+2 -10
View File
@@ -399,31 +399,23 @@ export class DocFrontend {
this.statusUpdatedSubject$.next(job.docId); this.statusUpdatedSubject$.next(job.docId);
} }
/**
* skip listen doc update when apply update
*/
private skipDocUpdate = false;
applyUpdate(docId: string, update: Uint8Array) { applyUpdate(docId: string, update: Uint8Array) {
const doc = this.status.docs.get(docId); const doc = this.status.docs.get(docId);
if (doc && !isEmptyUpdate(update)) { if (doc && !isEmptyUpdate(update)) {
try { try {
this.skipDocUpdate = true;
applyUpdate(doc, update, NBSTORE_ORIGIN); applyUpdate(doc, update, NBSTORE_ORIGIN);
} catch (err) { } catch (err) {
console.error('failed to apply update yjs doc', err); console.error('failed to apply update yjs doc', err);
} finally {
this.skipDocUpdate = false;
} }
} }
} }
private readonly handleDocUpdate = ( private readonly handleDocUpdate = (
update: Uint8Array, update: Uint8Array,
_origin: any, origin: any,
doc: YDoc doc: YDoc
) => { ) => {
if (this.skipDocUpdate) { if (origin === NBSTORE_ORIGIN) {
return; return;
} }
if (!this.status.docs.has(doc.guid)) { if (!this.status.docs.has(doc.guid)) {