2

I have a D8 site that's in development and I am getting this error thrown at random on pages which most of the time render quite happily. There doesn't seem to be any real pattern in it.

I can see that it looks like it's designed to prevent the renderer creating an infinite loop (the code is on line 133 of core/lib/Drupal/Core/Render/Renderer.php), but it isn't really clear what's actually causing it. The log error is pretty useless really.

Anyone seen this and found out the cause? Thanks

4

The error is caused by Renderer::renderRoot() in a wrong place, see the docs:

Renders final HTML given a structured array tree.

Calls ::render() in such a way that placeholders are replaced.

Should therefore only be used in occasions where the final rendering is happening, just before sending a Response:

  • system internals that are responsible for rendering the final HTML
  • render arrays for non-HTML responses, such as feeds

(Cannot be executed within another render context.)

Look for renderRoot() in custom code. Check if you need to render at all (most times you need not) and don't render too early, only in theming when there is a render context collecting the bubbled up metadata. Then replace it with Renderer::render().

The random behavior is probably because of caching.

  • Thanks for this, yes there was a renderRoot in some custom code, seems to have sorted it :-) – james-geldart Dec 14 '17 at 10:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.