Facet links with wrong attributes.

Created on 9 December 2022, over 1 year ago
Updated 17 April 2024, 2 months ago

Problem/Motivation

When the page doesn't use any filter (first load) and some facet contains an active item then all items of the next facet will be active too. It means that they will contain 'is-active' attribute class.

Really this is an interesting bug. The list widget prepares an URL by new function getUrlForRequest() https://git.drupalcode.org/project/facets/-/blob/2.0.x/src/Plugin/facets...
And this function stores the URL object in the drupal static https://git.drupalcode.org/project/facets/-/blob/2.0.x/src/Utility/Facet...
So, what we have in the result:

  • Facet module prepares URL for the first facet item by getUrlForRequest()
  • The item is active and adds 'is-active' class attribute to the URL object.
  • The URL object wasn't cloned so the URL in the drupal static updated too
  • Facet prepares the URL for the second item by getUrlForRequest() again but now the function returns the URL with attributes from the previous facet item

Result: every facet link shares its own attributes with the next one.

Looks like it was caused by #3291943: When rendering facets on non search page, it throws error instead of 404 on 404 pages

Proposed resolution

Clone the URL as we did for the other place where we use the same function.
https://git.drupalcode.org/project/facets/-/blob/2.0.x/src/Plugin/facets...

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇺🇦Ukraine HitchShock Ukraine

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

Merge Requests

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.69.0 2024