Skip to content

fix: keep extracted longhands from being reset by leftover shorthands - #499

Closed
dyk1454683243-sudo wants to merge 2 commits into
css:masterfrom
dyk1454683243-sudo:cursor/fix-shorthand-restructure-478-44b7
Closed

dyk1454683243-sudo wants to merge 2 commits into
css:masterfrom
dyk1454683243-sudo:cursor/fix-shorthand-restructure-478-44b7

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Problem

After restructure, a longhand that appears after a shorthand in the source can be pulled into a shared rule that sits before leftover shorthands. The later shorthand resets the longhand in the browser.

Minimal repro from #478:

.a {
    background: none;
    background-size: 1;
    b: c;
}
.b {
    background: some;
    background-size: 1;
    b: c;
}

Previously became:

.a,.b{background-size:1;b:c}.a{background:0 0}.b{background:some}

background then wipes background-size.

The same class of bug shows up with border / border-bottom (#417) and with all.

Root cause

8-restructRuleset extracts equal declarations into a new shared rule. For the usual merge-up path that rule is inserted before both leftovers. compareDeclarations only compares declaration identity — it does not know that background resets background-size.

Fix

  • Add a shorthand → atomic longhand map (lib/restructure/propertyFamily.js), in the same spirit as the unfinished property-family branch.
  • compareDeclarationsSafe refuses to extract a declaration when a leftover unique would sit on the other side of it and reset its atoms:
  • Unrelated equals still merge. Safe subset-before merges (background then background-size) are unchanged. Different !important flags make order irrelevant, so those longhands can still be extracted.
  • all is treated as resetting every property except unicode-bidi and direction.

Tests

  • fixtures/compress/restructure.merge/issue-478*.css — issue repro, shared unrelated props, subset after / before, !important, all
  • fixtures/compress/restructure.merge/issue-417.css — border-bottom / border
  • test/propertyFamily.js — overlap / reset helpers

npm test: 549 passing, 4 pending
npm run lint: clean

Fixes #478

Related: #196, #417

cursoragent and others added 2 commits September 20, 2026 19:31
Cover the css#478 background-size wipe, the same-class css#417 border case,
and guards for !important, subset-before, and `all`.

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
When restructRuleset pulls equal declarations into a shared rule, a
longhand such as background-size can end up before a leftover
background shorthand and get reset in the browser.

Refuse to extract a declaration when a remaining unique shorthand
would sit after it (or when an extracted shorthand would sit after a
remaining longhand) and reset its atoms. Unrelated equals still merge.
Fixes css#478.

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
@dyk1454683243-sudo

Copy link
Copy Markdown
Author

Withdrawing this PR while I clean up a high-volume open-PR backlog. Sorry for the noise — happy to come back later with a focused change if useful.

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.

A bug with restructuring and shorthands

2 participants