diff --git a/src/app/editor/[projectId]/FlowchartEditor.tsx b/src/app/editor/[projectId]/FlowchartEditor.tsx index 0c0f5e6..7179df9 100644 --- a/src/app/editor/[projectId]/FlowchartEditor.tsx +++ b/src/app/editor/[projectId]/FlowchartEditor.tsx @@ -1143,6 +1143,9 @@ function FlowchartEditorInner({ projectId, projectName, userId, userDisplayName, // Update last saved data ref to mark as not dirty lastSavedDataRef.current = flowchartData + // Broadcast full CRDT state so other connected clients sync up + crdtRef.current?.broadcastFullState() + setToast({ message: 'Project saved successfully', type: 'success' }) } catch (error) { console.error('Failed to save project:', error) diff --git a/src/lib/collaboration/crdt.ts b/src/lib/collaboration/crdt.ts index 57ac014..d99478d 100644 --- a/src/lib/collaboration/crdt.ts +++ b/src/lib/collaboration/crdt.ts @@ -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({