Skip to content

[lexical] Bug Fix: retain selection during updates on unfocused editor#7941

Merged
etrepum merged 3 commits intofacebook:mainfrom
fantactuka:retaining-selection
Oct 23, 2025
Merged

[lexical] Bug Fix: retain selection during updates on unfocused editor#7941
etrepum merged 3 commits intofacebook:mainfrom
fantactuka:retaining-selection

Conversation

@fantactuka
Copy link
Copy Markdown
Collaborator

Description

There's an issue when editor loses selection state when it's blurred (DOM selection is elsewhere), and editor update is triggered without user event (so window.event is null):

https://stackblitz.com/edit/lexical-selection-retention?file=index.html

E2e test is replicating the same thing: adds content and selection state to the editor, focus into font-size input, triggers programmatic update. Selection state is lost

@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 Oct 22, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Oct 22, 2025

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

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Oct 23, 2025 8:11am
lexical-playground Ready Ready Preview Comment Oct 23, 2025 8:11am

@fantactuka
Copy link
Copy Markdown
Collaborator Author

Found it when editor's text color was updated with debounce (so there's no associated window.event), and caret is within color picker input. skip-dom-selection tag does not do much, since selection is being set to null way before - when creating initial selection for pending editor state:

https://github.com/fantactuka/lexical/blob/9e4c5bdfe61264f9e5d594704fa4ed1c87b7cc1f/packages/lexical/src/LexicalUpdates.ts#L945-L949

@fantactuka fantactuka marked this pull request as ready for review October 22, 2025 16:08
page,
isPlainText,
}) => {
test.skip(isPlainText);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this also needs to skip collab

@etrepum etrepum added this pull request to the merge queue Oct 23, 2025
Merged via the queue into facebook:main with commit c28a7e5 Oct 23, 2025
39 checks passed
This was referenced Oct 27, 2025
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.

2 participants