Isolate lexxy-editor style and layout with CSS containment#983
Open
jorgemanrubia wants to merge 1 commit into
Open
Isolate lexxy-editor style and layout with CSS containment#983jorgemanrubia wants to merge 1 commit into
jorgemanrubia wants to merge 1 commit into
Conversation
Lexxy editor initialization mutates many descendants (adapter nodes, toolbar, content root) in sequence. Without containment, each mutation invalidates ancestor-dependent selectors (`:has()`, inherited custom properties, descendant combinators) across the whole document, so every style recalc has to walk the entire document tree. Chrome traces on a chat page with ~13,500 DOM elements show each editor init firing three style recalcs that each re-examine all 13,500 elements. Adding `contain: layout style` to `lexxy-editor` cuts the per-recalc element count roughly in half (the recalc no longer crosses the editor boundary in either direction) and brings total UpdateLayoutTree time on the same page from ~593ms down to ~365ms. `layout` containment also means the editor's layout computation is independent of its siblings — internal size/position changes never trigger layout outside the editor.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds CSS containment to lexxy-editor to reduce whole-page style/layout invalidation caused by editor initialization mutating many descendants, improving performance on large DOM pages.
Changes:
- Add
contain: layout styleto thelexxy-editorroot to isolate internal layout/style recalculation from the rest of the document. - Document the rationale and expected impact directly in the stylesheet comment.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Adds
contain: layout styletolexxy-editorso the editor's style and layout are isolated from its surroundings.Why
Editor initialization mutates many descendants (adapter nodes, toolbar, content root) in sequence. Without containment, each mutation invalidates ancestor-dependent selectors (
:has(), inherited custom properties, descendant combinators) across the whole document, so every style recalc walks the entire document tree.On a Basecamp chat page with ~13,500 DOM elements, Chrome traces show each editor init firing three style recalcs that each re-examine all ~13,500 elements. With two editors on the page that's six 50ms recalcs during initial render — plus all the post-init recalcs triggered by typing, selection changes, and so on.
Measurement
Same page, same number of editors, same content.
Before:
UpdateLayoutTreeevents touching 13,488 elements each, ~50ms per recalc. Total ~593ms across init.After:
UpdateLayoutTreeevents touching 6,913 elements each, ~28–35ms per recalc. Total ~365ms across init.That's a ~38% drop in total style recalc time and ~48% fewer elements re-evaluated per event.
Safety
contain: layout stylemeans:Does not prevent paint or size containment. The editor still paints normally and its intrinsic size still participates in the page layout. Selection, focus, and cursor positioning all continue to work across the boundary (they're browser-native and unaffected by
contain: layout style).