Skip to content

Commit

Permalink
perf: Don't send mutations for updates originating from this provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
grgbkr committed Dec 15, 2023
1 parent ed98815 commit 01b730f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/reflect-yjs/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Provider {
this.#serverUpdateMeta.length,
);
this.#vector = Y.encodeStateVectorFromUpdateV2(this.#serverUpdate);
Y.applyUpdateV2(ydoc, this.#serverUpdate);
Y.applyUpdateV2(ydoc, this.#serverUpdate, this);
}
}
if (isInitial) {
Expand All @@ -94,7 +94,7 @@ export class Provider {
// All other client updates will have originated from this ydoc
// and thus not need to be applied.
if (this.#clientUpdate) {
Y.applyUpdateV2(ydoc, this.#clientUpdate);
Y.applyUpdateV2(ydoc, this.#clientUpdate, this);
}
}
},
Expand All @@ -112,7 +112,10 @@ export class Provider {
return this.#awareness;
}

#handleUpdate = async () => {
#handleUpdate = async (_update: unknown, origin: unknown) => {
if (origin === this) {
return;
}
const diffUpdate = this.#vector
? Y.encodeStateAsUpdateV2(this.#ydoc, this.#vector)
: Y.encodeStateAsUpdateV2(this.#ydoc);
Expand Down

0 comments on commit 01b730f

Please sign in to comment.