Skip to content

[lexical] Bug Fix: Fix selected text not properly deleted after IME input on Safari (macOS)#8154

Open
sKawashima wants to merge 2 commits intofacebook:mainfrom
sKawashima:fix/safari-ime-composition-flag-clear
Open

[lexical] Bug Fix: Fix selected text not properly deleted after IME input on Safari (macOS)#8154
sKawashima wants to merge 2 commits intofacebook:mainfrom
sKawashima:fix/safari-ime-composition-flag-clear

Conversation

@sKawashima
Copy link

Description

In Safari on macOS, after confirming IME composition (e.g. Japanese input) with a non-backspace key (Enter, Space, etc.), pressing Backspace to delete a text selection (created via Shift+Arrow or Cmd+A) did not work correctly.

Root cause:

Safari fires compositionend before keydown (unlike other browsers).
isSafariEndingComposition is set to true on compositionend to defer composition finalization to the next keydown. However, the flag was only cleared when keydown fired with Backspace — leaving it as stale true when composition was confirmed with any other key.

When the user later pressed Backspace to delete a selection:

  1. $handleKeyDown saw isSafariEndingComposition = true and called $onCompositionEndImpl
  2. $updateTextNodeFromDOMContent called selection.setTextNodeRange(anchorNode, anchorOffset, anchorNode, focusOffset), forcing anchor and focus onto the same node
  3. For multi-node selections (e.g. Cmd+A spanning multiple paragraphs), this corrupted the selection
  4. The reconciler updated the DOM selection to match the corrupted Lexical selection
  5. The subsequent beforeinput deleteContentBackward operated on the wrong selection, producing incorrect deletion

Fix: When isSafariEndingComposition is true but the key is not Backspace, clear the flag without calling $onCompositionEndImpl. Composition finalization for non-backspace confirmations is already handled by the beforeinput event.

Closes #8153

Test plan

Before

After typing with Japanese IME and confirming with Enter, selecting all text with Cmd+A and pressing Delete does not delete the selected text correctly.

2026-02-19.21.37.49.mov

After

Deletion works correctly after IME composition confirmed with non-backspace
keys.

2026-02-19.22.10.23.mov

Ensure Safari composition state is properly reset for any key press
during composition end, not only backspace, to prevent state leaks
@meta-cla
Copy link

meta-cla bot commented Feb 19, 2026

Hi @sKawashima!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel
Copy link

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Feb 19, 2026 1:41pm
lexical-playground Ready Ready Preview, Comment Feb 19, 2026 1:41pm

Request Review

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Selected text not properly deleted with IME input (e.g. Japanese) on Safari (macOS)

1 participant

Comments