Layout builder should use #lazy_builder to render blocks

Created on 25 August 2023, over 1 year ago
Updated 7 February 2024, 11 months ago

Problem/Motivation

Layout builder has the class BlockComponentRenderArray which is called indirectly via the event dispatcher to generate a render array for a block.

This method directly calls $block_plugin->build() which generates a render array.

However, block module's block entity BlockViewBuilder builds a render array using #lazy_builder for all blocks.

This means that when you use the block system to render blocks, they will automatically be renderable via bigpipe and dynamic page cache, but when you use layout builder, they won't.

Steps to reproduce

Proposed resolution

It looks to me like conversion to a lazy_builder wouldn't be too bad.

The things passed to the event that are needed are the block plugin, which we can get the plugin ID from, the layout_builder.entity, which we can get the entity ID from, inPreview() which is a bool, and $event->getComponent()->getWeight() which will be an int.

We can then pass the block plugin ID and the layout builder entity ID, the in_preview bool and the weight int to the lazy_builder callback, get the plugin and load the layout builder entity, then do all the same logic as is currently done directly.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 4 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024