0

I have following code in my controller for route:

\Drupal::destination()->get();
return new TrustedRedirectResponse('http://www.google.com');

Which results in error:

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Routing\TrustedRedirectResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

How can I get destination without compromising TrustedRedirectResponse?

Or how should I use TrustedRedirectResponse not resulting in error?

(What is "controller provided cache metadata" and what is "leaked metadata"?)

  • 1
    This is a known issue: drupal.org/node/2708055. A workaround would be to get the destination directly from the request and either ignore caching or use the code from the patch in your controller to add the cache metadata to the response. – 4k4 Nov 8 '17 at 16:11
  • I too am getting same error :The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Routing\TrustedRedirectResponse. in <em class="placeholder">Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&g – neha Jun 12 '18 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.