Skip to content

perf(renderer): drop group-has-[:focus-visible] rules that restyle whole subtrees - #36098

Merged
nwparker merged 4 commits into
mainfrom
perf/remove-group-has-focus-visible-34312
Oct 29, 2026
Merged

nwparker merged 4 commits into
mainfrom
perf/remove-group-has-focus-visible-34312

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​68 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​68
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​275 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​272

Fixes #34312.

Diagnosis and the original fork PR (naufaldi#1) are by @naufaldi. Thank you. This re-implements it on current main, with co-author credit on every commit. The fork's main.css blur change is already covered by #34932.

Why: Tailwind compiles group-has-* to .x:is(:where(.group\/g):has(…) *), which is a non-subject :has() whose subject is *. The rule only has to exist in the stylesheet to cause harm. When it combines with any attribute :has() (e.g. has-data-[slot=card-action] in card.tsx) and a non-subject :has() on a large ancestor, Blink restyles the whole subtree under the anchor on every mutation. This is the same family as #34932, #33799 and #32065.

Changes

  • (a) SshTargetCard and the reasoning chevron now use the scoped [[class~='group/x']:has(:focus-visible)_&] shape (precedent fix(renderer): stop the modal toast rule from freezing large diffs #23721 / fix: bound combined diff editors and scope chat style invalidation #23725). This keeps the keyboard-only reveal (fix(native-chat): reveal message chrome on keyboard focus, not any focus #19426), and it accounts for the entire measured win.
  • (b) rich-markdown-editor.css drops a redundant :has() on the TOC header. Defence in depth; close to neutral once (a) lands.
  • Guard: check-has-restyle-scope.mjs compiles the renderer's Tailwind CSS with Tailwind's own API, then adds the plain renderer stylesheets and an explicit list of package stylesheets imported from renderer code. It lowers nesting with lightningcss and walks the selector AST. It fails on any non-subject :has() whose final subject has no class, id or attribute.
    • Context carries through :is, :where, :not and :nth-child(of).
    • Only :has(+ …) / :has(~ …) count as sibling-only.
    • Package CSS imports missing from the list fail the check.
    • Three pdf.js rules are baselined; measured, they cause no subtree restyle.
    • Not covered: ?inline, template-literal, .js and relative node_modules imports.
    • Runs in pnpm lint, check:changed and PR CI, in about 1.5 s.

Measurements (hidden Electron 43.8.1, real compiled Tailwind, ~8.3k-node DOM, per iteration):

Scenario Before After
Rich editor with TOC open 19.4 ms 1.6 ms
Native-chat code block streaming 12.5 ms (3,184 elements restyled) 3.6 ms (3)
Large group row 8.0 ms (2,003 elements) 2.4 ms (2)

Verified:

  • Keyboard focus still reveals SshTargetCard's Connect button and the reasoning chevron; pointer focus does not.
  • The guard fails on main's two rules and passes this branch.
  • The selector shapes and one real Tailwind compile are unit-tested.
  • Adversarially reviewed over 4 rounds by an Opus sub-agent and Codex (gpt-6.1-sol, xhigh). Final verdicts: Opus MERGE; Codex MERGE WITH CHANGES, and its two regex gaps (an import after a URL string, unquoted @import url()) are fixed in the last commit.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4deb5c8-9e51-4b23-82b0-44a1faf138c0
Commits

Reviewing files that changed from the base of the PR and between 63f6d83 and 007a973.

Files selected for processing: 9
  • .github/workflows/pr.yml
  • config/scripts/check-changed-selection.mjs
  • config/scripts/check-has-restyle-scope.mjs
  • config/scripts/check-has-restyle-scope.test.mjs
  • config/scripts/run-lint.mjs
  • package.json
  • src/renderer/src/assets/rich-markdown-editor.css
  • src/renderer/src/components/native-chat/NativeChatReasoningDisclosure.tsx
  • src/renderer/src/components/settings/SshTargetCard.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

nwparker and others added 4 commits October 29, 2026 14:12
…ole subtrees

Tailwind compiles group-has-* to `.x:is(:where(.group\/g):has(...) *)`: a
non-subject :has() whose subject is `*`. Together with any attribute :has()
in the sheet (e.g. card.tsx has-data-[slot=card-action]) and a non-subject
:has() on a large ancestor, Blink restyles the whole subtree under the
anchor on every mutation, so Mermaid label measurement, streaming code
blocks and rich-editor edits paid for thousands of elements per forced
style read.

(a) SshTargetCard and NativeChatReasoningChevron use the scoped
    [[class~='group/x']:has(:focus-visible)_&] shape from #23725, keeping
    the keyboard-only reveal (#19426). This is the whole measured win.
(b) rich-markdown-editor.css drops a redundant :has(): .markdown-toc-header
    only renders inside .markdown-toc-panel. Defence in depth; measured
    close to neutral once (a) lands.

Guard: check-has-restyle-scope.mjs compiles the renderer's Tailwind CSS
with Tailwind's own API, adds the plain renderer stylesheets, lowers
nesting with lightningcss and walks its selector AST. It flags any
non-subject :has() (outside sibling-only arguments) whose subject compound
has no class, id or attribute, carrying context through :is/:where/:not.
Reading compiled output covers the Tailwind spellings, @apply and nested
CSS forms tested so far. It runs in pnpm lint, check:changed and PR CI.

Hidden Electron 43.8.1, real compiled Tailwind, ~8.3k-node DOM, per
iteration, all from (a): rich editor with TOC 19.4 -> 1.6 ms; native-chat
code block append 12.5 -> 3.6 ms (3,184 -> 3 elements restyled); large
group row 8.0 -> 2.4 ms (2,003 -> 2).

Fixes #34312

Co-authored-by: Naufaldi <[email protected]>
…ted CSS

- :has(.a + .b) starts with a descendant step; only a leading :scope
  (:has(+ x) / :has(~ x)) counts as sibling-only.
- A :has() inside a complex :is()/:where()/:not() argument now sees the
  rule's final subject, so :is(.anchor:has(.t) .scoped) * is flagged.
- :nth-child(of …) / :nth-last-child(of …) arguments are traversed.
- Renderer-imported package stylesheets (xterm, monaco, pdf.js,
  react-grab) are checked through an explicit list; an unlisted CSS import
  fails. pdf.js's three tag-subject :has() rules are baselined: the
  harness showed no subtree restyle and no cost beyond the sheet's size.
- A :has() rule the parser recovers past is reported, untracked CSS is
  checked locally, and the lint step runs earlier in the pool.
- Tests name the selector shapes they cover and include one real
  Tailwind compile of group-has-*.

Co-authored-by: Naufaldi <[email protected]>
- Build selector text only for findings; slicing the sheet per rule
  dominated the run. The import scan reads only files git grep finds.
- Skip :host(), whose argument is one selector, not a list.
- A subject whose top-level :is()/:where() branches all carry a class,
  id or attribute counts as specific.
- Drop the line-based "unparsed" report, which only misfired on
  minified vendor sheets.
- The import scan ignores comments, reads default/namespace imports and
  plain-CSS @imports, and skips local `@/` aliases. ?inline,
  template-literal, .js and relative node_modules imports stay uncovered.
- Uninstalled vendor packages print Node's message instead of a stack.
- Trim redundant test rows.

Co-authored-by: Naufaldi <[email protected]>
@nwparker
nwparker force-pushed the perf/remove-group-has-focus-visible-34312 branch from fd6c4e3 to 007a973 Compare October 29, 2026 21:13
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The runtime changes stay in renderer interactions, while the new check reaches renderer styling workflows.

The PR appears safe to merge, with a non-blocking request for import-scan regression tests.

Findings

  1. P2 Import scan lacks regression tests ▶

Summary

Replaces two broad Tailwind focus selectors with scoped selectors and removes a redundant TOC :has() condition.

  • SSH and reasoning controls reveal on keyboard focus without broad restyles.
  • The editor TOC header keeps its divider without a panel check.
  • Renderer style checks catch broad :has() selectors.

Acknowledged scope: nwparker explicitly identifies ?inline, template-literal, .js, and relative node_modules imports as not covered.

Reviews (1) · Last reviewed commit: "fix(lint): keep imports after URL string..." · Reviewed by Greptile

Comment on lines +29 to +35
const CSS_IMPORT =
/(?:\bimport\s*(?:[\w*{}\s,]+?\bfrom\s*)?\(?|@import\s+(?:url\()?)\s*(?:['"]([^'"]+\.css)['"]|([^'"()\s]+\.css)\s*\))/g
const IMPORT_SCAN = ['src/renderer/*.ts', 'src/renderer/*.tsx', ...PLAIN_CSS]
const LS_FILES = ['ls-files', '-z', '--cached', '--others', '--exclude-standard', '--']
const GREP_CSS = ['grep', '-lz', '--untracked', '-F', '.css', '--']
// Whole-line comments only: stripping mid-line `//` would eat imports after a URL string.
const COMMENT = /^\s*\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Import scan lacks regression tests

The new tests cover selectors and Tailwind compilation, but never exercise CSS_IMPORT, comment removal, or the missing-package check. A small regex change could silently leave a loaded stylesheet unchecked or reject a valid import. Add regression tests, especially for imports after URL strings and unquoted @import url(...).

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Markdown view scrolling is laggy on a large .md file with many Mermaid diagrams (~100 KB, 19 diagrams)

1 participant