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
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
Comment #4
johnalbinThanks for the bug report, codebymikey!
Comment #6
johnalbinComment #8
johnalbinWhoops. 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.
Comment #9
johnalbinComment #12
johnalbinI've also turned on CI testing for D10 so this won't happen again.
Comment #15
berdirOpened #3564058: components_registry shows up as a cache tag invalidation on cold cache rebuilds as this causes a slight performance regression for us.