Is there a way to revert to specific version?

Hello,

I am working on a collaborative drawing application and using yjs websocket server.
If I can, I want to add version control function (like google-docs, revert to previous version).

I checked out ‘y-prosemirror-versions’ example(https://demos.yjs.dev/prosemirror-versions/prosemirror-versions.html), but it seems like it is usable for text editor.

Is it possible reverting to previous specific version using snapshot or undoManager?

I’m trying to overwrite y-docs with stored snapshot, but I’m not sure if it works or not.

Thanks and regards
Rory

Hi @rory,

The API for reverting to old document state is not yet public. y-prosemirror uses hidden methods to read the previous state using a state-vector. It is my intention to provide an easy-to-use API based on this approach this year.

For now, maybe you can find another way around it. You could, for example, store the versioned state as a JSON object and restore the previous state by updating the Yjs state to the previous version. For drawing applications, it is probably not a problem to simply replace the complete state.

1 Like

I recently implemented this and took a “git revert” approach rather than a “git reset; git push --force” approach. I created a new temporary document from the snapshot, instantiated an Y.UndoManager to track changes, then brought the snapshot up-to-date with the current document, then undid all those changes using the UndoManager, then brought the current document up-to-date with the temporary one.

This approach has the advantage that you don’t need to convince all the connected clients to suddenly reload the document from the server, it’s just treated as a regular update.

3 Likes