v13.6.29 causes incorrect event paths with multiple deep observers
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
YJS v13.6.29 introduces a slight change to the order of operations of deep event handlers. When attaching multiple deep event observers, this new order of operations can cause event.currentTarget to be set incorrectly and as a result causes event.path to return inconsistent results.
To Reproduce
import * as Y from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
const ydoc = new Y.Doc();
// initiate a nested map structure { a: { b: {}, c: {} } }
ydoc.getMap('a');
ydoc.get('a').set('b', new Y.Map());
ydoc.get('a').set('c', new Y.Map());
// deep observe 'a'
ydoc.getMap('a').observeDeep(events => {
events.forEach(event => {
console.log('event path:', event.path);
console.log('event target', event.currentTarget);
})
});
// write something to a.b and a.c
ydoc.transact(() => {
ydoc.get('a').get('b').set('foo', 'bar'); // this will result in an event path of ['b'], event.currentTarget is 'a'
ydoc.get('a').get('c').set('foo', 'bar'); // this will result in an event path of ['c'], event.currentTarget is 'a'
});
// now deep observe 'a.c'
ydoc.getMap('a').get('c').observeDeep(() => {});
// write something to a.b and a.c
ydoc.transact(() => {
ydoc.get('a').get('b').set('foo', 'bar'); // this will result in an event path of ['b'], event.currentTarget is 'a'
ydoc.get('a').get('c').set('foo', 'bar'); // this will result in an event path of [], event.currentTarget changed to 'a.c'
});
Expected behavior
event.currentTarget should always be the type originally observed so that event.path also remains relative to the type originally observed.
Environment Information
- Browser
- YJS
13.6.29
Additional context Add any other context about the problem here.
- I'm a sponsor
- This issue is a blocker for my project.
Source: yjs/yjs