Merging Changes In Debounce Function

Hello all, I am having some trouble optimizing my change updates.

Ideally, I would like to collect updates generated from one origin, debounce them, and then merge them to a single update I broadcast to peers.

Each change is the same as the previous, with items added to a Y.Array.

The topology is that each peer maintains a Y.Doc that is synced with other peers; There is no central source.

The problem I am facing is that the peers do not update from the merged updates, most likely because the ‘clock’ does not match.

const changes = []
const notifyPeers = debounce( ()=>{
   // Here is where I would like to combine changes and send a single update to peers.

  // I tried this:
  const merged = Y.mergeUpdates(changes)
  changes = []
  broadcast(merged)
}, 1000)

ydoc.on('update', (change, origin) => {
  if (origin === me) {
    changes.push(change)
    notifyPeers()
  }
})