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

fix(zone.js): should allow add passive/non-passive listeners together #49477

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JiaLiPassion
Copy link
Contributor

Close #45020
In the current version, if we add both passive and not passive listeners for the same eventName together, they will be registered with all passive or all non passive listeners depends on the order.

import 'zone.js';
div1.addEventListener('mousemove', (ev) => {}, { passive: true });
div1.addEventListener('mousemove', (ev) => {
ev.preventDefault(); // throws error since this one is also be registered as a passive event handler
});

div2.addEventListener('mousemove', (ev) => {
});
div2.addEventListener('mousemove', (ev) => {
ev.preventDefault(); // will not throw error since this one is also be registered as non passive event handler
}, { passive: true });

So this PR fix this issue and allow both passive and non-passive listeners registeration together whatever the order.

@JiaLiPassion JiaLiPassion added area: zones target: minor This PR is targeted for the next minor release labels Mar 19, 2023
@ngbot ngbot bot modified the milestone: Backlog Mar 19, 2023
packages/zone.js/lib/common/events.ts Outdated Show resolved Hide resolved
packages/zone.js/lib/common/events.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One NIT

packages/zone.js/lib/common/events.ts Outdated Show resolved Hide resolved
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release and removed target: minor This PR is targeted for the next minor release labels Dec 14, 2023
@alan-agius4 alan-agius4 removed the request for review from AndrewKushnir December 14, 2023 14:19
@alan-agius4
Copy link
Contributor

TGP

@alan-agius4 alan-agius4 added the action: global presubmit The PR is in need of a google3 global presubmit label Dec 14, 2023
@alan-agius4 alan-agius4 self-assigned this Dec 14, 2023
@@ -104,12 +104,25 @@ export function patchEventTarget(
const PREPEND_EVENT_LISTENER = 'prependListener';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks a large number of apps in Google.

Error:

TypeError: task.callback.apply is not a function
    at _ZoneDelegate.invokeTask (third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=1187

@alan-agius4 alan-agius4 added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Dec 14, 2023
@JiaLiPassion JiaLiPassion force-pushed the allow-passive-event branch 3 times, most recently from 320ff96 to 1cadb57 Compare December 16, 2023 21:52
@alan-agius4 alan-agius4 removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Dec 17, 2023
@alan-agius4
Copy link
Contributor

TGP

@JiaLiPassion JiaLiPassion force-pushed the allow-passive-event branch 2 times, most recently from 8caae4f to f174766 Compare December 18, 2023 14:08
In the current version, if we add both `passive` and `not passive` listeners for the
same eventName together, they will be registered with all passive or all non passive
listeners depends on the order.

```
import 'zone.js';
div1.addEventListener('mousemove', (ev) => {}, { passive: true });
div1.addEventListener('mousemove', (ev) => {
ev.preventDefault(); // throws error since this one is also be registered as a passive event handler
});

div2.addEventListener('mousemove', (ev) => {
});
div2.addEventListener('mousemove', (ev) => {
ev.preventDefault(); // will not throw error since this one is also be registered as non passive event handler
}, { passive: true });

```
So this PR fix this issue and allow both passive and non-passive listeners registeration
together whatever the order.

PR closes angular#45020
@alan-agius4
Copy link
Contributor

TGP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: global presubmit The PR is in need of a google3 global presubmit area: zones target: patch This PR is targeted for the next patch release
Projects
None yet
5 participants