Exclude initial loading step from transcript history?


We are converting a long-standing prosemirror application to use YJS. Currently, when we load the initial document we are using…

const ydoc = new Y.Doc();
Y.applyUpdate(ydoc, oldDocAsUpdate);

This works well. However… when a user presses the undo button - they delete the contents of the whole migrated document. Is there a simple way to exclude this from the history stack?

Are you using y-prosemirror’s undo plugin? If so, you could simply add a new origin to the transaction that adds the initial content. E.g.

ydoc.transact(() => {
  Y.applyUpdate(ydoc, oldDocAsUpdate)
}, "initialization")

The inner workings of the Y.UndoManager are further explained here: https://docs.yjs.dev/api/undo-manager

1 Like