Skip to content

Commit 240afe3

Browse files
Try storing global styles in static var in layout render (#74828)
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: andrewserong <[email protected]>
1 parent 7bc31f7 commit 240afe3

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

backport-changelog/7.0/10766.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ https://github.com/WordPress/wordpress-develop/pull/10766
22

33
* https://github.com/WordPress/gutenberg/pull/74725
44
* https://github.com/WordPress/gutenberg/pull/74795
5+
* https://github.com/WordPress/gutenberg/pull/74828
56

lib/block-supports/layout.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ function gutenberg_unique_id_from_values( array $data, string $prefix = '' ): st
631631
* @return string Filtered block content.
632632
*/
633633
function gutenberg_render_layout_support_flag( $block_content, $block ) {
634+
static $global_styles = null;
635+
634636
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
635637
$block_supports_layout = block_has_support( $block_type, array( 'layout' ), false ) || block_has_support( $block_type, array( '__experimentalLayout' ), false );
636638
// If there is any value in style -> layout, the block has a child layout.
@@ -897,8 +899,10 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
897899

898900
// Get default blockGap value from global styles for use in layouts like grid.
899901
// Check block-specific styles first, then fall back to root styles.
900-
$block_name = $block['blockName'] ?? '';
901-
$global_styles = gutenberg_get_global_styles();
902+
$block_name = $block['blockName'] ?? '';
903+
if ( null === $global_styles ) {
904+
$global_styles = gutenberg_get_global_styles();
905+
}
902906
$global_block_gap_value = $global_styles['blocks'][ $block_name ]['spacing']['blockGap'] ?? ( $global_styles['spacing']['blockGap'] ?? null );
903907

904908
if ( null !== $global_block_gap_value ) {

packages/block-editor/src/hooks/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ export const withLayoutStyles = createHigherOrderComponent(
439439
const { getSettings, getBlockSettings } = unlock(
440440
select( blockEditorStore )
441441
);
442-
const { disableLayoutStyles } = getSettings();
442+
const settings = getSettings();
443+
const { disableLayoutStyles } = settings;
443444

444445
if ( disableLayoutStyles ) {
445446
return;
@@ -452,7 +453,6 @@ export const withLayoutStyles = createHigherOrderComponent(
452453

453454
// Get default blockGap value from global styles for use in layouts like grid.
454455
// Check block-specific styles first, then fall back to root styles.
455-
const settings = getSettings();
456456
const globalStyles = settings[ globalStylesDataKey ];
457457
const globalBlockGapValue =
458458
globalStyles?.blocks?.[ name ]?.spacing?.blockGap ??

0 commit comments

Comments
 (0)