Upgrade from 2.x to 3.x breaks mail templates

Created on 23 May 2023, over 1 year ago
Updated 6 June 2023, over 1 year ago

We have recently updated components from 2.4 to 3.0.0-beta3 and noticed our component libraries are no longer available in our swiftmailer.html.twig template(s).

They still work everywhere else, so it is not a general issue. Only for the mails...

We also use the mailsystem + swiftmailer module to send HTML mails.
I know swiftmailer is deprecrated and we really should replace it, but I don't think swiftmailer has anything to do with the issue here.
It is the mailsystem module that sets/switched the theme to render the mail in.

We have configured mailsystem to render all mails in our frontend theme.

We also have a swiftmailer.html.twig file that has an include in it; we use it to include a generated css file:

{% include '@my-components/swiftmailer/dist/swiftmailer.css' ignore missing %}

The final rendered email does not include the CSS file, it is just blank.

Reverting to components 2.x fixes the issue.
Reverting to 3.0.0-beta1 also fixes the issue. beta2 and beta3 have the issue.
The breaking change/commit was introduced in https://www.drupal.org/project/components/issues/3191392

Also changing the include to

{% include '@my-theme/components/swiftmailer/dist/swiftmailer.css' ignore missing %}

fixes it.

I noticed version 2.x of components had some code to detect theme changes during a request and can't find this code in 3.x. Maybe that is the cause of this issue?

  /**
   * {@inheritdoc}
   *
   * @throws \Twig\Error\LoaderError
   */
  protected function findTemplate($name, $throw = TRUE) {
    // The active theme might change during the request, so we wait until the
    // last possible moment to check before delivering a template.
    $this->checkActiveTheme();

    return parent::findTemplate($name, $throw);
  }

UPDATE 1: Reverting to 3.0.0-beta1 also fixes the issue. beta2 and beta3 have the issue
UPDATE 2: The breaking change/commit was introduced in https://www.drupal.org/project/components/issues/3191392

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇧🇪Belgium weseze

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

Comments & Activities

  • Issue created by @weseze
  • 🇩🇪Germany macdev_drupal Wiesbaden

    Not sure if it is the same problem but downgrading from 3.0.0-beta3 to 3.0.0-beta1 fix this issue for us.
    It seems like the embed and includes do no loger work like that.

     {% block content %}
        {% include '@hw_radix_standard/navbar/navbar-brand.twig' with {
          prefix: site_name_prefix,

    Twig\Error\LoaderError: Template "@hw_radix_standard/navbar/navbar-brand.twig" is not defined in "themes/custom/hw_radix_standard/templates/block/block--system-branding-block.html.twig" at line 26. in Twig\Loader\ChainLoader->getCacheKey() (line 98 of /var/www/html/vendor/twig/twig/src/Loader/ChainLoader.php).
    Twig\Environment->getTemplateClass('@hw_radix_standard/navbar/navbar-brand.twig', NULL) (Line: 205)
    Drupal\Core\Template\TwigEnvironment->getTemplateClass('@hw_radix_standard/navbar/navbar-brand.twig') (Line: 381)
    Twig\Environment->loadTemplate('@hw_radix_standard/navbar/navbar-brand.twig', NULL) (Line: 333)
    Twig\Template->loadTemplate('@hw_radix_standard/navbar/navbar-brand.twig', 'themes/custom/hw_radix_standard/templates/block/block--system-branding-block.html.twig', 26) (Line: 199)
    __TwigTemplate_0c5736a4f96b51b76a13058fbc5c6d5f___75412211->block_content(Array, Array) (Line: 182)
    Twig\Template->displayBlock('content', Array, Array) (Line: 79)
    __TwigTemplate_8841fceebceb03af7747f1ab821ed205->doDisplay(Array, Array) (Line: 405)
    Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
    Twig\Template->display(Array, Array) (Line: 190)
    __TwigTemplate_0c5736a4f96b51b76a13058fbc5c6d5f___75412211->doDisplay(Array, Array) (Line: 405)
    Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
    Twig\Template->display(Array) (Line: 69)
    __TwigTemplate_0c5736a4f96b51b76a13058fbc5c6d5f->doDisplay(Array, Array) (Line: 405)
    Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
    Twig\Template->display(Array) (Line: 390)
    Twig\Template->render(Array) (Line: 55)
    twig_render_template('themes/custom/hw_radix_standard/templates/block/block--system-branding-block.html.twig', Array) (Line: 384)
    Drupal\Core\Theme\ThemeManager->render('block', Array) (Line: 433)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 446)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array) (Line: 479)
    Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 178)
    __TwigTemplate_83b2ac2dc15fc1e2e161799ddba49516->block_branding_top(Array, Array) (Line: 182)
    Twig\Template->displayBlock('branding_top', Array, Array) (Line: 60)
    __TwigTemplate_83b2ac2dc15fc1e2e161799ddba49516->doDisplay(Array, Array) (Line: 405)
    Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
    Twig\Template->display(Array) (Line: 390)
    Twig\Template->render(Array) (Line: 55)
    twig_render_template('themes/custom/hw_radix_standard/src/components/page/page.html.twig', Array) (Line: 384)
    Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 433)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array) (Line: 479)
    Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 132)
    __TwigTemplate_b3a54b59fb991600ee3d43e44ae0a08d->doDisplay(Array, Array) (Line: 405)
    Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
    Twig\Template->display(Array) (Line: 390)
    Twig\Template->render(Array) (Line: 55)
    twig_render_template('themes/custom/hw_radix_standard/src/components/system/html.html.twig', Array) (Line: 384)
    Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 433)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array) (Line: 162)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 163)
    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: 142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    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: 191)
    Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
    Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
    Drupal\page_cache\StackMiddleware\PageCache->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: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Production build 0.71.5 2024