Problem/Motivation
When using `ui_patterns` with a `BlockSource` plugin (e.g. as part of a Display Builder setup), empty block renders — such as a menu block with no links yet — do not propagate the block's cache metadata into the parent render array. Specifically, the block's config cache tags, cache contexts, and max-age are never merged into the component element when the block renders empty.
This means that after menu links are added, Drupal has no cache tag to invalidate, so the page continues to serve stale content and the menu never appears — even though the underlying data has changed.
This bug is particularly noticeable in PHPUnit functional tests: menus created during test setup are not visible on the page because the render cache is served without the block's config cache tag ever having been declared.
Steps to reproduce
- Set up a Display Builder layout using `ui_patterns` with a **Block Source** component pointing to a menu block (e.g. the main navigation).
- Ensure the menu block initially renders **empty** (no menu links exist yet, or the menu is freshly created).
- Add menu links to the menu.
- Visit the page — the menu block does **not** appear, because the page was cached without the block's config cache tag, and the cache was never invalidated.
Proposed resolution
In BlockSource::alterComponent(), explicitly merge the block plugin's cache metadata (tags, contexts, max-age) into the component element using CacheableMetadata, regardless of whether the block renders empty or not.
Additionally, the method was missing a guard to lazy-initialize $this->block if it had not been set before alterComponent() was called. This is now handled before the cache merge.
The fix ensures that even when a block produces no output, its config cache tags are still attached to the render array and will be correctly invalidated when the underlying configuration changes.
Remaining tasks
- None — the issue is fixed within the attached MR.
User interface changes
- None
API changes
- None
Data model changes
- None
Issue fork ui_patterns-3591705
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
steffenrComment #4
steffenrComment #5
just_like_good_vibesHello, Thanks @steffenr for the report and for the work.
This does not apply anymore. #3516063: No access check on Referenced entities dropped the empty
alterComponent()and moved the cacheability intogetPropValue(), beforebuild():Sources are
RefinableCacheableDependencyInterfacenow, andComponentElementBuildermergesthem into the element whether the value is empty or not, so an empty menu block still
carries
config:system.menu.xxx.Please not that the access cacheability got also fixed along the way too.
Closing as a duplicate.