Skip to content

Commit

Permalink
Editor: Revert caching of global styles for blocks.
Browse files Browse the repository at this point in the history
This reverts [58334] to fix a bug where edits to block styles made in the site editor were not showing in the front end.

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

Built from https://develop.svn.wordpress.org/trunk@58710


git-svn-id: http://core.svn.wordpress.org/trunk@58112 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
joemcgill committed Jul 12, 2024
1 parent 1287cb6 commit 897ec27
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
42 changes: 1 addition & 41 deletions wp-includes/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,44 +255,8 @@ function wp_add_global_styles_for_blocks() {

$tree = WP_Theme_JSON_Resolver::get_merged_data();
$block_nodes = $tree->get_styles_block_nodes();

$can_use_cached = ! wp_is_development_mode( 'theme' );
if ( $can_use_cached ) {
// Hash global settings and block nodes together to optimize performance of key generation.
$hash = md5(
wp_json_encode(
array(
'global_setting' => wp_get_global_settings(),
'block_nodes' => $block_nodes,
)
)
);

$cache_key = "wp_styles_for_blocks:$hash";
$cached = get_site_transient( $cache_key );
if ( ! is_array( $cached ) ) {
$cached = array();
}
}

$update_cache = false;

foreach ( $block_nodes as $metadata ) {

if ( $can_use_cached ) {
// Use the block name as the key for cached CSS data. Otherwise, use a hash of the metadata.
$cache_node_key = isset( $metadata['name'] ) ? $metadata['name'] : md5( wp_json_encode( $metadata ) );

if ( isset( $cached[ $cache_node_key ] ) ) {
$block_css = $cached[ $cache_node_key ];
} else {
$block_css = $tree->get_styles_for_block( $metadata );
$cached[ $cache_node_key ] = $block_css;
$update_cache = true;
}
} else {
$block_css = $tree->get_styles_for_block( $metadata );
}
$block_css = $tree->get_styles_for_block( $metadata );

if ( ! wp_should_load_separate_core_block_assets() ) {
wp_add_inline_style( 'global-styles', $block_css );
Expand Down Expand Up @@ -338,10 +302,6 @@ function wp_add_global_styles_for_blocks() {
}
}
}

if ( $update_cache ) {
set_site_transient( $cache_key, $cached, HOUR_IN_SECONDS );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-58709';
$wp_version = '6.7-alpha-58710';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 897ec27

Please sign in to comment.