developing #10

Merged
GHMiranda merged 64 commits from developing into master 2026-01-25 00:37:11 +00:00
2 changed files with 14 additions and 0 deletions
Showing only changes of commit cdaae6b965 - Show all commits

View File

@ -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)

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({