No way to add inline CSS to AJAX responses

Created on 22 September 2023, about 1 year ago
Updated 18 October 2023, about 1 year ago

Problem/Motivation

Since πŸ“Œ Improve Drupal\Core\Ajax\AddCssCommand to accept an array of CSS assets Fixed , 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

  1. Enable and configure the Critical CSS module β†’ .
  2. Try to trigger any AJAX request: can be a Webform submit, a media library modal πŸ› Critical CSS breaks media library button in CKeditor in D10 Needs review , anything.

Proposed resolution

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 β†’ ).

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
AjaxΒ  β†’

Last updated about 14 hours ago

Created by

πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @dieterholvoet
  • Open on Drupal.org β†’
    Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    Not currently mergeable.
  • @dieterholvoet opened merge request.
  • last update about 1 year ago
    30,168 pass
  • Status changed to Needs review about 1 year ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think we will need a test case to show the issue also

  • When trying this patch in conjunction with #3389161 - Not all attributes are used when considering an asset as unique πŸ› Not all attributes are used when considering an asset as unique Needs review , the JS error disappears but it looks like it's interfering with other append commands.

    In my case, in a site running Drupal 10.1.0, I have a Webform with: saving submissions disabled, Ajax enabled and confirmation Inline (reloads the current page and replaces the webform with the confirmation message). When I submit that form while critical_css is enabled (after patches attached), it doesn't replace the webform anymore. The exact response with commands for the POST is in the image.

    I could not determine if the problem is on the code of one of the modules or the changes in Ajax from D9.5 to D10.

Production build 0.71.5 2024