Problem/Motivation
After upgrading Twig from 3.29.0 to 3.30.0 (via composer update --with-dependencies), Drupal 11.4.7 sites throw a TypeError on every page request (front-end and admin):
TypeError: Twig\Runtime\EscaperRuntime::escape(): Argument #4 ($autoescape) must be of type bool, null given, called in .../sites/default/files/php/twig/... on line 58 in Twig\Runtime\EscaperRuntime->escape() (line 94 of vendor/twig/twig/src/Runtime/EscaperRuntime.php).
Twig 3.30.0 made the $autoescape parameter of EscaperRuntime::escape() stricter (now requires bool). Previously compiled Twig templates (from 3.29.0) still pass null, causing the failure.
Steps to reproduce
- On Drupal 11.4.7 + PHP 8.3, run
composer update --with-dependencies (this upgrades twig/twig from 3.29.0 to 3.30.0).
- Visit any page (front-end or admin).
- Observe the TypeError above.
Proposed resolution
- Investigate whether Drupal’s Twig integration needs updates for Twig 3.30.0’s stricter type requirements.
Workaround:
composer require "twig/twig:3.29.0" --no-update
composer update twig/twig
drush cr
After this, the site works normally with Twig 3.30.0.
Remaining tasks
- Decide on automatic cache clearing vs. documentation.
- Confirm whether any Drupal code needs changes for Twig 3.30.0 compatibility.
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Twig 3.30.0 introduces a stricter type requirement on EscaperRuntime::escape(). Sites upgrading from 3.29.0 must clear the compiled Twig cache (rm -rf sites/default/files/php/twig/* + drush cr) or the site will fatal with a TypeError.
Comments
Comment #2
cilefen commentedThis looks like an exact duplicate of #3625969: Twig's 3.30 TypeError: Twig\Runtime\EscaperRuntime::escape(): Argument #4 ($autoescape) must be of type bool, null given.