[regression] Entity view block not displayed after #2962166

Created on 24 June 2024, 5 months ago
Updated 20 September 2024, 2 months ago

Problem/Motivation

It seems πŸ› Rendering entity view block on an entity with the same view mode causes recursion infinite loop Fixed caused a regression. I'm experiencing it after updating ctools (4.0.4 => 4.1.0).
It looks like in some cases the entity can be rendered more than once during a page load.

In my case this happens with a wysiwyg Media embed, within the body field of a node.
The media itself uses layout builder and renders an "Extra" view mode via ctools.
Stacktraces in our project: https://gist.github.com/vever001/2f68dfae4f38b3ebda7ceefc87247a3b
The 1st call involves metatag and tokens.
And the 2nd call is the normal render (Media embed in the body field in this case).

Steps to reproduce

I am using ctools 3.x-dev and drupal core 10.2.x below.

- Install clean drupal: ./vendor/bin/drush si
- Enable required modules: ./vendor/bin/drush en ctools media media_library layout_builder
- Create a new Media view mode (e.g.: "Extra") and enable it for Media images
- Enable layout builder for the default Image view mode, set 2 columns
-- left: Image field
-- right: ctools Entity view (Media): using the "Extra" view mode
- Enable "Embed Media" for basic HTML + add ckeditor button
- Create a media image + create a page node and embed the image in the "Body" field
> OK, at this point everything works correctly, we see the 2 columns
- Now enable metatag module, and clear cache
> Actual: Only the left column is displayed
> Expected: Both columns should be displayed (with "Extra" view mode ctools block on the right)

Stacktraces in this scenario (very similar to the ones in the description):
https://gist.github.com/vever001/7937bf44e8dcd3ad5ae20fa1b99be056

Proposed resolution

Looking at the changes from the parent issue, the recursion limit is 1.
This may be too low in some scenarios.
Increase it to 20? (or some other arbitrary value, but \Drupal\media\Plugin\Filter\MediaEmbed::renderMedia uses 20).
+ log in case the recursion limit reaches > 20.

Remaining tasks

?

User interface changes

?

API changes

?

Data model changes

?

πŸ› Bug report
Status

Needs review

Version

4.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium herved

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

Merge Requests

Comments & Activities

  • Issue created by @herved
  • πŸ‡§πŸ‡ͺBelgium herved
  • πŸ‡§πŸ‡ͺBelgium herved
  • Merge request !67Resolve #3456722 "Regression entity view" β†’ (Open) created by herved
  • Status changed to Needs review 5 months ago
  • πŸ‡§πŸ‡ͺBelgium herved

    Ok, it seems metatag gets the [node:summary] token which increments the recursion counter. I guess that makes sense.
    MR opened, and static composer patch attached.

  • Pipeline finished with Failed
    5 months ago
    Total: 355s
    #206845
  • Pipeline finished with Success
    5 months ago
    Total: 456s
    #206903
  • πŸ‡§πŸ‡ͺBelgium herved

    Whoops, I made a silly mistake with the logger... disregard patch #5.
    Also fixing pre-existing cspell and phpcs issues in EntityView.php.

  • Pipeline finished with Success
    5 months ago
    Total: 525s
    #206958
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    I was experiencing a similar issue that only started happening after Drupal 10.3.0 where a ctools node block was not being rendered on the same page as the full node view.

    This patch seems to fix that for me. Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States john.oltman

    Patch #6 worked for me. Raised issue to Major since it will affect any site using the popular Diff module. Without the patch, the render of the second revision in the Diff comparison fails since the same node is rendered twice in a single page view. This makes it look like the second revision deleted all the content.

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

    Patch #6 worked for me as well.

Production build 0.71.5 2024