Skip to content

fix: make macOS text replacement work on contenteditable#51289

Merged
ckerr merged 3 commits into
electron:mainfrom
nmggithub:fix-contenteditable-backspace-behavior
Apr 27, 2026
Merged

fix: make macOS text replacement work on contenteditable#51289
ckerr merged 3 commits into
electron:mainfrom
nmggithub:fix-contenteditable-backspace-behavior

Conversation

@nmggithub

@nmggithub nmggithub commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Description of Change

Resolves #50432.

This is a pure Chromium patch and should probably be upstreamed. This fix was also came to through many conversations with AI.

Context

Pressing Backspace inside a contenteditable element incorrectly accepts macOS text replacements. This patch adds a check right before Chromium commits to accepting a text replacement with the following logic:

“If this replacement callback was created for an older snapshot of the text, only allow it to proceed if the current caret has moved past the replacement range. Otherwise, treat it as stale and ignore it.”

This is enough to bail early on Backspace, so it patches the bug. The check is (hopefully) sensible logic, but it does not address any underlying issues as to what causes a Backspace press to go down that text replacement acceptance path. That is a larger architectural issue which this patch does not attempt to address.

The bug does not exhibit in Safari (arguably because it follows the Input Events Level 2 spec more closely than Chromium; specifically around the use of the insertReplacementText value for the inputType property on events, but also event ordering). There is an issue around the inputType spec deviation filed for Chromium, but it started in 2019, and there has not been much movement since. Regardless, due to the behavior discrepancy, even with this patch there are remaining bugs in downstream libraries that use contenteditable (like Lexical, which many Electron apps use), but those can be addressed separately.

Longer-term, all bugs in this area may be more-properly addressed with an architectural alignment of Chromium with Safari when it comes to macOS text replacements in contenteditable elements.

Checklist

Release Notes

Notes: Fixed buggy behavior where Backspace would accept macOS text replacements inside contenteditable elements.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Apr 23, 2026
@nmggithub nmggithub marked this pull request as ready for review April 23, 2026 20:07
@nmggithub nmggithub requested a review from a team as a code owner April 23, 2026 20:07
Comment thread patches/chromium/.patches Outdated

@VerteDinde VerteDinde left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@nmggithub and I walked through this on a Huddle, LGTM!

@VerteDinde VerteDinde added semver/patch backwards-compatible bug fixes target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 25, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Apr 25, 2026
@ckerr

ckerr commented Apr 26, 2026

Copy link
Copy Markdown
Member

The error in Build / macos-arm64 / test / test (darwin, 2) (pull_request)Failing after 16m is unrelated to this PR but happily the fix for it just landed in main last night from #51302. I'll restart CI to try again.

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CI is green, code is approved by @VerteDinde and also LGTM at first read.

Only thing we need before merging is @nmggithub needs to add a release notes paragraph 😸

@nmggithub nmggithub requested a review from ckerr April 26, 2026 20:06
@ckerr ckerr merged commit 411e3be into electron:main Apr 27, 2026
139 of 142 checks passed
@release-clerk

release-clerk Bot commented Apr 27, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed buggy behavior where Backspace would accept macOS text replacements inside contenteditable elements.

@trop

trop Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "41-x-y", please check out #51343

@trop trop Bot removed the target/41-x-y PR should also be added to the "41-x-y" branch. label Apr 27, 2026
@trop

trop Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #51344

@trop

trop Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "40-x-y", please check out #51345

@trop trop Bot added in-flight/42-x-y in-flight/40-x-y and removed target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 27, 2026
@trop trop Bot removed the target/40-x-y PR should also be added to the "40-x-y" branch. label Apr 27, 2026
jkleinsc pushed a commit that referenced this pull request Apr 27, 2026
fix: make macOS text replacement work on `contenteditable` (#51289)

* fix: make macOS text replacement work on `contenteditable`

* fix: remove accidentally included patch line

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Noah Gregory <noahmgregory@gmail.com>
@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. and removed in-flight/42-x-y labels Apr 27, 2026
jkleinsc pushed a commit that referenced this pull request Apr 27, 2026
* fix: make macOS text replacement work on `contenteditable` (#51289)

* fix: make macOS text replacement work on `contenteditable`

* fix: remove accidentally included patch line

Co-authored-by: Noah Gregory <noahmgregory@gmail.com>

* chore: update patches (trivial only)

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Noah Gregory <noahmgregory@gmail.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
@trop trop Bot added merged/41-x-y PR was merged to the "41-x-y" branch. and removed in-flight/41-x-y labels Apr 27, 2026
ckerr added a commit that referenced this pull request Apr 28, 2026
* fix: make macOS text replacement work on `contenteditable` (#51289)

* fix: make macOS text replacement work on `contenteditable`

* fix: remove accidentally included patch line

Co-authored-by: Noah Gregory <noahmgregory@gmail.com>

* chore: update patches (trivial only)

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Noah Gregory <noahmgregory@gmail.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
@trop trop Bot added merged/40-x-y PR was merged to the "40-x-y" branch. and removed in-flight/40-x-y labels Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/40-x-y PR was merged to the "40-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backspace before autocorrect still places the autocorrected word

3 participants