Repository navigation
build: prevent root-anchored :has() selectors - #327690
Merged
Benjamin Christopher Simmonds (benibenj) merged 11 commits intoJul 27, 2026
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.
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.
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.
Add a stylelint check for root-level :has() selectors that cause workbench-wide style invalidation, together with focused parser tests. This is split from microsoft#327052 and should merge after it. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a build-time stylelint check preventing root-anchored :has() selectors that cause workbench-wide style invalidation.
Changes:
- Adds selector and stylesheet scanning.
- Integrates the check with stylelint and an escape hatch.
- Adds focused parser tests.
Show a summary per file
| File | Description |
|---|---|
build/stylelint.ts |
Runs the new check and reports violations. |
build/lib/stylelint/validateHasSelectors.ts |
Implements selector parsing and detection. |
build/lib/test/rootAnchoredHas.test.ts |
Tests anchors, nesting, escapes, and false positives. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Medium
roblourens
previously approved these changes
Jul 27, 2026
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]>
Paul (pwang347)
approved these changes
Jul 27, 2026
Benjamin Christopher Simmonds (benibenj)
enabled auto-merge (squash)
July 27, 2026 20:12
Benjamin Christopher Simmonds (benibenj)
merged commit Jul 27, 2026
3825df5
into
microsoft:main
45 of 47 checks passed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 a stylelint check that rejects
:has()selectors anchored tobody,html,:root, or.monaco-workbench, since they can make every DOM mutation trigger workbench-wide style invalidation.The check:
stylelint-disable has-anchor-checkerescape hatchContext
This restores the build/stylelint changes removed in 452ce0f so they can be reviewed independently from #327052.
Merge dependency: #327052 must merge first because it removes the existing root-anchored selectors that this check correctly flags. Its head is temporarily stacked into this branch so CI can pass; after #327052 merges, the overlapping eight files will drop from this PR's diff.
Validation
node --test build/lib/test/rootAnchoredHas.test.ts(6 tests pass)npm run typecheckfrombuild/npm run typecheck-clientnpm run valid-layers-checknpm run precommitnpm run compilenpm run stylelint