Fabian Franz, Tag1 Vice President of Software Engineering, joined the Talking Drupal team of Stephen Cross, John Picozzi, and Nic Laflin to talk about Yjs in 264 - YJS | Talking Drupal. In their talk, Fabian and the Talking Drupal team discuss bringing collaborative editing to Drupal.

This is a summary. Please watch the Talking Drupal episode for the technical details.

What is Yjs?

Yjs is a conflict-free replicated data type (CRDT) implementation that exposes its internal data structure as shared types. Yjs is a JavaScript implementation of CRDTs. It allows you to merge different content changes together - multiple users, offline and online, can work on a document at the same time. When those users come together, Yjs merges the entire change history into a single document.

One of the nicest things about the use of CRDTs is that they will always resolve a data conflict. Each piece of data in a CRDT has a unique address. This address is always known, even if that data is removed; the system knows where everything is, or was. Many systems, like Git, require human intervention to resolve merge conflicts. CRDT resolves them on its own; these resolutions may not always make sense though, and should still be reviewed.

Yjs is performant - because each piece of data has a unique address that never changes, there’s one data store. WIth some other editing tools, copy & pasting large amounts of data causes a slowdown over time. Yjs does not have that restriction.

Even when there are multiple users online, editing the same document, there is rarely conflict. Users tend to be aware of each other, and will work in different sections. When a user is working offline, conflicts are more likely. When data is deleted, but another user added more information that followed the deleted data, that can lead to problems, even though the resolution is mathematically correct.

Yjs enables real time collaboration - it’s not Google Docs, but it can help you build an implementation like that, for yourself.

Where is Yjs being used today?

Tag1 Consulting created a Yjs implementation for a Top 50 client, who is using it internally for collaborative editing as part of their intranet. Tag1 is also working on an implementation for the Gutenberg Wordpress editor. Yjs also has a Drupal integration, but it is still closed-source. Tag1 hopes to change this in the future.

Other companies such as room.sh use Yjs for whiteboards and meetings. As an open source product, it’s still in the maturing phase, according to Fabian. While there’s a lot going on, there’s room for improvement as this becomes a more mainstream technology.

Several shared editors are built on Yjs, and although it is being used more as the underlying technology to build text editors, it's used to do other things as well. While it’s ready for production, production isn’t what is holding back Yjs from becoming Drupal’s editing software.

Where is this useful in Drupal?

Trends are moving more towards managing everything in your CMS. Up to now, many content creators work collaboratively in something like Google docs, and then export or convert that to HTML, and then import it into a CMS. CMS editors don’t tend to be collaborative, but they are gaining more and more features over time.

Drupal’s editors are not collaborative, and there is room for improvement in this space. When you have complex workflows and legal content where multiple functional groups are reviewing content, being able to leave notes without causing conflicts is useful. Adding this collaborative capability would be highly useful.

Drupal’s revision system can be integrated as well, ensuring accountability through the use of a Javascript state vector. Saving a revision can save the state vector, which always points at a specific version of the data - a 1:1 correlation between the Yjs state vector and the Drupal revision.

Some significant complexities remain, but there are benefits to making this change, such as: speed, ongoing storage, and making the actual changes to Drupal required to make this integration work for everyone.

Security risks

Peer to peer security is very difficult. Fabian discusses a few ways that you can secure a collaborative document by granting limited tokens to allowed users. This token can be secured by various user attributes, hashing, and expiration dates.

Server-based models may be more complex. Breaking the data into parts - the document and the comments can be separated, each secured. However, this means your data is in two documents, but it also means that you can give some users editing privileges, and limit others to commenting.

The future

As Yjs continues to grow, Fabian’s hope is to see more integration with other projects. His biggest goal would be to have Yjs integrated into CKEditor 4, either by doing the work or sponsoring it. Completing the Gutenberg integration, or componentizing Drupal’s forms are other options that could bring Yjs into the Drupal project more fully. Yjs has integrations in several other editors, so bringing into Drupal would be a great addition.

For more Yjs content, see the Tag1 Yjs index page.

Photo by Caspar Camille Rubin on Unsplash.