Editor: Render theme.json element styles defined only inside a breakpoint - #12926
Editor: Render theme.json element styles defined only inside a breakpoint#12926ramonjd wants to merge 1 commit into
Conversation
…oint. Element styles written inside @mobile or @tablet in theme.json now produce CSS whether or not the same element is also styled outside the breakpoint. Previously, WP_Theme_JSON::get_block_nodes() only looped over elements present under styles.blocks.<block>.elements, so an element styled only inside a breakpoint never produced a node and no CSS was output. Backports WordPress/gutenberg#81265. See #65829.
|
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. |
|
looks like #12918 already has these changes and those in the follow-up PR |
|
Closing in favour of #12918 |
My robot puts these up 😄 Closed in favour of @talldan's |
What
Element styles written inside
@mobileor@tabletin theme.json now produce CSS whether or not the same element is also styled outside the breakpoint.Backport of WordPress/gutenberg#81265.
Trac ticket: https://core.trac.wordpress.org/ticket/65829
Why
WP_Theme_JSON::get_block_nodes()looks for a block's elements understyles.blocks.<block>.elementsand emits the breakpoint nodes from inside that loop. An element styled only inside a breakpoint is never looped over, so no node is created and no CSS is output. Adding a style for the same element outside the breakpoint makes the breakpoint rule appear, which made the bug look theme-dependent rather than like a missing loop.What changed
get_block_nodes()collects element names from the block node and from each breakpoint before looping, so an element styled only inside a breakpoint still gets a node.@mobile, only a pseudo state in@mobile, and styles split across@mobileand@tablet. All three fail without the source change.Manual testing
{ "version": 3, "styles": { "blocks": { "core/group": { "@mobile": { "elements": { "link": { "color": { "text": "red" } } } } } } } }@media (width <= 480px){:root :where(.wp-block-group a:where(:not(.wp-element-button))){color: red;}}."elements": { "link": { "color": { "text": "blue" } } }next to@mobileand confirm both the default rule and the media query rule appear.