fix(compiler): drop a namespace-qualified attribute selector - #449
Open
YevheniiKotyrlo wants to merge 2 commits into
Open
YevheniiKotyrlo wants to merge 2 commits into
YevheniiKotyrlo wants to merge 2 commits into
Conversation
Selectors §6 — `[ns|att]` represents only attributes in `ns`. React Native has no namespaced props, so nothing can match, and `component.namespace` was discarded: every one of these compiled to the same query as the unqualified form and matched the unqualified set instead. An UNDECLARED prefix reaches the same path. lightningcss passes it through rather than rejecting it, and Selectors L3 §6.3.3 makes such a selector invalid, so a rule the author's own stylesheet says cannot apply was applying. `[att]`, `[|att]` and `[*|att]` are untouched — measured, the first two report no namespace and the third reports `any`, and with no namespaced props those three denote the same set.
This was referenced Sep 10, 2026
Contributor
Author
The runtime cases assert that no style reaches the element, which a DROPPED rule and an emitted-but-unmatchable one both produce. Only the compiler can say which happened, and the difference is whether the stylesheet carries a rule to every device that can never match. Seven cases: the three spellings naming no namespace still emit their rule, the two qualified spellings emit nothing, and a sibling rule beside a dropped one survives. Reverting selector-builder.ts reddens exactly the three drop cases.
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
component.namespaceis discarded, so a namespace-qualified attribute selector matches the unqualified set instead of nothing — including an undeclared prefix, which Selectors L3 §6.3.3 makes an invalid selector.Measured — all five forms compile to the identical query
["d", "x", "=", "a"]:[data-x='a'][|data-x='a'][*|data-x='a'][ns|data-x='a']with@namespace ns …ns[undeclared|data-x='a']The last row is the worse half: a rule the author's own stylesheet says cannot apply was applying. lightningcss reports the prefix rather than rejecting it, so dropping it is this compiler's job.
Solution
A specific namespace can never match, because no React Native prop carries one — so the selector is dropped, at both attribute build sites.
The first three rows are untouched and stay correct for a reason worth stating: with no namespaced props in the tree, "no namespace" and "any namespace" denote the same set, so
[*|att]needs no special handling.Tests
Five cases in
src/__tests__/native/attributes.test.tsx— the three that must keep matching, plus a declared and an undeclared prefix. Mutation-proved: making the predicatefalseturns exactly the last two red.src/__tests__/compiler/attribute-namespaces.test.tsx— 7 cases on the compiler plane. The runtime cases assert that no style reaches the element, which a DROPPED rule and an emitted-but-unmatchable one both produce; only the compiler says which, and the difference is whether the stylesheet ships a rule that can never match. Revertingselector-builder.tsreddens exactly the three drop cases.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 and #448, though all three touch the same two build sites — whichever lands last needs a trivial rebase.
Base
Branched off
f70c402.mainhas since taken #451 (a5002c5). 2 of the 2 files this changes also moved there, and 1 genuinely conflict —src/__tests__/native/attributes.test.tsx. Every measurement above was taken onf70c402. Say the word and I will re-apply it onto currentmain.