Problem/Motivation

The following exception is thrown after enabling a new subtheme in Drupal 10.2:

Twig\Error\LoaderError: Template "@namespace/path/template-name.html.twig" is not defined

This is because the code relies on the cache being invalidated by the theme_registry tag. However the commit from #3335768: Manually clear cache keys from plugin managers with finite variations instead of using cache tags means that the cache is never invalidated, and newly enabled themes will always be set to an empty array rather than built using the findNamespaces method.

Steps to reproduce

Enable a new child theme that extends a parent theme making use of components. Going to a page making use of that component template will trigger a crash when using the child theme.

Proposed resolution

Add more cache tags, and explicitly clear the components cache ourselves via a hook like:

/**
 * Implements hook_themes_installed().
 */
function components_themes_installed($theme_list) {
  // Clear the cached namespaces components whenever a new theme is
  // installed.
  Cache::invalidateTags(['components_namespaces']);
}

Or just as easily, always attempt to find a namespace if it doesn't exist in the cache.

Remaining tasks

Provide issue fork.

Add GitLab CI testing of both Drupal 10 and Drupal 11 so that cache clearing is tested with legacy hooks and modern hooks.

User interface changes

N/A

API changes

N/A

Issue fork components-3469223

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

codebymikey created an issue. See original summary.

johnalbin made their first commit to this issue’s fork.

johnalbin’s picture

Status: Active » Reviewed & tested by the community

Thanks for the bug report, codebymikey!

  • johnalbin committed f72364ea on 3.x
    bug: #3469223 Enabling a new subthemes causes a crash on Drupal 10.2 and...
johnalbin’s picture

Status: Reviewed & tested by the community » Fixed

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.

johnalbin’s picture

Status: Fixed » Needs work

Whoops. I wrote the cache invalidator as a service first and wrote the D10 legacy hook using that service. Then I rewrote the cache invalidator without needing any dependency injection and removed the service definition. But forgot to update the D10 legacy hook because I was testing on 11.

Fixing.

johnalbin’s picture

Issue summary: View changes

  • johnalbin committed 4fa42f2b on 3.x
    bug: #3469223 Fix regression for Drupal 10
    
    By: johnalbin
    
johnalbin’s picture

Status: Needs work » Fixed

I've also turned on CI testing for D10 so this won't happen again.

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.

Status: Fixed » Closed (fixed)

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

berdir’s picture

Opened #3564058: components_registry shows up as a cache tag invalidation on cold cache rebuilds as this causes a slight performance regression for us.