@@ -217,14 +217,16 @@ export class WASqliteConnection
217217 // Ignore messages from the same connection
218218 return ;
219219 }
220- this . queueTableUpdate ( data . changedTables ) ;
220+
221+ // Ensuring that we don't rebroadcast the same message
222+ this . queueTableUpdate ( data . changedTables , false ) ;
221223 } ) ;
222224 }
223225
224- protected queueTableUpdate ( tableNames : Set < string > ) {
226+ protected queueTableUpdate ( tableNames : Set < string > , shouldBroadcast = true ) {
225227 tableNames . forEach ( ( tableName ) => this . updatedTables . add ( tableName ) ) ;
226228 if ( this . updateTimer == null ) {
227- this . updateTimer = setTimeout ( ( ) => this . fireUpdates ( ) , 0 ) ;
229+ this . updateTimer = setTimeout ( ( ) => this . fireUpdates ( shouldBroadcast ) , 0 ) ;
228230 }
229231 }
230232
@@ -248,14 +250,16 @@ export class WASqliteConnection
248250 return this . options ;
249251 }
250252
251- fireUpdates ( ) {
253+ fireUpdates ( shouldBroadcast = true ) {
252254 this . updateTimer = null ;
253255 const event : BatchedUpdateNotification = { tables : [ ...this . updatedTables ] , groupedUpdates : { } , rawUpdates : [ ] } ;
254256 // Share to other connections
255- this . broadcastChannel ! . postMessage ( {
256- changedTables : this . updatedTables ,
257- connectionId : this . connectionId
258- } satisfies WASQLiteBroadCastTableUpdateEvent ) ;
257+ if ( shouldBroadcast ) {
258+ this . broadcastChannel ! . postMessage ( {
259+ changedTables : this . updatedTables ,
260+ connectionId : this . connectionId
261+ } satisfies WASQLiteBroadCastTableUpdateEvent ) ;
262+ }
259263 this . updatedTables . clear ( ) ;
260264 this . iterateListeners ( ( cb ) => cb . tablesUpdated ?.( event ) ) ;
261265 }
0 commit comments