Library overrides are not being set correctly due to themes being out of order

Created on 26 April 2021, over 3 years ago
Updated 2 May 2024, 8 months ago

Problem/Motivation

I have a custom admin theme that is using claro as the base theme. I'm noticing some styling issues in certain areas of the back-end. I debugged this and found that certain stylesheets are not loading correctly. This appears to be because core is loading all the base themes in the wrong order, so the library overrides are not being set correctly.

So my admin theme is using claro as the base theme (while claro uses stable as its base theme). However Drupal is not loading these in the correct order. The issue is in /core/lib/Drupal/Core/Theme/ThemeInitialization.php:

// Get libraries overrides declared by base themes.
foreach ($base_themes as $base) {
  if (!empty($base->info['libraries-override'])) {
    foreach ($base->info['libraries-override'] as $library => $override) {
      $values['libraries_override'][$base->getPath()][$library] = $override;
    }
  }
}

The $base_themes array has the themes in the wrong order. So this incorrectly goes through claro first, before stable overrides are in place, and then can't find the overrides that stable overrides in core.

This doesn't appear to be an issue in Drupal 9, as claro does not depend on stable anymore. However I wanted to report this just in case someone else runs into this problem.

Proposed resolution

Core needs to somehow load the themes in the correct order so the library overrides are set correctly.

🐛 Bug report
Status

Closed: cannot reproduce

Version

11.0 🔥

Component
Theme 

Last updated about 1 hour ago

Created by

Live updates comments and jobs are added and updated live.
  • CSS

    It involves the content or handling of Cascading Style Sheets.

  • 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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This came up as a daily target for #bugsmash initiative

    Wonder if we can get steps to reproduce this in D9 or D10?

  • I'm no longer seeing this issue in my project since claro no longer uses stable as its base theme in D9.

    I've been trying to reproduce this in D9 by using classy as the base theme for my custom theme instead (since stable is still the base theme of classy). I added a custom libraries-override in classy.info.yml just to test this out. I'm actually not seeing the issue anymore (I see the custom override when I view the page source is coming from classy). If I reverse the theme order from the code snippet in my original post (which is how I fixed this issue locally in D8), I'm now incorrectly seeing the override come from stable instead. So it seems that this issue has been fixed and there is no need to reverse the base theme order in D9.

    One thing that is strange to me though is if I inspect, the theme order still looks to be incorrect (classy is loading first). So it appears that issue has been somehow fixed, I'm just not sure where/how as of yet.

  • Status changed to Closed: cannot reproduce 8 months ago
  • 🇺🇸United States bnjmnm Ann Arbor, MI
Production build 0.71.5 2024