Collab editing


I have studied some sources of information for co-editing:

ProseMirror Guide
website/src/collab/server at master · ProseMirror/website · GitHub
Collaborative Editing in ProseMirror

Conceptually, I understood the algorithm for making changes implemented through a single source of the editor’s state — the central server.

“When a client has made a change, they try to push that change to the server. If the change was based on the version of the document that the server considers current, it goes through.”
Collaborative Editing in ProseMirror

I want to understand how to act in situations where several people are making changes at the same time. For example:

Version of the central server editor: 3
My version: 3
Another user’s version: 3

We will make a decision on making changes at the same time:

  1. I’m sending the changes: the version of the central server editor becomes 4.
  2. At the same moment, a change comes from another user: his version is still 3 because he didn’t manage to get the changes I made at the same moment (for example, due to a weak Internet connection or operations that are too close in time.). This means that the editor of the central server cannot accept the changes without additional operations.

“If the change was based on the version of the document that the server considers current, it goes through. If not, the client must pull the changes that have been made by others in the meantime, and rebase their own changes on top of them, before retrying the push.”
Collaborative Editing in ProseMirror

But we can’t just tell the user that something is wrong with the version of his editor. If we try to solve this problem through the interface, or, for example, by reloading all the content, it will turn into a real nightmare. When typing fast at the same time, the problem will appear every second.

We need some kind of algorithm of actions that will try to make changes from the editor of the outdated version to the editor of the updated version.

I was thinking about how to do this using tools such as:

  1. Step.merge (ProseMirror Reference manual)
  2. Step.apply (ProseMirror Reference manual)
  3. (ProseMirror Reference manual)

Tell me, please, what do I understand wrong?

1 Like

The approach here is that the server returns a version mismatch status, the client fetches new updates from the server and uses receiveTransaction to apply it to its local state, moving its version forward, and then submits its local changes again.