[lexical-utils] Bug Fix: positionNodeOnRange leaking orphan rect nodes when rects shrink#8762
Merged
etrepum merged 1 commit intoJun 30, 2026
Conversation
When the number of selection rects decreases between repositions (e.g. a multi-line highlight collapses to one line), the cleanup loop popped the excess entries from the lastNodes tracking array but never detached the corresponding <div> from the DOM. The orphaned rectangles stayed painted inside wrapperNode until the next stop()/restart(). Call node.remove() on the popped node, mirroring the cleanup already done in stop(). Adds a regression test (fails before / passes after).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Jun 30, 2026
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.
Summary
positionNodeOnRange(used by@lexical/utilsmarkSelection/selectionAlwaysOnDisplay) renders one absolutely-positioned<div>per selection client-rect and reuses them across repositions. When the number of rects decreases between two repositions — e.g. a multi-line highlight collapses to a single line after an edit — the cleanup loop popped the excess entries from thelastNodestracking array but never detached the corresponding<div>from the DOM:So stale highlight rectangles remain painted inside
wrapperNodeuntil the nextstop()/restart(). Notestop()(a few lines below) already does the right thing —for (const node of lastNodes) node.remove()— this just applies the same cleanup on the reposition path.Fix
Detach the popped node:
Test plan
Added
packages/lexical-utils/src/__tests__/unit/positionNodeOnRange.test.tsx: renders two rects, then shrinks to one via a reposition and asserts the wrapper's child-node count drops to 1.expected 2 to be 1— orphan div remains).lexical-utilsunit suite: 225 passed, no regressions.