@@ -1124,4 +1124,68 @@ public function test_layout_support_flag_with_non_string_class_name() {
11241124 'Layout support should render the expected markup when className is not a string '
11251125 );
11261126 }
1127+
1128+ /**
1129+ * Tests that layout support returns early, without resolving global settings,
1130+ * for a block that cannot produce any layout output.
1131+ *
1132+ * Resolving global settings reads the user's `wp_global_styles` post with a
1133+ * `WP_Query`, which fires `the_posts`. A callback on that hook that renders
1134+ * blocks re-enters this filter, so the bail-out has to happen before the
1135+ * lookup or the recursion has no base case.
1136+ *
1137+ * @ticket 65741
1138+ *
1139+ * @covers ::wp_render_layout_support_flag
1140+ */
1141+ public function test_layout_support_flag_returns_early_before_resolving_global_settings () {
1142+ $ user_data_resolutions = 0 ;
1143+ add_filter (
1144+ 'wp_theme_json_data_user ' ,
1145+ static function ( $ theme_json ) use ( &$ user_data_resolutions ) {
1146+ ++$ user_data_resolutions ;
1147+ return $ theme_json ;
1148+ }
1149+ );
1150+
1151+ // A block with no layout support and no child layout, as produced by
1152+ // parsing content that has no block delimiters.
1153+ $ block_content = '<p>Not a block.</p> ' ;
1154+ $ block = array (
1155+ 'blockName ' => null ,
1156+ 'attrs ' => array (),
1157+ );
1158+
1159+ // Start from a cold cache, as on a front-end request.
1160+ wp_clean_theme_json_cache ();
1161+
1162+ $ this ->assertSame (
1163+ $ block_content ,
1164+ wp_render_layout_support_flag ( $ block_content , $ block ),
1165+ 'Block content should be returned unchanged when the block has no layout support. '
1166+ );
1167+ $ this ->assertSame (
1168+ 0 ,
1169+ $ user_data_resolutions ,
1170+ 'Global settings should not be resolved for a block that cannot produce layout output. '
1171+ );
1172+
1173+ // A block that does support layout still resolves global settings, which
1174+ // confirms the assertion above is not passing because of a warm cache.
1175+ wp_clean_theme_json_cache ();
1176+
1177+ wp_render_layout_support_flag (
1178+ '<div class="wp-block-group"></div> ' ,
1179+ array (
1180+ 'blockName ' => 'core/group ' ,
1181+ 'attrs ' => array ( 'layout ' => array ( 'type ' => 'constrained ' ) ),
1182+ )
1183+ );
1184+
1185+ $ this ->assertGreaterThan (
1186+ 0 ,
1187+ $ user_data_resolutions ,
1188+ 'Global settings should still be resolved for a block that supports layout. '
1189+ );
1190+ }
11271191}
0 commit comments