Repository navigation
fix: evaluate range pairs, and answer a condition the runtime cannot decide with unknown - #608
Merged
danstepanov merged 8 commits intoDec 4, 2026
Conversation
…decide with unknown Media and container queries now evaluate through one walk and one comparison in three-valued logic (MQ5 §3.1): a term the runtime cannot decide is unknown, its negation too, and a rule applies only when its condition is true, as in Chromium, Firefox and WebKit. - A range pair is its two comparisons, where both runtimes answered it false. - A term is unknown when its feature is unmeasured, its value is outside the feature's syntax (a keyword or a type Media Queries 5 does not give it, env(), a negative resolution or ratio component) or its operand is unresolved, which compiles to null so JSON carries it. A condition the compiler's unknown terms leave no way to be true compiles to no rule, as does a container condition CSS Conditional 5 §5.4 discards. - A number past the largest float compiles to the largest safe integer and a length to the same bound rounded, since JSON writes Infinity as null. - A feature in a boolean context is false only for zero, none and no-preference. - A viewport length in a condition resolves against the window. - hover, any-hover, pointer and any-pointer answer for the primary input, as Safari and Chrome do on a phone; color, color-index, monochrome, grid, scripting, update, overflow-block, overflow-inline, scan, color-gamut, dynamic-range and their video- forms answer as every React Native screen does, forced-colors as none off Windows, and -webkit-device-pixel-ratio as resolution. - A keyword and a media type match in any case. - A compiled condition is readonly at every depth, and the condition compiler reads lightningcss's AST through DeepReadonly.
The PR answers hover for the primary input, none on a touchscreen, which drops Tailwind's hover:, group-hover: and peer-hover: wherever a hover does arrive on iOS or Android (an iPad trackpad, a component that calls onHoverIn), unlike Nativewind v4 and every v5 release. Leaving hover unanswered would be worse: under three-valued logic (hover: hover) would be unknown, and hover: would apply nowhere. What hover should answer is left for later, so this keeps main's placeholder unchanged: every (hover: ...) comparison holds. any-hover and hover's boolean context go unanswered, as no Tailwind variant writes them. pointer and any-pointer keep answering for the primary input.
color, color-index, monochrome, grid, update, overflow-block, overflow-inline, scan, color-gamut, dynamic-range, their video- forms and -webkit-device-pixel-ratio go back to being unmeasured, and an <mq-boolean> compiles as before. No Tailwind variant queries any of them, so they are a feature of their own rather than part of evaluating a condition in three-valued logic. scripting and forced-colors stay: Tailwind's noscript: and forced-colors: reach them, and without an answer their not- forms would become unknown.
Drops safeNumber: a media number, resolution or calc() operand compiles as written again, and a length in a declaration keeps main's clamping. safeNumber changed stock Tailwind output (rounded-full's calc(infinity * 1px) went from 9007199254740991 to 9007199254740990) and covers only operands past the largest float, which no Tailwind variant writes. A viewport length lightningcss prints as an overflowing number, such as calc(NaN * 1vw), reaches a device as null and stays unknown, so its over-the-wire test row goes too.
Removes DeepReadonly, ReadonlyStyleDescriptor and the readonly tuples in MediaCondition, RenderGuard and the condition walkers, with condition-types.test.ts, which only checked them. They change no emitted code; MediaFeatureOperand keeps the shape a condition operand has. The container guard keeps the PR's honest type for a missing container, which the lint the PR enables on this file requires.
A condition still takes three values, since not unknown must stay unknown rather than become true, but undefined carries the third as well as a string did, so the Truth type and the UNKNOWN constant go.
Since nativewind#605 returns nothing from the visitor for an untouched rule, lightningcss no longer round-trips it through its serializer, which wrote -0 as 0. The operand now keeps its sign. It compares as 0, and JSON writes it as 0 for a device, so nothing renders differently.
With main's answer to every hover comparison kept, hover: and group-hover: apply whatever the platform, so the Mac Catalyst mock around those tests changed nothing, and the touchscreen tests repeated them on the iOS preset. The tests go back to main's layout, keeping the author's assertions that the colour is absent. The setup moves to the hover patch, where the platform decides the answer.
sammoore
force-pushed
the
fix/media-condition-unknown
branch
from
December 4, 2026 20:16
475a459 to
e2c0d89
Compare
danstepanov
approved these changes
Dec 4, 2026
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.
Supersedes #426, with some patches split out for separate review. See "Changes from the original PR" for details.
Problem
On
main:(400px < width < 800px)and every other intervalfalse.false, sonot (fictional-feature: 3)and@container not (orientation: bogus)apply everywhere. MQ5 §3.1 makes the term and its negation unknown, and Chromium, Firefox and WebKit apply neither.not ((width: env(safe-area-inset-top)) or (width > 9999px))applies, which no engine does.not (fictional-feature > 10px)applies.(width),(orientation),(scripting)(MQ5 §2.4.2).pointeris never answered, so(pointer: coarse)never matches on a phone.(prefers-color-scheme: DARK)and@media IOSnever match (css-values-4 §4.1, MQ4 §3).(min-resolution: -1dpi)applies on every screen, where css-values-4 §7.4 excludes it and the engines leave the feature unknown.(width > 50vw)never matches andnot (width: 100vw)always does.Solution
Media and container conditions evaluate through one walk,
evaluateCondition, and one comparison,compareMediaFeature, in three-valued logic (kleene.ts, MQ5 §3.1), withundefinedas unknown. A rule applies only when its condition istrue. A rule that the compiler's unknown terms leave no way to be true compiles to no rule.A term is unknown when:
env(), or a negative resolution or ratio component;nullsoJSON.stringifycarries it.A container condition that §5.4 discards compiles to no rule, as Chromium and WebKit drop it. A
style()query compiles to an unknown term.A viewport length in a condition resolves against the window (css-values-4 §6.1.2).
In a boolean context, zero,
noneandno-preferenceare false and every other value true.The runtime answers these features:
pointerandany-pointeranswer for the primary input (MQ5 §7.1), as Safari and Chrome do on a phone:coarseon iOS and Android,noneon a TV, andfineon Mac Catalyst and other platforms.scriptinganswersenabled.forced-colorsanswersnone, except on Windows (§12.4).prefers-reduced-motionis unknown untilAccessibilityInfoanswers.(hover: …)comparison holds, as onmain.any-hoverand a bare(hover)are unanswered.Under three-valued logic these answers keep Tailwind's
not-pointer-*:,not-noscript:andnot-forced-colors:applying.Keywords and media types fold to lowercase.
I changed #451's
container-rejectionexpectation thatnot ((width > 100px) and style(--theme: dark))applies at no width. At 50px the conjunction is false whateverstyle()answers, so its negation applies, as in all three engines.Tailwind impact
No stock Tailwind variant writes a range pair. I rendered 54 media variants and their
not-forms on iOS, Android, Mac Catalyst and a TV, in light, dark and system schemes, with motion unset,no-preferenceandreduce, idle and hovered. Againstmain:pointer-coarse:andany-pointer-coarse:apply on phones, and theirnot-forms stop applying.not-contrast-more:,not-contrast-less:andnot-inverted-colors:never apply, since React Native reports none of those settings.not-motion-safe:andnot-motion-reduce:don't apply untilAccessibilityInfoanswers.not-dark:doesn't apply aftercolorScheme.set("system")holdsnull, which fix(native): make colorScheme.set move every reader of the scheme #415 fixes.max-*,min-[…],portrait/landscape,print,dark:,motion-*,forced-colors:,noscript:,hover:andnot-hover:.Tests
compiler/condition-semantics.test.ts: what each condition that the native tests render compiles to, a value of another type, a condition lightningcss's types do not list, and the compiler's pruning against the runtime's answers.native/condition-semantics.test.tsx: each condition rendered on a screen or in a container, per platform where it differs, in memory and after a JSON round trip.compare.test.ts,kleene.test.tsandunits.test.tsxcover the shared helpers.vendor/tailwind/states.test.tsxandgroups.test.tsx:hover:andgroup-hover:on Mac Catalyst and on a touchscreen's platform. These and bothcontainer-queries.test.tsxassert the expected colour absent, astoHaveStyle(undefined)matched any style.main, 194 of the 550 cases in the twocondition-semanticsfiles andcontainer-rejection.test.tsxfail.Verification
yarn testpasses 2991 of 2991,yarn typecheckis clean, andyarn lintis clean apart fromnode/babel.mjs, which fails the same way onmainin a fresh checkout because it imports the unbuiltdist.bench/hermesis within noise againstmain, at −1.6% to +2.0% (mount, media query+0.3%), and memory is identical.Changes from the original PR
This is #426 rebased onto
main(now including #480, #605 and #607), with the author's commit kept intact and our changes as follow-up commits:main's answer, so Tailwind'shover:,group-hover:andpeer-hover:apply wherever a hover arrives, as in previous Nativewind releases.hovershould mean in React Native.color,color-index,monochrome,grid,update,overflow-block,overflow-inline,scan,color-gamut,dynamic-rangeand theirvideo-forms,-webkit-device-pixel-ratio, and<mq-boolean>compiling to an integer.NaN, and potentially changes output (even if barely). I want to reviewsafeNumberon its own to be sure it's the right shape.DeepReadonly, readonly tuples,condition-types.test.ts). They change no emitted code, and similar to the previous bullets, I want to review this refactor independently.undefined, not the string"unknown", so theTruthtype and theUNKNOWNconstant are gone.-0dppxcompiles to-0. Since fix(compiler): support lightningcss 1.30.2+ visitor deserialization #605, lightningcss no longer round-trips untouched rules through its serializer, which wrote-0as0. It compares as0and JSON sends it as0.Each of the first four bullets is a patch in the author's name that applies on its own to this branch, ready to be its own PR. The last two are changes to this branch and have no patch.
Source diff against
main: +772/−320 in 13 files as written → +650/−277 in 11 files.Known limits
(min-width)as(width)(parcel-bundler/lightningcss#1366).notof an equality range, sonot (width = 100vw)holds on every screen.calc(NaN)as an overflowing number, which a device reads as unresolved, so(width < calc(NaN * 1vw))is unknown there.(hover: …)comparison holds, as onmain, so(hover: none)matches too.color,color-index,monochrome,grid,update,overflow-*,scan,color-gamut,dynamic-rangeand theirvideo-forms, and-webkit-device-pixel-ratio.emin a media query and aremwithinlineRemoff are fix(compiler): read a media query's em and rem against the font size rem inlines #494's, a ratio is fix: evaluate aspect-ratio media and container queries #425's, and a heldnullcolor scheme is fix(native): make colorScheme.set move every reader of the scheme #415's.emin a container query, a math function, astyle()query, and the axes acontainer-typeallowsforced-colorson Windows, which react-native-windows'AppThemereportsprefers-contrast,prefers-reduced-transparencyandinverted-colorsdevice-widthanddevice-heightvwandvhPlatform.ios.js,Platform.android.js), so an attached mouse or stylus goes unseen.isMacCatalystis set at build time (RCTPlatform.mm), so an iPad app on a Mac answers as a touchscreen.isTVis always false (Platform.windows.js), so an Xbox answersfine.