Skip to content

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

Merged
etrepum merged 5 commits intofacebook:mainfrom
sKawashima:fix/safari-ime-composition-flag-clear
Feb 20, 2026
Merged

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

Conversation

@sKawashima
Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown

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 20, 2026 8:57am
lexical-playground Ready Ready Preview, Comment Feb 20, 2026 8:57am

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
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally there would be an e2e test here to confirm that it works

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Feb 19, 2026
…k#8153

Add tests to verify text deletion works correctly after IME composition
end event on Safari, covering both Cmd+A selection and multi-paragraph
Shift+ArrowUp selection scenarios
@sKawashima
Copy link
Copy Markdown
Contributor Author

@etrepum
Thank you for checking.
I added a WebKit-only regression test.

Note that Playwright has no IME simulation API for WebKit (unlike Chromium's CDP), so the test dispatches a compositionend event programmatically rather than driving real IME input.
It's white-box in nature but reliably exercises the bug's code path.

@etrepum etrepum added this pull request to the merge queue Feb 20, 2026
Merged via the queue into facebook:main with commit 7ce628c Feb 20, 2026
39 checks passed
@etrepum etrepum mentioned this pull request Feb 25, 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. extended-tests Run extended e2e tests on a PR

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)

2 participants