@@ -472,7 +472,8 @@ private function print_script_module( string $id ) {
472472 * @since 6.5.0
473473 */
474474 public function print_script_module_preloads () {
475- foreach ( $ this ->get_dependencies ( array_unique ( $ this ->queue ), array ( 'static ' ) ) as $ id ) {
475+ $ dependency_ids = $ this ->get_sorted_dependencies ( array_unique ( $ this ->queue ), array ( 'static ' ) );
476+ foreach ( $ dependency_ids as $ id ) {
476477 // Don't preload if it's marked for enqueue.
477478 if ( ! in_array ( $ id , $ this ->queue , true ) ) {
478479 $ src = $ this ->get_src ( $ id );
@@ -661,14 +662,16 @@ private function get_recursive_dependents( string $id ): array {
661662 *
662663 * @since 6.9.0
663664 *
664- * @param non-empty-string[] $ids The identifiers of the script modules to sort.
665+ * @param non-empty-string[] $ids The identifiers of the script modules to sort.
666+ * @param non-empty-string[] $import_types Optional. Import types of dependencies to retrieve: 'static', 'dynamic', or both.
667+ * Default is both.
665668 * @return non-empty-string[] Sorted list of script module identifiers.
666669 */
667- private function get_sorted_dependencies ( array $ ids ): array {
670+ private function get_sorted_dependencies ( array $ ids, array $ import_types = array ( ' static ' , ' dynamic ' ) ): array {
668671 $ sorted = array ();
669672
670673 foreach ( $ ids as $ id ) {
671- $ this ->sort_item_dependencies ( $ id , $ sorted );
674+ $ this ->sort_item_dependencies ( $ id , $ import_types , $ sorted );
672675 }
673676
674677 return array_unique ( $ sorted );
@@ -679,11 +682,12 @@ private function get_sorted_dependencies( array $ids ): array {
679682 *
680683 * @since 6.9.0
681684 *
682- * @param non-empty-string $id The identifier of the script module to sort.
683- * @param non-empty-string[] &$sorted The array of sorted identifiers, passed by reference.
685+ * @param non-empty-string $id The identifier of the script module to sort.
686+ * @param non-empty-string[] $import_types Optional. Import types of dependencies to retrieve: 'static', 'dynamic', or both.
687+ * @param non-empty-string[] &$sorted The array of sorted identifiers, passed by reference.
684688 * @return bool True on success, false on failure (e.g., missing dependency).
685689 */
686- private function sort_item_dependencies ( string $ id , array &$ sorted ): bool {
690+ private function sort_item_dependencies ( string $ id , array $ import_types , array &$ sorted ): bool {
687691 // If already processed, don't do it again.
688692 if ( in_array ( $ id , $ this ->done , true ) || in_array ( $ id , $ sorted , true ) ) {
689693 return true ;
@@ -694,7 +698,12 @@ private function sort_item_dependencies( string $id, array &$sorted ): bool {
694698 return false ;
695699 }
696700
697- $ dependency_ids = array_column ( $ this ->registered [ $ id ]['dependencies ' ], 'id ' );
701+ $ dependency_ids = array ();
702+ foreach ( $ this ->registered [ $ id ]['dependencies ' ] as $ dependency ) {
703+ if ( in_array ( $ dependency ['import ' ], $ import_types , true ) ) {
704+ $ dependency_ids [] = $ dependency ['id ' ];
705+ }
706+ }
698707
699708 // If the item requires dependencies that do not exist, fail.
700709 if ( count ( array_diff ( $ dependency_ids , array_keys ( $ this ->registered ) ) ) > 0 ) {
@@ -703,7 +712,7 @@ private function sort_item_dependencies( string $id, array &$sorted ): bool {
703712
704713 // Recursively process dependencies.
705714 foreach ( $ dependency_ids as $ dependency_id ) {
706- if ( ! $ this ->sort_item_dependencies ( $ dependency_id , $ sorted ) ) {
715+ if ( ! $ this ->sort_item_dependencies ( $ dependency_id , $ import_types , $ sorted ) ) {
707716 // A dependency failed to resolve, so this branch fails.
708717 return false ;
709718 }
0 commit comments