Repository navigation
Conversation
The native media query parser only understood the `(feature: value)` form, so range queries such as `(width >= 600px)`, `(600px <= width)` or `(400px < width < 800px)` threw "Invalid CSS media query" during render, while StyleX compiles them on web. Parse the range forms in `parseQuery` and turn them into the existing min/max expressions. `<` and `>` use new exclusive `lt`/`gt` modifiers. Refs react#531
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.
Fixes #531.
Summary
The native media query parser (
src/native/modules/mediaQuery.js, from css-mediaquery) only understands(feature: value). A range query like'@media (width >= 600px)'hits theSyntaxErrorinparseQuery, and sinceresolveStyledoes not catch it, the component throws during render. On web the same key works, because the StyleX compiler turns it intomin-width/max-width.This change keeps the existing parsing path and only falls back to a new range regex when
RE_MQ_EXPRESSIONdoes not match. The range forms become the expressionsmatchQueryalready knows:(width >= 600px)/(600px <= width)→min(width <= 600px)/(600px >= width)→max(width > 600px)/(width < 600px)→ newgt/ltmodifiers, compared with>/<(width = 600px)→ equality(400px <= width < 800px)→ two expressions on the same featureThese still throw: a
min-/max-prefix combined with an operator ((min-width >= 600px)), intervals whose operators point in opposite directions ((400px < width > 800px)), and a missing feature or value.One small difference from web: StyleX writes
(width > 600px)asmin-width: 600.01px, while native compares exactly (width > 600). Both agree for whole-number dimensions.How I found it
I was reading the native style resolution path (
resolveStyle→mediaQueryMatches→mediaQuery.match) and noticed thatRE_MQ_EXPRESSIONrequiresfeaturefollowed by an optional: value. Range syntax has no colon, so it cannot match. I compiled'@media (width >= 600px)'with the StyleX babel plugin from the lockfile (0.18.3) to confirm web accepts it, then rendered the same style with the native jest project, which threwInvalid CSS media query: "(width >= 600px)".Where this can show up in practice
This is my estimate; I have not seen a field report.
(width >= …)for web. Any native component that uses them fails to render, not only the one rule.Test
src/native/modules/__tests__/mediaQuery-test.js: each operator at the boundary (e.g. width exactly 600 for>=vs>), the value-first form, intervals,emunits,aspect-ratio,not screen and (...), and the invalid range forms that should still throw. The existing tests are unchanged.range syntaxblock totests/css/css-create-queries-test.native.js.SyntaxError. After it,npm testpasses on macOS (node 24): flow reports no errors, eslint is clean, and jest is 907 passed with 2 skipped, with the coverage thresholds met.prettier --checkis clean on the changed files.