Repository navigation
Conversation
…e editor no longer runs the browser's native history over the editor DOM Chromium and WebKit walk up the browser's undo scope, so when the focused control is outside the editor and has exhausted its own history — the URL field of the playground's floating link toolbar, for example — they dispatch `beforeinput`/`historyUndo` at the editor root. The editor has no selection at that point, so `$handleBeforeInput` returned at its range selection guard without calling `preventDefault`, and the browser ran its native undo over the Lexical-managed contenteditable. The editor state was then rebuilt from the mangled DOM: pasting a link after "Hello world " and pressing undo from the URL field produced "Hhttps://lexical.dev", a document that was never in Lexical's history. Prevent the default and dispatch UNDO_COMMAND/REDO_COMMAND from that branch. `@lexical/history` restores a whole editor state, so it does not need a selection, and undo now removes the pasted link as the user expects. Firefox keeps the undo scoped to the focused control and is unaffected.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 8, 2026 01:14
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chromium and WebKit walk up the browser's undo scope, so when the focused control sits outside the editor and has exhausted its own history — the URL field of the playground's floating link toolbar, for example — they dispatch
beforeinput/historyUndoat the editor root. The editor has no selection at that point, so$handleBeforeInputreturned at its range-selection guard without callingpreventDefault, and the browser ran its native undo over the Lexical-managed contenteditable. The state was then rebuilt from the mangled DOM: pasting a link after "Hello world " and pressing undo from the URL field producedHhttps://lexical.dev, a document that was never in Lexical's history.Handle
historyUndo/historyRedoin that branch: prevent the default and dispatchUNDO_COMMAND/REDO_COMMAND.@lexical/historyrestores a whole editor state, so it does not need a selection, and undo now removes the pasted link as the user expects. The change is additive — the range-selection path is untouched and the existing switch cases are unchanged.I traced this rather than inferring it: instrumenting
$handleBeforeInputcaptureshistoryUndo selection=null activeEl=link-input, and the retarget only happens once the input's own undo stack is exhausted — typing into the URL field first makes the same keystroke undo inside the input instead.e2e added to
Links.spec.mjs, chromium and webkit. Firefox keeps the undo scoped to the focused control and never dispatches the event, so it is skipped with a comment saying why.Fixes #6714