Ajax Search with Facet Summary triggers: Cannot read properties of undefined (reading 'indexOf')

Created on 28 January 2022, over 2 years ago
Updated 17 October 2023, 9 months ago

Problem/Motivation

When facet summary block is not on the page a subsequent search will result in a javaScript alert to be displayed with the message:

An error occurred while attempting to process /views/ajax?_wrapper_format=drupal_ajax: Cannot read properties of undefined (reading 'indexOf')

Thus preventing the use of the ajax view.

Steps to reproduce

1 - Create a faceted view
2 - Edit Facet Summary Settings and select:

  • Show a summary of how many results were found

3 - Test your view.


Select Facet Summary option: Hide Summary when Facet Source is not rendered

This time the search will work, bypassing the scenario 1 issue but you will see a 404 in the console logs.

An AJAX HTTP error occurred.\nHTTP Result Code: 404 "message":"No facet link or facet blocks found."}'


Proposed resolution

.

Update updateFacetsSummaryBlock function to check that the block is being render on the page prior to attempt an update.

Update FacetBlockAjaxController.php::ajaxFacetBlockView()
Check summary settings to bypass the exception thrown in php when the option Hide Summary when Facet Source is not rendered is selected

🐛 Bug report
Status

RTBC

Version

2.0

Component

Facet summary

Created by

🇮🇪Ireland asirjacques Dublin

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.

  • 🇨🇷Costa Rica adiaz San José, Costa Rica

    Can confirm that patch in #4 works as expected. Thanks a lot!

  • 🇨🇷Costa Rica adiaz San José, Costa Rica
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    424 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    424 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    424 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    370 pass, 10 fail
  • 🇳🇱Netherlands vinlaurens Utrecht, The Netherlands

    Patch in #4 seems to fix the issue, but causes another problem; When you input a text in the exposed fulltext search filter that yields zero results and then try to input text that actually does yield results, the count in the search summary is never updated again.

    The actual problem seems to be caused by the setting "Show a text when there are no results" in the Facets summary settings. When this is enabled, upon yielding zero results as a consequence of inputting a text yielding zero results, the whole summary-wrapper gets replaced causing the code in facets-views-ajax.js:126 (indexOf) to not being able to find the summary-wrapper.

    When "Show a text when there are no results" is disabled, this error does not happen. So this only seems to occur in specific situations.

    I have no time to write a patch right now, but maybe it will give someone some leads to look into this issue. If not, I can possibly supply a patch myself at a later time.

Production build 0.69.0 2024