Get started with a ProseMirror text editor using Liveblocks and Next.js
Liveblocks is a realtime collaboration infrastructure for building performant
collaborative experiences. Follow the following steps to start adding
collaboration to your Next.js application using the APIs from the
@liveblocks/prosemirror package.
Text is stored as LiveText
backed by Liveblocks Storage.
The ProseMirror LiveText integration is currently in beta, and LiveText documents are limited to 2 MB. Read the LiveText vs Yjs guide to compare both approaches.
If you are using Tiptap or BlockNote, use
@liveblocks/react-tiptap or
@liveblocks/react-blocknote
instead. They build on this package and add comments, mentions, and React
components.
Quickstart
Install Liveblocks and ProseMirror
Every Liveblocks package should use the same version.
TerminalInitialize the
liveblocks.config.tsfileWe can use this file later to define types for our application.
TerminalCreate a Liveblocks room
Liveblocks uses the concept of rooms, separate virtual spaces where people collaborate, and to create a realtime experience, multiple users must be connected to the same room. When using Next.js’
/approuter, we recommend creating your room in aRoom.tsxfile in the same directory as your current route.The collaboration plugin creates its Storage document when it first loads, so you can leave
initialStorageempty.Set up a Liveblocks client with
LiveblocksProvider, join a room withRoomProvider, and useClientSideSuspenseto add a loading spinner to your app.app/Room.tsxAdd the Liveblocks room to your page
After creating your room file, import it into your
page.tsxfile and place your editor inside it.app/page.tsxSet up the collaborative ProseMirror editor
Now that Liveblocks is set up, create a ProseMirror editor in
Editor.tsx. UsecreateLiveblocksCollaborationPluginto sync the document with Storage, andcreateLiveblocksCollaborationCaretPluginto show remote carets and selections. The collaboration plugin groups local edits into the room’s history, so connect your undo and redo shortcuts toroom.history.undo()androom.history.redo().app/Editor.tsxStyle your editor
Import the package stylesheet in your layout to display remote carets and selections, and add basic editor CSS:
app/layout.tsxapp/globals.cssNext: authenticate and add your users
Your editor is set up and working now, but each user is anonymous—the next step is to authenticate each user as they connect, and attach their name and color to remote carets.
Set up authentication and add user information
What to read next
Congratulations! You now have set up the foundation for your collaborative ProseMirror editor inside your Next.js application.
- @liveblocks/prosemirror API Reference
- @liveblocks/node-prosemirror API Reference
- Next.js and React guides
- ProseMirror website
If you are using Tiptap or BlockNote, which build on ProseMirror, see the Tiptap and BlockNote quickstarts instead.