Skip to content

fix(eslint-plugin): respect enableMediaQueryOrder in sort-keys - #1756

Open
gunjanjaswal wants to merge 1 commit into
facebook:mainfrom
gunjanjaswal:fix/1416-sort-keys-media-query-cascade
Open

fix(eslint-plugin): respect enableMediaQueryOrder in sort-keys#1756
gunjanjaswal wants to merge 1 commit into
facebook:mainfrom
gunjanjaswal:fix/1416-sort-keys-media-query-cascade

Conversation

@gunjanjaswal

Copy link
Copy Markdown

What

Adds an enableMediaQueryOrder option to the @stylexjs/sort-keys rule. When it is on, the rule keeps the authored order of @media condition keys instead of sorting them alphabetically. It defaults to false, 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 @media keys alphabetically inverts that cascade. A correctly authored max-width: 768px followed by max-width: 640px gets flipped by --fix, so mobile viewports pick up the tablet value. Right now the only workaround is wrapping every responsive property in an eslint-disable block.

How

All @media keys 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-keys passes 59/59.

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.
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
stylex Skipped Skipped Jul 13, 2026 2:39am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 13, 2026

@nmn nmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@stylexjs/sort-keys ESLint rule breaks max-width media query cascade when using enableMediaQueryOrder

2 participants