Block Supports: Guard elements hover rendering against missing hover selector#79511
Conversation
|
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. |
|
Flaky tests detected in f4c170d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28149287568
|
ramonjd
left a comment
There was a problem hiding this comment.
Nice find. I didn't test, but it's clear from the code that the guard makes sense since we're trying to access 'selector' => $element_config['hover_selector'], from within the condition block.
Only render `:hover` element styles for element types that actually define a hover selector. In `wp_render_elements_support_styles()`, only the `link` element type defines a `hover_selector`. If a block's `style.elements` carries a `:hover` object for `button` or `heading`, accessing `$element_config['hover_selector']` reaches for a key that does not exist, emitting an "Undefined array key 'hover_selector'" warning and passing an empty selector to the style engine. Add a `! empty( $element_config['hover_selector'] )` guard so hover processing is skipped for element types without a hover selector, and extend the elements styles test with a `button` `:hover` case that confirms only the base rule is emitted. Backport of Gutenberg PR WordPress/gutenberg#79511. Props aaronrobertshaw. See #65538.
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
|
I'll get this merged. I had overlooked an outdated regex in the test backported to core but that should all be good now. |
…selector (WordPress#79511) Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
What?
Related: #77894
Only render
:hoverelement styles for element types that actually define a hover selector.Why?
In
gutenberg_render_elements_support_styles(), only thelinkelement type defines ahover_selector. If a block'sstyle.elementscarries a:hoverobject forbuttonorheading, the code reaches for$element_config['hover_selector']on a type that doesn't have it. That emits an "Undefined array key 'hover_selector'" warning and passes an empty selector to the style engine.It's hard to reach through the default UI, but the attribute data can be persisted on a block directly, so the warning stands on its own.
How?
Testing Instructions
WP_Block_Supports_Elements_Testshould pass