jquery once is deprecated

Created on 30 May 2025, 29 days ago

Problem/Motivation

The once feature in Drupal was originally implemented via jQuery.once. A new, jQuery-independent version has since been developed and is distributed as the @drupal/once npm package. This version supports the same functionality using vanilla JavaScript and improves performance and modern compatibility. However, many parts of core and contrib still rely on jQuery.once, which keeps an unnecessary dependency on jQuery. To modernize Drupalโ€™s JavaScript ecosystem, this dependency should be removed.

Steps to reproduce

  • Locate a module or theme that uses jQuery.once.
  • Observe that removing jQuery breaks the once functionality.
  • Replace with once() from @drupal/once and confirm it works as expected.

Proposed resolution

  • Identify and refactor all usages of jQuery.once in core to use the @drupal/once library.
  • Remove the core/jquery.once library from core.
  • Ensure that backwards compatibility is preserved when needed through the BC layer.
  • Update related documentation and deprecation notices.

Remaining tasks

  • Audit all JavaScript files in core for usage of jQuery.once.
  • Replace usages with native once() functions:
    • once()
    • once.filter()
    • once.remove()
    • once.find()
  • Remove core/jquery.once from core.libraries.yml.
  • Add/Update automated tests to ensure feature parity.

User interface changes

None.

API changes

  • Deprecate and remove the core/jquery.once library.
  • Ensure once() is used as the standard mechanism for once functionality.
  • Maintain the BC layer so that existing jQuery.once calls work when once() is also used.

Data model changes

None.

๐Ÿ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia abhinesh

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

Comments & Activities

Production build 0.71.5 2024