Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Take advantage of passive event listeners #8866

Open
vicb opened this issue May 26, 2016 · 32 comments
Open

[feat] Take advantage of passive event listeners #8866

vicb opened this issue May 26, 2016 · 32 comments
Assignees
Labels
area: core Issues related to the framework runtime core: event listeners feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature hotlist: google state: Needs Design
Milestone

Comments

@vicb
Copy link
Contributor

vicb commented May 26, 2016

/ref https://github.com/WICG/EventListenerOptions

It's a way to declare that preventDefault() is not called by handler and make scrolling smoother.

Needs more investigation if support would be useful in Angular.

@robwormald
Copy link
Contributor

Agree this is a good idea. In a similar vein, a way to run outside of the zone would be useful as well.

Something like:

<div (scroll:{passive:true})="onScroll()"></div>

or

<div (scroll:{zone:false})="onScroll()"></div>

@aleksandar-b
Copy link

Current status of this?

@vicb
Copy link
Contributor Author

vicb commented Nov 29, 2016

Current status of this / any news

is not very helpful.

What is your use case, how this would help your app would be much more valuable.

@piyushgupta1
Copy link

piyushgupta1 commented Dec 26, 2016

Current Status of this.?
My use case is i am loading few charts with some few thousands data points each but as that is storage operation (Dexie) so the thread hangs till i load all the data . 1 approach is web worker. But the console keep throwing warnings that use passive event listener so i checked out passive event listener which seems to be simpler in long term. I have experimented with host listener for this and did not find any good way to handle events. So is this feature included in future releases?

@DzmitryShylovich
Copy link
Contributor

Current Status of this.?

needs design. #13371 (comment)

@vicb vicb added the area: core Issues related to the framework runtime label Dec 29, 2016
@tbosch tbosch added the feature Issue that requests a new feature label Apr 10, 2017
@cuznerdexter
Copy link

@nightwnvol I tried your snippet example and it worked in general (removes all the yellow chrome warnings on page load), but when I click on a [routerlink] in my application I now get red errors.

Unable to preventDefault inside passive event listener invocation.

This is a typical link in the component.
<li><a md-button class="md-button" [routerLink]="['messaging/templates']"><i class="nav-icon material-icons">mail</i><span class="nav-text">Message Templates</span></a></li>

@nightwnvol
Copy link

nightwnvol commented Aug 2, 2017

@cuznerdexter Hi, maybe this can help you.
Unable to preventDefault inside passive event listener invocation.
However, snippet is only a temporary solution (hopefully) until Angular will not support Passive Event Listener.

@PierreDuc
Copy link

For the time being, I've made a little module which you can use to add event listeners in templates, ng-event-options. It has some limitations, but without hooks into the compiler, this was the easiest way to do it.

@jtsom
Copy link

jtsom commented Jan 3, 2018

As a data point on this, I'm seeing an increase of messages in the Chrome console relating to this:

zone.js:1662 [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
customScheduleGlobal	@	zone.js:1662
ZoneDelegate.scheduleTask	@	zone.js:407
Zone.scheduleTask	@	zone.js:232
Zone.scheduleEventTask	@	zone.js:258
(anonymous)	@	zone.js:1841
addHandler	@	events_engine.js:144
(anonymous)	@	events_engine.js:349
iterateEventNames	@	events_engine.js:294
(anonymous)	@	events_engine.js:306
(anonymous)	@	events_engine.js:234
applyForEach	@	events_engine.js:58
(anonymous)	@	events_engine.js:64
initRender.each	@	renderer_base.js:545
applyForEach	@	events_engine.js:62
(anonymous)	@	events_engine.js:71
object.(anonymous function)	@	dependency_injector.js:24
setup	@	wheel.js:20
strategy.(anonymous function)	@	event_registrator.js:30
callMethod	@	events_engine.js:48
addHandler	@	events_engine.js:140
(anonymous)	@	events_engine.js:349
iterateEventNames	@	events_engine.js:294
(anonymous)	@	events_engine.js:306
(anonymous)	@	events_engine.js:234
applyForEach	@	events_engine.js:58
(anonymous)	@	events_engine.js:71
object.(anonymous function)	@	dependency_injector.js:24
(anonymous)	@	events_engine.js:473
(anonymous)	@	events_engine.js:234
applyForEach	@	events_engine.js:58
eventsEngine.subscribeGlobal	@	events_engine.js:471
_attachHandlers	@	emitter_registrator.js:34
ctor	@	emitter_registrator.js:25
inheritor	@	class.js:95
(anonymous)	@	emitter_registrator.js:190
../../../../devextreme/events/core/emitter_registrator.js	@	vendor.bundle.js:3240
__webpack_require__	@	inline.bundle.js:55
(anonymous)	@	click.js:18
../../../../devextreme/events/click.js	@	vendor.bundle.js:3208
__webpack_require__	@	inline.bundle.js:55
(anonymous)	@	accordion.js:13
../../../../devextreme/ui/accordion.js	@	vendor.bundle.js:3528
__webpack_require__	@	inline.bundle.js:55
(anonymous)	@	accordion.js:26
../../../../devextreme-angular/ui/accordion.js	@	vendor.bundle.js:384
__webpack_require__	@	inline.bundle.js:55
(anonymous)	@	index.js:26
../../../../devextreme-angular/index.js	@	vendor.bundle.js:376
__webpack_require__	@	inline.bundle.js:55
(anonymous)	@	app.module.ts:17
../../../../../src/app/app.module.ts	@	main.bundle.js:44
__webpack_require__	@	inline.bundle.js:55
(anonymous)	@	main.ts:4
../../../../../src/main.ts	@	main.bundle.js:188
__webpack_require__	@	inline.bundle.js:55
0	@	main.bundle.js:203
__webpack_require__	@	inline.bundle.js:55
webpackJsonpCallback	@	inline.bundle.js:26
(anonymous)	@	main.bundle.js:1

@JiaLiPassion
Copy link
Contributor

I just made a PR to be able to config zone in HostListener,#21681, I would like to make a PR to config passive.
It seems a lot of discussion have been discussed here, #11200, I will try to modify my PR #21681

@thorizer
Copy link

Current status of this?

@arnoldsi-tr
Copy link

Please update us on the current status of this feature.

@itanex
Copy link

itanex commented Sep 4, 2018

@ericcarraway , @JiaLiPassion What is the current status of this feature? What is the expected API for this? Code samples?

Thanks

@dharders
Copy link

This just bit me hard in iOS 11.3.

With the 11.3 update, Apple enabled passive listeners by default. i.e. {passive: true}

This essentially destroys all drag and drop libraries that rely on preventDefault() to work as expected, which avoids the horrible scroll while dragging using touchmove.

For anyone who doesn't want to waste days like I did, here's a (non-webworker friendly) workaround:

   // Add as early as possible in your code, in a service etc
   
    dragEnabled = false;

    window.addEventListener('touchmove', (event) => {
        if (!this.dragEnabled)
          return;
        event.preventDefault(); // Prevent scrolling
      },
      { passive: false },       // iOS 11.3 defaults to true
    );

   // now set this.dragEnabled = true when required, and reset on touchend/touchcancel events

I think this feature needs a bump in priority, given iOS 11.3 now defaults to passive listeners.

@Smiter15
Copy link

I was able to use this npm package
https://www.npmjs.com/package/default-passive-events
to add passive: true to all my event listeners.

My site now passes the Best Practices 'Does not use passive listeners to improve scrolling performance' test on the lighthouse audit.

Depends if you want this on all your event listeners but can be a good workaround.

@pedrovsp
Copy link

Will this feature make it possible to create passive event listeners with Renderer2? Do you guys think this is a good idea as well?

@raysuelzer
Copy link

I think something like this would be nice

@HostListener('touchstart:passive')

@m3hm3tk
Copy link

m3hm3tk commented Apr 20, 2019

Until Angular adds support for event options, ng-event-options is a good solution. If you do not use its options, it falls back to Angular's own EventManagerPlugin. One important thing is that you need to import NgEventOptionsModule after Angular imports.

@kmturley
Copy link

Google Lighthouse reports not using { passive: true } as a performance issue...

Uses Passive Event Listeners to Improve Scrolling Performance:
https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners

will you take this seriously now?

@SansDK
Copy link

SansDK commented Dec 9, 2019

This issue is > 3 years old.
What's the current status of this?

@AaronLavers
Copy link

AaronLavers commented Dec 17, 2019

Keen to know if the Angular team is taking steps to resolve this issue?
Angular 8.2.9, I have multiple warnings in Chrome such as:

zone-evergreen.js.pre-build-optimizer.js:1742 [Violation] Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

@penfold
Copy link

penfold commented Nov 19, 2020

Using (scroll) but it should be passive. Seeing issues in Lighthouse reports.

Is there any visibility of the priority of issues in Opertion Byelog?

Thanks

@JamesIves
Copy link

JamesIves commented May 11, 2021

Was there any update regarding this? Looking into ways to improve Lighthouse scores and this is a big one I'm hoping to check off the list. 😭

@angular-robot angular-robot bot added the feature: under consideration Feature request for which voting has completed and the request is now under consideration label May 21, 2021
@alxhub alxhub added this to Inbox in Feature Requests via automation Sep 23, 2021
@alxhub alxhub moved this from Inbox to Proposed Projects in Feature Requests Sep 23, 2021
@CiernaOvca
Copy link

Anything new with this issue?

@liesahead
Copy link

liesahead commented Jun 21, 2022

Some update? After 6 years 🤔

@misha98857
Copy link

I don't see a link to angular built-in solution for passive listeners. We can configure this by zone-flags. https://angular.io/guide/event-binding#binding-to-passive-events

JeanMeche added a commit to JeanMeche/angular that referenced this issue Apr 29, 2023
… listeners.

Usage : use `(scroll.passive)` as event binding.

Fixes angular#8866
@JeanMeche
Copy link
Member

JeanMeche commented Apr 29, 2023

I've proposed an EventManagerPlugin in #50082 to handle passive event listeners.

Even if the PR doesn't move forward, you'll have the code to implement it in your own project 😊

JeanMeche added a commit to JeanMeche/angular that referenced this issue Apr 29, 2023
… listeners.

Usage : use `(scroll.passive)` as event binding.

Fixes angular#8866
@AnwarMEQOR
Copy link

This might help if you are trying to bind to an event: angular.io

jim60105 added a commit to sound-buttons/sound-buttons that referenced this issue Nov 22, 2023
…g <some> event.

angular/angular#8866 (comment)
Angular doesn't seem to handle passive events well. Use package `default-passive-events` as a workaround.

Signed-off-by: 陳鈞 <jim60105@gmail.com>
jim60105 added a commit to sound-buttons/sound-buttons that referenced this issue Nov 22, 2023
…g <some> event.

angular/angular#8866 (comment)
Angular doesn't seem to handle passive events well. Use package `default-passive-events` as a workaround.

Signed-off-by: 陳鈞 <jim60105@gmail.com>
jim60105 added a commit to sound-buttons/sound-buttons that referenced this issue Nov 22, 2023
…g <some> event.

angular/angular#8866 (comment)
Angular doesn't seem to handle passive events well. Use package `default-passive-events` as a workaround.

Signed-off-by: 陳鈞 <jim60105@gmail.com>
@johncrim
Copy link

This is another useful way to hook up passive event listeners:

https://github.com/Tinkoff/ng-event-plugins

It would be nice if it was more automatic, eg if the ng compiler could always do the optimal thing based on whether the handler function possibly prevents default or stops propagation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime core: event listeners feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature hotlist: google state: Needs Design
Projects
No open projects
Feature Requests
Proposed Projects
Development

Successfully merging a pull request may close this issue.