Initial argument passed to Drupal behaviors is incorrect

Created on 18 July 2020, over 4 years ago
Updated 3 April 2023, over 1 year ago

Behaviors are initialized with this function Drupal.attachBehaviors = function(context, settings) {}. And we call it on load with those parameters:

Drupal.attachBehaviors(document, drupalSettings);

The idea is to have a DOM element as the context parameter so that attach scripts can use DOM methods on this context directly. Including doing

$(context).once('myonce');

The issue here is that document is not an actual DOM element, it's a Document and does not have all the methods and properties of an Element.

This is an issue with the new once script that expects an Element (so it can use setAttribute or getAttribute). The change here would pass the <html> element as the context for all behaviors. and make it possible to do

once([context], 'myonce');
🐛 Bug report
Status

Needs review

Version

10.1

Component
Javascript 

Last updated 1 day ago

Created by

🇫🇷France nod_ Lille

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024