Random page rendering error: A stray renderRoot() invocation is causing bubbling of attached assets to break
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.)
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.