Load block programmatically, result: <drupal-render-placeholder I want to load a block programmatically:

$block = \Drupal::entityManager()-&gt;getStorage('block')-&gt;load('contextualcart');
$block = \Drupal::entityManager()
  -&gt;getViewBuilder('block')
  -&gt;view($block);
$blockMarkup = \Drupal::service('renderer')-&gt;render($block);


But the result is:

&lt;drupal-render-placeholder callback="Drupal\block\BlockViewBuilder::lazyBuilder" arguments="0=velocontextualcart&amp;amp;1=full&amp;amp;2" token="5IaX-v_M8zGkro6F9hTE93zRfIj9p4nHeLFv8Ja6ZW0"&gt;&lt;/drupal-render-placeholder&gt;


This is fine, because I have to insert a block in AJAX.

What happened? How do I fix it?
When calling -&gt;render() it is rendering a structured array tree assuming that it is part of a whole page which will then do placeholder replacements later.

Use renderRoot() if you are the last instance and e.g. return this directly as an AJAX or JsonResponse.