Skip to content

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

Merged
MaggieCabrera merged 6 commits intotrunkfrom
fix-block-pseudo-selector-feature-css
Mar 11, 2026
Merged

Fix: Block pseudo-state styles incorrectly applied to default state#76326
MaggieCabrera merged 6 commits intotrunkfrom
fix-block-pseudo-selector-feature-css

Conversation

@MaggieCabrera
Copy link
Copy Markdown
Contributor

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 #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
Copy Markdown

github-actions bot commented Mar 9, 2026

Flaky tests detected in e499c7e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22949653068
📝 Reported issues:

@MaggieCabrera MaggieCabrera marked this pull request as ready for review March 10, 2026 14:49
@MaggieCabrera MaggieCabrera self-assigned this Mar 10, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 10, 2026

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: MaggieCabrera <[email protected]>
Co-authored-by: mikachan <[email protected]>

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

@MaggieCabrera MaggieCabrera added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Mar 10, 2026
Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

This is testing well for me:

Image

I've left some other comments but I don't think either are blockers.

Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! This LGTM 👍

@MaggieCabrera MaggieCabrera enabled auto-merge (squash) March 11, 2026 11:43
@MaggieCabrera MaggieCabrera merged commit 149f9ab into trunk Mar 11, 2026
42 checks passed
@MaggieCabrera MaggieCabrera deleted the fix-block-pseudo-selector-feature-css branch March 11, 2026 11:52
@github-actions github-actions bot added this to the Gutenberg 22.8 milestone Mar 11, 2026
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] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants