Fix: prevent remote edits from being silently deleted on concurrent updates#80
Merged
shikokuchuo merged 1 commit intomainfrom Mar 25, 2026
Merged
Fix: prevent remote edits from being silently deleted on concurrent updates#80shikokuchuo merged 1 commit intomainfrom
shikokuchuo merged 1 commit intomainfrom
Conversation
…pdates Remove the redundant `setFileContents` call in `handleContentChange` and the duplicate `onFileChanged`/`tryParseAndNotify` calls in `updateFileContent`. Both were overwriting the true merged Automerge document state with raw editor content, causing concurrent remote edits to be dropped by subsequent `updateText` diffs.
Collaborator
|
I looked at the change and your explanation and it makes a lot of sense to me fwiw. Thanks for adding comments that explain the flow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74.
When two people edit the same file at the same time, the second person's changes could get silently thrown away.
What was happening: When you type in the editor, two things happen: (1) your edit gets merged into the shared document via Automerge, and (2) the app updates its local copy of the file content. The problem was that step 2 was overwriting the local copy with just your text — ignoring any changes the other person made in the meantime. The next time you typed, the app would compare against that stale copy and effectively erase the other person's work.
We removed the redundant local state update in App.tsx and the redundant callback in the sync client. Both were unnecessary because the Automerge change handler already pushes the correctly-merged document state back to the app. Now there's only one source of truth for file content — the merged Automerge document — so remote edits can't get lost.