Rendering of paragraphs broken - recursive rendering attempt aborted

Created on 7 November 2023, 8 months ago
Updated 15 November 2023, 8 months ago

Problem/Motivation

No paragraphs are appearing on the website after upgrading to Drupal 10.1.6 (from Drupal 9).

Steps to reproduce

Upgrade to Drupal 10.1.6 and view a page with paragraphs. The paragraphs don't appear and the logs are filled with:

Recursive rendering attempt aborted for . In progress: Array ( [] => )

Proposed resolution

Fix the rendering when there are no cache keys.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Closed: duplicate

Version

10.1 ✨

Component
RenderΒ  β†’

Last updated less than a minute ago

Created by

πŸ‡¬πŸ‡§United Kingdom Rob230

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

Comments & Activities

  • Issue created by @Rob230
  • πŸ‡¬πŸ‡§United Kingdom Rob230

    It looks like the problem is this function:

    public function setRecursiveRenderProtection(array $build): array {
      // Checks whether entity render array with matching cache keys is being
      // recursively rendered. If not already being rendered, add an entry to track
      // that it is.
      $recursion_key = implode(':', $build['#cache']['keys'] ?? []);
      if (isset($this->recursionKeys[$recursion_key])) {
        $this->getLogger('entity')
          ->error('Recursive rendering attempt aborted for %key. In progress: %guards', [
            '%key' => $recursion_key,
            '%guards' => print_r($this->recursionKeys, TRUE),
          ]);
        $build['#printed'] = TRUE;
      }
      else {
        $this->recursionKeys[$recursion_key] = $recursion_key;
      }
      return $build;
    }
    

    For paragraph entities, $build['#cache']['keys'] is empty, so $recursion_key is an empty string. This empty string then matches for every paragraph so they don't render.

    From my investigations the reason why the keys array is empty for paragraphs is because of this code (also in EntityViewBuilder.php):

    if ($this->isViewModeCacheable($view_mode) && !$entity->isNew() && $entity->isDefaultRevision() && $this->entityType->isRenderCacheable()) {
    $build['#cache'] += [
      'keys' => [
        'entity_view',
        $this->entityTypeId,
        $entity->id(),
        $view_mode,
      ],
      'bin' => $this->cacheBin,
    ];
    

    $this->entityType->isRenderCacheable() is FALSE for paragraphs because the Paragraph entity has render_cache = FALSE in its definition.

    Simply checking if $recursion_key is a blank fixes this problem.

  • πŸ‡¬πŸ‡§United Kingdom Rob230

    I don't know if I'm missing something here, but regardless of the reason there are no cache keys, surely a blank key should never be used to detect recursion. This patch shows the way I fixed it.

  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Many sites are using paragraphs in Drupal 10 without this problem. Can we figure out the actual steps to reproduce? I assume the paragraphs are nested or something...

  • πŸ‡¬πŸ‡§United Kingdom Rob230

    It is affecting every paragraph, regardless of nesting, due to the problem I described (keys always being empty for paragraphs).

    If it's not affecting other sites then I suppose there must be some other reason that the $build['#cache']['keys'] array is empty on my site, but I couldn't find one. I searched the code for anything mentioning the cache. Not sure what else to look for.

    Do you know if my change would break anything? I can't see why it makes sense to try to detect recursion without any identifier. The only other way to fix this would be to stop $build['#cache']['keys'] from being empty but so far I couldn't figure out why that's the case - it looked intentional when I stepped through the code, maybe I need to dig deeper to see if it gets set later on and then removed.

  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Drupal 10 was released almost one year ago and I can assert that paragraphs are not in general broken in Drupal 10. If there are serious paragraphs bugs they would be listed here: https://www.drupal.org/project/issues/paragraphs?text=&status=Open&prior... β†’

  • Status changed to Postponed: needs info 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Hold on, core/lib/Drupal/Core/Entity/EntityViewBuilder.php doesn't even have as many lines as your patch suggests it does, and it doesn't have the comments I see in the patch context. Is the file patched already? What is the exact Drupal version? That isn't the core/lib/Drupal/Core/Entity/EntityViewBuilder.php file from 10.1.6.

    I am sending the patch for testing to see that it does not apply.

  • last update 8 months ago
    Patch Failed to Apply
  • πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

    Experiencing this too. I think it started when we began using the patch/MR in πŸ› Can only intentionally re-render an entity with references 20 times RTBC to address that issue. Rob230: using that patch too?

  • Status changed to Closed: duplicate 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom Rob230

    jeffschuler, yes we are using the merge request 4994 from that issue. Thanks for flagging this, I'll continue investigations in the other thread.

Production build 0.69.0 2024