Use once() and context to prevent accumulated event listeners

Created on 19 February 2024, 9 months ago
Updated 3 April 2024, 8 months ago

Problem/Motivation

Currently multiple redundant event listeners are added to the elements, whenever the behavior .attach() fires.

Steps to reproduce

  1. Install the module.
  2. Open a node form with ajax elements. E.g. a multiple-value link field.
  3. Inspect any text field (outside the multiple-value link element) with browser developer tools.
  4. Check the "Event listeners" inspection tab.
  5. Look for "blur" listeners.
  6. Click "Add another link" on the multiple-value link field.
  7. Refresh the event listeners inspection list.

Expected: Only one "blur" listener.
Actual: Another "blur" listener is added every time we click "Add another link".

Proposed resolution

Apply two techniques to avoid repeated listeners being added:

  • Use 'context' argument in the selector.
  • Use 'once()' as other core scripts do.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇩🇪Germany donquixote

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024