The fix for this issue, https://www.drupal.org/project/entity_embed/issues/3063398, caused the same issue seen here, https://www.drupal.org/project/drupal/issues/2940605, but now affecting embedded entities.

My site had a page with an embedded Media entity of a simple checkmark for a comparison table reused as many times as needed (I think around 40). I upgraded to the newest version of entity_embed, and all of a sudden I noticed that only 20 of those images were getting rendered. I tracked it back to the recursive limit now in place: https://git.drupalcode.org/project/entity_embed/blob/8.x-1.0/src/Plugin/...

Comments

tom.moffett created an issue. See original summary.

tom.moffett’s picture

oknate’s picture

perhaps data-recursion limit property would allow the embed to override the default, which is 20.

That way if you want to reuse a checkbox embed 150 times on a page, you could set the limit to 200.

There shouldn't be an option for unlimited re-use.

Setting it for each embed would present a UX issue, if you had to set the recursion limit on each embed. I guess we could just use a setting on the filter.

steveoriol’s picture

StatusFileSize
new54.33 KB

I have the same kind of problem, where and how can you change this limit?
show issue

weynhamz’s picture

Status: Active » Needs review
StatusFileSize
new2.25 KB

Bitten by this recently, a page migrated from a legacy system, is using a very small arrow image as list bullet, the image is migrated as embedded media entity, but it is used more than 20 times within the same page, thus triggered this recursion detection, but it is not a recursion at all. The current problem for this recursion detection is that it can count the total times the entity been rendered, not considering if it is truly a recursion or not.

Attached patch maybe can help on this.

Status: Needs review » Needs work

The last submitted patch, 5: 3067452-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

marcvangend’s picture

Thank you @weynhamz, the patch worked for me.

The code in this module seems to follow the code in Drupal Core (\Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter). In #2940605: Can only intentionally re-render an entity with references 20 times people are working on the same problem in the context of that formatter, but looking at the patch they seem to have come up with a different approach. It might be good to compare both solutions.

Of course to get anything committed, tests should pass. It looks like the tested render array should be made truly recursive, instead of merely repeating.

tobiberlin’s picture

I had the exact same issue as weynhamz, the patch from #5 resolved my issue

a.milkovsky’s picture

#5 works great, thank you!

+++ b/src/Plugin/Filter/EntityEmbedFilter.php
@@ -124,6 +124,9 @@ class EntityEmbedFilter extends FilterBase implements ContainerFactoryPluginInte
+    static $prv_depth = 0;

We can to use class properties instead of static variables.

gngn’s picture

#5 works for me too.

omkar06’s picture

Status: Needs work » Needs review
StatusFileSize
new852 bytes

Tried #5 and it works(not registering any watchdog message). I noticed that, `static::$recursiveRenderDepth[$recursive_render_id]` always remains 1. Even we embed the same entity 100 times, It will away work and it won't go to below condition block:

          if (static::$recursiveRenderDepth[$recursive_render_id] > static::RECURSIVE_RENDER_LIMIT) {
            $this->loggerFactory->get('entity')->error('Recursive rendering detected when rendering embedded entity %entity_type: %entity_id. Aborting rendering.', [
              '%entity_type' => $entity->getEntityTypeId(),
              '%entity_id' => $entity->id(),
            ]);
            $entity_output = '';
          }

I am not sure whether it is the correct approach or not. So providing another workaround(not a solution) in patch to increase recursion render limit.
The current limit is 20. If anyone wants to increase the limit to 60, can try this patch.

Status: Needs review » Needs work
a.milkovsky’s picture

The #11 does not include changes from #5

joshua.boltz’s picture

The patch in #5 addressed the issue for me too. Not sure why it's marked as Needs Work.
In my case, I was hitting the recursion limit error while embedding the same media image in a WYSIWYG in 6 to 8 simultaneous paragraph items.
For example, the first 6 paragraph items would render the image properly, but on the 7th paragraph item, the image would not render.

kiseleva.t’s picture

Status: Needs work » Needs review
StatusFileSize
new1.94 KB

I've applied patch from https://www.drupal.org/project/drupal/issues/2940605#comment-14033526 and extended the $recursive_render_id with parent info when possible, so it decreases the number of repeated entities if the same media used in different paragraphs for example.

imre.horjan’s picture

Patch #5 works for me

marcvangend’s picture

@imre.horjan thanks for letting us know. Did you also try the patch from #15? After all it's good if we have a patch that is known to work, but even better if we have a patch that is known to work and passes the tests.

imre.horjan’s picture

@markvangend I absolutely understand your point...a patch needs to pass tests.
patch #15 is a different approach than patch #5 and unfortunately didn't work in my use case.
My use case is embedding an image (media entity) multiple times in a rich text field.

(In my opinion the best approach would be porting patch 47 from issue 2940605, but there's a lot of code change in there, so that's not gonna be easy: https://www.drupal.org/project/drupal/issues/2940605#comment-13923591 )

marcvangend’s picture

@imre.horjan That's valuable feedback, thanks.

nikathone’s picture

I tried patch #15 and it didn't work for me but #5 did the trick.

sj.suraj’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Need tests

I also tried using patch in #5 and it's working for me and #15 is not working. Also, it seems that the reason #5 is failing a test is b/c it's testing for the exact thing that it's trying to fix.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs work

If #15 is not working then I would guess that "needs work" is probably the more appropriate status for this issue. :)

wylbur’s picture

We tried the patch in #5 and #15, but it did not resolve our issues.

We are using many paragraphs, each with just one instance of an icon. Only the first 20 instances appear.

This only affects a single page on our site, so we have a temporary workaround installed. We will wait for resolution of the core patch, which should provide a more permanent solution.
https://www.drupal.org/project/drupal/issues/2940605

joshf’s picture

The patch in #5 solved the problem for me; thanks!

It does need the test to be completely rewritten, as the current test only checks to see whether an item can be rendered more than 20 times with the same context and fails if it can (which is just completely wrong). The correct test won't be trivial to write because I think you'll need to provide some mock classes to set up the correct behavior. The patch also needs code quality fixes.

#11 is a very limited workaround, not a fix, and should not be considered for merging.

#15 is simply incomplete; the way it's written no behavior is changed. It might work if there was a call made to ::setRenderPath(), but there isn't. I'm hiding it because it's just not a solution and will only confuse things.

@wylbur this issue is specifically for the entity_embed module; the Drupal core patch you referenced will not fix this issue. Further, I don't think patching this module will fix any problems you're having with paragraphs.