ActiveLinkResponseFilter is not working with BigPipe (in some browsers)

Created on 28 June 2018, almost 7 years ago
Updated 3 June 2025, 4 days ago

tl;dr:

ActiveLinkResponseFilter + BigPipe + Browser conditions (currently Chrome) break 'is-active' class addition in ActiveLinkResponseFilter.php which was hard to find and seemed very strange, because it's server-side!

My current result / recommendation: Can't use BigPipe on multilang Drupal 8 sites with language switcher.

Context:

Drupal\Core\EventSubscriber\ActiveLinkResponseFilter is used to set "is-active" class on active links for anonymous users:

    // There are two distinct conditions that can make a link be marked active:
    // 1. A link has the current path in its 'data-drupal-link-system-path'
    //    attribute.
    // 2. We are on the front page and a link has the special '<front>' value in
    //    its 'data-drupal-link-system-path' attribute.

(ActiveLinkResponseFilter.php)

while authenticated users (plus 403/404) use javascript handling:

 // Handle setting the "active" class on links by:
  // - loading the active-link library if the current user is authenticated;
  // - applying a response filter if the current user is anonymous.
  // @see \Drupal\Core\Link
  // @see \Drupal\Core\Utility\LinkGenerator::generate()
  // @see template_preprocess_links()
  // @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter
  $route_name = \Drupal::request()->attributes->get('_route');
  if (\Drupal::currentUser()->isAuthenticated() || in_array($route_name, ['system.404', 'system.403'])) {
    $page['#attached']['library'][] = 'core/drupal.active-link';
  }

(active-link.js)

This is for example important for the Drupal core language switcher to mark the currently active language.

We were wondering why the language switcher had no .is-active class in some browsers (Chrome, anonymouse) while it worked logged in other browsers (Firefox, Opera, anonymous). I'm not sure if that conditions are met randomly. The problem is definitely server-side but it's unclear when / why it appears!

Problem / Reproduction:

We're running into the problem with BigPipe in all our multilanguage Drupal 8 sites so the problem definitely exists.

Environment:

  • Drupal 8 multilanguage site with language switcher block
  • BigPipe enabled (switch off for correct behaviour!)
  • Logged out (anonymous)

Expected behaviour: The current language is always marked .is-active in the language switcher
8.5.x / 8.6.x behaviour: In some browsers (for us it was Chrome to unknown reasons) the class is missing at all

Workaround

  • Switch off BigPipe

Proposed solution

  • Find out why browsers handle the request differently and the class is not added
  • Write tests against that conditions
  • Fix the problem
🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component

system.module

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024