Steps to reproduce.
1. Create a custom content block.
2. Add this block to the node using block_field.
3. Check the node page.
4. Make changes to the custom block.
5. Check the node page again.
Result: Cached version of the block without the last changes will be displayed.
Can be reproduced both as anonymous and logged in user.

Expected result:
Node (which displays the block) page cache should be invalidated when the block is updated.

The problem.
According to the current implementation cache metadata from the block content array is not merged in the field's build array.

$elements[$delta] = [
	'#theme' => 'block',
	'#attributes' => [],
	'#configuration' => $block_instance->getConfiguration(),
	'#plugin_id' => $block_instance->getPluginId(),
	'#base_plugin_id' => $block_instance->getBaseId(),
	'#derivative_plugin_id' => $block_instance->getDerivativeId(),
	'content' => $block_instance->build(),
];

/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$renderer->addCacheableDependency($elements[$delta], $block_instance);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andreyjan created an issue. See original summary.

andreyjan’s picture

Attaching a patch with a fix.

andreyjan’s picture

Status: Active » Needs review
andreyjan’s picture

The above patch applies on Dev version.

michaellander’s picture

Issue tags: +beta blocker
michaellander’s picture

Status: Needs review » Reviewed & tested by the community

I've tested this patch and confirmed that the cache metadata is merged/attached as expected. Thank you!

michaellander’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hussainweb’s picture

Thank you for committing the fix. Is it possible to create a release so that we don't have to switch to dev version?

weseze’s picture

Patch in #2 gives fatal error against alpha8 version. Attached is a corrected one.

EDIT: ignore this patch. It seemed to be issue with https://www.drupal.org/node/2855069

Would be really nice to see a new release so we can stop wasting time on all these issues and there intercompatibility... :)

weseze’s picture

michaellander’s picture

Thanks @weseze, I may aim to release another alpha shortly. I haven't had time to move on a number of the beta blocking issues and it doesn't seem too many others have been able to move them along either. I'd like to get them RTBC'd and rolled in before a beta. So another alpha might be the best route.

hussainweb’s picture

Thanks @michaellander. I am looking forward to the release. We will be able to switch back from dev in our project. :)