Multiple Active Themes - Only default theme namespaces work after upgrading to v3

Created on 24 July 2023, over 1 year ago
Updated 23 August 2024, 4 months ago

Problem/Motivation

Upgraded from Drupal 9.5.9 running Components v8.x-2.4 to Drupal 10.0.10 Components 3.0.0-beta3.

Site has multiple active front-end themes:

- Contributed Theme A
- Custom Theme B
- Custom Theme C (Default Theme)

Each theme registers it's own components namespace within it's own theme.info.yml. Note we are using the new API format already for example:

components:
  namespaces:
    theme_c: ./src/components

These namespaces are referenced throughout templates within the themes and within our custom modules. Sometimes we reference components in Theme A or Theme B within a template used in Theme C.

For example in our node.html.twig file within Theme C (default theme):
{% extends "@bc_base/node/node.twig" %}

We discovered after upgrading that only the default theme's name spaces can be referenced in this manner, and other active theme namespaces no longer work. Instead we receive errors:

The website encountered an unexpected error. Please try again later.

Twig\Error\LoaderError: Template "@theme_b/node/node.twig" is not defined in "themes/custom/theme_c/templates/content/node.html.twig" at line 7. in Twig\Loader\ChainLoader->getCacheKey() (line 99 of /var/www/html/drupal-site/html/vendor/twig/twig/src/Loader/ChainLoader.php).
Twig\Environment->getTemplateClass('@theme_b/node/node.twig', NULL) (Line: 204)
Drupal\Core\Template\TwigEnvironment->getTemplateClass('@theme_b/node/node.twig') (Line: 319)
Twig\Template->loadTemplate('@theme_b/node/node.twig', 'themes/custom/theme_c/templates/content/node.html.twig', 7) (Line: 42)
__TwigTemplate_e00c24621e5aa37876799c6770b633e0->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)
Twig\TemplateWrapper->render(Array) (Line: 53)
twig_render_template('themes/custom/theme_c/templates/content/node.html.twig', Array) (Line: 372)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 168)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 692)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Activate multiple themes, each with their own namespaces defined within their own theme info.yml
  2. Reference a template in a non-default theme via it's namespace... works fine
  3. Switch from Components v8.x-2.4 to Components 3.0.0-beta3.
  4. Note namespaces no longer work

Our workaround for now, is to include all the namespaces for the other active themes within the default theme's info.yml file.

For example:

components:
  namespaces:
    theme_c: src/components
    theme_b: ../theme_b/src/components
    theme_a: ../../contrib/theme_a/src/components

Proposed resolution

According to the module description, namespaces from all active themes should work, not just default theme. Has any one run into this issue? It does not appear related to any open tickets.

🐛 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