Problem/Motivation
In our Drupal system we need a page free from some current Drupal css files. This is done with an hook_page_attachments_alter removing some elements in the $attachments['#attached']['library'] array. Particularly olivero/global-styling.
With D9.5 it was okay. With D10.1 there is a problem: it is like olivero/global-styling is still here, and a lot of css files are attached to the page.
In hook_page_attachments_alter, setting $attachments['#attached']['library'] = []; do not resolve the problem.
Digging around, the problem seems to come through dependencies from toolbar/toolbar, and from there core/drupal.ajax, and from there core/drupal.message. Since neutralizing drupal.message in core.libraries.yml by an # as dependency of drupal.ajax makes the problem disappear. drupal.message is new in D10.1, and does not exist in D9.5.
The problem comes from olivero/drupal.message, through libraries-extend. In core/themes/olivero/olivero.info.yml,
libraries-extend:
core/drupal.message:
- olivero/drupal.message
From core/themes/olivero/olivero.libraries.yml the dependencies chain is,
drupal.message:
...
dependencies:
- olivero/messagesmessages:
...
dependencies:
- olivero/global-stylingand the unwanted library olivero/global-styling is got.
Steps to reproduce
With hook_page_attachments_alter remove the library olivero/global-styling from $attachments['#attached']['library'] for the target page.
Look at the page html. Last css files of the page,
- D9.5,
<link rel="stylesheet" media="all" href="/modules/contrib/admin_toolbar/css/admin.toolbar.css?ru1gmv" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/progress.css?ru1gmv" />- D10.1,
<link rel="stylesheet" media="all" href="/modules/contrib/admin_toolbar/css/admin.toolbar.css?rty47g" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/base/fonts.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/base/variables.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/base/base.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/layout.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/grid.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/layout-content-narrow.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/layout-content-medium.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/layout-footer.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/region.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/region-content.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/region-hero.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/region-secondary-menu.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/social-bar.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/views.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/layout/region-content-below.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/progress.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/block.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/breadcrumb.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/embedded-media.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/footer.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/button.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/container-inline.module.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/fieldset.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/field.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/form.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/form-boolean.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/form-text.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/form-textarea.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/form-select.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/header-buttons-mobile.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/header-navigation.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/header-site-branding.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/header-sticky-toggle.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/hero.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/links.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/messages.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/navigation/nav-button-mobile.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/node.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/node-teaser.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/page-title.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/site-header.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/skip-link.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/pager.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/table.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/text-content.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/tabledrag.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/wide-image.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/powered-by-block.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/feed.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/details.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/ui-dialog.css?rvjfqe" />
<link rel="stylesheet" media="all" href="/core/themes/olivero/css/components/tabs.css?rvjfqe" />
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 3357728-21.patch | 843 bytes | psf_ |
| #16 | interdiff-14_16.txt | 741 bytes | gauravvvv |
| #16 | 3357728-16.patch | 844 bytes | gauravvvv |
| #14 | 3357728-14.patch | 410 bytes | gauravvvv |
Comments
Comment #2
cilefen commentedPlease show the hook implementation in the issue summary.
Comment #3
chris64Here it is,
The remaining libraries after that,
It works on D9, and D10.0. Here the critical library is
global-styling.Comment #4
chris64@cilefen, we sought more elements about the problem and we get one. But strange. No trivial links to css files seen. Many experiments to identify the culprit in the
core/drupal.messagelibrary dependencies failed. But found a very simple change who made our problem disappear: rename the library incore.libraries.yml:drupal.message->drupal.messageb(two occurrences).Comment #5
chris64New elements. The problem comes from
olivero/drupal.message, throughlibraries-extend. The above rename causes the avoidance of this extension.Comment #6
chris64From above in
core/themes/olivero/olivero.libraries.ymlthe dependencies chain is,and the unwanted library
olivero/global-stylingis got.Comment #7
chris64Comment #9
chris64Comment #10
chris64Comment #11
chris64Comparing Drupal 9.5 and 10.1 about Olivero messages libraries, a major change concerns
olivero/messages, inolivero.libraries.yml,->
For both
css/components/messages.cssis underolivero/global-styling.Comment #12
shobhit_juyal commentedHi @Chris64,
Further should we exclude drupal.message library as well ?
Comment #13
chris64Hi @shobhit_juyal. The drupal.message library should not be exclude. But for my purpose the current approach in Drupal 10.1 causes some problems.
css/components/messages.cssis requested, but througholivero/global-stylinga lot of other and unnecessary files are gotten.Comment #14
gauravvvv commentedglobal-styling is what includes js/navigation-utils.js, which initializes Drupal.olivero. Any code using Drupal.olivero like messages.js using Drupal.olivero.closeMessage needs to have that run first. For that I have added
olivero/navigation-baseas a dependency on part of global styling.Comment #15
smustgrave commentedIf #14 is the fix the title and issue summary need to be updated. As the patch does not make sense based on the title.
Also will need a test case showing the problem.
Comment #16
gauravvvv commentedRoot cause of this issue is already there in the issue summary. you can see it here.
A dependency chain was there which causes the issue.
messageslibrary has dependency of global-styling anddrupal.messagehas the dependency ofmessageslibrary. That's why we're unable to remove attachments throughhook_page_attachments_alter.I have removed the global library dependency and added the required files to
messgaeslibarary.Status is NW, as need to add tests
Comment #17
chris64Apply 3357728-14.patch: OK: our problem disappears. Since the two last .css are as expected,
Apply 3357728-16.patch: PB: an error appends,
Error : Undefined constant "CSS_COMPONENTS" dans constant() (ligne 184 de */web/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php).May be an other problem? Drupal 10.1.1.
The corresponding line 184 is
$options['weight'] += constant($category_weight);in
Comment #18
chris64For the error see https://www.drupal.org/project/void/issues/3060386.
Comment #19
chris64The change
components:->component:solves this problem #17.Comment #21
psf_ commentedI do the change by Chris64 in #19.
I'm sorry, I don't know how do the interdiff.
The new patch apply to 10.3.2 too
Comment #22
dcam commentedA nearly identical change was introduced by #3515041: Move Olivero's messages.css to its messages library and committed earlier this year. This issue is outdated.