Bug: triggering an update from an mutation/update listener can lead to Yjs document corruption
- Dominant language
- TypeScript
- Stars
- 23.9k
- Forks
- 2.2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 55
Description
Lexical version: 0.33.1
## Steps To Reproduce
1. Register a mutation/update listener which triggers another editor update.
2. Register a mutation listener which calls `editor.read()`
3. Do an action which triggers the first mutation/update listener.
Example failing test: https://github.com/facebook/lexical/commit/635cb9665
## The current behavior
The `read()` from the second mutation listener calls `$commitPendingUpdates` which triggers update listeners. However, update listeners from the first update may not have not yet been called. This can lead to corruption of the Yjs document.
## The expected behavior
Update listeners are called in-order and Yjs is not corrupted.
## Impact of fix
For Yjs specifically, these updates being called out of order can lead to data loss or complete failure to load the document (`Expected shared type to include type attribute`).
Acknowledge that triggering an update from an update listener is an anti-pattern, but reporting this anyway given the impact.
Contributor guide
Assessment
This issue has not been assessed yet.