So it’s almost 2021 and there still nothing magic out of the box to add Real Time Collaboration to a Rails stack.
But as far as i know, we almost have everything to make it happen:
ActionCable for websockets client/server communication.
ActionText based on top of trix.js is using a document model,
OT algorithm or CRDT algorithm to solve collaboration conflicts. (Probably need to create new trix.js api’s to access operations)
Using a jsonb column instead storing the rendered html, we could store the solved document model for all nodes and broadcast it and restore the client document.
Adding multi cursor support + tooltip (to display who is editing name) to trix.js
ActiveStorage would be compatible since it’s just modifying the document model.
Am i missing anything ?
Does the rails team has any plan on implementing something of that nature ? That would make the world a better place and enabled collaboration for everyone.
Realtime updates of fields (handled with Turbo streams / action cable)
Realtime collaboration on text fields (not handled yet)
From my limited research it seems like there are two competing solutions for the latter:
OT (Operational Transform). This is well known, battle tested, centralized tech. It might be the best option for a rails default. It’s less performant than CRDT, and requires being online, but so does rails.
CRDT. This is maturing, but still kind of experimental - with Y.js leading the open source charge here as far as I can tell. It allows offline first apps and can be super performant. But: It’s also complicated, and might have some weird side effects when a client comes online a month later and does some changes that no longer make sense.
For CRDT there are bindings to the TipTap editor with Y.js, and it’s possible to set something up with a seperate node server running HocusPocus and Redis, and communicating with Rails - but as far as I can tell there are no stable, mature, ruby based implementations of either available open source. Anyone know of something?
that’s me. It does support realtime collaboration, I just haven’t documented it.
There’s a few ways to do it. The most “stable” way is using HocusPocus as your Y.js server. There’s a more bleeding edge approach using Yrb-ActionCable https://github.com/y-crdt/yrb-actioncable# happy to help if anyone gets stuck.
Yes. Although I don’t know the stability of the ActionCable YRB gem. It’s still largely experimental as far as I know. But in small local tests it seems to work.