Closed (fixed)
Project:
Drupal core
Version:
10.5.x-dev
Component:
asset library system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 Jul 2023 at 01:38 UTC
Updated:
1 Jul 2025 at 12:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
gareth.poole commentedComment #3
gareth.poole commentedComment #4
ivanmartil commentedI have the same problem. For now, I have solved it with @layer, but it not has support in some browsers.
Comment #5
mherchelThis is interesting. I see your point, but SDC's are meant to be self contained and any dependencies should be explicit.
My thought is if you had a theme level library called
reset, you should explicitly declare the dependency within the SDC by doing something likeThoughts on this? This might also be a question for a frontend framework manager.
Comment #6
mherchelFunny enough, running into this right now. The method in #5 doesn't work.
What I expect
If I load
mytheme/my-libraryas a dependency to a component, I expect to see the CSS files inmy-libraryloaded before the CSS files from my componentWhat I'm seeing:
Currently it gets added as the last file within the source order. If I change the group to
base, it still loads after the the component in the source order.Comment #7
mherchelUpdating IS
Comment #8
mherchelComment #9
dieterholvoet commentedComment #11
e0ipsoI may not be able to fully reproduce this.
I have tried to reproduce the conditions in the open MR. I cannot have the dependant load after the component stylesheet.
I do see the
reset.cssfile loaded after the component. However I can also seeresize.module.cssloaded beforereset.css. That CSS is part ofsystem.libraries.yml, and also declared with a component level.Do you think that creating the component inside the
sdc_test_themetheme instead of thesdc_testcomponent will make a difference?Comment #12
e0ipsoComment #13
mherchelTest case patch with a simple component within Olivero. Note that within the SDC, I don't declare any library dependencies.
This is the source order of the CSS.
Comment #14
mherchelHere's a test case where I create a dependency on the olivero/feed library to try to force the SDC to load CSS at the end.
Comment #15
_utsavsharma commentedFixed failures in #14.
Comment #16
e0ipsoIt looks like this is only triggered if the library being depended on lives inside of a theme.
This patch should turn tests red.
Comment #17
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #18
e0ipsoCC are unhappy.
Comment #19
e0ipsoOuf, the branch creation really thew me off. It created my branch against 10.1.x.
Let's see if the patch is fixed now and we can get a red.
Comment #20
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #21
_utsavsharma commentedFixed failures in #19.
Comment #22
e0ipsoAdded to cspell instead.
Comment #23
e0ipsoAs it turns out, this is not an SDC thing. Libraries autogenerated for components are owned by the SDC module.
Below there is a failing test that shows how a library owned by a module, that depends on a library owned by a theme, will not produce the expected load order of the
linktags.Moving this issue to the render system and re-titling it. Issue summary needs an update with new findings.
Comment #24
lauriiiRelated but probably unrelated issue #3073053: Theme library override can fail in when you have multiple parent themes.
Comment #25
e0ipsoA workaround could be to move the libraries your components depend on to a module. That should work.
I am also interested in knowing if adding a dependency in your theme to the SDC module helps at all. If anyone wants to test and report, add the following to your theme's info file:
That might, or might not work. I wasn't able to add it to the test because the functional tests installer fails to create the ephemeral site.
Comment #26
e0ipsoComment #27
eelkeblokComment #28
eelkeblokI am not so sure adding a dependency to the theme works. There is a fairly fundamental mechanism in the sorting of the assets that puts more weight on themes than on modules. In the LibraryDiscoveryParser, the group gets set to either CSS_AGGREGATE_THEME or CSS_AGGREGATE_DEFAULT, depending on whether the extension is a theme or not. When it comes to sorting assets, that happens in the AssetResolver. This comes with its own sort method, which will prioritise the group as set earlier in the LibraryDiscovery parser.
I think I will try if I can alter the library info from SDC to make my theme the owner of the libraries. That should get them below the base styling I have defined. Not sure if this could serve as a fix for this issue inside SDC, or whether there is a more fundamental problem at hand here.
Comment #29
web-beestPost op Drupal.org m.b.t. component css die eerder wordt ingeladen dan basetheme css
https://www.drupal.org/project/drupal/issues/3374901
I've run into this issue as well. I've created a subtheme of Bootstrap5 and my problem is that my styling is loaded prior to the base styling, rendering my styling useless.
The problem resides in LibraryDiscoveryParser as eelkeblok already suggested. The stylesheets are loaded by the SDC module, which will always result it in them being placed in the CSS_AGGREGATE_DEFAULT group, higher up the chain then CSS_AGGREGATE_THEME.
I don't have a solution for this but I've came with this workaround for anyone who encountered this problem:
Comment #30
mherchelI'm continuously running into this. Any progress? I'd like to help but not sure where to start.
Comment #31
catch@mherchel it might be worth double checking in 10.4/11.1 because #3467860: Ensure consistent ordering when calculating library asset order changed library ordering to more strictly follow dependencies.
#1945262: Introduce "before" and "after" for conditional ordering in library definitions is open for getting rid of custom weights more generally. #1924522: Remove separate CSS_AGGREGATE_THEME aggregate file is open for getting rid of
CSS_AGGREGATE_THEME.Probably getting rid of
CSS_AGGREGATE_THEMEis the real blocker here, and that in turn is blocked on #2880237: [meta] Refactor system/base library and friends which could use some help but was getting close.Comment #32
mherchelThanks for the response.
I re-checked 11.1.x and the problem is still occuring :(
I will look at those other issues.
Comment #33
joelsteidl commented@mherchel
Have you tried the workaround mentioned in #29. I know it's not the long-term fix, but want to know more out of curiosity.
Comment #34
sethhill commentedI made a small module called SDC CSS Relocator to help with a similar issue that I was seeing. If there's anything that would make it more helpful while this issue awaits resolution, feel free to comment on that project page.
Comment #35
mherchel@sethhill
Comment #36
petr illekI think this issue is closely related to this one LibraryDiscoveryParser overwrites theme CSS group ordering.
Comment #40
mglamanIt feels like something we'd have to fix in
\Drupal\Core\Asset\LibraryDependencyResolver::doGetDependencies. That if a library from a theme is resolved as a dependency. The CSS files should be iterated over and the group changed toCSS_AGGREGATE_DEFAULT.Comment #41
mglamanSo my dream in
doGetDependenciesdoesn't work. But any adjustments there do not matter because the code path ends up at\Drupal\Core\Asset\AssetResolver::getCssAssets.The library definition is fetched here with the group CSS_AGGREGATE_THEME.
And to make sure I'm understanding this correctly, because I've flipflopped in my head a few times: if a theme's library is a dependency for a component, that theme's library should not be in CSS_AGGREGATE_THEME to ensure proper ordering.
Comment #42
catchComment #44
mglamanI opened https://git.drupalcode.org/project/drupal/-/merge_requests/11633 to prove where a fix _could_ go but I have no idea how to solve it. Moving to the asset library system, as I think it belongs there. The problem is how theme libraries are treated special and break the idea of being a dependency
Comment #45
mglamanThe other solution and proposal: all SDCs should have their libraries in the theme aggregation group since they're theme level anyway
Comment #46
mglamanChatted w/ laurii about #45 and got a thumbs up with having SDCs grouped into the theme aggregate versus default
Comment #47
mglamanChatted w/ laurii about #45 and got a thumbs up with having SDCs grouped into the theme aggregate versus default
Comment #48
mglamanPer #36 we can't make SDCs have a specific group without #3046636: LibraryDiscoveryParser overwrites theme CSS group ordering
Comment #49
mglamanOkay. This will need a change record if it goes through along with the issue summary update and a title update. It also brings in #3046636: LibraryDiscoveryParser overwrites theme CSS group ordering so we may need to fix that first or decide to roll it in here.
SDCs libraries are now aggregated at the theme group
Comment #50
mherchelUpdating title.
Comment #51
mherchelUpdating issue summary.
Comment #52
mherchelAssigning credit (everyone gets credit)
Comment #56
mherchelDraft CR at https://www.drupal.org/node/3515838. Still needs screenshots, which I will add as I test this out.
Comment #57
mherchelComment #58
mglamanSo a bunch of performance tests bumped in their stylesheet counts, which I think is a consequence of the different group. It is documented as a reason in #1924522: Remove separate CSS_AGGREGATE_THEME aggregate file. Some of the jumps seem high, I'm not sure if this is expected or can be mitigated without #1924522
Comment #59
mherchelScreenshots showing that the issue is fixed. I'm going to double check this works as expected when aggregation is enabled.
Before
After
Comment #60
mglamanComment #61
mherchelConfirmed that this is fixed when aggregation is enabled. I tested this by modifying Olivero's CSS in two places:
1. In the teaser SDC component.
2. In the theme's base CSS.
The SDC styles take get injected after, which takes precedent, which is the correct behavior! YAY!!!
Here's a picture of Matt doing the work!! :D
Comment #62
mherchelImage showing issue is fixed with aggregation
Comment #63
mglamanWe made a change to avoid doing #3046636: LibraryDiscoveryParser overwrites theme CSS group ordering and exposing
groupas an API.Comment #64
mherchelReviewing now!
Comment #65
mherchelRe-tested. Confirmed new method outputs the same. Not including screenshots because they're exactly the same as in #59 and #62
Comment #67
lauriiiCommitted 73613e5 and pushed to 11.x. Thanks!
Comment #68
mherchelWhoohoo!! Thanks Matt and Lauri!!!
I'm hoping that this can be backported to 10.5.x. As it stands now if I want to make a theme that supports both D10 and D11, I still have to work around this bug by adding additional specificity onto my SDC CSS selectors. :D
Comment #69
catchI think this is reasonable to backport to 10.5.x so that behaviour is consistent between the two major branches, although it will need a backport MR at least for the performance test changes due to merge conflicts. Moving to 'to be ported' for that.
Comment #72
smustgrave commentedComment #75
smustgrave commentedComment #76
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #77
godotislateComment #80
catchCommitted/pushed the backport MR to 10.6.x and 10.5.x, thanks!