Prevent multiple ajax calls on views refresh

Created on 22 September 2022, almost 2 years ago
Updated 22 July 2024, about 2 months ago

Problem/Motivation

The Views HTML DIV element has multiple 'RefreshView' event handlers, when it should only have one.

This because:

  1. Drupal.behaviors.ViewsAjaxView.attach is run for each loaded html (html page + big piped blocks)
  2. which runs Drupal.views.ajaxView(ajaxViews[i])
  3. then
    const selfSettings = $.extend({}, this.element_settings, {
      event: 'RefreshView',
      base: this.selector,
      element: this.$view.get(0),
    });
    this.refreshViewAjax = Drupal.ajax(selfSettings)
  4. which adds the event handler again and again for each time behaviors attached is called.

Therefore when running JavaScript jQuery('.view-myviewid').triggerHandler('RefreshView'); many ajax calls are run instead of just one.

This is already fixed in Drupal 7 views. @see #2415027: View refresh: multiple ajax calls β†’

Steps to reproduce

Run JavaScript jQuery('.view-myviewid').triggerHandler('RefreshView'); in web browser console and many ajax calls are run instead of just one.

Proposed resolution

Add once() to code to do preflight check before Drupal.ajax(selfSettings)

Remaining tasks

Convert to MR
Decide if specific tests are needed

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia silverham

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • JavaScript

    Affects the content, performance, or handling of Javascript.

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