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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tregismoreira created an issue. See original summary.

ribel made their first commit to this issue’s fork.

  • ribel committed 07a7c415 on 2.0.x authored by tregismoreira
    Issue #3540437: Skip AJAX requests in RedirectSubscriber to avoid...
ribel’s picture

Version: 2.0.x-dev » 2.0.8
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.