Skip to content

[lexical] Bug Fix: Limit handled selection input suppression to macOS Chrome - #9251

Merged
etrepum merged 1 commit into
meta:mainfrom
etrepum:fix/9250-selection-command-insert-text
Sep 27, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
etrepum:fix/9250-selection-command-insert-text

Conversation

@etrepum

@etrepum etrepum commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Description

The workaround for #8416 suppresses the next nonempty insertText after a handled Backspace or select-all on every platform. An insertion without an intervening keydown, arriving before the zero-delay timer, is silently discarded and can collapse the selected range.

Only arm the workaround on desktop Apple Chromium browsers (IS_APPLE && !IS_IOS && IS_CHROME). Other platforms process the insertion normally. Add regression tests covering both commands across Android, desktop, and iOS platform flags, including preservation of the macOS Chrome workaround. Assert editor text, DOM text, and the resulting caret rather than relying on defaultPrevented alone.

This is the targeted mitigation proposed in the issue. A legitimate insertion in the same window on macOS Chrome remains indistinguishable from the unwanted native replacement and can still be suppressed.

Closes #9250

Test plan

Before

pnpm exec vitest run --project unit packages/lexical/src/tests/unit/LexicalHandledSelectionInsertText.test.ts

AssertionError: expected 'draf' to be 'drafswift' // Object.is equality
AssertionError: expected 'draft' to be 'swift' // Object.is equality

 Test Files  1 failed (1)
      Tests  10 failed | 4 passed (14)

After

The same regression command:

 Test Files  1 passed (1)
      Tests  14 passed (14)

pnpm exec vitest run --project unit packages/lexical/src/tests/unit/LexicalHandledSelectionInsertText.test.ts packages/lexical/src/tests/unit/LexicalEventsKeyDown.test.ts packages/lexical/src/tests/unit/LexicalEventsKeyDownApple.test.ts packages/lexical/src/tests/unit/IosEnterAcceptanceBoundary.test.ts packages/lexical/src/tests/unit/environment.test.ts

 Test Files  5 passed (5)
      Tests  25 passed (25)

TypeScript (tsconfig.test.json), ESLint and Prettier checks passed.

Also replayed the issue's collapsed-caret synthetic sequence in Chromium using navigator profiles: Android Backspace changes draf to drafswift; Android, iPhone and desktop-UA iPadOS select-all change draft to swift. The macOS Chrome profile still suppresses both immediate insertions. DOM and editor-state text agree in each case. These are emulated profiles, not physical-device tests; native macOS system text replacement was not exercised.

… Chrome

## Description

The workaround for meta#8416 suppresses the next nonempty insertText after a handled Backspace or select-all on every platform. An insertion without an intervening keydown, arriving before the zero-delay timer, is silently discarded and can collapse the selected range.

Only arm the workaround on desktop Apple Chromium browsers (IS_APPLE && !IS_IOS && IS_CHROME). Other platforms process the insertion normally. Add regression tests covering both commands across Android, desktop, and iOS platform flags, including preservation of the macOS Chrome workaround. Assert editor text, DOM text, and the resulting caret rather than relying on defaultPrevented alone.

This is the targeted mitigation proposed in the issue. A legitimate insertion in the same window on macOS Chrome remains indistinguishable from the unwanted native replacement and can still be suppressed.

Closes meta#9250

## Test plan

### Before

pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/LexicalHandledSelectionInsertText.test.ts

```
AssertionError: expected 'draf' to be 'drafswift' // Object.is equality
AssertionError: expected 'draft' to be 'swift' // Object.is equality

 Test Files  1 failed (1)
      Tests  10 failed | 4 passed (14)
```

### After

The same regression command:

```
 Test Files  1 passed (1)
      Tests  14 passed (14)
```

pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/LexicalHandledSelectionInsertText.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDown.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDownApple.test.ts packages/lexical/src/__tests__/unit/IosEnterAcceptanceBoundary.test.ts packages/lexical/src/__tests__/unit/environment.test.ts

```
 Test Files  5 passed (5)
      Tests  25 passed (25)
```

TypeScript (tsconfig.test.json), ESLint and Prettier checks passed.

Also replayed the issue's collapsed-caret synthetic sequence in Chromium using navigator profiles: Android Backspace changes draf to drafswift; Android, iPhone and desktop-UA iPadOS select-all change draft to swift. The macOS Chrome profile still suppresses both immediate insertions. DOM and editor-state text agree in each case. These are emulated profiles, not physical-device tests; native macOS system text replacement was not exercised.
@vercel

vercel Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 27, 2026 9:37pm UTC
lexical-playground Ready Ready Preview Sep 27, 2026 9:37pm UTC

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 Sep 27, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Sep 27, 2026
@etrepum
etrepum marked this pull request as ready for review September 27, 2026 21:39
@etrepum
etrepum added this pull request to the merge queue Sep 27, 2026
Merged via the queue into meta:main with commit a4d27c3 Sep 27, 2026
50 checks passed
@etrepum etrepum mentioned this pull request Sep 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — fe8e0b83 Deployed Sep 27, 2026 by vercel[bot]
Preview – lexical-playground — fe8e0b83 Deployed Sep 27, 2026 by vercel[bot]
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: Immediate insertText after handled Backspace or select-all is dropped

2 participants