You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Safari/WebKit can dispatch a native selectionchange event when interacting with links outside the editor, even when the Lexical selection has not actually changed.
Previously, onSelectionChange unconditionally dispatched SELECTION_CHANGE_COMMAND for every selectionchange event. This caused an unnecessary SELECTION_CHANGE_COMMAND when clicking the link in the floating link menu in Safari.
This change checks the previous Lexical selection before dispatching the command. The command is dispatched when:
the selection value has changed;
the selection is marked dirty; or
the selection changes between null and a non-null selection.
A browser regression test was added to verify that redundant selectionchange events are ignored while legitimate caret and range selection changes continue to dispatch SELECTION_CHANGE_COMMAND.
meta-claBot
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 8, 2026
Be patient. There are other PRs to review and other priorities for the project and its maintainers. Generating extra notifications by begging for review will only lower the priority of your PRs.
@kavyansh18 It’s a shame you closed the PR. This change improves the editor's stability. I don't think there was any need to rush the review; a new version of Lexical is released about once a month on average, so the PR would certainly have been noticed within two or three weeks
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
CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.extended-testsRun extended e2e tests on a PR
3 participants
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.
Description
Safari/WebKit can dispatch a native
selectionchangeevent when interacting with links outside the editor, even when the Lexical selection has not actually changed.Previously,
onSelectionChangeunconditionally dispatchedSELECTION_CHANGE_COMMANDfor everyselectionchangeevent. This caused an unnecessarySELECTION_CHANGE_COMMANDwhen clicking the link in the floating link menu in Safari.This change checks the previous Lexical selection before dispatching the command. The command is dispatched when:
nulland a non-null selection.A browser regression test was added to verify that redundant
selectionchangeevents are ignored while legitimate caret and range selection changes continue to dispatchSELECTION_CHANGE_COMMAND.Closes #8885
Test plan
Before
On the unmodified implementation, the regression test fails because a redundant
selectionchangedispatchesSELECTION_CHANGE_COMMAND:The failure was reproduced in WebKit against the unmodified base implementation.
After
The regression test passes with the fix in:
The test verifies that:
selectionchangeevents do not dispatchSELECTION_CHANGE_COMMAND;Additional validation:
pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalSelection*.test.tspnpm run ci-checkgit diff --check