Repository navigation
State Styles: Scope per-instance rules to the block's root element - #14039
aaronrobertshaw wants to merge 1 commit into
Conversation
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. |
|
Hey, @aaronrobertshaw What is the status of this backport PR? Are there any other blockers, or does this just need a review/approval? |
|
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. |
…ment. When a block's root selector starts with another block's class, such as List Item's `.wp-block-list > li`, scoping swapped that leading compound for the instance class and produced `.wp-states-xxxx > li`, which matches nothing. The instance class is on the block's own wrapper, so keep a leading compound that names a different block as an ancestor and put the instance class on the block's own compound. A leading compound followed by a `wp-block-*` class still describes a nested element, so those selectors keep the existing swap.
c45346d to
f3d7805
Compare
|
Sorry @Mamaduka I missed this at the end of last week. I've rebased. There are no blockers, we just need a review and approval 🙏 |
There was a problem hiding this comment.
🟢 Approval recommended
The localized fix includes targeted regression coverage, with no unresolved review findings.
No open issues 🎉
What changed in this PR
Fixes per-instance state styles for blocks such as List Item whose selectors begin with an ancestor block’s class.
Changes:
- Preserves ancestor selectors while placing the instance class on the block’s own element.
- Passes the block name into selector scoping.
- Adds selector and responsive-style regression tests.
| File | Description |
|---|---|
| tests/phpunit/tests/block-supports/states.php | Tests ancestor scoping, registered selectors, and responsive styles. |
| src/wp-includes/block-supports/states.php | Adds ancestor detection and block-aware selector scoping. |
Review effort: Balanced
ramonjd
left a comment
There was a problem hiding this comment.
Faithful backport of WordPress/gutenberg#83986.
Tests pass with --group 66252.
The List Item turns pink below 480px on the front end.
On trunk it doesn't.
Button hover still works.
I also ran every core block selector through the new scoping.
Only List Item's output changes.
Nice 👋
Backport of Gutenberg PR WordPress/gutenberg#83986
Trac ticket: https://core.trac.wordpress.org/ticket/66252
Per-instance state styles never applied to a block whose root selector starts with another block's class. List Item registers
.wp-block-list > li, so scoping swapped.wp-block-listfor the instance class and emitted.wp-states-xxxx > li, which matches nothing. The instance class is on theliitself.This PR backports:
wp_get_state_selector_ancestor()that returns the leading compound and its combinator when that compound names a different block,$block_nameparameter onwp_build_state_selector()so the ancestor is kept and the instance class lands on the block's own compound,core/list-item's registered selectors rather than a literal.Testing instructions
Only the front end can be exercised here, since the editor half is not in Core yet.
:hoveris not a valid state for List Item (WP_Theme_JSON::VALID_BLOCK_PSEUDO_SELECTORSlists Button and Navigation Link only), so use a breakpoint state.Without the patch the same markup emits
.wp-states-9f0f8a0d > li, which matches nothing, so the item stays its normal colour at any width.:hovercolour the same way and confirm it still works.Use of AI
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: the mechanical port and the test port; I reviewed and verified both.