Repository navigation
Fix issue with syncing yjs changes to Lexical - #4621
Conversation
…mpute the delta syncronously to avoid unexpected behavior
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
That makes sense, curious how did you catch it? |
This sometimes affects the changes coming from the yjs undo manager for some reason. I synced two clients on a yjs document. Then I started making some changes from client 1. And then did some undo/redo operations. At some point client 1's editor state goes out of sync. I noted that the yjs documents in both clients are synced, and only the editor's state does not show the correct state. Then I examined the delta coming from ydoc on undo/redo events and it was empty for some events. |
That would be useful! |

Issue explanation:
Lexical uses the delta in the events coming from yjs document to sync the state of the editor with the latest changes. According to yjs delta is a computed property, meaning that it is computed when it is accessed for the first time. yjs also says :
Link to yjs repo where it's explained.
Lexical accesses delta in a callback function passed to
editor.updateand this function can be scheduled to run in a separate event call. That means delta can be computed unsafely in a different event call. This affects the changes coming from undo manager particularly.