Problem/Motivation

Drupal 11 ships jQuery 4.0, which removed the deprecated `$.isFunction()` helper. `js/cookieContentBlocker.js` still uses it in `loadBlockedAssets()`:

```js
$.each(Drupal.behaviors, function (name, behavior) {
if (!originalBehaviors[name] && $.isFunction(behavior.attach)) {
behavior.attach(document, window.drupalSettings);
}
});

loadBlockedAssets() is called from handleConsent() on every attach() as soon as consent is stored in the cookie, regardless of whether the page contains blocked content. So on Drupal 11 every page load for a visitor who already gave consent throws:

Uncaught TypeError: $.isFunction is not a function

Because the exception is thrown inside the module’s own attach(), attachConsentEventListeners() and attachConsentEventTriggers() never run for that page: the consent-change buttons get no handlers, and behaviors are not re-attached to unblocked content. We see this in production monitoring (Microsoft Clarity) on a Drupal 11.3 site with cookie_content_blocker 2.6.1, about one second after page load.

Steps to reproduce

Install Drupal 11 with cookie_content_blocker 2.6.1 and configure the consent cookie.
Give consent so the accepted cookie is set.
Load any page (blocked content is not required) with the browser console open.
The console shows TypeError: $.isFunction is not a function immediately after load.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

aras.drupal created an issue. See original summary.

aras.drupal’s picture

Title: $.isFunction is not a function with jQuery 4 (Drupal 11): behaviors not re-attached after consent » $.isFunction removed in jQuery 4 (Drupal 11): attach() throws on every page load with stored consent

sjerdo’s picture

Status: Needs work » Reviewed & tested by the community

LGTM +1

  • sjerdo committed 27df2d8e on 2.6.x authored by aras.drupal
    fix: #3633463 $.isFunction removed in jQuery 4 (Drupal 11): attach()...
sjerdo’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.