Collaborative Editing
Tiptap provides first-class support for real-time collaborative editing through the Collaboration extension, which is powered by Yjs, a battle-tested CRDT (Conflict-free Replicated Data Type) framework.Installation
First, install the required packages:Basic Setup
The Collaboration extension requires a Yjs document to synchronize content between users.Understanding the Collaboration Extension
The Collaboration extension provides undo/redo functionality and real-time synchronization.packages/extension-collaboration/src/collaboration.ts:41
Collaboration Commands
The extension adds undo/redo commands that work with collaborative editing.packages/extension-collaboration/src/collaboration.ts:121
Keyboard Shortcuts
The extension provides standard keyboard shortcuts.packages/extension-collaboration/src/collaboration.ts:160
WebSocket Providers
To sync between multiple clients, you need a provider. Here are popular options:y-websocket
y-webrtc
For peer-to-peer connections without a server.Collaboration Cursor
Show where other users are editing with the CollaborationCursor extension.Styling Collaboration Cursors
Multiple Fields
You can use multiple editor instances with the same Yjs document.packages/extension-collaboration/src/collaboration.ts:49
Offline Support
Yjs can work offline and sync when reconnected.Persistence
Persist collaborative documents to a database.React Example
Complete React example with collaboration.Conflict Resolution
Yjs automatically handles conflicts using CRDTs.Performance Optimization
packages/extension-collaboration/src/collaboration.ts:73
Disabling Collaboration
Temporarily disable collaboration to prevent syncing.packages/extension-collaboration/src/collaboration.ts:12
Next Steps
TypeScript
Add type safety to your collaborative editor
Styling
Style collaboration cursors and indicators