Problem/Motivation
Reported case: a computed field on exhibition nodes implements CacheableDependencyInterface with the node_list:event tag. When an event is linked to an exhibition, the exhibition page is not updated until a cache clear.
Investigation found one cause in UI Patterns and three in Display Builder.
1. UI Patterns field formatter source
FieldFormatterSource loses computed field cacheability, and the access cacheability of denied referenced entities. This is the reported case, reproduced by a failing kernel test with the core computed test field. See [#UIP].
Fixing it in UI Patterns is not enough for a field source placed at root: its cacheability lands in the #cache that 2 and 3 lose.
2. Entity view wipes the cacheability of root sources
ComponentElementBuilder::buildSource() stores what a source collects (access results, block plugin cacheability, derived entities, max-age 0 on a missing context) in the top level #cache of the build. EntityViewDisplayTrait::buildSources() copies it, then overwrites it:
$build['#cache'] = $fake_build['#cache'] ?? [];
$cacheability->applyTo($build);
$cacheability is always empty, and CacheableMetadata::applyTo() replaces instead of merging. Checked on a node with a views_block source at root:
- collected: contexts
route,user,user.permissions,user.node_grants:view..., tagsnode:1,config:core.entity_view_display.node.article.full... - after
buildSources():{"contexts":[],"tags":[],"max-age":-1}
The rendered block keeps its own #cache, so this bites when a source renders empty or when its access varies. Sources nested in a component are not affected: they bubble through the component element.
3. Page layout drops the cacheability of root sources
PageLayoutPageVariant::build() keeps only the slot item:
$build = $this->componentElementBuilder->buildSource($data, 'content', [], $source, $contexts);
$data[] = $build['#slots']['content'][0] ?? [];
$build['#cache'] is discarded. Same consequences as 2.
4. Page layout selection cacheability is lost
AccessControlHandler::loadCurrentPageLayout() calls $this->access($page_layout, 'view') as a boolean. The cacheability of the conditions, for every layout checked including the rejected ones, never reaches the response. PageVariantSubscriber only adds the config prefix tag.
The impact is lower: Dynamic Page Cache does not cache the page variant, and Page Cache keys on the URL. It still matters for reverse proxies purging by tag and for max-age 0 on a missing context.
Views is not affected: PreprocessViewsView copies #cache without overwriting it.
Proposed resolution
- 1: remove the empty
CacheableMetadatafrombuildSources(). - 2: merge
CacheableMetadata::createFromRenderArray($build)of each source into the variant cacheability. - 3: collect each access result with
$return_as_object = TRUEinloadCurrentPageLayout(), and add it in the subscriber and the variant.
Remaining tasks
- Kernel tests failing first: root block source on entity view, root block source on page layout, a condition context on page layout selection.
- Fixes 2, 3, 4.
Issue fork display_builder-3613372
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
mogtofu33 commentedComment #3
mogtofu33 commentedComment #4
mogtofu33 commentedComment #6
mogtofu33 commentedProbably best to wait for next UI patterns release and change this MR to avoid 2.0.x-dev even temporarily.
Comment #7
mogtofu33 commentedComment #8
mogtofu33 commentedComment #10
mogtofu33 commented