Skip to content

Commit

Permalink
Prevent undo of initial sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyabo committed Oct 18, 2024
1 parent 43c8b1f commit c01199d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions assets/js/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const useAppStore = create<DrawingState>((set, get) => {
function initYDoc(guid = LOCAL_DOCUMENT_GUID) {
const ydoc = new Y.Doc({guid});
const yfeatures = getYFeatures(ydoc);
const yfeaturesUndo = new Y.UndoManager(yfeatures);
const yfeaturesUndo = new Y.UndoManager([yfeatures]);
const indexedDbProvider = new IndexeddbPersistence(guid, ydoc);
yfeatures.observe(syncFeatures);
indexedDbProvider.on("synced", syncFeatures);
Expand Down Expand Up @@ -150,8 +150,7 @@ export const useAppStore = create<DrawingState>((set, get) => {
console.log("Joined successfully");
if (resp) {
const initialState = new Uint8Array(resp);
yfeaturesUndo.stopCapturing(); // Don't add the initial state to the undo manager
Y.applyUpdate(ydoc, initialState); // Apply the initial state to the Yjs document
Y.applyUpdate(ydoc, initialState, 'initial-sync'); // Use custom origin to exclude from undo/redo
} else {
console.log("No initial state");
}
Expand Down

0 comments on commit c01199d

Please sign in to comment.