Skip to content

fix: preserve cascading order for @container queries (#1798) - #1802

Open
hum4nBeing wants to merge 2 commits into
facebook:mainfrom
hum4nBeing:fix/container-query-order
Open

fix: preserve cascading order for @container queries (#1798)#1802
hum4nBeing wants to merge 2 commits into
facebook:mainfrom
hum4nBeing:fix/container-query-order

Conversation

@hum4nBeing

Copy link
Copy Markdown

Fixes #1798

Description

Currently, @container queries do not preserve their cascading order because the lastMediaQueryWinsTransform logic in @stylexjs/shared strictly looks for @media prefixes, completely bypassing container queries.

This PR fixes the issue by:

  1. Expanding the Parser (style-value-parser): Updated atRuleNameParser in media-query.js to accept the @container keyword alongside @media. (The existing range-syntax machinery already natively handles >= and <= operators).
  2. Fixing Serialization: Updated the AST formatter to preserve the original at-rule name so it serializes back to @container instead of rewriting to @media.
  3. Refactoring the Transformer (shared): Extracted the sorting, negation, and range-slicing logic into a reusable helper function (applyQueryOrder) inside media-query-transform.js, and applied it sequentially to both @media and @container query families.

By routing container queries through this deterministic pipeline, they are correctly converted into mutually exclusive ranges. This guarantees that container rules never collide, making physical CSS injection order irrelevant—which aligns perfectly with StyleX's atomic CSS architecture.

Test Plan

  • Added new regression tests to parse-media-query-test.js verifying that @container (width >= 360px) successfully parses into a valid AST shape.
  • Added regression test cases to media-query-transform-test.js verifying that multiple container queries are correctly sorted and transformed into mutually exclusive ranges.
  • Ran test suites to confirm all existing and new tests pass successfully.

@meta-cla

meta-cla Bot commented Aug 9, 2026

Copy link
Copy Markdown

Hi @hum4nBeing!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel

vercel Bot commented Aug 9, 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 Ignored Ignored Aug 9, 2026 9:11pm

Request Review

@hum4nBeing
hum4nBeing force-pushed the fix/container-query-order branch from 4041a7e to ea2fec1 Compare August 9, 2026 21:01
@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 Aug 9, 2026
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.

Container query order is not preserved.

1 participant