jQuery is loaded again on AJAX requests

Created on 9 November 2024, 13 days ago

Problem/Motivation

I have an entity form with a paragraph widget. Also I use Chosen module which defines jQuery.fn.chosen() method. After I click the "Add paragraph" button (which triggers an AJAX request), jQuery 3.7.1 is loaded again when I click the, and jQuery.fn.chosen() becomes undefined, so that Chosen does not work on new elements. When I uninstall this module, the core jquery is loaded only once and is not loaded again on AJAX.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇾Cyprus alex.bukach

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

Comments & Activities

  • Issue created by @alex.bukach
  • 🇨🇭Switzerland florianmuellerch Aarau, Switzerland

    Hi @alex.bukach, thanks for reaching out!

    I have a hard time understanding the issue deep enough. This module only does one thing, which is to override the libraries at `core/jquery` and `core/jquery.once` (readding the latter), see jquery_once.module. The other thing it does is seperately providing the files as new dependencies called `jquery_once/jquery` and `jquery_once/jquery.once`.

    I could only assume that this could happen if you both declare a dependency on `core/jquery` and `jquery_once/jquery` or `jquery_once/jquery.once`, leading to both loading the jQuery library seperately (`core/jquery` and `jquery_once/jquery`).

    Can you check your dependencies that you for example only ever use `core/jquery` and `core/jquery.once`, and never `jquery_once/jquery`? Keep in mind that the core itself at this point still loads `core/jquery` sometimes automatically.

    Let me know if this helps!

Production build 0.71.5 2024