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.
Issue fork critical_css-3389128
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
Comment #2
dieterholvoet commentedComment #3
dieterholvoet commentedComment #4
dieterholvoet commentedComment #5
dieterholvoet commentedComment #6
dieterholvoet commentedUsing 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.
Comment #7
albertosilvaHi,
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
Comment #8
albertosilvaComment #11
cosolom commentedI'm not sure is my issue was project specific, but this patch help me on Drupal 10.3.1