Skip to content

Commit b3f3b9b

Browse files
committed
chore: fix up potential evvent buildup on failed connections
1 parent 573cb57 commit b3f3b9b

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
},
5555
{
5656
"path": "packages/event-bus-client/dist/esm/plugin.js",
57-
"limit": "1.1 KB"
57+
"limit": "1.2 KB"
5858
}
5959
],
6060
"devDependencies": {
@@ -91,4 +91,4 @@
9191
"@tanstack/solid-devtools": "workspace:*",
9292
"@tanstack/devtools-vite": "workspace:*"
9393
}
94-
}
94+
}

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class EventClient<
3030
#retryCount = 0
3131
#maxRetries = 5
3232
#connecting = false
33+
#failedToConnect = false
3334
#internalEventTarget: EventTarget | null = null
3435

3536
#onConnected = () => {
@@ -57,7 +58,7 @@ export class EventClient<
5758
'tanstack-connect',
5859
this.#retryConnection,
5960
)
60-
61+
this.#failedToConnect = true
6162
this.debugLog('Max retries reached, giving up on connection')
6263
this.stopConnectLoop()
6364
}
@@ -91,6 +92,7 @@ export class EventClient<
9192
this.debugLog(' Initializing event subscription for plugin', this.#pluginId)
9293
this.#queuedEvents = []
9394
this.#connected = false
95+
this.#failedToConnect = false
9496
this.#connectIntervalId = null
9597
this.#connectEveryMs = reconnectEveryMs
9698
}
@@ -108,6 +110,7 @@ export class EventClient<
108110

109111
private stopConnectLoop() {
110112
this.#connecting = false
113+
111114
if (this.#connectIntervalId === null) {
112115
return
113116
}
@@ -219,6 +222,14 @@ export class EventClient<
219222
eventSuffix: TSuffix,
220223
payload: TEventMap[`${TPluginId & string}:${TSuffix}`],
221224
) {
225+
if (!this.#enabled) {
226+
this.debugLog(
227+
'Event bus client is disabled, not emitting event',
228+
eventSuffix,
229+
payload,
230+
)
231+
return
232+
}
222233
if (this.#internalEventTarget) {
223234
this.debugLog(
224235
'Emitting event to internal event target',
@@ -231,12 +242,9 @@ export class EventClient<
231242
}),
232243
)
233244
}
234-
if (!this.#enabled) {
235-
this.debugLog(
236-
'Event bus client is disabled, not emitting event',
237-
eventSuffix,
238-
payload,
239-
)
245+
246+
if (this.#failedToConnect) {
247+
this.debugLog('Previously failed to connect, not emitting to bus')
240248
return
241249
}
242250
// wait to connect to the bus

0 commit comments

Comments
 (0)