Breadcrumbs disappear on cache clear, come back with subsequent cache clear I have a site where the breadcrumb is in different locations depending on what node type or page is being viewed.

In some places, it is interspersed with node content, so the only solution was for my colleague to inject it into the page as a variable, like so (from .theme):

$block = Block::load('breadcrumbs');
$variables['content']['breadcrumbs'] = \Drupal::entityTypeManager()-&gt;getViewBuilder('block')-&gt;view($block);


I've noticed that when I deploy code, the breadcrumbs disappear. I then have to clear the cache, clear Varnish, and clear the cache again and finally hard refresh in my browser to see them again.

Is this related to how breadcrumbs are being injected into the page and if so, is there a better way to do it?
In a node use the breadcrumb builder directly:

\Drupal::service('breadcrumb')-&gt;build(\Drupal::routeMatch())-&gt;toRenderable();


The node gets cached already and the cache metadata of the breadcrumbs bubbles up to the node.

In a page it's preferable to place the block in a region (can be a region of its own) and then place the variable of the region in the page template.

If you want to use code to place the block, make sure you use the block for the correct theme (you have to query the block table with the property theme for this). Now it seems like you use the breadcrumb block placed first on your site, not necessarily the one for your theme.