Make WordPress Core

Changeset 63474


Ignore:
Timestamp:
09/04/2026 05:41:47 PM (6 weeks ago)
Author:
westonruter
Message:

Editor: Skip state styles for blocks without a style attribute.

The wp_render_block_states_support() function is hooked on render_block, so it runs once per block on every front-end request. Before it could determine that a block has no state styles, it resolved the block type from the registry, called wp_get_global_settings(), and computed responsive media queries; all of this work is discarded for the overwhelming majority of blocks, which carry no style attribute at all.

Every CSS rule the function can produce is keyed off the block's style attribute, and the function already returns the content unchanged when no rules are generated. Resolving style first and returning early when it is absent is therefore behavior-preserving.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13051 and ​https://github.com/WordPress/gutenberg/pull/81908.
Follow-up to r62453, r62671.

Props mukesh27, westonruter, adamsilverstein, wildworks.
Fixes #65929.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/states.php

    r63426 r63474  
    543543        }
    544544
     545        /*
     546         * Every CSS rule this function can produce is keyed off the block's `style`
     547         * attribute. Without it there is nothing to generate, so bail before doing
     548         * any of the lookups below — this runs for every block on every request.
     549         */
     550        $style = $block['attrs']['style'] ?? array();
     551        if ( empty( $style ) || ! is_array( $style ) ) {
     552                return $block_content;
     553        }
     554
    545555        $block_name = $block['blockName'];
    546556        $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
    … …  
    550560
    551561        $supported_pseudo_states  = WP_Theme_JSON::VALID_BLOCK_PSEUDO_SELECTORS[ $block_name ] ?? array();
    552         $style                    = $block['attrs']['style'] ?? array();
    553562        $css_rules                = array();
    554563        $viewport_settings        = wp_get_global_settings( array( 'viewport' ) );
Note: See TracChangeset for help on using the changeset viewer.