fix(eslint-plugin): respect enableMediaQueryOrder in sort-keys - #1756
Open
gunjanjaswal wants to merge 1 commit into
Open
fix(eslint-plugin): respect enableMediaQueryOrder in sort-keys#1756gunjanjaswal wants to merge 1 commit into
gunjanjaswal wants to merge 1 commit into
Conversation
The sort-keys rule sorted `@media` condition keys alphabetically. When a project compiles with StyleX's `enableMediaQueryOrder`, overlapping media queries are resolved by source order (last matching query wins), so the alphabetical autofix inverted the cascade and made the wrong breakpoint win. Add an `enableMediaQueryOrder` rule option (default false, keeping current behavior). When enabled, the rule preserves the authored relative order of `@media` keys instead of sorting them alphabetically, while still sorting all other property keys. Fixes facebook#1416.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
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.
What
Adds an
enableMediaQueryOrderoption to the@stylexjs/sort-keysrule. When it is on, the rule keeps the authored order of@mediacondition keys instead of sorting them alphabetically. It defaults tofalse, so existing behavior is unchanged.Why
Fixes #1416. When a project compiles with StyleX's
enableMediaQueryOrder, overlapping media queries are resolved by source order, so the last matching query wins. Sorting@mediakeys alphabetically inverts that cascade. A correctly authoredmax-width: 768pxfollowed bymax-width: 640pxgets flipped by--fix, so mobile viewports pick up the tablet value. Right now the only workaround is wrapping every responsive property in aneslint-disableblock.How
All
@mediakeys share a single at-rule priority, so the comparator was falling through to an alphabetical tiebreak. With the option on, two media-query keys are treated as already ordered when reporting and compared as equal when autofixing (the sort is stable and falls back to the original index), so their source order is kept. Non-media keys still sort normally. This matches how the compiler orders queries by source order, and it can fall back to the #1407 breakpoint sort once that merges.Tests
Added regression tests to
stylex-sort-keys-test.js: valid cases for max-width and min-width cascades under the option, an invalid case confirming the default still reorders, and one confirming regular keys still sort with the option on.jest stylex-sort-keyspasses 59/59.