It seems that computing and comparing state vectors is not enough, since they don’t contain the delete set.
I see that a function called snapshotContainsUpdate exists, but it’s behavior is not documented. Should I compute updates from each documents (e.g. with encodeStateAsUpdate and use that function to check them against the other document’s snapshot?
I’m trying to implement this in the context of a remote provider, in which case the remote would send an ack to the client after the data has been persisted on the server side to let the client know. I’m trying to understand what data the remote would have to send back to the client so that it could perform the comparison.
Two documents are in-sync if their snapshots are identical.
You could request a snapshot from the backend (a snapshot contains the state vector AND the delete set). Then, check for equality of the bytearray. If you apply the check synchronously, then you should get a positive result even if other users are currently typing (sorry, I think in our meeting I said something different).
However, this still doesn’t give you a method to recover. If the snapshots don’t match, then you are in serious trouble (unless local updates are currently en route). It would mean that you missed some updates from other users. This really shouldn’t happen. In this case, I suggest that you close the connection and force the provider to perform a full sync again.
Yes, because the peer will always reply with the full delete set, which is quite small.
Never skip a sync. The recommended approach to sync is using state vectors, as the documentation describes. The reply (Y.encodeStateAsUpdate(ydoc, statevector)) should always be sent.