$libraries can't contain duplicate items from Navigation:UserLazyBuilder

Created on 17 February 2025, about 2 months ago

This is a really tricky issue to reproduce and debug:

  1. Ensure CSS/JS Aggregation is ENABLED
  2. Clear cache to remove aggregated CSS/JS files
  3. Run an ExistingSiteTest (weitzman/drupal-test-traits v2.5.0) that visits the home page. e.g. $this->visit('/');
  4. In the Recent Log messages, see the error "$libraries can't contain duplicate items"

When I debug this locally, I learn that the library being duplicated is "core/components.navigation--toolbar-button". During the BigPipe lazy loader, the "NavigationUserBlock" is causing this library to be added 5 times.

This happens when Drupal initially creating the CSS/JS aggregation files. If I visit the page manually in a browser, I do not get any error and that causes the aggregated files to be created properly. After creating the aggregated files, running the ExistingSiteTest no longer errors.

I can prevent the error by disabling the placeholder in NavigationUserBlock ('#create_placeholder' => FALSE), but that's not really a solution. I can also prevent the error by disabling the Navigation module completely and going back to AdminToolbar.

If I visit the home page manually in a browser after clearing cache, this error does not occur, nor is it in the recent log messages. So it's possible this is somehow related to building the CSS/JS cache from ExistingSiteText. I realize that makes it more difficult to reproduce since that's not part of Core. But I'm posting this in case someone else more experienced with this lazy building process has any idea what might be causing it so it can hopefully be fixed before Navigation is no longer experimental.

This was reproduced in a fresh version of Drupal CMS 1.0 on Drupal 11.1.2, php8.3.6.

Full error dump (not that I found it very helpful):

Exception: $libraries can't contain duplicate items. Duplicate libraries: core/components.navigation--toolbar-button in Drupal\Core\Asset\LibraryDependencyResolver->getMinimalRepresentativeSubset() (line 85 of /var/www/docroot/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php)
#0 /var/www/docroot/core/lib/Drupal/Core/Asset/CssCollectionOptimizerLazy.php(112): Drupal\Core\Asset\LibraryDependencyResolver->getMinimalRepresentativeSubset(Array)
#1 /var/www/docroot/core/lib/Drupal/Core/Asset/AssetResolver.php(251): Drupal\Core\Asset\CssCollectionOptimizerLazy->optimize(Array, Array, Object(Drupal\Core\Language\Language))
#2 /var/www/docroot/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(279): Drupal\Core\Asset\AssetResolver->getCssAssets(Object(Drupal\Core\Asset\AttachedAssets), true, Object(Drupal\Core\Language\Language))
#3 /var/www/docroot/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(123): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries(Object(Drupal\Core\Asset\AttachedAssets), Array)
#4 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipeResponseAttachmentsProcessor.php(97): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))
#5 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))
#6 /var/www/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#7 /var/www/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'kernel.response', Object(Symfony\Component\HttpKernel\Event\ResponseEvent))
#8 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipe.php(668): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response')
#9 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipe.php(646): Drupal\big_pipe\Render\BigPipe->filterResponse(Object(Symfony\Component\HttpFoundation\Request), 2, Object(Drupal\Core\Render\HtmlResponse))
#10 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipe.php(413): Drupal\big_pipe\Render\BigPipe->filterEmbeddedResponse(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#11 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipe.php(279): Drupal\big_pipe\Render\BigPipe->sendNoJsPlaceholders('<!DOCTYPE html>...', Array, Object(Drupal\Core\Asset\AttachedAssets))
#12 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipe.php(247): Drupal\big_pipe\Render\BigPipe->sendPreBody('<!DOCTYPE html>...', Array, Object(Drupal\Core\Asset\AttachedAssets))
#13 /var/www/docroot/core/modules/big_pipe/src/Render/BigPipeResponse.php(113): Drupal\big_pipe\Render\BigPipe->sendContent(Object(Drupal\big_pipe\Render\BigPipeResponse))
#14 /var/www/vendor/symfony/http-foundation/Response.php(395): Drupal\big_pipe\Render\BigPipeResponse->sendContent()
#15 /var/www/docroot/index.php(20): Symfony\Component\HttpFoundation\Response->send()
#16 {main}
πŸ› Bug report
Status

Active

Version

11.1 πŸ”₯

Component

navigation.module

Created by

πŸ‡ΊπŸ‡ΈUnited States mpotter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024