Making other assets asynchronous fails in AJAX requests since Drupal 10.1.0

Created on 22 September 2023, 9 months ago
Updated 29 December 2023, 6 months ago

Problem/Motivation

In addition to not being able to add inline CSS to AJAX requests, there's another issue caused by πŸ“Œ Improve Drupal\Core\Ajax\AddCssCommand to accept an array of CSS assets Fixed . In CssCollectionRenderer::makeAssetsAsync, we duplicate the asset and add some attributes for print media.

The problem is that the uniqueBundleId in Drupal.AjaxCommands.prototype.add_css() is not unique enough: it joins style.href and ajax.instanceIndex, but both of those are the same in case of the print media duplicates we make. This causes an error in loadjs (relevant line), the JS library which is used for loading the JS/CSS files, because it thinks we're adding the same asset twice.

Steps to reproduce

Try to trigger any AJAX request: can be e.g. a Webform submit.

Proposed resolution

I'm not sure this can be fixed in the Critical CSS module, this might be something that needs to be fixed in Drupal core. Drupal.AjaxCommands.prototype.add_css() will need to include a hash of all attributes in the unique bundle ID.

Remaining tasks

  • Check if we can find a temporary workaround for this module.
  • Create a core issue.
πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium DieterHolvoet Brussels

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

Comments & Activities

Production build 0.69.0 2024