Steps to reproduce

  1. Create a text format with CKeditor enabled and add the Insert media button
  2. Create a new page, edit the body field and click the Insert media button
  3. Nothing happens
  4. 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?

Comments

gaele created an issue. See original summary.

gaele’s picture

Issue summary: View changes
gaele’s picture

Status: Active » Needs review
StatusFileSize
new579 bytes
tarazingo’s picture

I 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

albertosilva’s picture

Assigned: Unassigned » albertosilva
Status: Needs review » Active

Hi @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

gaele’s picture

Status: Active » Fixed

@albertosilva confirmed. I tried 8.x-1.20 and this is fixed. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.