Skip to content

Commit 7e7355b

Browse files
committed
fix(event-bus): respect explicit connection config
1 parent 5380540 commit 7e7355b

3 files changed

Lines changed: 38 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,33 @@ 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+
try {
113+
const bus = new ClientEventBus({
114+
connectToServerBus: true,
115+
port: 443,
116+
host: 'devtools.example.com',
117+
protocol: 'https',
118+
})
119+
bus.start()
120+
121+
expect(mockWebSocketInstances[0].url).toBe(
122+
'wss://devtools.example.com:443/__devtools/ws',
123+
)
124+
bus.stop()
125+
} finally {
126+
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_PORT__')
127+
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_HOST__')
128+
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_PROTOCOL__')
129+
}
130+
})
104131
})
105132

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

0 commit comments

Comments
 (0)