Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-buses-connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/devtools-event-bus': patch
---

Honor explicit client connection options when bundlers inject event bus defaults.
12 changes: 6 additions & 6 deletions packages/event-bus/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ export class ClientEventBus {
this.#eventTarget.dispatchEvent(new CustomEvent('tanstack-connect-success'))
}
constructor({
port = 4206,
host = 'localhost',
protocol = 'http',
port = getDefaultPort(4206),
host = getDefaultHost('localhost'),
protocol = getDefaultProtocol('http'),
debug = false,
connectToServerBus = false,
}: ClientEventBusConfig = {}) {
this.#debug = debug
this.#broadcastChannel = new BroadcastChannel('tanstack-devtools')
this.#eventSource = null
this.#port = getDefaultPort(port)
this.#host = getDefaultHost(host)
this.#protocol = getDefaultProtocol(protocol)
this.#port = port
this.#host = host
this.#protocol = protocol
this.#socket = null
this.#connectToServerBus = connectToServerBus
this.#eventTarget = this.getGlobalTarget()
Expand Down
28 changes: 28 additions & 0 deletions packages/event-bus/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ describe('ClientEventBus', () => {
expect(mockEventSourceInstances.length).toBe(0)
bus.stop()
})

it('should prefer explicit config over bundler-injected defaults', () => {
Object.assign(globalThis, {
__TANSTACK_DEVTOOLS_PORT__: 4206,
__TANSTACK_DEVTOOLS_HOST__: 'localhost',
__TANSTACK_DEVTOOLS_PROTOCOL__: 'http',
})

let bus: ClientEventBus | undefined
try {
bus = new ClientEventBus({
connectToServerBus: true,
port: 443,
host: 'devtools.example.com',
protocol: 'https',
})
bus.start()

expect(mockWebSocketInstances[0].url).toBe(
'wss://devtools.example.com:443/__devtools/ws',
)
} finally {
bus?.stop()
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_PORT__')
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_HOST__')
Reflect.deleteProperty(globalThis, '__TANSTACK_DEVTOOLS_PROTOCOL__')
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})
})

describe('connectWebSocket with protocol', () => {
Expand Down