Unexpected event.delta if accessed asynchronously

Hi - I could not find a discussion about this topic. Apologies if it’s touching a discussed topic.

We recently found a bug in Lexical which was caused by accessing the event.delta asynchronously in a separate event call. We managed to fix this by accessing delta in the initial event call so it’s computed sooner safely. (Thank you for the documentation in code)

I understand that computing delta on-demand avoids unnecessary computation if delta is not to be used. But at the same time I’m guessing many editors are designed to use and apply the event.delta asynchronously, and they may overlook the fact that delta should be accessed and stored in the initial event call. I was wondering if there’s a way to avoid this by redesigning the transaction model so deltas can be computed safely asynchronously.

Thank you

1 Like

If the Doc changes state before the asynchronous handler is called, then theoretically you could calculate a new delta by composing all the deltas that occurred in the interim.

State1… Delta 1
State2… Delta 2
State3… Delta 3 *async handler fires*

New delta: Delta 1 + Delta 2 + Delta 3

Just a thought. I haven’t worked with deltas personally.

1 Like