Rails Gem for Collaborative Editing with ProseMirror

I’m working on a Rails gem to make collaborative editing with ProseMirror drop-in for Rails apps.

Currently, it is an extremely early prototype (notably, no automated tests yet), but I wanted to get feedback on the current implementation. I’ll be working to make it more stable so we can use the gem in production.

The gem uses Rails ActionCable to handle the communication (websockets) and runs ProseMirror in a NodeJS child process to apply steps server-side.

I use a modified version of the prosemirror-collab algorithm, basically:

  • Steps are grouped into “commits” before being sent to the server.
  • Rather than use a client id, the client tracks commits by attaching a random “ref”. This allows the client or server to merge the steps within a commit without affecting the client’s internal representation (related to this post). It also helps prevent bad-acting clients from causing trouble
  • Due to the gem’s reliance on background processing for broadcasting commits & applying changes to documents, it’s possible a client may receive commits out of order. The client side code handles this by queueing future commits until prior ones are received.
  • I’ve added lodash's throttle function so that the server is less likely to be overwhelmed by a single client. I will likely want to add some form of rate-limiting on the server-side.

Currently, there is no handling for connection interruption. This should be easily solvable by simply reconnecting & recommitting on disconnect.

I also plan to use prosemirror-recreate-steps to handle a client who goes offline for a long period with uncommitted changes. The gem stores old steps, but a client could go offline for long enough that old steps were thrown out - in this case, it would be important to not only recover the changes, but support some type of interactive merging. Again though, this likely would require UI which would have to be implemented by library users. How has this been handled by others?