Problem/Motivation
Using Drupal 9, the upgrade from version 2.10 to 3.2 causes WSOD.
Steps to reproduce
Install fresh Drupal 9
Install and enable twig_tweak 2.10 using:
composer require 'drupal/twig_tweak:^2.10'
Enable twig_tweak module
Clear all caches
Login and navigate to status page at /admin/reports/status
Notice you can view the status report successfully
Upgrade the twig tweak module to ver 3.2.1 with composer require 'drupal/twig_tweak:^3.2'
Clear all caches
Navigate to status page at /admin/reports/status
Notice the WSOD and error:
The website encountered an unexpected error. Please try again later.
Error: Class "Drupal\twig_tweak\TwigExtension" not found in Drupal\Component\DependencyInjection\Container->createService() (line 259 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal\Component\DependencyInjection\Container->createService(Array, 'twig_tweak.twig_extension') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('twig_tweak.twig_extension', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 273)
Drupal\Component\DependencyInjection\Container->createService(Array, 'twig') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('twig') (Line: 207)
Drupal::service('twig') (Line: 47)
twig_render_template('core/modules/views/templates/views-view-field.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('views_view_field', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 1746)
Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object) (Line: 777)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 374)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 716)
Proposed resolution
Fix the code? I tried stepping through but didn't find an obvious issue. I was suspecting a missing include statement but
I was able to reproduce this on two different sites which are in the process of being upgraded from Drupal 9 to Drupal 10.
If I uninstall version 2.10, clear caches, install version 3.2.1, enable version 3.2.1, it works fine.
This makes deployment more challenging. I have to disable the module locally, commit, deploy. Then add the new module locally, enable it, commit and deploy again.