Skip to content

fix(extractor): let later StyleX keys override an include() - #975

Merged
owjs3901 merged 1 commit into
mainfrom
fix/stylex-include-override
Nov 17, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
fix/stylex-include-override

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keys written after ...stylex.include(base.member) inside stylex.create() now override the included values. This is resolved statically at build time (#688).

Problem

  • When s0.a is { color: 'red', margin: '1px' }, { ...stylex.include(s0.a), color: 'blue' } resulted in "margin red blue".
    • Both the red and blue classes were attached.
    • So red could win depending on CSS order.
  • The included classes were always put first, so the position where include() was written was also ignored.
    • Example: in { color: 'blue', ...stylex.include(s0.a) }, by StyleX's rules the included red should win.
  • Namespaces with an include had no key information. So stylex.props(s.x, other) did not merge per key (later-wins) and just concatenated classes.

Changes

  • Added position to StylexIncludeRef. It is the number of keys written before include().
  • When a namespace and the namespaces it includes are all static, keys are merged in written order (merge_included_keys).
    • A later key replaces the same key.
    • Nested includes, multiple includes, and condition keys like ':hover' all follow the same rule.
    • The namespace's className is the classes of the merged keys.
  • The merged keys are recorded in stylex_keys, so stylex.props() also resolves this namespace per key.
  • Dynamic (arrow function) namespaces have no keys. Including one puts its classes first, as before. StyleX does not support including dynamic styles in the first place.
  • Docs: changed the include() explanation in apps/landing/src/app/(detail)/docs/migration/stylex/page.mdx. It states that overriding is guaranteed at build time, and the dynamic namespace exception.

Snapshot changes

  • stylex_include_basic: "fancy": "a b c" became "b a c".
    • Only the order of the class tokens changed, because it follows the key order (color, fontSize, backgroundColor).
    • The generated CSS and the set of classes are the same.
  • Fixed the props(s.red, s.inc) case of test_stylex_props_merge_keys to check the actual result.
    • The old expected value color-0-red--255 matched on the s.red definition line, so it was effectively not a check.
    • It now checks { className: "margin-0-1px--255 color-0-green--255" }. Red is dropped.

Overlapping PRs

Test plan

  • Reproduced on main first. test_stylex_include_later_declarations_override failed.
    • "margin red blue"
    • A later include was ignored
    • Duplicate margin with nested includes
    • The :hover key was not replaced
  • 7 cases in test_stylex_include_later_declarations_override
    • Later key, later include, include vs. include, nested include, condition key, key resolution through props(), dynamic include fallback
  • cargo test -p extractor --tests -j 2 all pass
  • cargo clippy -p extractor --all-targets -- -D warnings, cargo fmt --all
  • bunx prettier --single-quote --no-semi --check (mdx)
  • CI coverage

요약

stylex.create() 안의 ...stylex.include(base.member) 뒤에 쓴 key가 포함된 값을 덮어쓰도록 바꿨습니다. 빌드 타임에 정적으로 해결합니다(#688).

문제

  • s0.a가 { color: 'red', margin: '1px' }일 때 { ...stylex.include(s0.a), color: 'blue' }의 결과는 "margin red blue"였습니다.
    • red와 blue class가 둘 다 붙었습니다.
    • 그래서 CSS 순서에 따라 red가 이길 수 있었습니다.
  • 포함된 class를 항상 앞에 붙였기 때문에 include()를 쓴 위치도 무시됐습니다.
    • 예: { color: 'blue', ...stylex.include(s0.a) }에서는 StyleX 기준으로 포함된 red가 이겨야 합니다.
  • include가 있는 namespace는 key 정보가 없었습니다. 그래서 stylex.props(s.x, other)에서 key별 병합(later-wins)이 되지 않고 class만 이어 붙였습니다.

변경

  • StylexIncludeRef에 position을 추가했습니다. include() 앞에 쓴 key 개수입니다.
  • namespace와 그것이 포함하는 namespace가 모두 static이면 key를 작성 순서대로 병합합니다(merge_included_keys).
    • 뒤의 key가 같은 key를 대체합니다.
    • 중첩 include, 여러 include, ':hover' 같은 조건 key 모두 같은 규칙입니다.
    • namespace의 className은 병합된 key의 class입니다.
  • 병합된 key를 stylex_keys에 기록합니다. 그래서 stylex.props()도 이 namespace를 key 단위로 해결합니다.
  • 동적(arrow function) namespace는 key가 없습니다. 이것을 include하면 이전처럼 class를 앞에 붙입니다. StyleX는 원래 동적 스타일의 include를 지원하지 않습니다.
  • 문서: apps/landing/src/app/(detail)/docs/migration/stylex/page.mdx의 include() 설명을 바꿨습니다. 덮어쓰기가 빌드 타임에 보장된다는 것과 동적 namespace 예외를 적었습니다.

스냅샷 변경

  • stylex_include_basic: "fancy": "a b c"가 "b a c"로 바뀌었습니다.
    • class 토큰의 순서만 바뀌었습니다. key 순서(color, fontSize, backgroundColor)를 따르기 때문입니다.
    • 생성된 CSS와 class 집합은 같습니다.
  • test_stylex_props_merge_keys의 props(s.red, s.inc) 케이스를 실제 결과로 검사하도록 고쳤습니다.
    • 기존 기대값 color-0-red--255는 s.red 정의 줄에서 매칭되어 사실상 검사가 아니었습니다.
    • 이제 { className: "margin-0-1px--255 color-0-green--255" }를 확인합니다. red가 빠집니다.

겹치는 PR

테스트 계획

  • main에서 먼저 재현했습니다. test_stylex_include_later_declarations_override가 실패했습니다.
    • "margin red blue"
    • 뒤에 쓴 include가 무시됨
    • 중첩 include에서 margin 중복
    • :hover key가 대체되지 않음
  • test_stylex_include_later_declarations_override 7개 케이스
    • 뒤의 key, 뒤의 include, include끼리, 중첩 include, 조건 key, props()를 통한 key 해결, 동적 include fallback
  • cargo test -p extractor --tests -j 2 전체 통과
  • cargo clippy -p extractor --all-targets -- -D warnings, cargo fmt --all
  • bunx prettier --single-quote --no-semi --check (mdx)
  • CI 커버리지

Refs #690
Refs #688

🤖 Generated with Claude Code

`{ ...stylex.include(s0.a), color: 'blue' }` prepended the included
classes to the namespace's own, so both the red and the blue class were
applied and red could win by stylesheet order. An include() written after
a key was prepended too, so its position was ignored.

Each include() now records how many keys come before it. When the
namespace and every namespace it includes are static, their keys are
merged in written order, a later key replacing the same key from before,
and the namespace gets the merged classes. Its keys are also recorded,
so stylex.props() resolves it per key instead of joining classes. A
dynamic namespace has no keys, so including one keeps prepending.

The StyleX migration page says the override now holds.

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 Δ
...tractor/src/extractor/extract_style_from_stylex.rs 100.00% <100.00%> (ø)
libs/extractor/src/lib.rs 100.00% <ø> (ø)
libs/extractor/src/stylex.rs 100.00% <ø> (ø)
libs/extractor/src/visit.rs 100.00% <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
owjs3901 merged commit 20ccc83 into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/stylex-include-override branch November 17, 2026 05:56
owjs3901 added a commit that referenced this pull request Nov 17, 2026
#975 now lets keys written after include() override the included ones; keep this PR's legacy-include framing and state the new override rule instead of the old 'only added' caveat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
visit.rs imports both main's include() key merging (StylexIncludeRef,
joined_key_classes, merge_included_keys from #975) and this branch's
typed_variable_rule; the two touch separate code paths and merged
cleanly otherwise. The StyleX migration page keeps main's include()
override rule and adds this branch's note that types.*() registers
@Property in defineVars().

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