Bring Real Time Collaboration to ActionText

Hi,

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.

Regards

Useful links:

GitHub - ball-hayden/ot.rb: A Ruby port of the Operational Transformation library ot.js

GitHub - Operational-Transformation/ot.js

GitHub - automerge/automerge: A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.

GitHub - benaubin/rails-collab: Collaborative Editing on Rails (using ProseMirror)

8 Likes

I’ve been following this space pretty closely for the last few years, and I have a few suggestions for anybody else that is interested:

Some general resources on realtime collaboration:

1 Like

I think you’ll find this thread interesting

It doesn’t have anything specific about real time collaboration but it does touch on the subject of actiontext in the long run

This would be an absolutely amazing addition to Rails, making building 2020+ era collaborative apps in rails a no-brainer.

I think the things needed for a true real time app are almost all there now, with the only missing pieces being CRDT/OT for text:

  • Presence (already handled, with additional PR available here that will make it more robust: https://github.com/rails/rails/pull/50039 )
  • 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?

Just found this ActionText integration for Tiptap in another thread here: Configurable ActionText - #12 by ParamagicDev

:wave: 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.

So, with yrb-actioncable we don’t need hocuspocus at all, and ActionCable can be the backend?

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.

What happens if it fails? Will anyone get data loss, or will it just revert to a non collaborative editor?