Entity browser enhancements should only be executed once

Created on 6 October 2023, about 1 year ago
Updated 10 April 2024, 9 months ago

Problem/Motivation

This module enhances entity browser forms with its own JS using Drupal's JS behaviors API. This code can be invoked many times, especially on sites that use Bigpipe / Dynamic Page Cache. These modules cause Drupal behaviors to be executed multiple times, but with different contexts passed in.

Since this module adds click handlers to checkboxes in the entity browser selection form, if the behaviors are executed an even amount of times (2x, 4x, 6x, etc), the click handler registered by this module essentially cancels itself out, and the checkbox becomes impossible to click in the entity browser.

To help understand the issue, here's an example of this type of problem causing issues elsewhere in core: 🐛 Form API #states property/states should use .once() to apply its rules (Can cause failures with BigPipe and possibly other situations) Needs work

Steps to reproduce

I personally only encountered this after testing an upgrade from Drupal 9.5 to 10.1, so something in the Drupal upgrade, combined with my set of enabled modules (Bigpipe and Dynamic Page Cache?) is causing an extra execution of Drupal JS behaviors.

Proposed resolution

The once JS library should be used to ensure that the Backbone JS enhancements this module adds to Entity Browsers are only added one time. This is why the library exists and is commonly used in Drupal JS behaviors.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

5.0

Component

Code

Created by

🇺🇸United States bkosborne New Jersey, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @bkosborne
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    31 pass, 2 fail
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States bkosborne New Jersey, USA

    test failure unrelated

  • 🇺🇸United States bkosborne New Jersey, USA
  • 🇺🇸United States jmcintyre

    Subscribing. This patch almost worked for me. I'm still unable to select items once I've used the exposed filters on the entity browser, though.

    I've only seen the issue occur when the entity browser is used on a field (image, in my case) that accepts multiple values. I have single-value image fields, on the same node form even, that work just fine.

    I think disabling Big Pipe is going to have to do for now. Thanks for working on this!

  • 🇺🇸United States lisagodare@gmail.com

    Similar to @jmcintyre, I've noticed this issue on when entity browser is used on an Image field that accepts more than 1 value. When the entity browser is initially loaded, I cannot select an image. Clicking over to "Upload" tab and back to the "Library" tab allows me to select images again. The only difference I could see is that BigPipe is loaded with the initial entity browser load, but not when clicking through the tabs.

    Using filters causes it to break again, using a pager does not. This is due to the call to "once", the element returned via Ajax isn't being updated due to having already been applied once before.

    I'm testing an updated patch locally, where I've added a call to .ajaxStop() to add the functionality there as well. So far it is working.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 9 months ago
    32 pass
  • 🇮🇳India rahulrasgon

    @lisagodare, patch is not working after clicking on Load More Button on entity browser.

Production build 0.71.5 2024