I am having trouble with the Cache API in Drupal 8. I embedded a views block with pagination through a field preprocess function into a node. When caching is off, I can normally use the pager and will always get the right results, but once caching is one, every block page (e.g. /node/1?page=2) shows the same block content rendering the pager useless.
I assume my hacky method is preventing the node cache to let the view in the field handle it's own caching, hence I always get the content from the page I visited first after clearing cache.
This is how the view is embedded:
function foo_preprocess_field(&$variables) {
$field_name = $variables['field_name'];
if($field_name === 'bar'){
foreach ($variables['items'] as &$item) {
$item['content'] = views_embed_view($item['content']['#markup']);
}
}
}