Deleting non-empty Y.Map child from Y.Map triggers YMapEvent with **empty Y.Map** as `oldValue`.
Please save me some time and use the following template. In 90% of all issues I can't reproduce the problem because I don't know what exactly you are doing, in which environment, or which y-* version is responsible. Just use the following template even if you think the problem is obvious.
Checklist
- Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
- Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/
Describe the bug
The YMapEvent.oldValue is an empty YMap when deleting a non-empty YMap child from a YMap parent it is nested in.
To Reproduce Steps to reproduce the behavior:
- Install YJS version 13.6.31
- Write this file
test.mjs:
import * as Y from "yjs";
const ydoc = new Y.Doc()
const ymap = ydoc.getMap("map");
ymap.observe(ymapEvent => {
// sample code.
ymapEvent.changes.keys.forEach((change, key) => {
if (change.action === 'add') {
console.log(`ymap: Property "${key}" was added. Initial value: `, ymap.get(key).toJSON())
} else if (change.action === 'update') {
console.log(`ymap: Property "${key}" was updated. New value: "${ymap.get(key)}". Previous value: `,change.oldValue)
} else if (change.action === 'delete') {
console.log(`ymap: Property "${key}" was deleted. New value: undefined. Previous value: `,change.oldValue.toJSON())
}
})
})
const ymap2 = new Y.Map();
ymap2.observe(ymapEvent => {
// sample code.
ymapEvent.changes.keys.forEach((change, key) => {
if (change.action === 'add') {
console.log(`ymap2: Property "${key}" was added. Initial value: `, ymap.get(key).toJSON())
} else if (change.action === 'update') {
console.log(`ymap2: Property "${key}" was updated. New value: "${ymap.get(key)}". Previous value: `,change.oldValue)
} else if (change.action === 'delete') {
console.log(`ymap2: Property "${key}" was deleted. New value: undefined. Previous value: `,change.oldValue.toJSON())
}
})
})
ymap2.set('hello', 'world')
ymap.set('key', ymap2)
ymap.delete('key')- Run
node test.mjs(but this bug also occurs on the web browser, with y-websocket and y-indexeddb attached) - See this in the console:
ymap: Property "key" was added. Initial value: { hello: 'world' }
ymap: Property "key" was deleted. New value: undefined. Previous value: {}(incorrect, since if "hello" were deleted from YMap first that would have appeared as a log.)
Expected behavior
ymap: Property "key" was added. Initial value: { hello: 'world' }
ymap: Property "key" was deleted. New value: undefined. Previous value: { hello: 'world' }Screenshots Not applicable.
Environment Information
- Browser / Node.js Node.js OR Chromium OR Firefox
- Yjs version: 13.6.31
Additional context I'm away this evening, but I'd be willing to look into fixing this bug tomorrow (Friday).
- I'm a sponsor
- This issue is a blocker for my project.
Source: yjs/yjs