Repository navigation
Avoid :has() selectors that trigger workbench-wide style invalidation - #327052
Conversation
A :has() whose anchor exists in the live DOM makes Blink re-evaluate it on DOM mutations anywhere in the document - including the inline style writes the editor performs on every layout. With a populated chat working set, every forced style recalc traversed the whole visible workbench (~218ms per Recalculate Style in a large workspace; sash drag nearly frozen). Same issue class as microsoft#324985. Per-rule profiling showed the chat editing session scrollbar rule alone accounted for 77% of the per-recalc cost; the root-anchored rules in floatingPanels.css and sessionsPolicyBlocked.css are the same hazard. - chat.css: key the scrollbar padding off an 'overflowing' class toggled in chatInputPart.ts, which already computes the condition. The padding now applies whenever the list overflows instead of only while the auto-hide scrollbar is faded in. - floatingPanels.css: use 'activitybar-compact' (mirrored by activitybarPart.ts) and 'noactivitybar' (toggled by layout.ts like the other part visibility classes). - sessionsPolicyBlocked.css: toggle a class for the overlay's lifetime. - build/stylelint.ts: error on root-anchored :has() (body/html/:root/ .monaco-workbench), with a has-anchor-checker disable escape.
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Benjamin Christopher Simmonds (@benibenj)Matched files:
|
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
Replaces workbench-rooted :has() selectors with explicit state classes to avoid costly global style recalculation.
Changes:
- Mirrors overflow, activity-bar, and policy-overlay state into CSS classes.
- Updates affected selectors to consume those classes.
- Adds lint detection for root-anchored
:has()selectors.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
build/stylelint.ts |
Adds the root-anchor lint check. |
src/vs/workbench/browser/layout.ts |
Tracks hidden activity-bar state on the workbench root. |
src/vs/workbench/browser/media/floatingPanels.css |
Replaces root :has() selectors. |
src/vs/workbench/browser/parts/activitybar/activitybarPart.ts |
Mirrors compact activity-bar state. |
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts |
Tracks working-set overflow. |
src/vs/workbench/contrib/chat/browser/widget/media/chat.css |
Uses the overflow class for padding. |
src/vs/sessions/contrib/policyBlocked/browser/sessionsPolicyBlocked.ts |
Tracks overlay lifetime on the root. |
src/vs/sessions/contrib/policyBlocked/browser/media/sessionsPolicyBlocked.css |
Uses the policy-blocked root class. |
Addresses Copilot review feedback: the previous regex missed root tokens that are not first in the compound (.style-override.monaco-workbench:has()) and matched incomplete tokens (.monaco-workbench-test, bodyguard). Extracted into build/lib/stylelint/validateHasSelectors.ts with focused tests.
Benjamin Christopher Simmonds (benibenj)
left a comment
There was a problem hiding this comment.
Thanks for looking into this and adding the styling rules! There is just one NIT
Review feedback: inject IWorkbenchLayoutService instead of walking the DOM with container.closest(). The caller already passes mainContainer as the overlay container. Stub the layout service in the component fixture.
|
cc Benjamin Christopher Simmonds (@benibenj) runninng the workflows on this, i think would be nice to get in 🚀 |
btw two checks failed. Component Fixtures is just the shallow fetch — main moved on too far since my last sync so it can't find the merge-base, merged latest main and pushed, should be green on rerun. the engineering system one blocks any build/ change from people without write access, so that one stays red no matter what — can split the stylelint bit into its own PR if that's easier, your call |
|
Justin Chen (@justschen) workflows need another approve after the push. also fair warning, the engineering system check will fail again no matter what — that's the build/ restriction from above. still happy to split that part into a separate PR if it's blocking |
|
Yeah I don't think we allow community PRs for build folder changes. If you change the PR to only include none build folder changes, I can create the PR for the linting rules |
Head branch was pushed to by a user without write access
done, dropped the build/ stuff — the PR only touches src/ now |
f57741d
into
microsoft:main
Temporarily stack the selector replacements so the new stylelint rule can pass while microsoft#327052 is still awaiting merge. Once that PR lands, these overlapping file changes drop from this PR's diff. Co-authored-by: Copilot <[email protected]>
* Avoid :has() selectors that trigger workbench-wide style invalidation A :has() whose anchor exists in the live DOM makes Blink re-evaluate it on DOM mutations anywhere in the document - including the inline style writes the editor performs on every layout. With a populated chat working set, every forced style recalc traversed the whole visible workbench (~218ms per Recalculate Style in a large workspace; sash drag nearly frozen). Same issue class as #324985. Per-rule profiling showed the chat editing session scrollbar rule alone accounted for 77% of the per-recalc cost; the root-anchored rules in floatingPanels.css and sessionsPolicyBlocked.css are the same hazard. - chat.css: key the scrollbar padding off an 'overflowing' class toggled in chatInputPart.ts, which already computes the condition. The padding now applies whenever the list overflows instead of only while the auto-hide scrollbar is faded in. - floatingPanels.css: use 'activitybar-compact' (mirrored by activitybarPart.ts) and 'noactivitybar' (toggled by layout.ts like the other part visibility classes). - sessionsPolicyBlocked.css: toggle a class for the overlay's lifetime. - build/stylelint.ts: error on root-anchored :has() (body/html/:root/ .monaco-workbench), with a has-anchor-checker disable escape. * Match root-anchored :has() as complete tokens at any compound position Addresses Copilot review feedback: the previous regex missed root tokens that are not first in the compound (.style-override.monaco-workbench:has()) and matched incomplete tokens (.monaco-workbench-test, bodyguard). Extracted into build/lib/stylelint/validateHasSelectors.ts with focused tests. * Use layoutService.mainContainer for the policy-blocked root class Review feedback: inject IWorkbenchLayoutService instead of walking the DOM with container.closest(). The caller already passes mainContainer as the overlay container. Stub the layout service in the component fixture. * small tweaks * Drop build/ changes; lint rule moves to a separate PR * build: prevent root-anchored :has() selectors Add a stylelint check for root-level :has() selectors that cause workbench-wide style invalidation, together with focused parser tests. This is split from #327052 and should merge after it. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: zmr233 <[email protected]> Co-authored-by: zmr-233 <[email protected]> Co-authored-by: Copilot <[email protected]>

Fixes #327048
A
:has()whose anchor exists in the live DOM makes every DOM mutation, including the inlineletter-spacingwrites the editor performs on each layout, pay a style recalc that scales with the whole visible workbench (measurements and per-rule profiling in the issue). The single biggest offender is the chat working set scrollbar rule; the root-anchored rules in floatingPanels.css and sessionsPolicyBlocked.css are the same hazard and the same class of problem that #324986 already fixed for the automations dialog.Changes:
chat.css: the working set scrollbar padding is keyed off anoverflowingclass toggled inchatInputPart.ts, which already computes the overflow condition (allEntries.length > maxItemsShown), instead of:has(.visible.scrollbar.vertical). Behavior note: the padding now applies whenever the list overflows, not only while the auto-hide scrollbar is faded in. This also stops the labels from shifting under the scrollbar mid-scroll.floatingPanels.css: the two root-anchored:has()rules are replaced byactivitybar-compact(mirrored onto the workbench root byactivitybarPart.ts) andnoactivitybar(toggled bylayout.tslike the other part visibility classes). A:not(.noactivitybar)on the compact rule keeps the hidden+compact case resolving to the hidden inset, matching the specificity behavior of the old rules.sessionsPolicyBlocked.css:.monaco-workbench:has(.sessions-policy-blocked-overlay)becomes a class toggled for the overlay's lifetime.build/stylelint.ts: new check that errors on:has()anchored to a root compound (body/html/:root/.monaco-workbench), with astylelint-disable has-anchor-checkerescape. It flags all three historical instances (including the original UI performance degrades after opening Hover, Command Palette, or main menu #324985 one) and has no hits on currentsrc/**/*.css.Testing:
src/**/*.css(no findings).