Problem/Motivation
The Views HTML DIV element has multiple 'RefreshView' event handlers, when it should only have one.
This because:
Drupal.behaviors.ViewsAjaxView.attach
is run for each loaded html (html page + big piped blocks)- which runs
Drupal.views.ajaxView(ajaxViews[i])
- then
const selfSettings = $.extend({}, this.element_settings, { event: 'RefreshView', base: this.selector, element: this.$view.get(0), }); this.refreshViewAjax = Drupal.ajax(selfSettings)
- 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)