Critical CSS module prevents from using the admin theme

Created on 22 August 2023, about 1 year ago

Problem/Motivation

On Drupal 10.1.x, simply enabling critical_css module without activating it will prevent any user from using the admin theme.

Steps to reproduce

Tested on a clean Drupal 10.1.x install.

  1. Activate critical_css
  2. Navigate the page as a user with permission to see the admin pages. Use an admin page, such as /admin/content
  3. The page will be rendered with the public theme independently of the enabled/disabled config of the module.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.19

Component

Code

Created by

🇪🇸Spain idiaz.roncero Madrid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @idiaz.roncero
  • 🇪🇸Spain idiaz.roncero Madrid

    I can't tell why, but the simple injection of the Twig service (TwigEnvironment) seems to be the enough to cause the problem.

    It is not tied to any particular use of that service. You can delete all uses of $twig inside the decorated service and it will fail the same.

    To reproduce, just delete the Twig injected service:

    critical_css/critical_css.services.yml

    services:
      asset.css.collection_renderer.critical_css:
        public: false
        class: Drupal\critical_css\Asset\CssCollectionRenderer
        decorates: asset.css.collection_renderer
        arguments:
          - '@asset.css.collection_renderer.critical_css.inner'
          - '@config.factory'
          - '@twig' <-----------------REMOVE THIS
          - '@critical_css'
    

    ...and also from critical_css/src/Asset/CssCollectionRenderer.php.

    Then, it will work as usual.

  • 🇪🇸Spain idiaz.roncero Madrid

    WORKAROUND! This is NOT a fix for the issue
    WORKAROUND! This is NOT a fix for the issue
    WORKAROUND! This is NOT a fix for the issue

    The attached patch removes the twig injected service (and, of course, the debug functionality of the module).

    This will make the bug disappear but can't be considered a solution to the issue, just a workaround.

  • Assigned to albertosilva
  • 🇪🇸Spain albertosilva Basque Country

    Hi,

    I cannot reproduce this issue, could you please try it again and provide more details?

    Thanks

  • Dealing with the same issue here, the work around of idiaz.roncero works, but waiting for a better solution here :)

  • Status changed to Closed: works as designed 9 months ago
  • 🇧🇪Belgium dieterholvoet Brussels

    This problem is caused by 🐛 Enabling SDC causes the frontend theme to be used in admin routes Needs work and can be fixed by patching Drupal core with the MR from that issue. This issue only occurs when the SDC module is installed, that's why not everyone seems to be able to reproduce it.

  • 🇮🇳India wil2091

    Can replicate this on 10.2.4, with SDC enabled. The patch from this MR fixes the problem.

  • 🇮🇳India ankithashetty Karnataka, India

    +1 to this issue.

Production build 0.71.5 2024