- 🇪🇸Spain rodrigoaguilera Barcelona
Interesting.
Someone on my team has been bitten by this.
Personally I think is bad developer experience having to remember selectors to avoid (like .block-xxxx) because they might be the context itself or adding additional logic to check if the context is the element you are trying to match.Not sure of the way forward but adding the logic to check for the context matching the selector (with
context.matches(selector)
) would be ideal for me.Updated the IS to use Drupal once as jQuery Once is removed in Drupal 10. Also use vanila JS.
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
But, when big-pipe is enabled and you are logged-in, the context passed is the element returned by bigpipe and no longer the HTML document, in this case
....That is how the Drupal Behaviors API works, it's not related to BigPipe.
You can observe this in the AJAX API too — see
Drupal.AjaxCommands.insert
:// Attach all JavaScript behaviors to the new content, if it was // successfully added to the page, this if statement allows // `#ajax['wrapper']` to be optional. if ($newContent.parents('html').length) { // Attach behaviors to all element nodes. $newContent.each((index, element) => { if (element.nodeType === Node.ELEMENT_NODE) { Drupal.attachBehaviors(element, settings); } }); }
👆 this only attaches behaviors to the newly inserted content, i.e. with the context not being the full document, but only the relevant DOM subtree.
So this is completely unrelated to BigPipe, but is just one of the several ways to surface this.
I do see how this can be confusing! Rescoping.