Steps to reproduce
- Create a text format with CKeditor enabled and add the Insert media button
- Create a new page, edit the body field and click the Insert media button
- Nothing happens
- Clicking again will pop up the Media library modal, however without the accompanying javascript
Diagnosis
The problem is that getCriticalCss()->isEnabled() will return TRUE for the Insert media button, which is at route /media-library. This is not an admin route (and should not be).
The ajax response after clicking the Insert media button will then contain this:
{
"command":"add_css",
"data":[
{"id":"critical-css"},
{"rel":"stylesheet","media":"all","href":"/core/modules/views/css/views.module.css?rz61hm"},
{"rel":"stylesheet","media":"all","href":"/core/themes/claro/css/components/icon-link.css?rz61hm"},
{"rel":"stylesheet","media":"all","href":"/core/themes/claro/css/components/media-library.ui.css?rz61hm"},
{"rel":"stylesheet","media":"all","href":"/core/themes/claro/css/components/views-exposed-form.css?rz61hm"},
{"rel":"stylesheet","media":"all","href":"/core/themes/claro/css/components/file.css?rz61hm"},
{"rel":"stylesheet","media":"all","href":"/core/themes/claro/css/theme/media-library.css?rz61hm"}
]
},Because the "critical-css" entry has no href, ajax.js wil fail on line 1693, leading to this error message from loadjs in the console:
An error occurred during the execution of the Ajax response: TypeError: e is undefined
Proposed resolution
The solution should be in critical_css, not in media_library module. I’m not sure how to proceed though. Should we add a special case to getCriticalCss()->isEnabled() just for the Media library module?
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Critical-CSS-breaks-media-library-button-3380662-3.patch | 579 bytes | gaele |
Comments
Comment #2
gaele commentedComment #3
gaele commentedComment #4
tarazingo commentedI experienced the same issue but with the Layout Paragraphs module (admin page) and custom AJAX Dialogs (frontend).
Here is a more universal solution - https://www.drupal.org/project/critical_css/issues/3394895
Comment #5
albertosilvaHi @gaele,
Could you confirm if the solution provided by https://www.drupal.org/project/critical_css/issues/3394895 is working for you? I have already committed the the patch from that issue, and I think it should also work for you use case.
Thanks
Comment #6
gaele commented@albertosilva confirmed. I tried 8.x-1.20 and this is fixed. Thanks.