When we inject the toolbar loader code at the end of body in WebprofilerEventSubscriber we directly use the render() function, but it doesn't work anymore because of #2450993: Rendered Cache Metadata created during the main controller request gets lost:

The website encountered an unexpected error. Please try again later.

LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in Drupal\Core\Render\Renderer->doRender() (line 229 of core/lib/Drupal/Core/Render/Renderer.php).

Drupal\Core\Render\Renderer->render(Array)
render(Array)
Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber->injectToolbar(Object)
Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber->onKernelResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object)
Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(Object, 'kernel.response', Object)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object)
Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.response', Object)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lussoluca’s picture

dawehner’s picture

+++ b/src/EventSubscriber/WebprofilerEventSubscriber.php
@@ -72,7 +77,7 @@ class WebprofilerEventSubscriber implements EventSubscriberInterface {
-        $content = mb_substr($content, 0, $pos) . render($toolbar) . mb_substr($content, $pos);
+        $content = mb_substr($content, 0, $pos) . $this->renderer->renderRoot($toolbar) . mb_substr($content, $pos);

Do we have attachments we care about here, for example?

lussoluca’s picture

No it's just used to render the toolbar javascript preloader (/templates/Profiler/webprofiler_loader.html.twig)

lussoluca’s picture

Status: Active » Reviewed & tested by the community

lussoluca: dawehner: it's just used to render the toolbar javascript preloader
dawehner: lussoluca: oh I see, well then +1 RTBC

  • lussoluca committed 771278f on 8.x-1.x
    Issue #2527154 by lussoluca: Render context is empty
    
lussoluca’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Committed to 8.x-1.x

Status: Closed (fixed) » Needs work

The last submitted patch, 1: render_context_is_empty-2527154-1.patch, failed testing.

lussoluca’s picture

Status: Needs work » Closed (fixed)