Skip to content

feat: support passive events by define global variables in zone.js config file#34503

Closed
JiaLiPassion wants to merge 1 commit intoangular:masterfrom
JiaLiPassion:passive
Closed

feat: support passive events by define global variables in zone.js config file#34503
JiaLiPassion wants to merge 1 commit intoangular:masterfrom
JiaLiPassion:passive

Conversation

@JiaLiPassion
Copy link
Copy Markdown
Contributor

@JiaLiPassion JiaLiPassion commented Dec 19, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #8866

It is not easy to addEventListener with passive option. We may need to discuss to add something like in this PR, #21681 in the future.

What is the new behavior?

For now, this PR is just a temp solution until we can add a new template syntax in event listener.
In this PR, we can define a global variable before importing zone.js

(window as any)['__zone_symbol__PASSIVE_EVENTS'] = ['touchstart', 'scroll'];

and then all event listeners defined here will be automatically be passive: true.

Does this PR introduce a breaking change?

  • Yes
  • No

If this idea is ok, I will update the document. And of course we still need to discuss the formal way to resolve this issue by introducing some new options in template event binding syntax.

@JiaLiPassion JiaLiPassion requested a review from a team December 19, 2019 22:59
@JiaLiPassion JiaLiPassion requested a review from a team December 19, 2019 23:57
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@mhevery, please check whether this temp solution is ok, thank you!

@JiaLiPassion JiaLiPassion requested a review from mhevery December 20, 2019 01:58
@atscott atscott added the area: zones Issues related to zone.js label Jan 9, 2020
@ngbot ngbot Bot added this to the needsTriage milestone Jan 9, 2020
Comment thread packages/zone.js/test/browser/browser.spec.ts Outdated
Comment thread packages/zone.js/lib/common/events.ts Outdated
Comment thread packages/zone.js/lib/common/events.ts Outdated
Comment thread packages/zone.js/lib/common/events.ts Outdated
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Jan 29, 2020

Looks like a reasonable approach. Needs documentation explaining how to use it.

@JiaLiPassion JiaLiPassion force-pushed the passive branch 2 times, most recently from b543ecb to d2909ca Compare January 30, 2020 03:26
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@mhevery, thanks for the review, I have updated the PR and add the document.

@JiaLiPassion JiaLiPassion requested a review from mhevery January 30, 2020 04:33
Comment thread packages/zone.js/lib/common/events.ts Outdated
Comment thread packages/zone.js/test/browser/browser.spec.ts Outdated
Comment thread integration/_payload-limits.json Outdated
Comment thread packages/zone.js/test/browser/browser.spec.ts Outdated
@JiaLiPassion JiaLiPassion force-pushed the passive branch 2 times, most recently from 3525ed1 to 203918b Compare February 5, 2020 13:49
@JiaLiPassion JiaLiPassion added the target: patch This PR is targeted for the next patch release label Feb 5, 2020
@JiaLiPassion JiaLiPassion requested a review from mhevery February 5, 2020 22:47
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Feb 11, 2020

presubmit

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Feb 11, 2020
@kara kara added target: major This PR is targeted for the next major release action: review The PR is still awaiting reviews from at least one requested reviewer and removed target: patch This PR is targeted for the next patch release labels Feb 11, 2020
@JiaLiPassion JiaLiPassion force-pushed the passive branch 2 times, most recently from 623fe10 to feb7db8 Compare February 15, 2020 05:44
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@kara, I have rebased the PR, please review, thanks.

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Feb 20, 2020

presubmit

@mhevery mhevery removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 20, 2020
Copy link
Copy Markdown
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

Can we also add a descriptive commit message that explains why this change is necessary?

Comment thread aio/content/guide/user-input.md Outdated
Comment thread aio/content/guide/user-input.md Outdated
Comment thread aio/content/guide/user-input.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

before import zone.js => before importing zone.js

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, updated, thanks.

Comment thread aio/content/guide/user-input.md Outdated
Comment thread integration/_payload-limits.json Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a somewhat large increase. Do we know why? Can we find out how much is just accumulation?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree, this seems excessive especially for the diff in this PR. Let's find out how did we accumulate this much (I've reset the polyfills limits recently so it seems like a recent accumulation of code)

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Feb 21, 2020

This was accidentally merged. Reverting until we have better docs review.

@mhevery mhevery reopened this Feb 21, 2020
mhevery added a commit that referenced this pull request Feb 21, 2020
…les in zone.js config file (#34503)"

This reverts commit d7d359e.
@mhevery mhevery added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: core Issues related to the framework runtime labels Feb 22, 2020
@JiaLiPassion JiaLiPassion force-pushed the passive branch 6 times, most recently from 063165d to 87b34e0 Compare February 22, 2020 06:07
@JiaLiPassion JiaLiPassion 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 Feb 22, 2020
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@kara, @mhevery , I have updated the doc and remove some unused code. Now the size will have no changes. Please review, thanks.

@JiaLiPassion JiaLiPassion requested a review from kara February 22, 2020 06:29
@mhevery mhevery removed the request for review from kara February 24, 2020 21:59
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Feb 24, 2020

presubmit

Copy link
Copy Markdown
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

Thanks for updating the PR! There are still a few things to do:

  1. Update the commit message to describe what problem this PR is fixing and why (should not just be one sentence).

  2. A few more docs updates below to fix

Comment thread aio/content/guide/user-input.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Angular also supports passive event listeners. For example, you can use the following steps to make scroll event passive.
Angular also supports passive event listeners. For example, you can use the following steps to make the scroll event passive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks, updated.

Comment thread aio/content/guide/user-input.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
3. In the `src/polyfills.ts` file, before importing zone.js, import the new created `zone-flags`.
3. In the `src/polyfills.ts` file, before importing zone.js, import the newly created `zone-flags`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, updated, thanks.

Now Angular doesn't support add event listeners as passive very easily.
User needs to use `elem.addEventListener('scroll', listener, {passive: true});`
or implements their own EventManagerPlugin to do that.
Angular may finally support new template syntax to support passive event, for now,
this commit introduces a temp solution to allow user to define the passive event names
in zone.js configurations.

User can define a global varibale like this.

```
(window as any)['__zone_symbol__PASSIVE_EVENTS'] = ['scroll'];
```

to let all `scroll` event listeners passive.
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@kara, thank you for the review, I have updated the doc and the commit message. Please review.

@JiaLiPassion JiaLiPassion requested a review from kara February 25, 2020 00:55
Copy link
Copy Markdown
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for updating the PR @JiaLiPassion!

@sod
Copy link
Copy Markdown
Contributor

sod commented Mar 4, 2020

What's the release schedule for zone.js? I ask as I saw quite some changes over time, but the last release was 8 months ago (0.10.2 from August 14, 2019 - https://yarnpkg.com/package/zone.js). Quite interesting that all changes are mentioned in the angular changelog anyway.

@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@sod, there should be a new version very soon.

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime area: zones Issues related to zone.js cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants