Skip to content

fix(sheet): write a longhand after every shorthand that covers it - #974

Merged
owjs3901 merged 2 commits into
mainfrom
fix/sheet-longhand-after-shorthand
Nov 17, 2026
Merged

owjs3901 merged 2 commits into
mainfrom
fix/sheet-longhand-after-shorthand

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Changed the sheet ordering so that, within the same selector and the same breakpoint, a longhand rule always comes after the shorthands that cover it.

Problem

  • Under StyleX's default policy (property-specificity), a longhand beats a shorthand regardless of order.
  • The devup sheet wrote rules within the same group in alphabetical order of property name. So the shorthand won in cases like these:
    • border-width came after border-top-width
    • place-items came after align-items
  • It only worked where alphabetical order happened to be right, such as padding/padding-top.
  • This ordering is the shared sheet path (prop_cmp), so it was not a StyleX-only problem. Box props, css(), styled and the compat APIs all had the same problem. There was no existing code that ordered by a shorthand's "level".

Changes

  • Added a new css::property_order.
    • It holds a table of CSS shorthands and the properties each one directly sets. It covers border, margin, padding, inset, place-, flex, grid, font, background, mask, transition, animation, scroll-, and more.
    • The sort key is (the largest name among itself and every shorthand that covers it, the depth of coverage, the name).
    • So a covered property moves to just after its last shorthand, and unrelated properties keep their current alphabetical order.
    • all goes first.
  • prop_cmp (ordering of class rules and at-rule rules) uses this order.
    • Order layers (@layer oN) and breakpoint groups are unchanged. The order changes only within those groups.
    • Class names do not change.
  • globalCss follows authoring order, so it was not changed.

Output changes

  • No byte changes in existing Rust snapshots. None of the sheet, binding-core or wasm snapshots had a shorthand and its longhand appearing in reverse order in the same group.
  • In user CSS, covered longhands move after their shorthand. Example: the align-items rule moves after display, right after place-items.
    • This move only reorders unrelated properties relative to each other. The cascade result changes only for shorthand/longhand pairs.

Out of scope

Overlapping PRs

Test plan

  • Reproduced first with tests that fail on main. The border-width/border-top-width and place-items/align-items cases of longhand_rule_follows_its_shorthand failed.
  • sheet::longhand_rule_follows_its_shorthand
    • Checked in the default group, a hover selector, and a breakpoint inside @layer o1.
    • The result is the same with insertion order flipped in both directions.
  • sheet::extracted_longhands_win_over_shorthands: checked by actually extracting StyleX props() and Box props.
  • css::property_order
    • Checks that every (shorthand, covered property) pair in the table comes first transitively.
    • Individual cases are checked with rstest.
  • cargo test -p css -p sheet -p devup-ui-binding-core -p devup-ui-wasm --tests -j 2 passes
  • cargo clippy -p css -p sheet --all-targets -- -D warnings, cargo fmt --all
  • CI coverage

요약

같은 selector, 같은 breakpoint 안에서 longhand 규칙이 그것을 덮는 shorthand보다 항상 뒤에 오도록 sheet의 정렬을 바꿨습니다.

문제

  • StyleX 기본 정책(property-specificity)에서는 순서와 관계없이 longhand가 shorthand를 이깁니다.
  • devup sheet는 같은 묶음 안의 규칙을 속성 이름 알파벳 순으로 썼습니다. 그래서 다음처럼 shorthand가 이겼습니다.
    • border-width가 border-top-width 뒤에 옴
    • place-items가 align-items 뒤에 옴
  • padding/padding-top처럼 알파벳 순이 우연히 맞는 경우만 동작했습니다.
  • 이 정렬은 sheet 공통 경로(prop_cmp)라서 StyleX만의 문제가 아니었습니다. Box props, css(), styled, compat API 모두 같은 문제가 있었습니다. 기존에 shorthand의 "level"에 따라 정렬하는 코드는 없었습니다.

변경

  • css::property_order를 새로 추가했습니다.
    • CSS shorthand와 그것이 직접 설정하는 속성 표를 담습니다. border, margin, padding, inset, place-, flex, grid, font, background, mask, transition, animation, scroll- 등이 들어 있습니다.
    • 정렬 키는 (자신과 자신을 덮는 모든 shorthand 이름 중 가장 큰 것, 덮이는 깊이, 이름)입니다.
    • 그래서 덮이는 속성은 마지막 shorthand 바로 뒤로 가고, 서로 관계없는 속성은 지금처럼 알파벳 순을 유지합니다.
    • all은 맨 앞에 둡니다.
  • prop_cmp(class 규칙과 at-rule 규칙 정렬)가 이 순서를 씁니다.
    • order layer(@layer oN)와 breakpoint 묶음은 그대로입니다. 순서는 그 묶음 안에서만 바뀝니다.
    • class 이름은 바뀌지 않습니다.
  • globalCss는 작성 순서를 따르므로 바꾸지 않았습니다.

출력 변화

  • 기존 Rust 스냅샷에는 바이트 변화가 없습니다. sheet, binding-core, wasm 스냅샷 중 shorthand와 그 longhand가 같은 묶음에서 역순으로 나오던 경우가 없었습니다.
  • 사용자 CSS에서는 덮이는 longhand가 shorthand 뒤로 이동합니다. 예: align-items 규칙이 display 뒤, place-items 바로 뒤로 갑니다.
    • 이 이동은 서로 관계없는 속성끼리의 순서만 바꿉니다. cascade 결과는 shorthand/longhand 쌍에서만 달라집니다.

범위 밖

  • devup 자체 경로에서 "뒤에 쓴 shorthand가 앞의 longhand를 이긴다"([전수조사/A] 조합 우선순위: 뒤에 쓴 스타일이 이기게 (빌드 타임 정적 해결) #688)는 이번 변경과 별개입니다.
    • 예: css({ borderTopWidth: 2, borderWidth: 1 })
    • 이전에는 알파벳 순서 덕분에 우연히 그렇게 동작했습니다. 이제는 sheet 순서상 longhand가 이깁니다.
    • 정적으로 해결하려면 앞의 atom을 빼는 조합 단계가 필요합니다.
  • StyleX 추출기가 shorthand에 찍는 [stylex] WARNING: Shorthand property ... 경고는 그대로 뒀습니다. #915가 같은 파일을 크게 바꾸기 때문입니다.

겹치는 PR

테스트 계획

  • main에서 실패하는 테스트로 먼저 재현했습니다. longhand_rule_follows_its_shorthand의 border-width/border-top-width, place-items/align-items 케이스가 실패했습니다.
  • sheet::longhand_rule_follows_its_shorthand
    • 기본 묶음, hover selector, @layer o1 안의 breakpoint에서 확인합니다.
    • 삽입 순서를 양방향으로 바꿔도 결과가 같습니다.
  • sheet::extracted_longhands_win_over_shorthands: StyleX props()와 Box props를 실제로 추출해서 확인합니다.
  • css::property_order
    • 표의 모든 (shorthand, 덮이는 속성) 쌍이 전이적으로 앞에 오는지 확인합니다.
    • 개별 케이스는 rstest로 확인합니다.
  • cargo test -p css -p sheet -p devup-ui-binding-core -p devup-ui-wasm --tests -j 2 통과
  • cargo clippy -p css -p sheet --all-targets -- -D warnings, cargo fmt --all
  • CI 커버리지

Refs #690
Refs #688

🤖 Generated with Claude Code

Atomic rules of one selector and breakpoint were sorted by property
name, so `border-width` came after `border-top-width` and `place-items`
after `align-items`, and the shorthand won. StyleX's default
property-specificity policy, and atomic CSS generally, let a longhand win
regardless of order.

css::property_order lists each CSS shorthand and the properties it sets.
A property sorts under the greatest name among itself and its covering
shorthands, then by how deeply it is covered, so it lands right after
its last shorthand while unrelated properties keep their alphabetical
order. `all` sorts first. The sheet uses this order for class and
at-rule declarations of every source, not only StyleX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/css/src/lib.rs 100.00% <ø> (ø)
libs/css/src/property_order.rs 100.00% <100.00%> (ø)
libs/sheet/src/lib.rs 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

No conflicts. main's sheet changes (rm_file and the stylesheet stack
from #951) merge beside the property_order sort in prop_cmp; the css,
sheet, binding-core, wasm and extractor tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
…-wins

No conflicts. Brings in main through #974's merge; the shorthand
composition in the extractor merges beside main's stylesheet stack and
removeFile changes, and the css, sheet, extractor, binding-core and
wasm tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 16, 2026
Brings in main through #974 and #978. In the vite, rsbuild, webpack and
bun plugins, the setupWarning (#945) imports and main's
createNodeModulesExcludeRegex sit beside normalizeStylexOptions, and
styleResolution is still set next to registerShorthands wherever main
configures the engine.

The ABI now has 31 names: main's removeFile plus
setStylexStyleResolution. Updated the count in script.js, the consumer,
the native README and typings, and compiler-types (30 without Output).
Validation covers 47 positions in 20 functions (276 cases), and the
summary reports 20 functions. The e2e host lists both names and
counts 27 corpus scenarios.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
…overs

The lint sorts JSX attributes by name (perfectionist/sort-jsx-props), so
their order is not the order the author chose: `backgroundClip` always
comes before `bg`. Treating it as written order dropped the
`background-clip: text` atom of `<Text backgroundClip="text"
bg="linear-gradient(...)" />`, which broke the gradient text of the
landing DevupUICard and its mobile benchmark screenshot.

Attributes between two spreads now replace none of each other's
longhands, and the sheet order (a longhand after its shorthands) decides
as in #974. A spread keeps its place: a shorthand in a later spread or in
the attributes after a spread still replaces an earlier longhand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit 88f3df1 into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/sheet-longhand-after-shorthand branch November 17, 2026 02:47
owjs3901 added a commit that referenced this pull request Nov 17, 2026
#974 landed on main as a squash, so its files came in as add/add
conflicts. property_order.rs keeps this branch's
version (#974's table plus covers()); sheet/lib.rs keeps main (with
#961's token tests) and only re-sorts the Box test props.
extract_style_from_expression.rs imports both main's
descendants and this branch's LaterDeclarations. The
style_results_read_as_values snapshot takes main's __devupStyled
wrapper (#958) on top of this branch's dropped animation-name atoms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Brings in main through the base branch. Its merge with main (0e409e3,
9f46158) already resolved property_order.rs,
extract_style_from_expression.rs, the style_results_read_as_values
snapshot and sheet/lib.rs against #974, so this merge applies cleanly
and origin/main adds nothing beyond it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant