Problem/Motivation
Notice when using a views block as block field that the cache metadata is not correct.
The cache metadata for the block is being set here: https://git.drupalcode.org/project/ds/-/blob/8.x-3.x/src/Plugin/DsField/...
When $block_build = $block->build(); is called on the views block it renders the display handler. The display handler passes the cache property of the array by reference here https://git.drupalcode.org/project/drupal/-/blob/main/core/modules/views...
If $add_wrappers is false then the render element is assigned as
$render_element = $block_build;
While that assignment is by value, as the #cache property of $block_build is a reference it still points to the same thing.
For for example for the cache tags when when this code runs:
if ($tags = $block->getCacheTags()) {
$render_element['#cache']['tags'] = [];
if (isset($block_build['#cache']) && isset($block_build['tags']) && is_array($block_build['#cache']['tags'])) {
$render_element['#cache']['tags'] = $block_build['#cache']['tags'];
}
$render_element['#cache']['tags'] = array_unique(array_merge($render_element['#cache']['tags'], $tags));
}
We loose the tags as $render_element['#cache']['tags'] = []; actually sets $block_build['#cache']['tags'] to []
Steps to reproduce
- Add a custom display suite block field using a views block that shows a list of content
- Render this on node a
- Add an additional node b
- When node a is viewed, the view has not been updated as the node_list cache tag from the view is not present in the ds block cache tags
Proposed resolution
Fix merging cache metadata behaviour
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork ds-3624874
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 #3
ericgsmith commentedSeeing test failures locally on 8.x-3.x branch - will aim to come back to this to take a closer look