Repository navigation
Sort rem/em media-query breakpoints within their unit - #1964
Open
gunjanjaswal wants to merge 1 commit into
Open
gunjanjaswal wants to merge 1 commit into
gunjanjaswal wants to merge 1 commit into
Conversation
collectWidthBounds only accepted px (or zero), so rem/em min-/max-width breakpoints got no sort key and fell through to source order. When they come from defineConsts, that leaves a rem cascade in declaration order rather than ascending, breaking last-wins resolution (reported on meta#1756). Carry the unit on WidthBound and compare only within a unit: two rem (or two px) bounds keep their order for any root font size, so they sort by value, while px and rem are grouped separately rather than interleaved by their bare numbers (which would need a root size that isn't known at build time). px-only output is unchanged. Updates the deterministic-order snapshot, whose rem queries now participate in the sort.
|
@gunjanjaswal is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
Quick note on the red checks for anyone reviewing. The |
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.
Summary
Media-query breakpoints in
rem/emweren't being sorted, so a rem-based responsive cascade could come out in declaration order instead of ascending — which breaks last-wins resolution. This came up in #1756 (thanks @davidhellmann for the clean repro).collectWidthBoundsinprocessStylexRulesonly produced a sort key when the bound's unit waspx(or0); rem/em returnednull, so those queries fell through to source order. When the breakpoints come fromdefineConsts, that's where it bites:Output today — rem block is reversed, so at ≥90rem the 48rem rule wins:
The fix
Carry the unit on
WidthBoundand compare only within a unit. Two bounds in the same unit keep their order for any root font size (scaling by a positive constant preserves order), so rem sorts against rem and em against em exactly like px does. Different units are kept in separate blocks rather than interleaved by their bare numbers — px and rem genuinely aren't comparable without a root size that isn't known at build time, so grouping is the honest behavior rather than assuming1rem = 16px.Tests
does not sort rem breakpoints→sorts rem breakpoints by value within the rem unit.groups px and rem breakpoints by unit, each ascending.sort is deterministic regardless of input ordersnapshot updates because its rem queries now take part in the sort; all three input orders still produce identical output.Full
transform-processsuite passes (44 tests), Flow and Prettier clean.