Skip to content

Fix: Block pseudo-state styles incorrectly applied to default state#11226

Open
MaggieCabrera wants to merge 2 commits intoWordPress:trunkfrom
MaggieCabrera:fix-pseudo-styles-bug
Open

Fix: Block pseudo-state styles incorrectly applied to default state#11226
MaggieCabrera wants to merge 2 commits intoWordPress:trunkfrom
MaggieCabrera:fix-pseudo-styles-bug

Conversation

@MaggieCabrera
Copy link

@MaggieCabrera MaggieCabrera commented Mar 11, 2026

Backport for WordPress/gutenberg#76326
Core trac ticket: https://core.trac.wordpress.org/ticket/64838

What?

When a block defines a custom feature selector in its block.json (e.g. core/button uses .wp-block-button for writingMode rather than the root .wp-block-button .wp-block-button__link), styles set on a pseudo-state like :hover via theme.json were being output under the default-state selector instead of the pseudo-state selector.

Why?

This bug will become more apparent when there's a UI to change the state of the button block after WordPress/gutenberg#75627 lands.

How?

In get_block_nodes, the metadata node for a block pseudo-state was built with the original $feature_selectors (e.g. .wp-block-button) rather than the pseudo-scoped version (e.g. .wp-block-button:hover). The fix builds a $pseudo_feature_selectors array that appends the pseudo-selector to every feature selector string before the node is created.

We have added a test to catch this problem should there be a regression

Testing Instructions

Add writing mode to a button block on hover on theme.json, check the frontend and you will see the CSS generated:

Before:
:root :where(.wp-block-button) { writing-mode: vertical-rl; }

After:
:root :where(.wp-block-button:hover) { writing-mode: vertical-rl; }

The unit tests should all pass too

@github-actions
Copy link

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@MaggieCabrera MaggieCabrera marked this pull request as ready for review March 11, 2026 11:10
@github-actions
Copy link

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props onemaggie.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant