Edge case with redundant commerce/toolbar library for big_pipe + no JS

Created on 30 May 2025, 6 days ago

Describe your bug or feature request.

When using commerce + big_pipe with JavaScript disabled, an assertion is emitted from the asset library subsystem of core which interrupts the page rendering and makes the page unusable.

This came up in the context of writing automated functional tests against a Commerce site, luckily it shouldn't affect end users because we shouldn't have assertions on in production.

If a bug, provide steps to reproduce it from a clean install.

I used DDEV to test locally from a clean install. Please note that assertions need to be enabled.

  1. Install Drupal 11, standard profile. I used core 11.1.7.
  2. Install Commerce
  3. Log in as user 1
  4. Disable JavaScript
  5. Refresh the page

The expected result would be that the page still renders, but instead we get an assertion message:

AssertionError: $libraries can't contain duplicate items. in assert() (line 82 of core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php).

Proposed resolution

Remove the commerce/toolbar library attachment for the commerce inbox toolbar item, we already have:

/**
 * Implements hook_toolbar_alter().
 */
function commerce_toolbar_alter(&$items) {
  $items['administration']['#attached']['library'][] = 'commerce/toolbar';
}

I am by no means a big_pipe expert but my interpretation is that big_pipe is trying to render the toolbar chunk and ending up with two copies of the commerce/toolbar library. It seems like this shouldn't break things, but at the same time I can't see a strong reason to attach the library with the "Commerce Inbox" toolbar item specifically, when we already include it more generally.

🐛 Bug report
Status

Active

Version

3.0

Component

Commerce

Created by

🇨🇦Canada star-szr

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

Comments & Activities

  • Issue created by @star-szr
  • 🇨🇦Canada star-szr

    Seeing somewhat different and unexplicable behaviour in my test site, so going to come back to this.

    I've still pushed some code to the issue fork that resolves the issue on our real-world site, but my next step will be to roll that back and try to write a failing test for this.

  • 🇨🇦Canada star-szr

    I have a manual test case that consistently reproduces, but have not successfully gotten a PHPUnit Functional test to fail with the same setup.

    1. Install Drupal 11, minimal profile
    2. Install commerce, toolbar, big_pipe, contact (others may trigger it, unclear)
    3. Change default theme to Claro (unclear as to why Stark doesn't show the error)
    4. In Firefox/Chromium web inspector disable JavaScript
    5. Navigate to /user

    You should then see the assertion error, assuming you have assertions enabled.

    Of note, I was not able to reproduce any errors in a CLI browser (I used links) or with curl. The big_pipe no-js detection was working well for these, it seems.

    I updated the issue summary, after digging into this I'm less and less convinced this is actually a Commerce issue. I am fairly sure the changes here are just a workaround. Closing this.

Production build 0.71.5 2024