@@ -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