Single directory component CSS asset library not picked up in admin theme immediately after module install without cache clear

Created on 10 July 2024, 8 days ago
Updated 12 July 2024, 6 days ago

Problem/Motivation

After installing a new module with one or more single directory components that are immediately used and visible on the page, the CSS that comes with the SDC is not included in the admin theme.

Steps to reproduce

I've created a minimal reproducible module to illustrate the issue here: https://git.drupalcode.org/sandbox/m4olivei-3460588. Clone the project an put it in your modules folder.

  • Install Drupal from scratch. eg. drush si -y standard
  • Using the UI, navigate to Admin > Extend
  • Enable the SDC Cache Issue module

Expected result

A hotpink bar should appear at the top of every page with the text "beep boop foo" aligned right. The bar being hotpink and aligned right are indicators that the componet CSS was included on the page.

Actual result

The bar is included on the page but is unstyled. The expected CSS is not included on the page.

Also note that if you navigate to the front-end theme (assuming it's different from the admin theme), the component is styled and does include the expected CSS.

In order for the expected styles to be included on the page, a cache clear is required.

Proposed resolution

TBD

Remaining tasks

Debug to understand the core issue, then fix accordingly.

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
single-directory componentsΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @m4olivei
  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON
  • πŸ‡¬πŸ‡§United Kingdom catch

    Install Drupal from scratch. eg. drush si -y standard
    Using the UI, navigate to Admin > Extend
    Enable the SDC Cache Issue module

    What happens if the module is installed via drush instead of the UI?

    I'm wondering if this is a race condition somehow between the sdc being rendered immediately after a form submission vs. the libraries being discovered - i.e. is the first SDC somehow rendered before the library exists as such on the system.

    However I'm not finding in the code where the component libraries are actually attached (as in #attached) by component rendering to see how that happens.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    @catch If it helps, that happens AFAIK in ComponentNodeVisitor::leaveNode, adding attach_library to the compiled twig.

  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    What happens if the module is installed via drush instead of the UI?

    It depends. The following produces the expected result:

    $ ddev drush si -y minimal
    $ ddev drush en -y sdc_cache_issue
    $ ddev drush uli

    However the following reproduces the bug noted here:

    $ ddev drush si -y minimal
    $ ddev drush uli
    [use login link to view the site]
    $ ddev drush en -y sdc_cache_issue

    So it would appear that there is some core code managing the front-end theme cache when the module gets turned on, but not the admin theme, and so the admin theme cache as it concerns SDC assets is stale.

Production build 0.69.0 2024