Problem/Motivation
When Core's CSS aggregation is enabled, Drupal attempts to combine CSS files but fails when processing the gin/dialog library, creating broken aggregate files with missing references. This manifests as:
- Missing aggregated CSS files (e.g.,
css_WoF7WDetc.css)
- 404 errors in the browser console for non-existent CSS files
- Broken or missing styles for authenticated users only (anonymous users unaffected)
Error looks like:
Refused to apply style from 'https://test.lndo.site/sites/default/files/css/css_WoF7WD96Du1YbxRdmtucRgfNlBjte-WwTrSHdIgmY1A.css?delta=6&language=en&theme=gnwt&include=eJx1UltyxCAMuxCE2RMxBtzEUwKMDdumpy95t9PuB8GSlSArQJgp2ZpzdMBWENhPZt8U_Oqtu5gDDeRzUn1V_KwNogncCsThZvSh7CJG4_NccsJUZRjTR9UaInLVDlLCV5I3whhe9AqMqCeE0N8OIJPLwOE0pwI-sVtan5cNDFQzEzwei_lR60iOgReF6Umc09wPsZQCeeiSc6x_m2qkZPqyDgQvMPUPf_UUIJ7JqdWyWUVW6hJRDiLnKpWh7DDlgPatxXjCmrVAOsSF0dYJZ9ygvUe-KrtGokbOrVw5FGAY-wmTnIPczNBSaS6STBgUo2sUg_XgJ7TgPYqYg9QbqXfyipNR-h8RenZf4GK3TrEim5vXG68ke-pZzD1zsJHSu5i_1LDPJotUnLeoVBO84l_r7cbJN425DAw' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
I've narrowed this down to the following line:
https://git.drupalcode.org/project/gin_toolbar/-/blob/3.0.x/gin_toolbar.module?ref_type=heads#L411
Commenting out the gin_toolbar_css_alter results in clearing the error.
Steps to reproduce
- Install and enable the Gin admin toolbar.
- Enable CSS aggregation under Configuration → Development → Performance.
- Log in as an authenticated user and visit a front-end page that includes admin toolbar or Gin dialog assets.
- Open browser DevTools → Console/Network tab.
- Observe 404 errors for aggregated CSS files (e.g.,
Invalid filename responses or Refused to apply style MIME errors).
Comments
Comment #2
tanner.svg commentedI think we can substitute the
gin_toolbar_css_altermethod for changing thecomponents/dialog.cssweight to 101 for doing this in thegin_toolbar_library_info_alter. After applying this switch, thedialog.cssappears to be in the same order in the DOM and I'm no longer seeing the missing aggregated CSS file error when i enable CSS aggregation.Comment #3
tanner.svg commentedComment #4
tanner.svg commentedPatch here, see my last comment.
Comment #5
tanner.svg commentedComment #6
jurgenhaasCan you please turn this into an MR?
Also, this raises a question: should we instead update the weight of that library in the Gin theme rather than altering it after the event?
Comment #8
tanner.svg commentedMR opened.
Updating the weight in the Gin theme might be the better approach. I'm not sure I completely understand the importance of having dialog.css attach after the custom theme CSS. I suppose it's for the cascade so that Dialog UI styling has priority when rendering on the front-end and it has to compete with custom theme styles, but that probably should be mitigated by the custom theme.
But it is a good question, is the re-ordering only relevant when using the Gin Toolbar?
Comment #9
tanner.svg commentedComment #10
tuutti commentedWe recently ran into this issue after updating to Drupal 11.
The dialog library causes the core asset hash calculation to fail, which triggers a redirect to the correct file. The redirect in turn causes the next aggregated asset request to throw a 400 error due to an invalid group name.
The patch seems to fix the issue.
Comment #11
jurgenhaasLet's do it.