Collaboration
Real-time collaborative editing over the sync server
Collaboration runs on the same sync server and the same websocket.
Set collab on the sync prop:
import { MdxEditor } from "@fumadocs-editor/ui";
export function CollabEditor({ path, name }: { path: string; name: string }) {
return <MdxEditor sync={{ path, collab: { user: { name, color: "#7c3aed" } } }} />;
}
user is the presence identity shown at your caret on other screens.
collab: true joins as a guest. Yjs is loaded lazily, so editors that
never enable collab never download it.
How it works
With collab on, the server owns the file:
- Every open file has one shared document on the server, and the server is the only writer to disk. Blocks nobody touched still serialize byte-for-byte.
- Changes on disk (a
git pullmid-session) merge into the shared document. When the same block changed on both sides, the editor wins and the disk is rewritten. There is no conflict chip: the document is shared, so there is no local side to keep. - When the last client leaves, the server flushes and drops the document
after
evictAfterMs(60 s by default).
What changes
| Sync | Collab | |
|---|---|---|
| Document lives in | your editor | a shared document on the server |
| Writes to disk | each client (compare-and-swap) | the server only |
| External edits | merged client-side, conflict chip | merged server-side, editor wins |
| Undo | full local history | your own edits only |
| Raw MDX tab | available | disabled (no merge with a live shared doc) |
| Status dot | session status | connectivity only |
Presence carets show each peer's name. A server auth scope with a
user overrides whatever name a client claims. Plain sync tabs and collab
tabs can edit the same file: a sync write reaches the server's document like
any other disk change.
Restarts
There is no persistence beyond the file. A server restart, or eviction followed by a reopen, re-seeds the document from disk, and clients holding older state rebuild from the server. Two windows where edits can be lost:
- A hard kill can lose edits still inside the save debounce (under a second). An orderly shutdown flushes.
- Edits typed while the server was down are discarded by the reset. Edits made while merely disconnected (server up, network down) are buffered and converge on reconnect.
Your own session
createCollabSession from @fumadocs-editor/core/collab is the collab
counterpart of createFileSession: it returns the
shared document and awareness for a shell that is not React.
Last updated on