Skip to content

fix(extractor): let a later shorthand replace the longhands it covers - #978

Open
owjs3901 wants to merge 7 commits into
mainfrom
fix/css-later-shorthand-wins
Open

owjs3901 wants to merge 7 commits into
mainfrom
fix/css-later-shorthand-wins

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR is stacked on #974. It includes the commits of #974 (fix/sheet-longhand-after-shorthand). #974 must be merged first; until then the diff also shows #974's changes.

Drops an earlier longhand atom at the composition stage so that a later shorthand beats an earlier longhand (#688).

Problem

Change

  • Added css::property_order::covers(shorthand, property). It reads fix(sheet): write a longhand after every shorthand that covers it #974's shorthand table transitively. E.g. border covers border-top-width.
  • New module extractor::composition::shorthands
    • Reads a style object's declarations from the end.
    • Drops earlier longhand atoms covered by a shorthand in a later declaration.
  • Where it applies
    • css() objects, styled objects: the root object of extract_projected
    • Nested selector objects such as _hover
    • Box props: spread boundaries. A shorthand inside a later spread, or a shorthand in a prop after a spread, drops an earlier longhand. JSX props between two spreads don't drop each other (see below).
    • css() multi-argument composition: Composition::overlay. This is the existing "later argument wins" path.
  • As a result, the later shorthand wins regardless of sheet order.

JSX prop order is not treated as "authoring order"

Lint (perfectionist/sort-jsx-props) enforces alphabetical JSX props, so the order between props is not one the author chose. Applying the rule as-is makes gradient text like <Text backgroundClip="text" bg="linear-gradient(...)"> lose background-clip to background (confirmed by a screenshot regression in the landing DevupUICard). So props within the same spread segment are both kept, and #974's sheet order (longhand later) decides. Spread positions reflect authoring intent, so they are treated as boundaries.

Conditions for dropping (conservative)

An earlier longhand atom is dropped only when all of the following hold.

  • Both atoms are static values.
  • Both atoms apply unconditionally.
  • Selector, breakpoint, layer, and style order are the same.

In these cases both are kept and the sheet order (longhand later) decides.

  • Conditional values: on ? 1 : 3, the conditional side of css(a, cond && b)
  • Variable (dynamic) values
  • Different breakpoints: breakpoint 1 of borderTopWidth: [2, 3] is kept.
  • Different style order

globalCss / <Global> write declarations into one rule in the order written, so the later declaration already wins. So nothing is dropped there (same policy as #974).

Output changes

  • test_style_results_read_as_values snapshot
    • In css({ animationName, animation }) and <Box animationName {...{ animation }} />, the earlier animation-name atom is dropped.
    • This is an intended change.
  • static_numbers_when_css_prop_expands_keep_shorthands_and_unitless_values: mx came before margin, so margin-left was dropped. To keep the test's purpose (checking that mx numbers become px), the order was changed to margin, mx.
  • fix(sheet): write a longhand after every shorthand that covers it #974's extracted_longhands_win_over_shorthands Box case is left as is (with sorted Box props, the longhand wins).

Test plan

  • composition_shorthand_tests (20 cases)
    • Dropped cases
      • css() objects, transitive (border), place-items, styleOrder, nested _hover
      • css(b, {...}) composition
      • Spread after Box props, segment between spreads, Box _hover
      • styled.div, styled('div')
    • Kept cases
      • Longhand written later, different selector, different breakpoint, unrelated property
      • Box props in the same spread segment (including backgroundClip + bg gradient text)
      • Conditional shorthand/longhand, different style order
      • Dynamic values on both sides, globalCss
  • css::property_order::covers_what_a_shorthand_sets
  • cargo test -p extractor -p css -p sheet -p devup-ui-binding-core -p devup-ui-wasm --tests -j 2 passes
  • cargo clippy -p extractor -p css -p sheet --all-targets -- -D warnings, cargo fmt --all
  • CI coverage

#974 위에 쌓은 PR입니다. #974(fix/sheet-longhand-after-shorthand)의 커밋을 포함합니다. #974가 먼저 merge되어야 하며, 그 전까지 diff에는 #974의 변경도 함께 보입니다.

요약

뒤에 쓴 shorthand가 앞에 쓴 longhand를 이기도록(#688) 조합 단계에서 앞의 longhand atom을 뺍니다.

문제

  • fix(sheet): write a longhand after every shorthand that covers it #974 이후 sheet는 longhand를 그것을 덮는 shorthand 뒤에 씁니다. 그래서 순서와 관계없이 longhand가 이깁니다.
  • 그 결과 css({ borderTopWidth: 2, borderWidth: 1 })에서 앞에 쓴 border-top-width가 이겼습니다. #688의 "뒤에 쓴 스타일이 이긴다"와 맞지 않습니다.

변경

  • css::property_order::covers(shorthand, property)를 추가했습니다. #974의 shorthand 표를 전이적으로 읽습니다. 예: border는 border-top-width를 덮습니다.
  • 새 모듈 extractor::composition::shorthands
    • 스타일 객체의 선언을 뒤에서부터 읽습니다.
    • 뒤의 선언에 있는 shorthand가 덮는 앞의 longhand atom을 뺍니다.
  • 적용 위치
    • css() 객체, styled 객체: extract_projected의 루트 객체
    • _hover 같은 중첩 selector 객체
    • Box props: spread 경계. 뒤쪽 spread 안의 shorthand나 spread 뒤 속성의 shorthand가 앞의 longhand를 뺍니다. 두 spread 사이의 JSX 속성끼리는 서로 빼지 않습니다(아래 참고).
    • css() 다중 인자 조합: Composition::overlay. 기존 "later argument wins" 경로입니다.
  • 결과적으로 sheet 순서와 관계없이 뒤의 shorthand가 이깁니다.

JSX 속성 순서는 "작성 순서"로 보지 않음

lint(perfectionist/sort-jsx-props)가 JSX 속성을 이름순으로 강제하므로, 속성 사이의 순서는 작성자가 고른 순서가 아닙니다. 그대로 적용하면 <Text backgroundClip="text" bg="linear-gradient(...)"> 같은 gradient text가 background에 background-clip을 잃습니다(랜딩 DevupUICard 스크린샷 회귀로 확인). 그래서 같은 spread 구간의 속성끼리는 둘 다 남기고 #974의 sheet 순서(longhand가 뒤)가 결정합니다. spread 위치는 작성 의도이므로 경계로 봅니다.

빼는 조건 (보수적)

다음을 모두 만족할 때만 앞의 longhand atom을 뺍니다.

  • 두 atom이 모두 정적(static) 값입니다.
  • 두 atom이 모두 조건 없이 적용됩니다.
  • selector, breakpoint, layer, style order가 같습니다.

다음 경우에는 둘 다 남기고 sheet 순서(longhand가 뒤)가 결정합니다.

  • 조건부 값: on ? 1 : 3, css(a, cond && b)의 조건 쪽
  • 변수 값(dynamic)
  • 다른 breakpoint: borderTopWidth: [2, 3]의 1번 breakpoint는 남습니다.
  • 다른 style order

globalCss / <Global>은 선언을 쓴 순서대로 한 규칙에 쓰므로 이미 뒤의 선언이 이깁니다. 그래서 빼지 않습니다(#974와 같은 방침).

출력 변화

  • test_style_results_read_as_values 스냅샷
    • css({ animationName, animation })과 <Box animationName {...{ animation }} />에서 앞의 animation-name atom이 빠졌습니다.
    • 의도한 변화입니다.
  • static_numbers_when_css_prop_expands_keep_shorthands_and_unitless_values: mx가 margin보다 앞에 있어서 margin-left가 빠졌습니다. 테스트의 목적(mx 숫자를 px로 바꾸는지 확인)을 유지하려고 margin, mx 순서로 바꿨습니다.
  • #974의 extracted_longhands_win_over_shorthands Box 케이스는 원래대로 둡니다(정렬된 Box 속성에서는 longhand가 이김).

테스트 계획

  • composition_shorthand_tests (20 cases)
    • 빼는 경우
      • css() 객체, 전이(border), place-items, styleOrder, 중첩 _hover
      • css(b, {...}) 조합
      • Box 속성 뒤 spread, spread 사이 구간, Box _hover
      • styled.div, styled('div')
    • 남기는 경우
      • longhand를 나중에 쓴 경우, 다른 selector, 다른 breakpoint, 관계없는 속성
      • 같은 spread 구간의 Box 속성(backgroundClip + bg gradient text 포함)
      • 조건부 shorthand/longhand, 다른 style order
      • 양쪽 dynamic 값, globalCss
  • css::property_order::covers_what_a_shorthand_sets
  • cargo test -p extractor -p css -p sheet -p devup-ui-binding-core -p devup-ui-wasm --tests -j 2 통과
  • cargo clippy -p extractor -p css -p sheet --all-targets -- -D warnings, cargo fmt --all
  • CI 커버리지

Refs #688
Refs #690

🤖 Generated with Claude Code

owjs3901 and others added 2 commits November 15, 2026 23:24
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>
Now that the sheet writes a longhand after every shorthand covering it,
`css({ borderTopWidth: 2, borderWidth: 1 })` let the earlier longhand win.
A shorthand written later drops the earlier longhand's atom instead, so it
wins by construction whatever the sheet order:

- `css::property_order::covers` reads the shorthand table transitively.
- A style object's declarations (css(), styled objects, nested selectors)
  and Box attributes drop a longhand a later declaration's shorthand covers.
- css() composition drops it when a later part sets the shorthand.

Only static, unconditional atoms at the same selector, breakpoint, layer
and style order are dropped; conditional or dynamic values keep both, and
global rules keep their declarations in the order written.

Refs #688

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 and others added 2 commits November 16, 2026 08:33
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>
…-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>
…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>
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/css/src/property_order.rs 100.00% <ø> (ø)
libs/extractor/src/composition.rs 100.00% <100.00%> (ø)
libs/extractor/src/composition_shorthands.rs 100.00% <100.00%> (ø)
...tor/src/extractor/extract_style_from_expression.rs 100.00% <100.00%> (ø)
libs/extractor/src/lib.rs 100.00% <ø> (ø)
libs/extractor/src/visit.rs 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.

owjs3901 and others added 2 commits November 17, 2026 12:40
#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>
Pick up the #983 snapshot fix so CI runs against current main.

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