Repository navigation
[lexical-playground] Bug Fix: Reset the cached selection format on clear formatting - #8889
Merged
etrepum merged 3 commits intoAug 1, 2026
Merged
Conversation
…ear formatting clearFormatting cleared the format on the selected nodes but left the format cached on the RangeSelection, which is what hasFormat() reads. The toolbars kept rendering the cleared formats as active, so a format button needed an extra click to re-apply. Core's $formatText already keeps the two in sync; this does the same after clearing. Fixes meta#8881
Yjason-K
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
July 29, 2026 12:33
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Jul 30, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
Looks like the e2e tests don't work in collab mode
…ollab mode The new meta#8881 test looked the bold button up with page.locator(), which only searches the top-level document. In collab mode the playground runs in a two-iframe split view, so the toolbar is not there and the assertion failed with "element(s) not found". Use the locate() helper, which resolves through getPageOrFrame() into the left frame like the rest of the e2e utils do.
Contributor
Author
|
Thanks — fixed in 2b37e7b. The test used |
etrepum
approved these changes
Aug 1, 2026
etrepum
added a commit
to mayrang/lexical
that referenced
this pull request
Aug 2, 2026
Our branch extracted the body of clearFormatting into the $clearFormatting $function; main (meta#8889) appended a reset of the format/style cached on the RangeSelection. Kept both: the reset now lives at the end of $clearFormatting, still inside the range/table selection branch and after the collapsed-selection early return, so clearFormatting remains the thin editor.update wrapper. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Merged
This branch was successfully deployed
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.
Description
Clicking Clear Formatting removes the formatting from the text, but the toolbar keeps drawing the format buttons in their active state. Because the button still looks toggled on, re-applying the format takes two clicks — one to "turn off" the stale state and one to actually apply it.
hasFormat()reads the format bitmask that aRangeSelectioncaches on itself, not the format of the nodes:https://github.com/facebook/lexical/blob/main/packages/lexical/src/LexicalSelection.ts#L872-L875
clearFormattingclearedformat/styleon the selected nodes but never updated that cache, so both toolbars kept reporting the old formats:Core already treats these as a pair —
$formatTextassignsselection.formatright after mutating the nodes. This change does the same at the end ofclearFormatting.TableSelection.hasFormat()derives its value from its nodes, so it needs no equivalent reset.The collapsed-selection path returns early (it only clears block formatting), so the pending format a caret carries is untouched and #7383 keeps working.
Why the issue says it only reproduces mid-node
The stale cache happens for any non-collapsed selection — the added unit test fails for a whole-node selection too, before this change. The difference is only whether the browser happens to fire a
selectionchangeafterwards, which makesonSelectionChangerecompute the format from the nodes and paper over the bug:https://github.com/facebook/lexical/blob/main/packages/lexical/src/LexicalEvents.ts#L458-L485
Closes #8881
Test plan
Both added tests fail without the change in
utils.tsand pass with it.Before
ClearFormatting.spec.mjs— the HTML assertion passes (the formatting is cleared), only the toolbar state is wrong:ToolbarPluginClearFormatting.test.ts:After
Added coverage:
ClearFormatting.spec.mjs— bolds a word in the middle of a paragraph, clears formatting from the dropdown, and asserts the bold button losesactive(the reported scenario, end to end).ToolbarPluginClearFormatting.test.ts— assertsselection.format/styleare reset after clearing, plus a companion test pinning that a collapsed selection still keeps its pending format (Bug: [lexical-playground] clear-formatting doesn't clear text-left/right/center alignment when no formatting to text #7383).