Fix inconsistencies in feature selector processing part 1: global styles#78276
Conversation
|
Size Change: +272 B (0%) Total Size: 7.97 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 69245ba. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26132114597
|
98cbc49 to
f3b21c8
Compare
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| * @return array Array of pseudo-selector declarations. | ||
| */ | ||
| private static function process_pseudo_selectors( $node, $base_selector, $settings, $block_name ) { | ||
| private function process_pseudo_selectors( $node, $base_selector, $settings, $block_name, $block_metadata = null, $style_variation = null ) { |
There was a problem hiding this comment.
They should both fix all those cases, but #77868 just patches the existing hack; this one introduces get_block_style_variation_feature_selector to standardise the selector construction everywhere it's needed and tries to clean up the conditional cut-paste process of that construction as much as possible.
talldan
left a comment
There was a problem hiding this comment.
This tests well for me. A definite improvement. I think there's a couple of bits that could be tightened up to protect against weird selectors or other future changes in the code.
| } | ||
|
|
||
| $variation_class = ".is-style-$variation_name"; | ||
| $selector_parts = explode( ',', $feature_selector ); |
There was a problem hiding this comment.
This might fail if the selector has comma separated parts like wp-block:is(.foo, .bar).
I don't think there are any core blocks that have this issue though, but there might be third parties. List item block's border is an example of a near miss as it uses :not, but without a comma.
If there's a way to tighten it up to handle that case, it might be good to explore alongside a test case.
There was a problem hiding this comment.
I just pushed an update to fix this in 62ea6a9. It adds a splitting function that ensures only top-level commas (outside of brackets) are used for splitting, and some tests.
| $variation_path = $style_variation['path'] ?? array(); | ||
| $variation_name = is_array( $variation_path ) ? end( $variation_path ) : null; |
There was a problem hiding this comment.
Maybe it'd be possible to store $style_variation['name'] so that it doesn't have to be deconstructed from the path.
What?
Alternative to #77868
Also seeks to fix bad selectors in pseudo states for block instances.I'll leave that to another PR because there's no real overlap in the code changes.Testing Instructions
Use of AI Tools
Some use of GPT 5.5/codex