Undefined js functions after drupal upgrade

Created on 7 July 2025, 5 days ago

Problem/Motivation

After upgrading to jQuery 4 (which ships with Drupal 11), several deprecated functions were removed from the jQuery API — including isArray, trim, and isFunction. While this is not an issue for custom code that can be easily updated, it becomes problematic when third-party jQuery plugins or components — often outdated and unmaintained — still depend on these removed functions.

This change has led to broken functionality in several contributed modules and libraries that extend or rely on jQuery.

The problem is compounded by the fact that many of these libraries are no longer actively maintained and are unlikely to be updated to reflect the jQuery 4 changes.

Steps to reproduce

Install a module or theme that uses a third-party jQuery plugin (e.g., a jQuery extension that hasn’t been updated in years).

Upgrade to Drupal 11 with jQuery 4.

Open a page where that plugin is used.

Observe JavaScript errors related to removed jQuery functions ($.isArray, $.trim, $.isFunction, etc.).

Proposed resolution

Create a lightweight compatibility patch or shim for the most commonly removed jQuery functions (e.g., isArray, trim, isFunction) that can be optionally enabled by developers and site builders.

This would allow teams to:

Identify and monitor deprecated usage without immediately breaking the site.

Have time to remove or update affected plugins.

Maintain backward compatibility in the short term while working toward full compliance with jQuery 4.

This shim should include developer-facing warnings in the console to discourage long-term use.

Remaining tasks

Evaluate which jQuery functions are most commonly missing and still in use.

Draft a compatibility layer (JavaScript shim).

Document the shim and how to enable/disable it.

Propose patches for modules known to be affected.

Discuss whether this shim should be included in core or as a contrib utility.

User interface changes

None directly, unless JS errors prevent expected frontend behavior.

Introduced terminology

jQuery 4 shim: A compatibility layer that restores removed jQuery functions for legacy support.

API changes

None to Drupal's PHP APIs, but JavaScript behavior may change depending on whether the shim is enabled.

Data model changes

None.

Release notes snippet

Upgrading to Drupal 11 introduces jQuery 4, which removes several deprecated functions. Developers using outdated jQuery plugins may encounter issues. A temporary compatibility shim is proposed to help transition affected modules and themes more smoothly.

💬 Support request
Status

Active

Version

11.0 🔥

Component

javascript

Created by

🇧🇷Brazil andrelzgava

Live updates comments and jobs are added and updated live.
  • jQuery

    Affects the version, handling, or usage of the jQuery javascript library.

Sign in to follow issues

Comments & Activities

  • Issue created by @andrelzgava
  • This was announced for developers in jQuery updated to 4.0.0-beta , and I think those functions were previously deprecated. The issues you related have been fixed appropriately. I am unsure of the reasons for doing this.

  • It looks like projects that are maintained are upgrading the deprecations. I suggest creating a contributed module.

  • 🇧🇷Brazil andrelzgava

    I developed this patch to restore 11 jQuery functions that were available in version 3.7 but removed in version 4. With this patch, you can continue using these functions in jQuery 4, which may help keep your site and other dependent packages functioning properly after the upgrade.

    However, I strongly recommend updating your custom code to align with the changes in jQuery 4. You can also contribute to updating third-party packages, or, if that’s not feasible, consider removing packages that are no longer maintained or compatible with jQuery 4.

    Please note: this is an emergency workaround intended to help maintain functionality temporarily after upgrading Drupal.

  • 🇬🇧United Kingdom longwave UK

    Agree with #3, if someone wants to maintain a contributed module that contains BC shims for previous versions of jQuery then they are free to do so, but this doesn't fit with our BC policy for core; we are trying to minimise JavaScript and so don't want to load backward compatibility code that probably won't be used on 99% of sites.

Production build 0.71.5 2024