Repository navigation
Commit c85f246
feat(css): join rules a third stands between, behind an option (#21969)
* feat(css): join rules a third stands between, behind an option
`mergeDistantRules` gives a rule the selectors of a later one printing the
same block, past the rules standing between them — sound only where nothing
between declares a property that block does, since such a rule won before the
merge and would lose after it.
Which properties those are is read from a table the generator derives from
`mdn-data`, not from the property name: not every shorthand prefixes its
longhands, so `inset` sets `top` and `font` sets `line-height` under no
prefix at all.
Off by default. Over the framework stylesheets it cuts 2457 raw bytes and
costs 27 gzip ones.
Co-authored-by: aryanraj45 <[email protected]>
* test(css): add the new option to the CLI flags snapshot
The flags are derived from the schema, so a property under
`optimization.minimize.css` adds one entry there and one under
`optimization.minimizeOptions.css`.
* fix(css): record a rule flushed by an at-rule it cannot join
A top-level node that is not a rule the printer can join — `@keyframes`,
`@font-face` — is written out on its own path, and that path also writes out
the rule waiting behind it. Neither was noted, so a later rule could take its
selectors past declarations that were never recorded: with `.a{color:red}
.b{color:blue} @Keyframes k{…} .c{color:red}`, `.c` joined `.a` and an element
matching `.b` and `.c` read blue where it had read red. Over five framework
stylesheets that path writes out a held rule 58 times.
The note now happens inside `_emitHeld`, so every path that flushes one
records it, and a node this cannot see into is noted as declaring everything.
Reported by CodeRabbit on #21969.
* perf(css): release what the distant-rule tables hold after a print
Each holds a piece of the stylesheet just printed, so the last one printed
stayed reachable until the next parse replaced the maps. They are emptied
with the other per-parse buffers now, and cleared rather than replaced at
setup, which allocates nothing per parse.
Also covers the merge inside a block, which the unit tests reached only
through the stylesheet's own stream: the same gates asked a second way.
Reported by CodeRabbit on #21969.
---------
Co-authored-by: aryanraj45 <[email protected]>1 parent f01f902 commit c85f246
17 files changed
Lines changed: 1282 additions & 11 deletions
File tree
- .changeset
- declarations
- lib/css
- schemas
- test
- __snapshots__
- configCases/css/minimize-merge-distant-rules
- __snapshots__
- tooling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2459 | 2459 | | |
2460 | 2460 | | |
2461 | 2461 | | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
2462 | 2467 | | |
2463 | 2468 | | |
2464 | 2469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
0 commit comments