Repository navigation
perf(renderer): drop group-has-[:focus-visible] rules that restyle whole subtrees - #36098
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
…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]>
…url() in the :has() guard Co-authored-by: Naufaldi <[email protected]>
fd6c4e3 to
007a973
Compare
[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
SummaryReplaces two broad Tailwind focus selectors with scoped selectors and removes a redundant TOC
Acknowledged scope: Reviews (1) · Last reviewed commit: "fix(lint): keep imports after URL string..." · Reviewed by Greptile |
| 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 |
There was a problem hiding this comment.
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!
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.cssblur 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
SshTargetCardand 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.rich-markdown-editor.cssdrops a redundant:has()on the TOC header. Defence in depth; close to neutral once (a) lands.check-has-restyle-scope.mjscompiles 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.:is,:where,:notand:nth-child(of).:has(+ …)/:has(~ …)count as sibling-only.?inline, template-literal,.jsand relative node_modules imports.pnpm lint,check:changedand PR CI, in about 1.5 s.Measurements (hidden Electron 43.8.1, real compiled Tailwind, ~8.3k-node DOM, per iteration):
Verified:
@import url()) are fixed in the last commit.