Skip to content

Commit 5f0beaf

Browse files
Add devtools usage in NextJS (#454)
* Add devtools usage in NextJS * Apply suggestion from @oskarscholander * Fix
1 parent cf19b8a commit 5f0beaf

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

docs/getting-started/devtools.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,27 @@ const App = () => {
5353
</>
5454
)
5555
}
56-
```
56+
```
57+
58+
## Using with Next.js (or without a Vite plugin)
59+
60+
`connectToServerBus: true` relies on a WebSocket/SSE server on port 4206 that is normally started by `@tanstack/devtools-vite`. If you're using Next.js (or any non-Vite bundler), you need to start `ServerEventBus` manually at server boot.
61+
62+
In Next.js, do this in `instrumentation.ts`:
63+
64+
```ts
65+
export async function register() {
66+
if (
67+
process.env["NEXT_RUNTIME"] === "nodejs" &&
68+
process.env.NODE_ENV === "development"
69+
) {
70+
const { ServerEventBus } = await import(
71+
"@tanstack/devtools-event-bus/server"
72+
);
73+
const bus = new ServerEventBus();
74+
await bus.start();
75+
}
76+
}
77+
```
78+
79+
This sets globalThis.__TANSTACK_EVENT_TARGET__ so the server-side devtoolsMiddleware (which runs automatically inside every chat() call) can emit tool call events to the bus, which then forwards them to the devtools panel.

0 commit comments

Comments
 (0)