Ajax facets not reappearing when their results change from 0 to something >0

Created on 21 March 2022, over 2 years ago
Updated 10 November 2023, 11 months ago

I'm sorry if this belongs to another issue, I've skimmed through the other AJAX related issues and couldn't find any fitting place to post this one.

Problem/Motivation

Facet block doesn't reappear when the situation changes from that facet not having any results to the facet having some results.
The other way around does work (facet blocks get hidden when there are no results).

This is because the facet block is rendered back into the div with the classes 'facet-empty' (and optionally 'facet-hidden').

Steps to reproduce

Patches used:
#3052574: https://www.drupal.org/files/issues/2022-01-21/facets-ajax_not_working-3... β†’
#3191608: https://www.drupal.org/files/issues/2021-01-08/facets-widget-range-slide... β†’
#3008615: https://www.drupal.org/files/issues/2019-04-30/facets-rest_pager-3008615... β†’

Steps:

  • View with multiple facets
  • Filter by "Facet 1" (making sure that "Facet 2" has no results then)
  • The "Facet 2" should disappear -> expected behaviour!
  • Remove "Facet 1"'s value
  • "Facet 2" does not reappear, because the facet block is rendered inside the div tag with the classes: 'facet-empty' and 'facet-hidden'.

Proposed resolution

Find a solution to replace the 'facet-empty' + 'facet-hidden' div instead of rendering the facet block inside of it.

Remaining tasks

Patches, I haven't got to debugging this but I'll try to do so and attach a patch if I find the solution.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium RandalV

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.

  • πŸ‡ΊπŸ‡ΈUnited States jlstrecker Athens, Ohio, USA

    I ran into what may be the same bug. It started happening when I applied a similar patch to one listed above (#3052574: https://git.drupalcode.org/project/facets/-/merge_requests/113.diff).

    I have a View with Ajax enabled that initially shows no results. As expected, facets are hidden at that point. Once I enter search text into the exposed filter and the View shows some results, the facets should appear. That was the case before I applied the patch. But now, the facets remain hidden (they appear in the HTML but have class "hidden").

    I was able to work around the problem by changing each facet's "Empty facet behavior" from "Do not display facet" to "Display text" and leaving the "Empty text" field empty.

Production build 0.71.5 2024