feat: broadcast full CRDT state to other clients after manual save

When a user saves, the full Yjs document state is broadcast so all
connected clients converge, even if they missed incremental updates.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gustavo Henrique Santos Souza de Miranda
2026-01-24 16:12:58 -03:00
co-authored by Claude Opus 4.5
parent 34815d70ee
commit cdaae6b965
2 changed files with 14 additions and 0 deletions
+11
View File
@@ -173,6 +173,17 @@ export class CRDTManager {
this.callbacks.onEdgesChange(this.getEdges())
}
/** Broadcast the full document state to sync all connected clients */
broadcastFullState(): void {
if (!this.channel || this.isDestroyed) return
const fullState = Y.encodeStateAsUpdate(this.doc)
this.channel.send({
type: 'broadcast',
event: BROADCAST_EVENT,
payload: { update: Array.from(fullState) },
})
}
private broadcastUpdate(update: Uint8Array): void {
if (!this.channel || this.isDestroyed) return
this.channel.send({