Y.Map observeDeep triggered with empty event delta

We’re using YJS+y-prosemirror+Tiptap/Hocuspocus and are trying to debug why the server side (Hocuspocus) onChange event fires seemingly erroneously on initial document load (in our app, it makes anyone who loads the document appear as though they edited it)

We’re trying to observe just the prosemirror content (the ‘default’ YMap key) using observeDeep and are surprised to see it fire with empty deltas (see code below).

Any ideas what this might mean? If the delta is empty, is it safe to assume that the content in that key hasn’t changed?

 document
  .getXmlFragment('default')
  .observeDeep((events, transaction) => {
    if (events.length == 1 && !events[0].changes.delta.length) {
      // Empty event. Safe to assume no change?
    }
  });

Hi @jamis0n,

delta only expresses changes on list structures (e.g. the children of Y.XmlFragment, or the text in a Y.Text), but not the properties of a Y.XmlElement. If observe deep was fired, then certainly something in the structure changed.

Btw, you are only checking the first event in the list of events. You get one event for each type that was changed. Probably, the first event contained a change on a property - hence the delta is empty.

Thanks @dmonad !

So we noticed that too and have updated to look at every delta as well as transaction.changed.

I guess my question now is if there is any scenario in which this condition would be true (no deltas and no transaction changes)?

document
  .getXmlFragment('default')
  .observeDeep((events, transaction) => {
    if (
      // Events.changes appears to account for added/removed types
      events.every((event) => !event.changes.delta.length) &&
      // Transaction.changed appears to cover modified types
      transaction.changed.size === 0
    ) {
      // Empty event. Safe to assume no change?
    }
  })

There is a single scenario when an event might be fired without any content. It is when formatting attributes are removed due to a conflicting remote change. If the removal of the formatting attributes doesn’t have any effect then you might receive an event without any content. This might happen when the local and the remote user both apply the same formatting attributes at the same time (e.g. ABC ⇒ ABC). The result will be ABC. We will remove the inner bold when the event is calculated.

This is the only case when this might happen.

This is the only case when this might happen.

Is it possible that this is likely to happen when a server and client initialize a doc for the first time (cold start)?

Thats the only case where were observing this behavior.

I actually don’t think so. But maybe…