Skip to content

build: prevent root-anchored :has() selectors - #327690

Merged
Benjamin Christopher Simmonds (benibenj) merged 11 commits into
microsoft:mainfrom
benibenj:benibenj/agents/create-a-pr-which-brings-back-the-changes
Jul 27, 2026
Merged

Benjamin Christopher Simmonds (benibenj) merged 11 commits into
microsoft:mainfrom
benibenj:benibenj/agents/create-a-pr-which-brings-back-the-changes

Conversation

@benibenj

@benibenj Benjamin Christopher Simmonds (benibenj) commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a stylelint check that rejects :has() selectors anchored to body, html, :root, or .monaco-workbench, since they can make every DOM mutation trigger workbench-wide style invalidation.

The check:

  • parses complete selector tokens, including escaped identifiers and nested selectors
  • reports the source line of the first offending selector
  • supports a file-level stylelint-disable has-anchor-checker escape hatch
  • includes focused tests for root anchors, false positives, CSS nesting, comments, and escapes

Context

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 typecheck from build/
  • npm run typecheck-client
  • npm run valid-layers-check
  • npm run precommit
  • npm run compile
  • npm run stylelint
  • Full review of the lint-rule diff; no issues found

zmr-233 and others added 10 commits July 22, 2026 13:05
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]>
Copilot AI review requested due to automatic review settings July 27, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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]>
@benibenj
Benjamin Christopher Simmonds (benibenj) merged commit 3825df5 into microsoft:main Jul 27, 2026
45 of 47 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 27, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants