-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create media query transformer to ensure last query wins #898
base: media-query-parser-simplify
Are you sure you want to change the base?
Conversation
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
774212d
to
a165bd6
Compare
a165bd6
to
a211a64
Compare
a211a64
to
3f67953
Compare
3f67953
to
e29d33b
Compare
e29d33b
to
a4032ec
Compare
a4032ec
to
f9f0d63
Compare
f9f0d63
to
8fa00d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "last wins" mean exactly in this context? FWIW, the "last wins" approach to property merging in StyleX is only true for properties with the same name. The way we handle short/long form merging (inc within a single style object) is really problematic and something we're trying to undo. So if last-wins for MQ is a local concern within a style, I'm concerned that will also be problematic. Anything that relies on order of keys in authored code is going to have those problems
const expectedStyles = { | ||
gridColumn: { | ||
default: '1 / 2', | ||
'@media (max-width: 1440px) and (not (max-width: 1024px)) and (not (max-width: 768px))': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be concerned at how bloated generated code gets with this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a work in progress where we will be simplifying the media queries as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the doc here provides a bit more context - https://docs.google.com/document/d/1KlMnWz__zVBNcH_HQmd64sPEFf6AdaXeG46rL_eU5ec/edit?tab=t.uwqdsvafq1l7#heading=h.m5zrpmurwti
the plan is to eventually rewrite the media query parser to do the simplification step for us, or to pass this return to another fn to do a second round of parsing
packages/style-value-parser/src/at-queries-from-tokens/__tests__/media-query-transform-test.js
Show resolved
Hide resolved
56c7fe9
to
2187f31
Compare
8fa00d5
to
9154ba7
Compare
9154ba7
to
d244fde
Compare
d244fde
to
3d234fa
Compare
b90123c
to
0d5a240
Compare
3d234fa
to
464c2c6
Compare
464c2c6
to
30a458b
Compare
updated implementation to ensure object key ordering is preserved |
create media query transformer to ensure “last query wins” logic
Context
Now that we have a usable media query parser in #743, we can finally implement last media query wins logic.
Implementation
High level approach: traverse through styles, search for media queries, do two passes at each node - one to build up a list of negations for each query, and another to apply the negation.
traverse nested styles with dfs
iterate media queries in reverse order
accumulate negations
-backwards, for single pass
MediaQuery.parser.parseToEnd
to convert query string into object representationMediaQuery.toString()
Testing
Use
json.stringify
to ensure object key order is maintainedScenarios like:
Missing:
Pre-flight checklist
Contribution Guidelines