fix(compiler): read [class=…] from the prop the class list arrives on - #448
Open
YevheniiKotyrlo wants to merge 3 commits into
Open
YevheniiKotyrlo wants to merge 3 commits into
YevheniiKotyrlo wants to merge 3 commits into
Conversation
CSS 2.1 §5.8.1's own example is `span[class=example]`, and it matches nothing here: an attribute query built from the name `class` reads `props.class`, which no React Native element has, so every element answers false for every operator. The compiler already knows the mapping — a second class name in the same compound builds `["a", "className", "*=", name]` — so this routes both attribute-query build sites through one `attributePropName` rather than adding a third spelling of it.
This was referenced Sep 10, 2026
`[class=…]` is the headline case and the four cases covered `~=`, `*=`, presence and the `:is()` build site — so the mutation proof never exercised the operator in the title. The new case pins both directions of §6.1's exact match: the value it compares is the WHOLE class list, so `[class='test example']` matches `className="test example"` and `[class='example']` does not — the same answer a browser gives for `span[class=example]`.
Contributor
Author
The commit before this one is named `test(compiler)` and put its cases in src/__tests__/native/attributes.test.tsx, so the compiler plane had no coverage of a fix(compiler) change. A runtime test can only observe the RESULT of evaluating the query, which makes a wrong prop name and a wrong evaluation the same red. Seven cases over the emitted stylesheet: the four operators `class` reaches, plus a data-* and a plain attribute that must keep their own channels. Reverting selector-builder.ts reddens exactly the four class cases and leaves the other two green, so the set discriminates rather than merely coupling to the change.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
[class=…],[class~=…]and[class]match nothing, on every element. CSS 2.1 §5.8.1's own worked example isspan[class=example].An attribute query built from the name
classreadsprops.class. React Native delivers the class list asclassName, so the prop never exists and every operator answers false:.test[class~='example']<Text className="test example" />.test[class*='xamp'].test[class]Solution
One mapping, applied at both build sites. The compiler already knows it — a second class name in the same compound builds
["a", "className", "*=", name]— so this routes both sites throughattributePropNamerather than adding a third spelling.Tests
Five cases in
src/__tests__/native/attributes.test.tsx, covering=,~=,*=, presence, and the:is()build site. The=case pins both directions of Selectors 4 §6.1 exact matching — the value compared is the WHOLE class list, so[class='test example']matchesclassName="test example"and[class='example']does not, which is what a browser answers forspan[class=example]. Mutation-proved: makingattributePropNamethe identity turns all five red and nothing else.src/__tests__/compiler/attribute-selectors.test.tsx— 7 cases on the compiler plane. A runtime test observes the result of evaluating the query, so a wrong prop name and a wrong evaluation are the same red there; this reads the emitted query itself. Revertingselector-builder.tsreddens exactly the four[class…]operators and leaves thedata-*and plain-attribute cases green.Verification
yarn typecheckandyarn lintclean;yarn test1053 passed, 3 failed, 21 skipped. The three failures are two babel suites that fail identically on an untouchedmainworktree (Windows-only module-specifier rewrites) — this touches no babel file.Known limits
Independent of #447 — that one is what the operators do with a value, this is a name that never resolves. Both touch the same two build sites, so whichever lands second needs a trivial rebase. #449 is a third, same story.
Base
Branched off
f70c402.mainhas since taken #451 (a5002c5). 2 of the 2 files this changes also moved there, and 2 genuinely conflict —src/__tests__/native/attributes.test.tsx,src/compiler/selector-builder.ts. Every measurement above was taken onf70c402. Say the word and I will re-apply it onto currentmain.