Editor for two (P14)
Two people write one document at the same time and see where the other is writing. The relay between them holds only ciphertext.
The document
The document is a Yjs document bound to ProseMirror with y-prosemirror. Its schema draws the design system's own blocks: paragraphs, three levels of heading, bullet and numbered lists, checklists, quotes, code and dividers. Lists are flat blocks with an indent, as in the design system's editor. Letters typed at the same time on two devices merge in place.
The key
The key is 32 random bytes in the link, after the #. A browser never sends that part of a link to a server. The document's id on the relay is a hash of the key, so the relay can keep the log without knowing the key.
Every Yjs update is encrypted with AES-GCM before it leaves the browser. Each cursor position and each name is encrypted the same way. The relay reads none of them.
The relay
A Durable Object numbers each update, keeps it and passes it to the other people on the document over a WebSocket. When a person joins, the others send their cursor again. A socket that stops answering a ping for 9 seconds is closed. The browser's offline event closes it at once.
The relay cannot merge updates it cannot read. When the log passes 60 entries, a device sends the whole document, encrypted, and the relay replaces the entries it covers.
Offline
Every edit is kept on the device in IndexedDB until the relay confirms it. With no network, the edits wait, and they are sent when the connection is back. Yjs merges them with what the other person wrote meanwhile.
Versions
A version is a Yjs snapshot, kept inside the document, so it is encrypted too. One is made after a pause in the writing, at most every 20 seconds, and a person can save one by hand. A version is shown in the editor with its changes since the version before: added text in the writer's color, removed text struck through. A restore puts the old text in as a new edit, so every later version stays in the history.
Undo
Command Z undoes only the person's own edits, in bursts of typing. Edits by the other person stay.
What was measured
In Chromium on the development machine, a letter typed by one person reached the other person's editor in under 6 milliseconds, through the local Worker and with the encryption on both ends.
Previous: Team vault (P13). Next: Club platform (P15).