Versioning yDocs for storage on a server

Hey @dmonad,
I am trying to implement a version based system for storing yDocs on my server. (Not the yjs websocket server, but a specific server for storage)

I checked out the versioning example for Prosemirror ( In the code, I can see a render snapshot version which directly applies to the prosemirror instance.

editorview.dispatch(, { snapshot: Y.decodeSnapshot(version.snapshot), prevSnapshot: prevSnapshot == null ? Y.emptySnapshot : Y.decodeSnapshot(prevSnapshot) }))

I wanted to know how I could modify it such that I can store the snapshots on my server, and then directly switch to a previous version using the snapshots from the server. What according to you should be the best approach for this? Specifically, I want to allow for a google-docs like revert to previous version, hence the necessity to serialize/de-serialize the yDoc state from the browser to the server.


Hi @Mansehej,

If you want to revert to a specific version, I suggest that simply overwrite the new ProseMirror state with the snapshotted ProseMirror state. You could first render the snapshotted state:

// using the same snapshot as prevSnapshot will disable showing the differences
editorview.dispatch(, { snapshot: Y.decodeSnapshot(version.snapshot), prevSnapshot: Y.decodeSnapshot(version.snapshot) }))

Then you grab the snapshotted ProseMirror state, disable rendering the snapshot, and overwrite the ProseMirror state with the snapshotted ProseMirror state.

Then the reverted changes will be synced to all clients.

Hey @dmonad,

I’m going to try and give a PR on the yjs prosemirror with versions demo, so you can reset back to any of the older snapshots - perhaps that clarifies the problem for me. Any pointers to the code and where I would have to work on to give this PR?

Additionally, mutliple clients working on this yjs will split (network disconnect), will continue working on the document and creating snapshots offline, and will rejoin at a later time. Would it be possible to have a list of combined snapshots there too?

Hi @Mansehej,

You can encode the snapshot to a binary format and then share it with other clients, for example in a Y.Array. Use the experimental function binary = Y.encodeSnapshot(snapshot) and snapshot = Y.decodeSnapshot(binary).

What exactly do you mean by combined snapshot? What would be the expected outcome?