I am using hammer for dragging and it is getting choppy when loading other stuff, as this warning message is telling me.
Handling of 'touchstart' input event was delayed for X ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responsive.
So I tried to add 'passive' to the listener like so
Hammer(element[0]).on("touchstart", function(ev) {
// stuff
}, {
passive: true
});
but I'm still getting this warning.
This question is related to
javascript
jquery
angularjs
touch
hammer.js
I found a solution that works on jQuery 3.4.1 slim
After un-minifying, add {passive: true}
to the addEventListener function on line 1567 like so:
t.addEventListener(p, a, {passive: true}))
Nothing breaks and lighthouse audits don't complain about the listeners.
Also encounter this in select2 dropdown plugin in Laravel. Changing the value as suggested by Alfred Wallace from
this.element.addEventListener(t, e, !1)
to
this.element.addEventListener(t, e, { passive: true} )
solves the issue. Why he has a down vote, I don't know but it works for me.
For jquery-ui-dragable with jquery-ui-touch-punch I fixed it similar to Iván Rodríguez, but with one more event override for touchmove:
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ) {
this.addEventListener('touchstart', handle, { passive: !ns.includes('noPreventDefault') });
}
};
jQuery.event.special.touchmove = {
setup: function( _, ns, handle ) {
this.addEventListener('touchmove', handle, { passive: !ns.includes('noPreventDefault') });
}
};
For those stuck with legacy issues, find the line throwing the error and add {passive: true}
- eg:
this.element.addEventListener(t, e, !1)
becomes
this.element.addEventListener(t, e, { passive: true} )
This hides the warning message:
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ) {
this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
}
};
Source: Stackoverflow.com