Problem/Motivation

Writing a custom rest endpoint that use MetatagToken service i got this error:

LogicException</em>: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early

Searching into the MetatagToken module i saw that the method replace() don't use the bubbleable_metadata as Drupal\Core\Utility\Token
do. Even if this parameter is optional in Drupal\Core\Utility\Token, there is a specific case in replace() that can't be controlled without it

if (!$bubbleable_metadata_is_passed_in && $this->renderer->hasRenderContext())

In that case the bubbleable metadata are collected in the active context and the render function is called.

Proposed resolution

In order to be able to define cacheable dependencies to token in other modules, the proposed solution is to add the missing bubbleable_metadata parameter to the replace() method in MetatagToken

CommentFileSizeAuthor
#2 2987107.patch1.35 KBziomizar

Comments

ziomizar created an issue. See original summary.

ziomizar’s picture

StatusFileSize
new1.35 KB
ziomizar’s picture

Status: Needs work » Needs review
ziomizar’s picture

Issue summary: View changes
damienmckenna’s picture

Thanks for finding that and putting together a patch.

Do you have any suggestions on how this could be tested?

damienmckenna’s picture

Status: Needs review » Fixed
Parent issue: » #2957104: Plan for Metatag 8.x-1.6

Committed. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.