Skip to content

Commit 1f6d663

Browse files
YousefEDclaude
andcommitted
docs: document serverExternalPackages config for Next.js + server-util
Adds documentation for using @blocknote/server-util in Next.js App Router API routes, including the required serverExternalPackages configuration and shared schema pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7e4d771 commit 1f6d663

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

docs/content/docs/features/server-processing.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ Additionally, `ServerBlockNoteEditor` provides functions for processing Yjs docu
3535
- `yDocToBlocks` or `yXmlFragmentToBlocks`: use this to convert a Yjs document or XML Fragment to BlockNote blocks
3636
- `blocksToYDoc` or `blocksToYXmlFragment`: use this to convert a BlockNote document (blocks) to a Yjs document or XML Fragment
3737

38+
## Next.js App Router
39+
40+
If you're using `@blocknote/server-util` in a Next.js App Router API route (Route Handler), you need to add the BlockNote packages to `serverExternalPackages` in your `next.config.ts`:
41+
42+
```typescript
43+
import type { NextConfig } from "next";
44+
45+
const nextConfig: NextConfig = {
46+
serverExternalPackages: [
47+
"@blocknote/core",
48+
"@blocknote/react",
49+
"@blocknote/server-util",
50+
],
51+
};
52+
53+
export default nextConfig;
54+
```
55+
56+
This tells Next.js to load these packages using Node.js `require()` instead of bundling them with Turbopack, which is necessary because BlockNote's dependencies use APIs that aren't available in React Server Components.
57+
58+
You can share the same custom schema (using `createReactBlockSpec`) between your API routes and client-side editor — see the [Next.js setup guide](/docs/getting-started/nextjs) for the full pattern.
59+
3860
## React compatibility
3961

4062
If you use [custom schemas in React](/docs/features/custom-schemas), you can use the same schema on the server side.

docs/content/docs/getting-started/nextjs.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,42 @@ function App() {
5858
}
5959
```
6060

61+
## Server-side processing (API Routes)
62+
63+
If you want to use `@blocknote/server-util` in a Next.js API route (Route Handler) — for example, to convert blocks to HTML on the server — you need to add BlockNote packages to `serverExternalPackages` in your `next.config.ts`:
64+
65+
```typescript
66+
import type { NextConfig } from "next";
67+
68+
const nextConfig: NextConfig = {
69+
serverExternalPackages: [
70+
"@blocknote/core",
71+
"@blocknote/react",
72+
"@blocknote/server-util",
73+
],
74+
};
75+
76+
export default nextConfig;
77+
```
78+
79+
Then you can use `ServerBlockNoteEditor` in your API route as usual:
80+
81+
```typescript
82+
// app/api/convert/route.ts
83+
import { ServerBlockNoteEditor } from "@blocknote/server-util";
84+
85+
export async function POST(req: Request) {
86+
const { blocks } = await req.json();
87+
const editor = ServerBlockNoteEditor.create();
88+
const html = await editor.blocksToFullHTML(blocks);
89+
return Response.json({ html });
90+
}
91+
```
92+
93+
If you use a [custom schema](/docs/features/custom-schemas) with `createReactBlockSpec`, you can share it between your API routes and your client-side editor. Just define the schema in a separate file and import it in both places — the `serverExternalPackages` config ensures it works in both contexts.
94+
95+
See the [server-side processing docs](/docs/server-side-processing) for more details on `ServerBlockNoteEditor`.
96+
6197
## React 19 / Next 15 StrictMode
6298

6399
BlockNote is not yet compatible with React 19 / Next 15 StrictMode. For now, disable StrictMode in your `next.config.ts`:

0 commit comments

Comments
 (0)