I have a strange behavior with my block facet. I use bootstrap theme.

When I create a facet block, and check the checkbox ' Hide facet when facet source is not rendered'
all is good, on my search page, I see my block that I have added to the sidebar-second.

but when I go to other pages like front or Content type page, the sidebar second is displayed but there are no other blocks with my facet block in these region !

When I preproces_region to see the dump of these region, I have a strange output linked to facet ! Thus in the twig, the content variable is always true ... and the sidebar second is displayed.

with my dump(), I see that markup :

"content" => Markup {#5188 
    #string: "<drupal-render-placeholder callback="Drupal\block\BlockViewBuilder::lazyBuilder" arguments="<strong>0=themes&amp;1=full&amp;2</strong>" token="b4276344"></drupal-render-placeholder>"
  }

my facet is called themes.

If I set a path visibility on the block I don't have the problem for front and other pages, the sidebar variable 'content' is really empty but the block facet disappears from my search page too :(
I have tested with the checkbox 'Hide facet when facet source is not rendered' checked and unchecked.

Has anyone ever encountered this problem?

CommentFileSizeAuthor
#5 facet-blocks.gif2.99 MBborisson_
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pixelpreview created an issue. See original summary.

pixelpreview@gmail.com’s picture

I have setted the path from my search in the block visibility too
only the option 'Hide facet when facet source is not rendered' checked is not sufficient to hide completely the block from sidebar region in my case

borisson_’s picture

I've tried but can't reproduce this problem.

sylvainar’s picture

I got the same problem here, even if facets blocks are not rendered, they produce markup, so the region is not empty, and all the things like (example from Bootstrap theme) :

            set content_classes = [
            page.sidebar_first and page.sidebar_second ? 'col-sm-6',
            page.sidebar_first and page.sidebar_second is empty ? 'col-sm-9',
            page.sidebar_second and page.sidebar_first is empty ? 'col-sm-9',
            page.sidebar_first is empty and page.sidebar_second is empty ? 'col-sm-12'
            ]

wont work. I don't think this issue should be closed, checkout those which report the same bug :
- https://www.drupal.org/node/2797167
- https://www.drupal.org/node/2817265

borisson_’s picture

FileSize
2.99 MB

So, I think this is a problem related to lazy building of blocks and probably really hard to fix, if it is at all possible.

So what happens is this:

.1 The block gets replaced by a lazy builder tag by the rendering system
.2 The theme will see that blocks are placed in the sidebar and will add the required classes, it notices that the lazy builders are present so that's why the classes are added. (\bartik_preprocess_html)
.3 The block gets built (\Drupal\facets\Plugin\Block\FacetBlock::build)
.4 The block is empty, but the sidebar is still shown (but empty)

The way to fix is this, is to use block visiblity settings to make sure it only gets displayed on the search pages.

See attached gif for the output, in that gif we first see the homepage with an empty sidebar. I inspect the source to verify that it's actually empty.
Then, I set the visiblity settings so that the facets only display on the correct page, we go back to the homepage and see that the sidebar is actually empty.

This means, I think we can close this as "works as designed"; but I'll tweet about it to see if people who are more knowledgeable can tell me where I went wrong and how to fix this issue.

Wim Leers’s picture

Duplicate of #953034: [meta] Themes improperly check renderable arrays when determining visibility.

Solution is simple: do not rely on conditional regions. Conditional regions have always been buggy, the problem is just more prominent now in Drupal 8 with its lazy builders.

jwilson3’s picture

"Solution is simple" ... except not so much when a design system is built around dynamically changing page layout based on whether a page has a sidebar or not. Doh!