Map updates applied in changed order lead to inconsistent transient states

Hi,

I just ran into the phenomenon that if you create 3 updates like this

  1. Create a new Map and set two properties, say X and Y
  2. Set X to a new value
  3. Set Y to a new value

And then apply these these updates to a new document in a changed order (1,3,2), you’ll have a transient state where the Map will be missing the Y property altogether.

This may or may not be considered an Y.js bug, but it certainly causes pain for me as an application developer - I’ll have to build defensive measures against all sorts of invalid states. I’m not familiar with the implementation details but to me this behaviour doesn’t make sense - a property is removed as a result of an update that instead should be changing the value of another property.

Is there a fix or a workaround to this issue? Except of course from “always apply your updates in order” which kinda makes sense and can mostly be implemented but in multi-client scenarios this kind of situations might still occur, right?

Here’s a Sandbox for easy reproduction: https://codesandbox.io/p/sandbox/zkgcdx

Hi @raimohanska ,

This particular issue could be solved (Y is deleted, but no new content is created until you merge the second update). I agree that this shouldn’t happen.

In Yjs, updates are “dependent” on each other. The expectation is that updates from a specific user are applied in-order. Leaving out updates (and applying them later) is not something that should happen in a real-world application. But even if you do that, you will reach a consistent state after you applied all updates (in any order).

However, updates from different users can be applied in any order.

If you still want to have the issue fixed, feel free to open a ticket in the Yjs repository.

1 Like

Thanks for your swift, helpful and kind reply Kevin!

I created an issue on this matter. If there’s a way to fix this in Y.js, I’m sure that would be great!

For context, I ran into this when it turned out that Hocuspocus Server ends up applying updates out-of-order with some configurations. For that I created a Hocuspocus issue.

1 Like