From 4cf9dd0048e3f0d80804017e491cb3e4c5edd7a5 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 20 Dec 2024 13:06:18 +0100 Subject: [PATCH] Pull in module_deps handling from https://github.com/WordPress/wordpress-develop/pull/8024 --- lib/client-assets.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 13884f90fb3ea5..c19d2d407cf7fc 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -70,9 +70,28 @@ function gutenberg_override_script( $scripts, $handle, $src, $deps = array(), $v // See: `_WP_Dependency::__construct` . $script->src = $src; - $script->deps = $deps; $script->ver = $ver; $script->args = $in_footer ? 1 : null; + + $module_deps = array(); + $script_deps = array(); + if ( array() !== $deps ) { + foreach ( $deps as $dep ) { + if ( is_string( $dep ) ) { + $script_deps[] = $dep; + } elseif ( + isset( $dep['type'], $dep['id'] ) && + 'module' === $dep['type'] && + is_string( $dep['id'] ) + ) { + $module_deps[] = $dep['id']; + } + } + } + $script->deps = $script_deps; + if ( array() !== $module_deps ) { + $scripts->add_data( $handle, 'module_deps', $module_deps ); + } } else { $scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) ); }