Hi,
I get an unexpected error when moving an YArray item, when the item is a YMap. The idea is to remove an item and then re-insert it into another position, but the problem can be re-produced with the following snippet of code:
const ydoc = new Y.Doc();
const items = ydoc.getArray("items");
items.push([new Y.Map(), new Y.Map()]);
const removedItem = items.get(0);
items.delete(0);
items.push([removedItem]);
When pushing the removed item back into the array, I get an error like
Uncaught TypeError: Cannot read properties of null (reading 'forEach')
at YMap._integrate (yjs.cjs:6005:60)
at ContentType.integrate (yjs.cjs:9387:15)
at Item.integrate (yjs.cjs:9948:20)
at eval (yjs.cjs:5394:22)
at Array.forEach (<anonymous>)
at typeListInsertGenericsAfter (yjs.cjs:5367:11)
at typeListPushGenerics (yjs.cjs:5477:10)
at eval (yjs.cjs:5828:9)
at transact (yjs.cjs:3416:14)
at YArray.push (yjs.cjs:5827:7)
You can see it in action in this CodeSandbox: https://codesandbox.io/p/sandbox/yjs-move-array-item-f7tvvj?file=%2Fsrc%2FApp.tsx%3A19%2C24
If I use strings instead of YMaps as items, there are no errors. Is there something special I should do in order to be able to re-insert a Y.Map into an array?
Thanks for Y.js btw, it’s awesome! Hoping to be able to contribute at some point, still learning the ropes.