0

I am using SVG.js with the optional svg.draggable.js, extension and the basic implementation uses this code sample:

rect.draggable().on('beforedrag', (e) => {
  e.preventDefault()
  // no other events are bound
  // drag was completely prevented
})

For my code I removed the e.preventDefault() and it is working as expected except that I am getting the following warning:

event.js:53 [Violation] Added non-passive event listener to a 
scroll-blocking 'touchstart' event. Consider marking event handler 
as 'passive' to make the page more responsive.

NOTE: the event I am calling is beforedrag and warning occurs on touchstart

My code:

node.on('beforedrag', function(e) {
  // stuff
})

Recommendations for this warning is to explicitly call option for passive (as referenced in this question), but because this is a different event passing a passive option (true or false) has no effect on the warning.

node.on('beforedrag', function(e) {
  // stuff
}, null, { passive: false })

My updated question:

Is there anything that I can do to suppress this warning?

I will be opening an issue with the maintainer, but am more interested in what I can do instead of waiting for someone else to fix it.

Phil M
  • 432
  • 7
  • 16
  • What are you trying to pass to what? Also, this is client-side code and has absolutely nothing to do with node.js or with a nodejs `EventEmitter` object so it is only confusing things to bring those up at all. It appears to me that you have to look into your svg library and see if it supports passive listeners or not. This is not a generic question about `.on()`. It's a question about the specific library you're using only. – jfriend00 Aug 05 '19 at 22:50
  • Personally, I'd fire off a feature request to the library maintainer – Jaromanda X Aug 05 '19 at 22:54
  • @jfriend00 You are correct, it is NOT what I originally assumed, and the author has undocumented custom on() handler buried deep inside the code (https://github.com/svgdotjs/svg.js/blob/master/src/modules/core/event.js). I will update the question. – Phil M Aug 05 '19 at 23:12
  • Good detective work to find that code. Now the question is whether that `options` argument is something you can put parameters in or not from where you would normally call `.on()`. – jfriend00 Aug 05 '19 at 23:24

0 Answers0