Make WordPress Core


Ignore:
Timestamp:
07/12/2024 07:59:34 PM (2 years ago)
Author:
joemcgill
Message:

Editor: Revert caching of global styles for blocks.

This reverts [58334] to fix a bug where edits to block styles made in the site editor were not showing in the front end.

Reviewed by hellofromtonya.
Merges [58710] to the 6.6 branch.

Props joemcgill, spacedmonkey, andrewserong, hellofromtonya, audrasjb.
See #59595.

Location:
branches/6.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.6

  • branches/6.6/src/wp-includes/global-styles-and-settings.php

    r58334 r58711  
    308308        $tree        = WP_Theme_JSON_Resolver::get_merged_data();
    309309        $block_nodes = $tree->get_styles_block_nodes();
    310 
    311         $can_use_cached = ! wp_is_development_mode( 'theme' );
    312         if ( $can_use_cached ) {
    313                 // Hash global settings and block nodes together to optimize performance of key generation.
    314                 $hash = md5(
    315                         wp_json_encode(
    316                                 array(
    317                                         'global_setting' => wp_get_global_settings(),
    318                                         'block_nodes'    => $block_nodes,
    319                                 )
    320                         )
    321                 );
    322 
    323                 $cache_key = "wp_styles_for_blocks:$hash";
    324                 $cached    = get_site_transient( $cache_key );
    325                 if ( ! is_array( $cached ) ) {
    326                         $cached = array();
    327                 }
    328         }
    329 
    330         $update_cache = false;
    331 
    332310        foreach ( $block_nodes as $metadata ) {
    333 
    334                 if ( $can_use_cached ) {
    335                         // Use the block name as the key for cached CSS data. Otherwise, use a hash of the metadata.
    336                         $cache_node_key = isset( $metadata['name'] ) ? $metadata['name'] : md5( wp_json_encode( $metadata ) );
    337 
    338                         if ( isset( $cached[ $cache_node_key ] ) ) {
    339                                 $block_css = $cached[ $cache_node_key ];
    340                         } else {
    341                                 $block_css                 = $tree->get_styles_for_block( $metadata );
    342                                 $cached[ $cache_node_key ] = $block_css;
    343                                 $update_cache              = true;
    344                         }
    345                 } else {
    346                         $block_css = $tree->get_styles_for_block( $metadata );
    347                 }
     311                $block_css = $tree->get_styles_for_block( $metadata );
    348312
    349313                if ( ! wp_should_load_separate_core_block_assets() ) {
    … …  
    391355                }
    392356        }
    393 
    394         if ( $update_cache ) {
    395                 set_site_transient( $cache_key, $cached, HOUR_IN_SECONDS );
    396         }
    397357}
    398358
Note: See TracChangeset for help on using the changeset viewer.