Menu block renders when tree is empty as of 8.x-1.8 [regression]

Created on 23 March 2022, almost 3 years ago
Updated 21 April 2023, almost 2 years ago

Problem/Motivation

Removing the access check in πŸ› Module causes double rendering of blocks just to check access Fixed now means that empty menu blocks are being rendered. For themes that depend on only blocks with links rendering, this means visually empty regions are now appearing.

#3216265-15: Module causes double rendering of blocks just to check access β†’ gave a recommendation for how to address this problem without re-adding the access check and it worked well, so I'm rolling a patch

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jastraat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡΅πŸ‡ΉPortugal rutiolma

    +1 for patch 17

  • πŸ‡³πŸ‡ΏNew Zealand jweowu

    The patch in #17 is working for some cases but not others.

    It seems to me that the obvious solution to avoiding repeated rendering was already mentioned by mglaman back in #15:

    add static caching for the build() output, so access builds the block, and calling build() reuses the cached output

    Is there some reason why re-using a cache of the rendered block would be problematic? I'm very surprised something along those lines wasn't the original change made for this issue.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Composer require failure
  • πŸ‡³πŸ‡ΏNew Zealand jweowu

    #17 did not resolve the issue for me nor some other users.

    This new patch implements the caching approach described in comment #26 above (and in #15) to deal with the performance concern raised in πŸ› Module causes double rendering of blocks just to check access Fixed , and restoring the blockAccess() method to fix the bugs described in this issue.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    9 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & pgsql-14.1
    last update over 1 year ago
    9 pass
  • Patch #27 works for our use case.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    I think we can close πŸ› Empty blocks get displayed Needs review as a duplicate of this issue (#3271218)?

    And maybe add contrib credit here, for folks who contributed over there.

  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    FYI the render|striptags|trim check may not work correctly if the block renders using a lazy builder, there was an issue in the Gin theme where I ran into the same problem.

    Patch #27 is also working for me.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    At the risk of causing confusion...... #27 fixed our issue of "if page.region_name" being "incorrectly" evaluated as true. We haven't used any of the twig workarounds, nor have we added/used the core patch on 🌱 [meta] Themes improperly check renderable arrays when determining visibility Needs work .

    Does that track with what folks expect this patch to do? (I'm very pleased haha, I was just rereading the issue summary today, and I wasn't sure if I lost track of what was meant to be addressed in this issue vs. the core issue.)

    -------
    Put another way...

    Page template excerpt -- "sidebar_primary" is a region that contains a menu block:

          {% if page.sidebar_primary %}
          <div id="sidebar-top" class="secondary">
            {{ page.sidebar_primary }}
          </div>
          {% endif %}
    

    Without the patch (#27), the resulting markup is this:

    <div id="sidebar-top" class="secondary"></div>
    

    With #27, the div simply isn't there πŸŽ‰ And that's certainly what I was hoping for, but...

    Does that fit with everyone's intentions/expectations? -- even without the twig filter workarounds?

  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    Confirming #31, I only applied the patch from #27 and did not change any Twig or check any render arrays.

  • πŸ‡³πŸ‡ΏNew Zealand jweowu

    That's 100% the intention of the patch, yes. It solves the problem raised in πŸ› Module causes double rendering of blocks just to check access Fixed without the side-effect of causing the present issue (and in turn causing people to use twig-based workarounds); so what you're seeing is exactly what's intended.

  • Status changed to Fixed 10 months ago
  • πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

    Thanks @jweowu for fixing the regression without too much changes. It seems like people are happy with this change and it will be in the next release

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡³πŸ‡ΏNew Zealand ericgsmith

    I believe this caused a performance regression - πŸ› Performance issue caused by rendering in access check Active

    If anybody who experienced an issue that was fixed by this issue are able test that πŸ› Performance issue caused by rendering in access check Active does not cause a regression, or outline some steps that I can add to the automated tests I would be very grateful.

  • πŸ‡³πŸ‡ΏNew Zealand jweowu

    I believe the issue I experienced was something like this:

    1. A menu block is configured to display the menu for children of the current page (children which may or may not exist; or indeed the current page may simply not be in the menu at all).
    2. The block is assigned to a block region which has no other blocks -- it exists for the sole purpose of displaying that menu, and only if there is a menu to display.
    3. If the block's access check returns false, then the block is not included in the region, and the region is not displayed, as it has no contents.
    4. If the block's access check returns true, then the block is included in the region (with a minimum of some generic block boiler-plate markup), and the region is rendered.
    5. If the latter still happens when the menu was "empty", then we see an empty region/sidebar displayed on the page, effectively pushing the rest of the content out as if it were padding.
Production build 0.71.5 2024