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?
}
});
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.
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.