Skip to content

Commit 2df2e04

Browse files
authored
fix(event-bus): respect explicit connection config (#500)
* fix(event-bus): respect explicit connection config * test(event-bus): guarantee client cleanup
1 parent 5380540 commit 2df2e04

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

.changeset/calm-buses-connect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools-event-bus': patch
3+
---
4+
5+
Honor explicit client connection options when bundlers inject event bus defaults.

packages/event-bus/src/client/client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ export class ClientEventBus {
8989
this.#eventTarget.dispatchEvent(new CustomEvent('tanstack-connect-success'))
9090
}
9191
constructor({
92-
port = 4206,
93-
host = 'localhost',
94-
protocol = 'http',
92+
port = getDefaultPort(4206),
93+
host = getDefaultHost('localhost'),
94+
protocol = getDefaultProtocol('http'),
9595
debug = false,
9696
connectToServerBus = false,
9797
}: ClientEventBusConfig = {}) {
9898
this.#debug = debug
9999
this.#broadcastChannel = new BroadcastChannel('tanstack-devtools')
100100
this.#eventSource = null
101-
this.#port = getDefaultPort(port)
102-
this.#host = getDefaultHost(host)
103-
this.#protocol = getDefaultProtocol(protocol)
101+
this.#port = port
102+
this.#host = host
103+
this.#protocol = protocol
104104
this.#socket = null
105105
this.#connectToServerBus = connectToServerBus
106106
this.#eventTarget = this.getGlobalTarget()

packages/event-bus/tests/client.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,34 @@ describe('ClientEventBus', () => {
101101
expect(mockEventSourceInstances.length).toBe(0)
102102
bus.stop()
103103
})
104+
105+
it('should prefer explicit config over bundler-injected defaults', () => {
106+
Object.assign(globalThis, {
107+
__TANSTACK_DEVTOOLS_PORT__: 4206,
108+
__TANSTACK_DEVTOOLS_HOST__: 'localhost',
109+
__TANSTACK_DEVTOOLS_PROTOCOL__: 'http',
110+
})
111+
112+
let bus: ClientEventBus | undefined
113+
try {
114+
bus = new ClientEventBus({
115+
connectToServerBus: true,
116+
port: 443,
117+
host: 'devtools.example.com',
118+
protocol: 'https',
119+
})
120+
bus.start()
121+
122+
expect(mockWebSocketInstances[0].url).toBe(
123+
'wss://devtools.example.com:443/__devtools/ws',
124+
)
125+
} finally {
126+
bus?.stop()
127+
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_PORT__')
128+
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_HOST__')
129+
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_PROTOCOL__')
130+
}
131+
})
104132
})
105133

106134
describe('connectWebSocket with protocol', () => {

0 commit comments

Comments
 (0)