Opened 3 weeks ago
Closed 3 days ago
#65929 closed defect (bug) (fixed)
Block Supports: Bail early in wp_render_block_states_support() when a block has no style attribute
| Reported by: | mukesh27 | Owned by: | westonruter |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1.1 |
| Component: | Editor | Version: | 7.1 |
| Severity: | normal | Keywords: | has-patch gutenberg-merge fixed-major dev-reviewed |
| Cc: | Focuses: | performance |
Description
wp_render_block_states_support() is hooked on render_block, so it runs once per block on every front-end request. Before it can determine that a block has no state styles, it resolves the block type from the registry, calls wp_get_global_settings( array( 'viewport' ) ), and computes responsive media queries:
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name ); $supported_pseudo_states = WP_Theme_JSON::VALID_BLOCK_PSEUDO_SELECTORS[ $block_name ] ?? array(); $style = $block['attrs']['style'] ?? array(); $css_rules = array(); $viewport_settings = wp_get_global_settings( array( 'viewport' ) ); $responsive_media_queries = WP_Theme_JSON::get_viewport_media_queries( $viewport_settings );
Most blocks on a page carry no style attribute, so all of this is discarded.
The viewport lookup is the costly part. Core's theme.json defines no viewport key, and wp_get_global_settings() falls back to _wp_array_get( $settings, $path, $settings ), so a missing path returns the entire settings array. sanitize_viewport_settings() then finds no mobile/tablet members, discards it, and rebuilds DEFAULT_VIEWPORT_BREAKPOINTS — two preg_match() calls and two media-query strings — for every block, on every request.
Every CSS rule this function can produce is keyed off $style, and the function already returns $block_content unchanged when $css_rules ends up empty. So resolving $style first and returning early when it is absent skips the above without changing behaviour.
Change History (12)
This ticket was mentioned in PR #13051 on WordPress/wordpress-develop by @mukesh27.
3 weeks ago
#2
- Keywords has-patch added; needs-patch removed
#3
@
2 weeks ago
- Milestone Awaiting Review → 7.1.1
Since Block State is a new feature in 7.1, this ticket can be addressed in a minor release.
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
2 weeks ago
This ticket was mentioned in Slack in #core by adrianduffell. View the logs.
4 days ago
#7
@
4 days ago
@westonruter - do want to own this one and get it committed before the RC next week?
#10
@
4 days ago
- Keywords fixed-major dev-feedback added
- Resolution fixed
- Status closed → reopened
@adamsilverstein Re-opening for 7.1 merge consideration.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/65929
## Use of AI Tools
Yes. For drafting the details.