Skip to main content

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.
Source: packages/extension-collaboration/src/collaboration.ts:41

Collaboration Commands

The extension adds undo/redo commands that work with collaborative editing.
Source: packages/extension-collaboration/src/collaboration.ts:121

Keyboard Shortcuts

The extension provides standard keyboard shortcuts.
Source: 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.
Source: 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

Source: packages/extension-collaboration/src/collaboration.ts:73

Disabling Collaboration

Temporarily disable collaboration to prevent syncing.
Source: packages/extension-collaboration/src/collaboration.ts:12
The Collaboration extension is not compatible with the History extension. The collaboration extension provides its own undo/redo functionality.

Next Steps

TypeScript

Add type safety to your collaborative editor

Styling

Style collaboration cursors and indicators