@codemirror/collab: Check if two ChangeSets are identical

Hi, I noticed that the receiveUpdates function from @codemirror/collab takes an array of Updates and checks how many of the updates received are the client’s own by comparing the client id. I am curious how it ensures a remote update is correctly mapped to the corresponding local unconfirmed update? What if a client has 4 unconfirmed updates but receives 1 remote update from the server and this remote update relates to the latest unconfirmed update for the client. Doesn’t the code incorrectly remove the first unconfirmed update, i.e. the oldest unconfirmed update? Or, is it expected that the server sends remote updates also in a certain order?

Would it make instead sense to check if a remote update is identical to a local unconfirmed update by comparing the client id and ChangeSet included? Also curious if there is a way to check if two ChangeSets are identical - my immediate thought was applying both ChangeSets on the document and checking if both produces the same final document but not sure about how expensive that could become for large number of unconfirmed updates. Would love to hear your insights or any corrections to my understanding.

That would violate the protocol—local changes need to be sent to the server in order (or, generally, as a chunk including all pending local changes). I don’t see any situation in which there’s any reason for a client to skip some of its changes when sending them to the server, or for a server to provide the changes it received out of order to clients.

That would violate the protocol—local changes need to be sent to the server in order (or, generally, as a chunk including all pending local changes).

Isn’t this possible to happen though? Message could be lost due to disconnection or some server issues. Wouldn’t the client incorrectly remove the first local unconfirmed update in that case?

Anyways, I am still curious what the best way to check if two ChangeSets are identical if you have any insights. Thank you!

No, it’s not. That’s why clients only confirm their local changes when they receive them back from the server. So that even if requests get cut off at odd points, the state remains consistent.

It doesn’t look like ChangeSet has a comparison method. I guess nothing in the system required it. You could compare their JSON representation or, if you are sure you really need this, try to convince me to add such a method.