Skip to content
Source
Sign inSign up
TanStack/devtools

feat: deliver devtools events from isolated server runtimes via Vite HotChannel #384

MergedAlemTuzlakmerged 30 commits intomain fromrefs/pull/384/headmerged by AlemTuzlak View on GitHub

Showing 28 changed files with 173 additions and 0 deletions (loading 24).

x
0 of 28 viewed, 28 left
9 additions and 0 deletions.changeset/devtools-vite-runtime-bridge.mdAdded
View file
@@ -0,0 +1,9 @@
+---
+'@tanstack/devtools-vite': minor
+---
+​
+feat: deliver devtools events from isolated server runtimes over Vite's native HotChannel
+​
+Server code running in an isolated runtime (Nitro v3 worker thread, Cloudflare `workerd`, or any separate thread/process) does not share `globalThis.__TANSTACK_EVENT_TARGET__` with the Vite dev process, so devtools events emitted on the server never reached the panel.
+​
+The Vite plugin now bridges those events over the framework's existing `import.meta.hot` HotChannel — the same connection the runtime already uses for HMR. It injects a tiny, dev-only bridge into the event client when it runs in a non-client environment and wires each server environment's hot channel to the in-process `ServerEventBus`. No new WebSocket, no fetch, no reconnect logic, and no new runtime dependencies; the bridge is fully tree-shaken in production.
162 additions and 0 deletionsexamples/react/start-cloudflare/src/devtools/ServerEventsPanel.tsxAdded
View file
@@ -0,0 +1,162 @@
+import { useEffect, useState } from 'react'
+import { serverEventClient } from './server-event-client'
+import type { ServerEvent } from './server-event-client'
+​
+export function ServerEventsPanel() {
+ const [events, setEvents] = useState<Array<ServerEvent>>([])
+​
+ useEffect(() => {
+ const cleanup = serverEventClient.on(
+ 'server-fn-called',
+ (event) => {
+ setEvents((prev) => [event.payload, ...prev].slice(0, 100))
+ },
+ { withEventTarget: true },
+ )
+​
+ return cleanup
+ }, [])