How do I properly detect if region is empty? I have condition for printing regions in my page template as is not empty, but it will always print empty regions no matter what. What is the proper way to detect empty regions?

For example, {% if page.local_tasks is not empty %}{{ page.local_tasks }}{% endif %} prints out &lt;div class="region region-local-tasks"&gt;&lt;/div&gt;.

If I render the region in themename_preprocess_page() with var_dump(drupal_render($variables['page']['highlighted'])); I will get SafeString with placeholder token:

&lt;div class="region region-highlighted"&gt;&lt;drupal-render-placeholder callback="Drupal\Core\Render\Element\StatusMessages::renderMessages" arguments="0" token="a8c34b5e"&gt;&lt;/drupal-render-placeholder&gt;&lt;/div&gt;


So, technically the region is not empty but I can do nothing about it.
try to apply filters after render, like this : 

{% set has_sidebar_first = page.sidebar_first|render|striptags|trim is not empty %}
{% if has_sidebar_first %}
    {# ... #}
{% endif %}