Skip to content

Commit 190cac8

Browse files
authored
Merge pull request #11 from TanStack/feat/bus-connection
feat: create event bus server + client communication for devtools
2 parents f61c97e + 9500cc6 commit 190cac8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1609
-125
lines changed

.changeset/metal-aliens-juggle.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@tanstack/devtools-event-client': minor
3+
'@tanstack/react-devtools': minor
4+
'@tanstack/solid-devtools': minor
5+
'@tanstack/devtools-event-bus': minor
6+
'@tanstack/devtools': minor
7+
---
8+
9+
Added event bus functionality into @tanstack/devtools
10+
11+
- @tanstack/devtools now comes with an integrated Event Bus on the Client.
12+
- The Event Bus allows for seamless communication between different parts of your running application
13+
without tight coupling.
14+
- Exposed APIs for publishing and subscribing to events.
15+
- Added config for the client event bus

examples/react/basic/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
"test:types": "tsc"
1010
},
1111
"dependencies": {
12+
"@tanstack/devtools-event-client": "workspace:^",
1213
"@tanstack/react-devtools": "^0.1.1",
1314
"@tanstack/react-query": "^5.83.0",
1415
"@tanstack/react-query-devtools": "^5.83.0",
1516
"@tanstack/react-router": "^1.130.2",
1617
"@tanstack/react-router-devtools": "^1.130.2",
1718
"react": "^19.1.0",
18-
"react-dom": "^19.1.0"
19+
"react-dom": "^19.1.0",
20+
"zod": "^4.0.14"
1921
},
2022
"devDependencies": {
2123
"@types/react": "^19.1.2",

examples/react/basic/src/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import ReactDOM from 'react-dom/client'
22
import Devtools from './setup'
3+
import { queryPlugin } from './plugin'
4+
setTimeout(() => {
5+
queryPlugin.emit('test', {
6+
title: 'Test Event',
7+
description:
8+
'This is a test event from the TanStack Query Devtools plugin.',
9+
})
10+
}, 1000)
311

12+
queryPlugin.on('test', (event) => {
13+
console.log('Received test event:', event)
14+
})
415
function App() {
516
return (
617
<div>

examples/react/basic/src/plugin.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { EventClient } from '@tanstack/devtools-event-client'
2+
3+
interface EventMap {
4+
'query-devtools:test': {
5+
title: string
6+
description: string
7+
}
8+
'query-devtools:init': {
9+
title: string
10+
description: string
11+
}
12+
'query-devtools:query': {
13+
title: string
14+
description: string
15+
}
16+
}
17+
class QueryDevtoolsPlugin extends EventClient<EventMap> {
18+
constructor() {
19+
super({
20+
pluginId: 'query-devtools',
21+
})
22+
}
23+
}
24+
25+
export const queryPlugin = new QueryDevtoolsPlugin()

examples/react/start/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@
1717
"@prisma/extension-accelerate": "^2.0.2",
1818
"@prisma/studio-core": "^0.5.1",
1919
"@tailwindcss/vite": "^4.0.6",
20+
"@tanstack/devtools-event-bus": "workspace:^",
21+
"@tanstack/devtools-event-client": "workspace:^",
2022
"@tanstack/react-devtools": "^0.1.1",
2123
"@tanstack/react-query": "^5.83.0",
2224
"@tanstack/react-query-devtools": "^5.83.0",
2325
"@tanstack/react-router": "^1.130.2",
2426
"@tanstack/react-router-devtools": "^1.130.2",
2527
"@tanstack/react-router-with-query": "^1.130.2",
26-
"@tanstack/react-start": "^1.130.2",
28+
"@tanstack/react-start": "^1.130.15",
2729
"@tanstack/router-plugin": "^1.121.2",
2830
"prisma": "^6.13.0",
2931
"react": "^19.1.0",
3032
"react-dom": "^19.1.0",
3133
"tailwindcss": "^4.0.6",
32-
"vite-tsconfig-paths": "^5.1.4"
34+
"vite-tsconfig-paths": "^5.1.4",
35+
"zod": "^4.0.14"
3336
},
3437
"devDependencies": {
38+
"@tanstack/devtools": "workspace:^",
3539
"@testing-library/dom": "^10.4.0",
3640
"@testing-library/react": "^16.2.0",
3741
"@types/react": "^19.1.2",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { queryPlugin } from '@/plugin'
2+
import { useEffect, useState } from 'react'
3+
4+
export default function ClientPlugin() {
5+
const [events, setEvents] = useState<
6+
Array<{ type: string; payload: { title: string; description: string } }>
7+
>([])
8+
useEffect(() => {
9+
const cleanup = queryPlugin.on('test', (event) => {
10+
console.log('Received message in here:', event)
11+
setEvents((prev) => [...prev, event as any])
12+
})
13+
14+
return cleanup
15+
}, [])
16+
return (
17+
<div>
18+
<h1>Client Plugin Initialized</h1>
19+
<p>Devtools Client is connected.</p>
20+
<button
21+
className="bg-blue-500 text-white px-4 py-2 rounded"
22+
onClick={() => {
23+
console.log('Button clicked, emitting event')
24+
queryPlugin.emit('test', {
25+
title: 'Button Clicked',
26+
description:
27+
'This is a custom event triggered by the client plugin.',
28+
})
29+
}}
30+
>
31+
Click me
32+
</button>
33+
{events.map((event, i) => (
34+
<div key={i}>
35+
<h2>{event.payload.title}</h2>
36+
<p style={{ color: 'gray' }}>{event.payload.description}</p>
37+
</div>
38+
))}
39+
</div>
40+
)
41+
}

examples/react/start/src/components/devtools.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
33
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
44
import { TanstackDevtools } from '@tanstack/react-devtools'
55
import { StudioPlugin } from './prisma-plugin'
6+
import ClientPlugin from './client-plugin'
67

78
const queryClient = new QueryClient()
89

@@ -11,6 +12,9 @@ export default function DevtoolsExample() {
1112
<>
1213
<QueryClientProvider client={queryClient}>
1314
<TanstackDevtools
15+
eventBusConfig={{
16+
debug: true,
17+
}}
1418
plugins={[
1519
{
1620
name: 'Tanstack Query',
@@ -24,6 +28,10 @@ export default function DevtoolsExample() {
2428
name: 'Prisma Studio',
2529
render: <StudioPlugin />,
2630
},
31+
{
32+
name: 'Client Plugin',
33+
render: <ClientPlugin />,
34+
},
2735
]}
2836
/>
2937
</QueryClientProvider>

examples/react/start/src/plugin.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { EventClient } from '@tanstack/devtools-event-client'
2+
3+
interface EventMap {
4+
'query-devtools:test': {
5+
title: string
6+
description: string
7+
}
8+
'query-devtools:init': {
9+
title: string
10+
description: string
11+
}
12+
'query-devtools:query': {
13+
title: string
14+
description: string
15+
}
16+
}
17+
18+
class QueryDevtoolsClient extends EventClient<EventMap> {
19+
constructor() {
20+
super({
21+
pluginId: 'query-devtools',
22+
})
23+
}
24+
}
25+
26+
export const queryPlugin = new QueryDevtoolsClient()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ServerEventBus } from '@tanstack/devtools-event-bus/server'
2+
3+
const devtoolsServer = new ServerEventBus()
4+
5+
devtoolsServer.start()
6+
7+
export { devtoolsServer }

examples/react/start/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { tanstackStart } from '@tanstack/react-start/plugin/vite'
33
import viteReact from '@vitejs/plugin-react'
44
import viteTsConfigPaths from 'vite-tsconfig-paths'
55
import tailwindcss from '@tailwindcss/vite'
6+
//import { devtoolsServer } from './src/server-setup'
67

78
const config = defineConfig({
89
plugins: [
910
// this is the plugin that enables path aliases
1011
viteTsConfigPaths({
1112
projects: ['./tsconfig.json'],
1213
}),
14+
1315
tailwindcss(),
1416
tanstackStart({
1517
customViteReactPlugin: true,

0 commit comments

Comments
 (0)