Avoid duplicate status messages on AJAX requests from RedirectSubscriber

Created on 8 August 2025, 3 months ago

Problem/Motivation

The data_policy module’s RedirectSubscriber adds a status message on every request when a new data policy is available, using:

$this->messenger->addStatus($this->t('We published a new version of the data protection statement...'));

However, this message is also added during AJAX requests, such as when using Views AJAX pagination or Facet filters, resulting in duplicate status messages being displayed to the user β€” once from the original page load, and again after each AJAX interaction.

This occurs because the RedirectSubscriber::checkForRedirection() method is invoked on every KernelEvents::REQUEST, regardless of the request type.

Steps to reproduce

1. Add a new Policy version, keep it non-required
2. Login as a user that should accept the policy
3. Execute any ajax request (e.g. Views pagination)

You should see the status message repeated along the results.

Proposed resolution

Add a conditional check to skip AJAX requests in the subscriber:

$request = $event->getRequest();
if ($request->isXmlHttpRequest()) {
  return;
}

This ensures that status messages are only added during full page loads, not partial AJAX requests, avoiding duplication and improving UX consistency.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil tregismoreira

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