Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295104

Layout builder discards cacheability metadata from blocks when they are rendered without content

$
0
0

Problem/Motivation

Layout builder will discard cacheability metadata from blocks if they are visited and produce no content.

Digging into how core blocks function, it looks like this is explicitly captured:

\Drupal\block\BlockViewBuilder::preRender

      // If $content is not empty, then it contains cacheability metadata, and
      // we must merge it with the existing cacheability metadata. This allows
      // blocks to be empty, yet still bubble cacheability metadata, to indicate
      // why they are empty.

With the offending code in LB discarding the cacheability metadata in the same circumstance:

\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender

      $content = $block->build();
      $is_content_empty = Element::isEmpty($content);
      $is_placeholder_ready = $event->inPreview() && $block instanceof PreviewFallbackInterface;
      // If the content is empty and no placeholder is available, return.
      if ($is_content_empty && !$is_placeholder_ready) {
        return;
      }

Proposed resolution

Make it consistent, capture the metadata from empty blocks and bubble it appropriately.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 295104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>