diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
index 6d5030c9544a6b..93e11449c8fac7 100644
--- a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
+++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
@@ -118,10 +118,11 @@ protected static function get_blocks_metadata() {
 	 *
 	 * @since 5.8.0
 	 *
-	 * @param array $theme_json     The tree to extract style nodes from.
+	 * @param array $theme_json The tree to extract style nodes from.
+	 * @param array $selectors  List of selectors per block.
 	 * @return array
 	 */
-	protected static function get_style_nodes( $theme_json ) {
+	protected static function get_style_nodes( $theme_json, $selectors = array() ) {
 		$nodes = array();
 		if ( ! isset( $theme_json['styles'] ) ) {
 			return $nodes;
@@ -147,7 +148,7 @@ protected static function get_style_nodes( $theme_json ) {
 			return $nodes;
 		}
 
-		$nodes = array_merge( $nodes, static::get_block_nodes( $theme_json ) );
+		$nodes = array_merge( $nodes, static::get_block_nodes( $theme_json, $selectors ) );
 
 		// This filter allows us to modify the output of WP_Theme_JSON so that we can do things like loading block CSS independently.
 		return apply_filters( 'gutenberg_get_style_nodes', $nodes );
@@ -166,12 +167,14 @@ public function get_styles_block_nodes() {
 	 * An internal method to get the block nodes from a theme.json file.
 	 *
 	 * @param array $theme_json The theme.json converted to an array.
+	 * @param array $selectors  Optional list of selectors per block.
 	 *
 	 * @return array The block nodes in theme.json.
 	 */
-	private static function get_block_nodes( $theme_json ) {
-		$selectors = static::get_blocks_metadata();
+	private static function get_block_nodes( $theme_json, $selectors = array() ) {
+		$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
 		$nodes     = array();
+
 		if ( ! isset( $theme_json['styles'] ) ) {
 			return $nodes;
 		}
@@ -215,9 +218,9 @@ private static function get_block_nodes( $theme_json ) {
 	/**
 	 * Gets the CSS rules for a particular block from theme.json.
 	 *
-	 * @param array $block_metadata Meta data about the block to get styles for.
+	 * @param array $block_metadata Metadata about the block to get styles for.
 	 *
-	 * @return array Styles for the block.
+	 * @return string Styles for the block.
 	 */
 	public function get_styles_for_block( $block_metadata ) {
 		$node         = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
diff --git a/lib/compat/wordpress-6.1/script-loader.php b/lib/compat/wordpress-6.1/script-loader.php
index d45a3a9344053b..bfa515b16a4aee 100644
--- a/lib/compat/wordpress-6.1/script-loader.php
+++ b/lib/compat/wordpress-6.1/script-loader.php
@@ -19,6 +19,9 @@
  * @return array A filtered array of style nodes.
  */
 function filter_out_block_nodes( $nodes ) {
+	if ( ! is_array( $nodes ) ) {
+		return array();
+	}
 	return array_filter(
 		$nodes,
 		function( $node ) {