Random page rendering error: A stray renderRoot() invocation is causing bubbling of attached assets to break

Solutions

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.

Tags: Drupal 8 / Theming

Similar questions

When rendering paragraphs in a theme, is there a way to look at the last rendered paragraph while rendering the current one?
I have about two dozen paragraph types. One of them inserts an h2, and generates a jump menu at the top of the page (I am generating that myself). The pattern lab has the content that comes next (whatever the next Paragraph inserted may be) with a special CSS class on the container, because of the particular aforementioned type being used. Is there...
Drupal rendering order - how to define order of rendering?
I'm building a site with Drupal and I have a small problem. I'm rendering a form using hook_menu. The form renders fine and all is good. I am then adding some more markup to the page using hook_page_alter(). Hook_page_alter looks like this: So in my local MAMP install, the content is displayed with the results from hook_page_alter() first then foll...
Adding assets (css/js) for a custom module block (and withstanding a cache enabled install)
I've created my own block which calls a hook_theme implementation which then prepares some data and then renders myblock.tpl.php All of the above is working fine but my module does have some required assets, specifically some css & js files, currently I was doing drupal_add_css/js in my hook_block($delta = 'view') but I've discovered that both ...
Is there any way to force https:// to be used for assets and still be able to define a theme CSS files in its .info file?
I have a theme which defines its CSS files in its .info file, for example with a line like the following. The site is accessed using https://, but for some reason, Drupal tries to load all the files via http://. Is there any way to force Drupal to use https:// on assets and still be able to define a theme CSS files in its .info file?
Create drupal content programmatically with custom entity ( assets )
I am using asset module : https://www.drupal.org/project/asset I creates a new entity type = asset. I get a form where I can add ( document, image, video..). How can I, from a custom module add a content of asset ? I think that I cannot do it the way we creat nodes ... like : Please help thank you
How can I use webform to upload assets and create a project that can be assigned to different users
I am trying to put together a creative request form that a client would fill out. A studio manager would then follow up and assign to a project manager. I am using webform and rules as a starting point with the possibility of using Open Atrium.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.