Editor: order viewport breakpoints only against a comparable base - #12948
Editor: order viewport breakpoints only against a comparable base#12948jigneshbhavani wants to merge 2 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
68578bd to
75d766d
Compare
Media queries resolve em and rem against the initial font size, so a px breakpoint cannot be ordered against a font-relative one. Keep tablet only when both breakpoints share a base, matching how it is already dropped when it is not larger than mobile. See #65833.
75d766d to
34994cc
Compare
Co-Authored-By: Claude <noreply@anthropic.com>
|
@jigneshbhavani Thanks for the PR! I have submitted a similar PR to Gutenberg. WordPress/gutenberg#81388 Let's ask for opinions on this approach. Also, I made minor code refactoring and test changes in 4d14624. |
WP_Theme_JSON::sanitize_viewport_settings()proves thattabletis larger thanmobileusing values normalized at a hardcoded 16px, butget_viewport_media_queries()emits the authored units. A media query resolvesemandremagainst the initial font size rather than anything set on the page, so the ordering proven at 16px does not transfer to the browser when the two breakpoints are measured against different bases.With
mobile: 30em, tablet: 500pxthe guard passes because 30 x 16 = 480 < 500, and core emits@media (30em < width <= 500px). Above a 16px base that range is empty, and@media (width <= 30em)and@media (width > 500px)begin to overlap instead, so two viewport states apply at once.emandremshare a base in a media query, so they can be ordered against each other. Apxlength and a font-relative one cannot, at any base. This addsget_viewport_breakpoint_base()and keepstabletonly when both breakpoints are measured against the same base, dropping it in the mixed case exactly as it is already dropped when it is not larger thanmobile.No new string, so it is available after hard string freeze.
settings.viewportis new in 7.1 and unreleased, so no existing theme depends on the current behavior.Approach agreed with wildworks in comment:3. The warning message requested there is a follow-up rather than part of this change, since it needs a translatable string.
Gutenberg mirrors this logic in
packages/global-styles-engine/src/utils/viewport.tsandlib/class-wp-theme-json-gutenberg.php, so the editor preview needs the same change upstream. Not part of this PR.Testing instructions
In a theme's
theme.json:{ "version": 3, "settings": { "viewport": { "mobile": "30em", "tablet": "500px" } } }Add a paragraph with block visibility set to hide on tablet, then view the post. Before this change the page emits
@media (30em < width <= 500px). After it,tabletis not a configured breakpoint and only the mobile query is emitted.mobile: 30em, tablet: 40remkeeps both breakpoints, since those share a base.Trac ticket: https://core.trac.wordpress.org/ticket/65833
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Investigation, browser measurements, drafting the change and the tests. I
reviewed, tested and take responsibility for everything in this pull request.