Error: Call to a member function leave() on null

Created on 25 July 2023, over 1 year ago
Updated 18 June 2024, 5 months ago

Problem/Motivation

Sometimes when Twig debugging is disabled, SDC Twig template compilation seems to fail with the following error:

Error: Call to a member function leave() on null in file [...]/web/sites/default/files/php/twig/64bf9e0bd0c77_same_page_preview:setting_UAdx53yvzVORzVoXou1fqsv-K/c2DvwrUT2BAXYR9hT2ihhvjQ_WgTJm6o1hzJlVVW0TE.php on line 59

For me, it happened with a same_page_preview component.

I was able to track down the root cause. Drupal\sdc\Twig\ComponentNodeVisitor overwrites nodes under display_start at fixed indexes. display_start has a EnterProfileNode as first node and display_end has a LeaveProfileNode as first node. If ComponentNodeVisitor overwrites the EnterProfileNode without overwriting the LeaveProfileNode, the error above is triggered.

Steps to reproduce

I'm not sure under what exact circumstances this happens, it depends very much on the structure of the template and whether Twig debugging is enabled.

Proposed resolution

Collect existing nodes before adding new ones, to make sure none are overwritten.

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component
single-directory components 

Last updated 2 days ago

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024