CodeArenalive editor · by Maira Younus
session · loading…
ringside
live preview
0 ops applied 1 peers in this browser Sync scope: browser tabs on this device (BroadcastChannel) · CRDT: custom RGA · state persisted to localStorage

How the collaboration works

Try it: open this page in two or more browser tabs. Each tab is a "user." Type in one tab and watch it appear live in the others, with a colored flag showing their cursor.

Conflict resolution: each character is a node in a custom RGA (Replicated Growable Array) CRDT — a linked-list sequence type. Every insert gets a globally unique id (site:clock) and points to the node it was typed after. When two people insert at the same spot at once, both edits land — ordered deterministically by comparing ids — instead of one silently overwriting the other, which is what plain last-write-wins would do.

Mid-session join: a new tab asks the others for the current document over the channel, and also restores instantly from a local snapshot, so it never starts blank.

Honest limits: BroadcastChannel only reaches other tabs of this browser on this device — it's a real, working CRDT and presence system, but wiring it to strangers on other machines would mean swapping BroadcastChannel for a WebSocket relay that forwards the same ops. Everything else here — the CRDT, cursors, and preview — works exactly the same over that transport.