Get started with a SuperDoc DOCX 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/yjs package, and
SuperDoc, a collaborative DOCX editor for the web.
Quickstart
Install Liveblocks, Yjs, and SuperDoc
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.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, it’s time to join it. Import your room into your
page.tsxfile, and place your collaborative app components inside it.app/page.tsxSet up the collaborative SuperDoc editor
Now that we set up Liveblocks, we can start integrating SuperDoc and Yjs in the
Editor.tsxfile. We usegetYjsProviderForRoomto get a Yjs document and provider, then pass them to the<SuperDocEditor />component throughmodules.collaboration. The component is SSR-safe and handles mounting and cleanup for you. It rebuilds whenmoduleschanges, so we memoize it.app/Editor.tsxImport the SuperDoc styles
Import the SuperDoc styles into the root layout of your app, so the editor and toolbar are styled correctly.
app/layout.tsxNext: authenticate and add your users
Text 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, color, and avatar, to their cursors and mentions.
Add your users to Text Editor
What to read next
Congratulations! You now have set up the foundation for your collaborative SuperDoc DOCX editor inside your Next.js application.
- @liveblocks/yjs API Reference
- @liveblocks/react API Reference
- SuperDoc website
- SuperDoc collaboration docs