Installation
Install Yjs peer dependencies:prosekit package:
Styling
Import Yjs styles to show user selections:Usage
API reference
defineYjs(options)
Creates a Yjs extension for collaborative editing.
The Yjs document to sync with.
The Yjs XML fragment to use for the document. Typically obtained with
doc.getXmlFragment('prosemirror').Origin identifier for ProseMirror transactions. Used to distinguish local vs remote changes.
Color palette for user selections. Defaults to a preset palette.
Complete example
See the Collaboration guide for a complete working example with WebSocket synchronization.Key concepts
Y.Doc
A Yjs document contains shared data structures. Each client has its own instance that syncs with others.Y.XmlFragment
The ProseMirror document is stored as an XML fragment in the Yjs document:Network providers
Yjs supports various network providers:- y-websocket - WebSocket server synchronization
- y-webrtc - Peer-to-peer WebRTC
- y-indexeddb - Local persistence
User awareness
Yjs includes awareness for showing user cursors and selections:Persistence
Save document state to IndexedDB:Offline support
Yjs automatically handles offline editing:- Users can edit while offline
- Changes are queued locally
- When connection resumes, changes sync automatically
- Conflicts are resolved automatically
Custom colors
Use cases
Collaborative documents
Multiple users editing the same document
Real-time notes
Shared note-taking and brainstorming
Team wikis
Collaborative knowledge bases
Offline-first apps
Apps that work without internet connection
Related
- Collaboration guide - Complete setup guide
- Loro - Alternative CRDT implementation
- Commit - Track document changes