Enabling a new subthemes causes a crash on Drupal 10.2 and up

Created on 20 August 2024, 11 months ago

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 📌 Manually clear cache keys from plugin managers with finite variations instead of using cache tags Fixed 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.

User interface changes

N/A

API changes

N/A

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024