components icon indicating copy to clipboard operation
components copied to clipboard

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

Open jvbianchi opened this issue 9 years ago • 33 comments

Bug, feature request, or proposal:

In chrome 58, warnings started appearing on console:

zone.min.js:1 [Violation] 'readystatechange' handler took 190ms
zone.min.js:1 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.
zone.min.js:1 [Violation] 'load' handler took 517ms

What is the expected behavior?

Don't get this warning on console: screen shot 2017-04-22 at 20 02 47

What are the steps to reproduce?

Just running the template plunker you get this console warning. Console must be in the verbose level

Plunker: https://goo.gl/DlHd6U

Which versions of Angular, Material, OS, browsers are affected?

Chrome 58.0.3029.81 Mac OSX 10.12.4 (Sierra)

jvbianchi avatar Apr 22 '17 23:04 jvbianchi

Looks like it's related to the new event listener options. More on it here and here

There is no a new options object that can be passed to the addEventListener. The warning is saying the passive event listeners on the page should be passed the {passive: true} option to improve scroll performance. document.addEventListener('touchstart', handler, {passive: true});.

These warnings are only performance recommendation so it's not really something to get too worried about, although performances improvements are always good.

jackvial avatar May 08 '17 13:05 jackvial

Using https://github.com/zzarcon/default-passive-events will remove some of those violation warnings, but there is still some left.

tarlepp avatar May 09 '17 08:05 tarlepp

what about "bind"?

acronHou avatar Sep 04 '17 06:09 acronHou

I can not understand why this is closed, the problem always exist and only this: https://github.com/zzarcon/default-passive-events solved my problem, the above problem thx to @tarlepp

Zwilla avatar Oct 04 '17 20:10 Zwilla

Yup, can confirm that this is still happening

Dunos avatar Oct 10 '17 13:10 Dunos

Yes still getting this warning:

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

FredvanRijswijk avatar Oct 10 '17 14:10 FredvanRijswijk

@andrewseguin are there any recommended solutions for this issue?

mackelito avatar Oct 11 '17 08:10 mackelito

This seems to have gotten worse with beta 12. Displaying a dialog used to appear instantly, now it takes close to 2 seconds for the dialog to appear. [Violation] 'click' handler took 1690ms

The following message is logged about 1200 times from the time I click the button to display a dialog and it appearing. On Material beta 11 it was not logged at all while displaying the dialog. [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.

It looks my specific issue is being caused by a mat-autocomplete with a large data set. I'll create a plunker to demonstrate it.

micahwood avatar Oct 11 '17 20:10 micahwood

Here is a plunker showing the issue with slowing down substantially with large data sets. I added a button to display the autocomplete to make it easier to see the slow down. Also if you open the dev tools and set logging to verbose you can see how many event listeners are being created. It looks like it creates two listeners for each item that is added. I will create a new issue for this. https://plnkr.co/edit/QhlHy7FrlvQbDeRfncCo?p=preview

micahwood avatar Oct 12 '17 20:10 micahwood

FWIW, those touchstart handlers were added to accommodate the ripple effect on buttons. They have since been removed because they were problematic.

crisbeto avatar Oct 12 '17 20:10 crisbeto

this is still happening, should we create a new issue about this, because this one is "closed" when it really isn't resolved at anyway ?

Or @casesandberg did you close this issue by mistake ?

tarlepp avatar Oct 13 '17 18:10 tarlepp

@tarlepp - This should be resolved with #7557 ( doesn't happen on master ) so it should just be a matter of waiting on the next tag or running on a nightly build if it's absolutely critical.

joshwiens avatar Oct 19 '17 18:10 joshwiens

Thanks @d3viant0ne do you know when this is likely to be released?

I'm getting a lot of [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' events appearing in the console and my forms are really slow to load.... It reports back that [Violation] 'click' handler took 17807ms

Keeping my fingers crossed that #7557 resolves these issues!

debslord avatar Nov 03 '17 18:11 debslord

I'm running on "@angular/material": "git+https://github.com/angular/material2-builds#2.0.0-beta.12-62b149f", & the associated CDK & the problem no longer exists.

That build is stable & works with Angular 5.x, at least within the scope of what I am doing. material2-builds are static if you target the hash, really no different than a published build in the strictest sense.

joshwiens avatar Nov 03 '17 19:11 joshwiens

Thanks again @d3viant0ne

Upgraded my project to Angular 5 and the build you're on - weirdly still an issue for me.

This occurs 8000+ times - [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event.
[Violation] 'click' handler took 18268ms [Violation] 'load' handler took 477ms

As a result the form takes around 20 seconds to load - same as @micahwood plunker as he said the larger the dataset the more event listeners

debslord avatar Nov 06 '17 10:11 debslord

@debslord - I'll take another look with the filters off. 90% sure the touchstart stuff is no longer an issue ( on my side at least )

joshwiens avatar Nov 06 '17 10:11 joshwiens

Thank you! I will see about implementing default-passive-events I might have to result to that fix instead

debslord avatar Nov 06 '17 10:11 debslord

I think my issues are probably more around the autocomplete issues mentioned in #5113 and #7749 So it might be slightly different to the issues you were getting @d3viant0ne

Implementing default-passive-events doesn't work either as there seems to be an issue around click events already having this set by default and so it throws an error instead and although the toughstart issues aren't displayed in the console the click still takes much too long. I'm hoping the other two issues will resolve this. Thanks for you help.

debslord avatar Nov 07 '17 08:11 debslord

Please when is this going to be fixed, this is slowing down my app's performance like crazy. Thank you

lexyfeito avatar Nov 30 '17 15:11 lexyfeito

This is back in 5.0.0-rc.3(?)

vegarda avatar Dec 06 '17 11:12 vegarda