diff --git a/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php b/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php
index 4c31c1b124bac0162339365143d209df8623fa09..153801aa902862984428e61ba011e3526f2ab432 100644
--- a/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php
+++ b/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php
@@ -86,7 +86,7 @@ public function getMinimalRepresentativeSubset(array $libraries) {
     foreach ($libraries as $library) {
       $with_deps = $this->getLibrariesWithDependencies([$library]);
       // We don't need library itself listed in the dependencies.
-      $all_dependencies += array_diff($with_deps, [$library]);
+      $all_dependencies = array_unique(array_merge($all_dependencies, array_diff($with_deps, [$library])));
     }
 
     return array_values(array_diff($libraries, array_intersect($all_dependencies, $libraries)));
diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php
index 24f21b35b391a43d069ee7a0eee412e15b1cd0bd..a8425ac20783d4efa8ca18e60ebc9be4f8206030 100644
--- a/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php
+++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php
@@ -41,9 +41,11 @@ class LibraryDependencyResolverTest extends UnitTestCase {
     'no_deps_a' => ['js' => [], 'css' => []],
     'no_deps_b' => ['js' => [], 'css' => []],
     'no_deps_c' => ['js' => [], 'css' => []],
+    'no_deps_d' => ['js' => [], 'css' => []],
     'deps_a' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_a']],
     'deps_b' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_a', 'test/no_deps_b']],
     'deps_c' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_b', 'test/no_deps_a']],
+    'deps_d' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_d']],
     'nested_deps_a' => ['js' => [], 'css' => [], 'dependencies' => ['test/deps_a']],
     'nested_deps_b' => ['js' => [], 'css' => [], 'dependencies' => ['test/nested_deps_a']],
     'nested_deps_c' => ['js' => [], 'css' => [], 'dependencies' => ['test/nested_deps_b']],
@@ -139,6 +141,8 @@ public function providerTestGetMinimalRepresentativeSubset() {
       [['test/deps_b', 'test/deps_a'], ['test/deps_b', 'test/deps_a']],
       [['test/deps_b', 'test/deps_c'], ['test/deps_b', 'test/deps_c']],
       [['test/deps_c', 'test/deps_b'], ['test/deps_c', 'test/deps_b']],
+      [['test/deps_a', 'test/deps_d', 'test/no_deps_a'], ['test/deps_a', 'test/deps_d']],
+      [['test/deps_a', 'test/deps_d', 'test/no_deps_d'], ['test/deps_a', 'test/deps_d']],
       // Multi-level (indirect) dependencies.
       [['test/nested_deps_a'], ['test/nested_deps_a']],
       [['test/nested_deps_b'], ['test/nested_deps_b']],