In Drupal 9.4, jQuery.once() has been removed. However, there's a Javascript function, once(), that can replace it with a little rewriting:
var closeButton = $("#off-canvas .offcanvas__close");
closeButton.once().on("click", function () {
closeOffCanvas();
});
once takes 3 arguments: 1. Arbitrary key, 2. CSS selector, 3. context
It looks like passing a jQuery object as the CSS selector works too 🤷🏽♀️
var closeButton = $("#off-canvas .offcanvas__close");
$(once("closeButton", closeButton, context)).on("click", function () {
closeOffCanvas();
});
$("iframe").once().fitVids({
customSelector: ['iframe[src*="youtu.be"]'],
});
$(once("iframe", "iframe", context)).fitVids({
customSelector: ['iframe[src*="youtu.be"]'],
});