Problem/Motivation

Today I found out that I had the following structure in a *.libraries.yml.

global-styling:
  css:
    component:
      assets/css/components/mycomponent1/mycomponent1.css:
      assets/css/components/mycomponent2/mycomponent2.css: {}

In Drupal 11, that missing {} translates to a bricked site. I could not even login using drush uli.

The error message that was displayed was
AssertionError: CSS must be nested under a category. See https://www.drupal.org/node/2274843. in assert() (line 128 of /var/www/html/docroot/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php)..

The returns in LibraryDiscoveryParser::validateCssLibrary should be updated so that is_array is not the only test.

Steps to reproduce

  1. Open a library and remove the {}.
  2. Site is now bricked

Proposed resolution

The current messages implies that a libray is missing one of the 5 SMACSS keywords. The message does not state what the actual issue is; the yml is malformed.

Remaining tasks

TBD

User interface changes

TBD

Introduced terminology

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

Issue fork drupal-3634418

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

tregonia created an issue. See original summary.

leandro713’s picture

Assigned: Unassigned » leandro713

liking to work on this

leandro713’s picture

Assigned: leandro713 » Unassigned
Status: Active » Needs review

I’ve opened an MR that improves the assertion message when a CSS library entry is missing its {} options array, and adds a regression test for this case. The targeted test and the full LibraryDiscoveryParserTest class pass.

smustgrave’s picture

Category: Feature request » Task
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Very nice work. I really have no objection to the change, think it's a nice improvement.

damienmckenna’s picture

+1 for this improvement - simply bugs in library definitions are a common mistake, having a little help would be a great improvement for developers.