How to use Liveblocks with Next.js /app directory

A pattern we’d recommend when using Next.js /app directory is creating a providers client component for LiveblocksProvider and importing it into layout.tsx.

app/Providers.tsx
app/layout.tsx

To join rooms, create a Room.tsx client component in the current route, using RoomProvider within here.

app/Room.tsx

Doing this avoids an issue when importing LiveObject/LiveMap/ListList into server components. You can then use Room.tsx in your page component, and everything will work as expected.

app/page.tsx

Structuring your app

To take this one step further, you can then server-render your layout within Room’s children, whilst using other client components for realtime parts of your app:

room.tsx