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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2987107.patch | 1.35 KB | ziomizar |
Comments
Comment #2
ziomizar commentedComment #3
ziomizar commentedComment #4
ziomizar commentedComment #5
damienmckennaThanks for finding that and putting together a patch.
Do you have any suggestions on how this could be tested?
Comment #7
damienmckennaCommitted. Thanks.