Skip to content

Responsive global styles: use responsive nodes - #77881

Merged
talldan merged 3 commits into
try/responsive-global-block-stylesfrom
try/responsive-global-block-styles-with-media-query-nodes
May 4, 2026
Merged

talldan merged 3 commits into
try/responsive-global-block-stylesfrom
try/responsive-global-block-styles-with-media-query-nodes

Conversation

@talldan

@talldan talldan commented May 1, 2026

Copy link
Copy Markdown
Contributor

What?

Based on #77513 and merges into that branch

Tries a variation of the theme.json code in that branch.

Instead of looping through and building styles for responsive breakpoints inside get_styles_for_block, this PR instead tries assembling the breakpoint styles as nodes inside get_block_nodes.

Does so by adding a media_query property to a node, which when present get_styles_for_block will use to wrap the output styles.

… manual rendering

Responsive breakpoint states (mobile/tablet) are now represented as
first-class style nodes in get_block_nodes(), matching the existing
pattern used for pseudo states. This replaces ~160 lines of manual
breakpoint loops in get_styles_for_block() with a simple media_query
wrapper, reducing duplication and improving maintainability.
@talldan talldan self-assigned this May 1, 2026
@talldan talldan added the [Type] Code Quality Issues or PRs that relate to code quality label May 1, 2026
@talldan
talldan requested a review from tellthemachines as a code owner May 1, 2026 10:14
@talldan talldan added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label May 1, 2026
@talldan talldan changed the title Responsive global styles: responsive nodes Responsive global styles: use responsive nodes May 1, 2026
@github-actions

github-actions Bot commented May 1, 2026 •

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@tellthemachines tellthemachines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this LGTM! It reduces a lot of the duplication and works well in testing 🎉

$nodes[] = array(
'name' => $name,
'path' => array( 'styles', 'blocks', $name, $breakpoint ),
'media_query' => static::RESPONSIVE_BREAKPOINTS[ $breakpoint ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere we've been using viewport, though in #77513 we also use media_query as an option to get_layout_styles. Should we standardise on one of these? viewport is already used for block visibility too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think media_query is ok here, as it does represent the media query string for the generated css.

Comment thread lib/class-wp-theme-json-gutenberg.php Outdated
// 8. Wrap the entire block output in a media query if this is a responsive node.
// Responsive nodes are created by get_block_nodes() for each breakpoint and carry
// a 'media_query' key. This replaces the previous manual responsive sections that
// duplicated rendering logic for each breakpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can probably remove the last sentence if we're merging this into #77513 😄

@tellthemachines

Copy link
Copy Markdown
Contributor

It should be fine to merge into #77513 even if the tests are failing? I don't think those failures are related to this changeset. One of them is I think related to the changes in #77513 but we can fix it there.

@talldan
talldan merged commit c919c21 into try/responsive-global-block-styles May 4, 2026
36 of 38 checks passed
@talldan
talldan deleted the try/responsive-global-block-styles-with-media-query-nodes branch May 4, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants