Problem/Motivation

Various CSS files in libraries split out from system/base, such as progress.module.css, resize.module.css, tablesort, fieldgroup, item-list and more have an explicit negative weight. That almost certainly isn't required anymore, especially now when they are their own library that others depend on, so library dependencie should take care of this.

With #3565258: Support library-specific aggregates, this causes an unfortunate issue which puts those files, if required on a page, into their own group ahead of system/base, making it a tiny and not-well-aggregated separate asset request.

Steps to reproduce

Proposed resolution

Remove all weight definitions from CSS libraries in core.libraries.yml, mostly those moved from system.base, but also ajax-progress.module.css for example.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#11 diff.png105.13 KBdcam

Issue fork drupal-3568157

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review

Unsure about the scope and impact here. This obviously overlaps with #1945262: Introduce "before" and "after" for conditional ordering in library definitions, so I'm wondering if we can really split off, doing a quick test.

I think it should work for a library like core/drupal.progress, that's loaded as a dependency of another. However, where it gets tricky is with core/normalize for example. claro/umami/.. load that as a global library, and not a dependency of their own global theming library. That means that normalize.css is not actually loaded first, so it's unclear how that is supposed to work, also with before/after dependencies, since there isn't anything depending on it? We might just need to keep that for edge cases like that?

catch’s picture

There's a different issue (will link later) about themes not being able to add their own reset styles because it gets loaded after module CSS. So I think anyway we might want a new CSS 'reset' group and put normalize in there.

catch’s picture

Found the issue again:

Agree this is fairly frustrating and more than slightly nonsensical that there is no way to define a "base" SMACSS in a theme and make it appear first before higher SMACSS groups defined by core or contrib modules.

Even stable9 theme in Drupal core suffers from this exact issue out of the box:

#3046636: LibraryDiscoveryParser overwrites theme CSS group ordering

We should leave normalize.css alone here and tackle that in the before/after issue or another similar one.

berdir’s picture

Yes, leaving alone normalize.css sounds like a good plan. No test fails/performance changes with this yet. What I'll do with this I think is a diff of the non-aggregated CSS files on umami and claro or so, but I need to find a page that adds at least some of them, because I don't think umami does, at least not on the pages we tested.

berdir’s picture

Testing the impact of this might be tricky, both positive and negative.

On it's own, with aggregation off, there's a shift in order of CSS files with this, but it's pretty contained. Diffing it is tricky, because the query strings change on every cache clear, so I put the HTML of node/add/article into a file, cut of the query string for all the claro CSS classes and then compared that before/after this change.

That gave me this diff:

@@ -31,18 +31,18 @@
   <link rel="stylesheet" media="all" href="/core/assets/vendor/jquery.ui/themes/base/checkboxradio.css" />
   <link rel="stylesheet" media="all" href="/core/assets/vendor/jquery.ui/themes/base/resizable.css" />
   <link rel="stylesheet" media="all" href="/core/assets/vendor/jquery.ui/themes/base/button.css" />
-  <link rel="stylesheet" media="all" href="/core/misc/components/progress.module.css" />
-  <link rel="stylesheet" media="all" href="/core/themes/claro/css/components/ajax-progress.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/system/css/components/align.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/system/css/components/container-inline.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/system/css/components/clearfix.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/system/css/components/hidden.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/system/css/components/js.module.css" />
   <link rel="stylesheet" media="all" href="/core/themes/claro/css/components/autocomplete-loading.module.css" />
-  <link rel="stylesheet" media="all" href="/core/misc/components/resize.module.css" />
+  <link rel="stylesheet" media="all" href="/core/misc/components/progress.module.css" />
+  <link rel="stylesheet" media="all" href="/core/themes/claro/css/components/ajax-progress.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/ckeditor5/css/ckeditor5.dialog.fix.css" />
   <link rel="stylesheet" media="all" href="/core/modules/contextual/css/contextual.module.css" />
   <link rel="stylesheet" media="all" href="/core/modules/contextual/css/contextual.toolbar.css" />
+  <link rel="stylesheet" media="all" href="/core/misc/components/resize.module.css" />
   <link rel="stylesheet" media="all" href="/core/profiles/demo_umami/css/toolbar-warning.css" />
   <link rel="stylesheet" media="all" href="/core/themes/claro/css/components/toolbar.module.css" />
   <link rel="stylesheet" media="all" href="/core/themes/claro/css/state/toolbar.menu.css" />

so both progress and resize css files are pushed a bit down, not significantly.

Combined with #3565258: Support library-specific aggregates, there's no change yet in number of aggregate files. The first is normalize + jquery.ui + drupal.dialog + drupal.autocomplete, so essentially all those that have explicit negative weights. Then a separate one for system.base and then everything else, which interestingly also again has autocomplete and dialog library files, for those without an explicit weight.

Came up with this one-liner to summarize the libraries in a given css group: implode(',', array_unique(array_column($css_groups[0]['items'], 'library'))), which gives me:

0: core/normalize,core/internal.jquery_ui,core/drupal.dialog,core/drupal.autocomplete
1: system/base
2: core/drupal.autocomplete,core/drupal.progress,core/drupal.ajax,core/drupal.dialog,contextual/drupal.contextual-links,contextual/drupal.contextual-toolbar,core/drupal.textarea-resize,demo_umami/toolbar-warning,toolbar/toolbar,toolbar/toolbar.menu,ckeditor5/internal.drupal.ckeditor5,ckeditor5/internal.drupal.ckeditor5.media,ckeditor5/internal.drupal.ckeditor5.mediaAlign,ckeditor5/internal.drupal.ckeditor5.table,shortcut/drupal.shortcut,user/drupal.user.icons,claro/global-styling,system/admin,claro/form-two-columns,claro/claro.jquery.ui,claro/card,filter/drupal.filter,claro/icon-link,media_library/widget

I didn't look into the weights of jquery, dialog and autocomplete yet ,but as long normalize is up there, there's not much to gain with this for claro. It needs a theme that doesn't use normalize and a scenario where you can remove all libraries with explicit weights with this. Which we have.

dcam’s picture

Status: Needs review » Needs work

I haven't done a complete review of this issue yet, but the MR needs a rebase.

berdir’s picture

Status: Needs work » Needs review

Rebased and created an 11.x version off the previous state. main and 11.x are drifting apart pretty significantly, going to be quite a bit of work to do backports.

dcam’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new105.13 KB

I verified @berdir's results for the unaggregated, ungrouped CSS files. The diff can be seen in the following screenshot.
A screenshot showing the difference in raw HTML output before and after the MR's change which caused a few CSS files to be moved down in the order
The remaining weights for CSS files include:

  • jQuery UI files, which have explicit negative weights
  • normalize.css, noted in #5 we need to leave alone
  • autocomplete-loading.module.css, which I assume needs to be grouped with and just under the jQuery UI files that are part of its library and will likely be aggregated with those other files as part of #3565258: Support library-specific aggregates anyway.

The MR changes are simple, only removing weights from CSS files in libraries. I think this one is OK to go.

catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

This looks great and will help reduce the scope of #1945262: Introduce "before" and "after" for conditional ordering in library definitions. Committed/pushed to main, thanks!

Doesn't apply to 11.x, so moving there for backport.

  • catch committed 0e664363 on main
    task: #3568157 Remove explicit weight from CSS files in core.libraries....

berdir’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

@catch: There's already a 11.x MR open, based on the previous state before the conflicts with the BC removals in main. it had fails, which I assume were random, can't see it on 11.x, rebased it to trigger a retest.

  • catch committed afc714c5 on 11.x
    task: #3568157 Remove explicit weight from CSS files in core.libraries....

catch’s picture

Status: Reviewed & tested by the community » Fixed

Sorry for missing the existence of the 11.x MR. Committed/pushed to 11.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

joelpittet’s picture

This is awesome! Thanks for doing this! I’ve always found that an itch I meant to scratch!
Thanks berdir

#ex-theme-system-maintainer

Status: Fixed » Closed (fixed)

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