Skip to content

fix(hub-client): replace updateText with positional splice for CRDT sync#87

Open
shikokuchuo wants to merge 2 commits intomainfrom
fix-sync
Open

fix(hub-client): replace updateText with positional splice for CRDT sync#87
shikokuchuo wants to merge 2 commits intomainfrom
fix-sync

Conversation

@shikokuchuo
Copy link
Copy Markdown
Collaborator

Fixes #74 - a race condition where edits from other users could be silently deleted during collaborative editing.

Problem

When you type in the editor, the app sends your full document text to the sync engine, which diffs it against its own copy to figure out what changed. But if a collaborator's edit arrives between reading the editor and running that diff, the diff sees their new text as "not in the editor" and deletes it.

Fix

Instead of sending the full document and diffing, we now send the exact edit operations — "insert 'x' at position 5" or "delete 3 characters at position 10". The sync engine applies these directly as positional splices. Since it never diffs against the full document, there's no window where a collaborator's edit can be misinterpreted as something to delete. Automerge's CRDT is designed to merge concurrent positional edits correctly.

This also improves how the preview panel writes content back to the editor (e.g., when you reorder slides by dragging). Previously this used the same racy full-document path. Now it routes through the editor as a normal edit, which also means Ctrl+Z undoes it.

Unchanged

Replay mode still uses the old full-document path, which is fine — it doesn't involve concurrent editing.

… sync

Eliminates race condition where concurrent remote edits were lost because `updateText` diffed against stale Automerge state. Monaco's `IModelContentChange` events now map directly to Automerge splice operations
@shikokuchuo
Copy link
Copy Markdown
Collaborator Author

@vezwork just leaving a note as you were interested in this. This will probably be merged by the time you get to this, but we can always amend further depending on how you envisage bidirectional changes to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hub: edits can get lost

1 participant