Hello @dmonad –
I’ve got another curious bug that I’m trying to sort out. Same context as before, with content being modeled as a YArray where nodes contain text. I’m using y-websocket to handle communication. Mostly things work fine – if I have multiple clients, changes from one client are propagated to the other, etc.
When I create a new client and connect with the server, the initial update returned from the server always contains an ArrayEvent that represents the entire current state of the document – this gets applied to the application level representation, and things are fine.
But here’s the weird part – for any YArray elements for which one or more characters was removed from its text contents at any point during its lifetime, the initial update will also contain a TextEvent that inserts the entire text contents of that element into the same node – meaning that since I propagate the effect of all events to the application level, I end up seeing duplicated text in the application level representation corresponding to those YArray elements – i.e., the first copy coming from the content contained in the ArrayEvent, then the second coming from the TextEvent.
I only see this behavior for YArray elements where one or more characters were deleted from their text contents at some point – for elements for which no characters were ever deleted, I only see them showing up in the ArrayEvent – the update message doesn’t contain the corresponding TextEvent.
I’ve attempted to watch what’s happening on the server side through judicious use of .observeDeep() and logging of events there, but I don’t see anything untoward – just the expected TextEvents as I add and remove characters. And when I try and reproduce the problem in a unit test by replicating the sequence of manual events (and validating that I see the same sequence of TextEvents on the simulated server document), it of course Just Works – i.e., I don’t see the extra TextEvents and the resulting text duplication in the application level.
- Does this ring any bells with you?
- Can you think of any reason why the initial update contains the extra TextEvents in these conditions, even though their effect already seems to be fully represented in the ArrayEvent that is also contained in the same update?
- If this is intended/expected behavior from Yjs, is there any straightforward policy that I can employ at the application level to filter out the extra TextEvents when appropriate?