Re-saving blocks after Context install causes pages to be uncacheable

Created on 2 June 2023, almost 2 years ago
Updated 8 June 2023, almost 2 years ago

Problem/Motivation

After installing Context module and re-saving an existing block, that block causes the page to get the header X-Drupal-Dynamic-Cache: UNCACHEABLE.

Steps to reproduce

Setup a clean Drupal site, enable Dynamic Page cache and set cache time in /admin/config/development/performance. Create a test page, view it as incognito and verify with developer tools that you get header X-Drupal-Dynamic-Cache with MISS or HIT value.

Then go to /admin/structure/block, edit some existing block that exists on the page you created, ie. 'Site branding'-block and re-save it without changing any values. Now view the test page again as incognito and check the header X-Drupal-Dynamic-Cache value, it will show UNCACHEABLE.

If you run drush cex and view the changed configs for the block in question, you'll see that the block has received Context-related configurations. If you manually remove these and the run drush cim, the test page will show X-Drupal-Dynamic-Cache with MISS or HIT value again.

Proposed resolution

I have not looked deeper into this but the added configuration for the block includes

user_status:
    id: user_status
    negate: false
    context_mapping:
      user: '@user.current_user_context:current_user'
    user_status:
      viewing_profile: '0'
      logged_viewing_profile: '0'
      own_page_true: '0'
      field_value: '0'
    user_fields: uid

which seems something that could mess up the caching.

Remaining tasks

Identify the issue and fix it.

🐛 Bug report
Status

Active

Version

4.1

Component

Code

Created by

🇫🇮Finland thatguy

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

Comments & Activities

Production build 0.71.5 2024