Block access is checked even if block is inside a group that is not displayed

Created on 13 July 2023, about 1 year ago

Problem/Motivation

We noticed that some of ours block access function were executed even if the block is inside a group that is not displayed on the current page.

It seems to happen because groups are regions.
BlockPageVariant::build() calls BlockRepository::getVisibleBlocksPerRegion() and this method calls the access function of every block in each region.

Steps to reproduce

  1. Create a block that has slow access function or one that returns a short max-age:
        protected function blockAccess(AccountInterface $account) {
          return AccessResult::allowed()->setCacheMaxAge(0);
        }
      
  2. Create a block group and place it with a condition that makes it not displayed on most pages.
  3. Place your block in this block group without any condition.
  4. The cache parameters from the block access are applied to every page event if the block group is not displayed.
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France prudloff Lille

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

Comments & Activities

Production build 0.71.5 2024