Problem/Motivation

Since #3110517: Improve Drupal\Core\Ajax\AddCssCommand to accept an array of CSS assets , JS/CSS assets are sent in AJAX responses as arrays of attributes instead of rendered HTML strings. Because of this, inline CSS can no longer be added to AJAX responses through AddCssCommand's (see nod_'s comment here).

Drupal.AjaxCommands.prototype.add_css(), the JS behaviour that adds the assets to the page, expects an href attribute for every asset, something inline assets don't have.

Steps to reproduce

Try to trigger any AJAX request: can be a Webform submit, a media library modal, anything.

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. AjaxResponseAttachmentsProcessor will need to check which CSS assets have an href attribute: those that do should be added with AddCssCommand, those that don't should be added with AppendCommand (see gapple's comment here).

Remaining tasks

  • Check if we can find a temporary workaround for this module.
  • Create a core issue.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

DieterHolvoet created an issue. See original summary.

dieterholvoet’s picture

Issue summary: View changes
dieterholvoet’s picture

Title: Critical CSS is broken in AJAX requests since Drupal 10.1.0 » Appending inline critical CSS is broken in AJAX requests since Drupal 10.1.0
dieterholvoet’s picture

dieterholvoet’s picture

Status: Active » Needs work

Using the patch from #3389148: No way to add inline CSS to AJAX responses fixes the issue, but we should look into a workaround that doesn't involve applying patches.

albertosilva’s picture

Assigned: Unassigned » albertosilva
Status: Needs work » Active

Hi,

Could you please confirm if the solution provided by https://www.drupal.org/project/critical_css/issues/3394895 is working for you? I have already committed the patch from that issue, and I think it should also work for you use case.

Thanks

albertosilva’s picture

Status: Active » Postponed (maintainer needs more info)

cosolom made their first commit to this issue’s fork.

cosolom’s picture

Version: 8.x-1.x-dev » 2.0.3
Status: Postponed (maintainer needs more info) » Needs review

I'm not sure is my issue was project specific, but this patch help me on Drupal 10.3.1