Early rendering issue in big_pipe_page_attachments() for controllers returning Response objects

Created on 16 August 2022, almost 2 years ago
Updated 8 March 2023, over 1 year ago

Problem/Motivation

In HtmlRenderer::prepare, the main content is rendered by wrapping the execution in the following:

$this->renderer->executeInRenderContext();

The page attachments are generated in the same method, but without executing the rendering in a context:

$this->invokePageAttachmentHooks($page);

The issue is that big_pipe_page_attachments calls Url::toString which invokes RendererInterface:render in the background, trying to render something without a render context. This causes the following exception to be thrown:

The controller result claims to be providing relevant cache metadata, but leaked metadata was detected.

Steps to reproduce

1. Enable bigpipe
2. In a custom route controller use this:

    $build = [
      '#title' => 'A title',
      'content' => ['#markup' => 'Some content'],
    ];
    return \Drupal::service('main_content_renderer.html')->renderResponse($build, \Drupal::requestStack()->getCurrentRequest(), \Drupal::routeMatch());

3. Visit the URL of the custom route
4. Notice the error.

Proposed resolution

Two solutions:
- Adjust HtmlRenderer::prepare so it invokes invokePageAttachmentHooks inside a render context.
- Adjust big_pipe_page_attachments so it calls Url::toString inside a render context.

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

n/a

🐛 Bug report
Status

Fixed

Version

9.5

Component
BigPipe 

Last updated about 13 hours ago

Created by

🇸🇮Slovenia alecsmrekar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024