Skip to content

Fix: prevent remote edits from being silently deleted on concurrent updates#80

Merged
shikokuchuo merged 1 commit intomainfrom
fix-update
Mar 25, 2026
Merged

Fix: prevent remote edits from being silently deleted on concurrent updates#80
shikokuchuo merged 1 commit intomainfrom
fix-update

Conversation

@shikokuchuo
Copy link
Collaborator

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.

…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.
@shikokuchuo shikokuchuo marked this pull request as ready for review March 25, 2026 17:47
@shikokuchuo shikokuchuo merged commit 014a094 into main Mar 25, 2026
4 checks passed
@shikokuchuo shikokuchuo deleted the fix-update branch March 25, 2026 17:47
@vezwork
Copy link
Collaborator

vezwork commented Mar 26, 2026

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.

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

2 participants