Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions hub-client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ function App() {
}, [navigateToProjectSelector]);

const handleContentChange = useCallback((path: string, content: string) => {
// updateFileContent fires handle.change(), which synchronously triggers the
// 'change' event on the DocHandle. The registered changeHandler calls
// callbacks.onFileChanged with the true merged Automerge document state,
// which propagates to setFileContents via onFileContent. Setting fileContents
// directly here with the raw editor content would overwrite that merged state,
// causing concurrent remote edits to be silently deleted by subsequent
// updateText calls that diff against the stale Monaco content.
updateFileContent(path, content);
setFileContents((prev) => {
const next = new Map(prev);
next.set(path, content);
return next;
});
}, []);

const handleProjectCreated = useCallback(async (
Expand Down
8 changes: 5 additions & 3 deletions ts-packages/quarto-sync-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,11 @@ export function createSyncClient(callbacks: SyncClientCallbacks, astOptions?: AS
updateText(doc, ['text'], content);
});

// Notify callback (local change)
callbacks.onFileChanged(path, content, []);
tryParseAndNotify(path, content);
// onFileChanged and tryParseAndNotify are called by the 'change' event handler
// registered in subscribeToFile/subscribeToFileInternal, which passes the true
// merged Automerge document state. Calling them again here with the raw editor
// content would overwrite the merged state in fileContents, causing concurrent
// remote edits to be silently deleted on the next updateFileContent call.
}

/**
Expand Down
Loading