Bug: The result gets empty when rewriting larger selection with composition (IME)
Hi, I came across this while debugging a similar issue in DraftJS and wanted to know if Lexical has this solved. It solves it in a more consistent way than DraftJS, but still incorrectly
When you select some more complex content (I wasn't able to reproduce the same with two simple blocks of text), and insert some more complex composition (tried with Arabic via Google Input Tools)

The result of the replacement is an empty block instead of the expected char(s). When you do Undo (CTRL+Z), it reverts to the expected state.

I am not typically using IME, so cannot tell how much the issue affects scenarios in other languages or ways of input, but I can imagine it might...
Note:
I debugged a similar case in DraftJS (which we use) I found out that it gets way too many unrelated mutations (e.g. also a mutation of the whole editor content) via its mutation observer through re-rendering in the meantime via the first composition update and through them makes an additional update to the editor in an incorrect place(s).
Unfortunately, I am not knowledgeable enough in Lexical to be able to give more technical insights into it. Not even sure if Lexical uses similar concepts.
I noticed you use some compositionKey so you may want to revise those against the real mutations that happen and perhaps restrict them only to ones that are nearby the selection (which is something I plan to try for DraftJS)
Lexical version: Latest on https://playground.lexical.dev/
Steps To Reproduce
- Use Google Input Tools https://www.google.com/inputtools/ with Arabic language - There may be easier ways, I am just not that knowledgeable about composition (IME)
- Open Lexical playground https://playground.lexical.dev/
- Select two blocks with content in the playground example
- Input some Arabic char(s) to replace those blocks
- Result is an empty block ❌ instead of inserted Arabic char(s)
- When you perform Undo (CTRL+Z), it brings back the Arabic char(s) ✔ with RTL direction ✔
It seems that the composition got processed OK, but then it did something more that should be ignored.
Link to code example: https://playground.lexical.dev/
The current behavior
The resulting block is empty. After Undo (CTRL+Z) the input is the one that I would expect.
The expected behavior
The result should be the newly inserted char(s) without the need to do Undo
If it helps, I got to debug it to learn more about how Lexical deals with it compared to DraftJS, and it seems that Google Input Tools emit an extra input event deleteContentBackward (assuming to delete the previous selection), but Lexical seems to first do the replacement with the composition (including the delete) and then the delete again on the replaced content ...

Tested with Google Input Tools (Arabic) on the latest Chrome — selecting multiple blocks and replacing via composition works correctly without double deletion.
Compared the deleteContentBackward code path in $handleBeforeInput between v0.10.0 and current main: on Chrome Desktop, both versions dispatch DELETE_CHARACTER_COMMAND unconditionally (the PR #5644 refactor only affects Android Chrome). Since the Lexical code path is unchanged, the extra deleteContentBackward event identified in this thread is no longer being emitted by Google Input Tools. Does anyone still reproduce this?