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

Created on 23 March 2022, over 2 years ago
Updated 20 May 2024, 6 months 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

Fixed

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 about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 5.7
    last update about 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 about 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 about 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 10 months 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 7 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.

Production build 0.71.5 2024