CSS-Library: use postcss to reorder media queries#2072
Conversation
|
I attempted to resolve this by updating the _uswds-theme.scss config like this: But since we are not changing the names of the other breakpoints they they already exist in the USWDS map and the result was the same. |
|
postcss-sort-media-queries consolidates media queries, which is an unexpected optimization. Here is what that means:
|
|
USWDS PR to fix root issue here: uswds/uswds#6610 |
There was a problem hiding this comment.
Pull request overview
This PR updates the css-library build pipeline to reorder generated media queries to be mobile-first (addressing a breakpoint override issue caused by USWDS appending custom media queries at the end).
Changes:
- Add PostCSS tooling and configuration to sort media queries (
postcss-sort-media-queries). - Update
css-librarybuild scripts to run PostCSS after Sass compilation. - Regenerate
dist/CSS outputs (and associated token timestamps/source maps) to reflect the new ordering.
Reviewed changes
Copilot reviewed 2 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds PostCSS-related dependencies to the repo lockfile. |
| packages/css-library/yarn.lock | Adds PostCSS-related dependencies to the css-library lockfile. |
| packages/css-library/postcss.config.js | New PostCSS config enabling mobile-first media query sorting. |
| packages/css-library/package.json | Updates build scripts to run PostCSS; adds PostCSS dependencies; bumps version. |
| packages/css-library/dist/tokens/scss/variables.scss | Regenerated token output (timestamp update). |
| packages/css-library/dist/tokens/css/variables.css | Regenerated token output (timestamp update). |
| packages/css-library/dist/stylesheets/uswds-typography.css.map | Regenerated stylesheet source map reflecting PostCSS processing. |
| packages/css-library/dist/stylesheets/uswds-typography.css | Regenerated stylesheet output (formatting/order updates). |
| packages/css-library/dist/stylesheets/shame.css.map | Regenerated stylesheet source map reflecting PostCSS processing. |
| packages/css-library/dist/stylesheets/shame.css | Media queries reordered/combined per mobile-first sort. |
| packages/css-library/dist/stylesheets/mobile-typography.css.map | Regenerated stylesheet source map reflecting PostCSS processing. |
| packages/css-library/dist/stylesheets/mobile-typography.css | Regenerated stylesheet output (formatting/order updates). |
| packages/css-library/dist/stylesheets/core.css.map | Regenerated stylesheet source map reflecting PostCSS processing. |
| packages/css-library/dist/stylesheets/core.css | Media queries reordered/relocated per mobile-first sort. |
jamigibbs
left a comment
There was a problem hiding this comment.
This looks good although copilot brings up a question about generated source maps that we might want to verify when you test the release candidate.
Chromatic
https://6069-overwrite-media-query-ordering--65a6e2ed2314f7b8f98609d8.chromatic.com
Summary
Reorders media-queries on build and minify to be mobile first, resolves issue with medium breakpoints overwriting desktop
Description
USWDS appends custom media-queries to the end of the generated media-queries, since the css-library has a custom "medium" query, it was being added after other media-queries causing it to overwrite desktop and widescreen breakpoints. This fix adds postcss to re-order the media-queries after build.
Related tickets and links
Closes #6069
Screenshots
Before

After

Testing and review
Provide any testing instructions or review steps as needed.
Approvals
See the QA Checklists section below for suggested approvals. Use your best judgment if additional reviews are needed. When in doubt, request a review.
Approval groups
Add approval groups to the PR as needed:
QA checklists
Use the QA checklists below as guides, not rules. Not all checklists will apply to every PR but there could be some overlap.
In all scenarios, changes should be fully tested by the author and verified by the reviewer(s); functionality, responsiveness, etc.
✨ New Component Added
minorlabel🌱 New Component Variation Added
minorlabel🐞 Component Fix
patchlabel♿️ Component Fix - Accessibility
patchlabel🚨 Component Fix - Breaking API Change
majorlabel🔧 Component Update - Non-Breaking API Change
minorlabel📖 Storybook Update
ignore-for-releaselabel🎨 CSS-Library Update
css-librarylabel