Cache prevents display of alert

Created on 26 August 2025, 2 months ago

Problem/Motivation

When a page is rendered for a user A and there is no alert, \Drupal\sitewide_alert\SitewideAlertRenderer::build() will return an empty array. This result is cached. If an admin enables an alert, the next time user A refreshes the page, the cache will work, \Drupal\sitewide_alert\SitewideAlertRenderer::build() will not even run and as a result the alert is not displayed.

Steps to reproduce

  1. Clear the cache.
  2. As anonymous, visit the homepage.
  3. In another browser session, create an alert.
  4. In the first browser session, as anonymous, refresh the page. The alert is not displayed, but it should!
  5. Clear the cache.
  6. In the first browser session, as anonymous, refresh the page. The alert is now displayed, as it should.

Proposed resolution

This seems to be a regression after Unnecessary invocation of sitewide_alert/load route when no active alert exists increases server load Active , these lines. But I don't think we should remove these lines, that prevent attaching the javascript library.
I suggest to clear the cache once an alert is created.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇵🇹Portugal dxvargas

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024