View refresh: multiple ajax calls (Drupal 8/9/10)

Created on 22 September 2022, almost 3 years ago
Updated 27 January 2023, over 2 years 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

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
ViewsΒ  β†’

Last updated about 17 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.

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