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

Make touch events passive like mouse events #4279

Merged
merged 2 commits into from
May 31, 2022

Conversation

erikdubbelboer
Copy link
Contributor

Prevent console messages like:

[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

See also:

const opts = platform.passiveEvents ? { passive: true } : false;
if (this._useMouse) {
window.addEventListener('mouseup', this._upHandler, opts);
window.addEventListener('mousedown', this._downHandler, opts);
window.addEventListener('mousemove', this._moveHandler, opts);
window.addEventListener('wheel', this._wheelHandler, opts);

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Prevent console messages like:

  [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

See also: https://github.com/playcanvas/engine/blob/9a0697c6b2cd521db510df49f90028f414006696/src/input/element-input.js#L421-L426
willeastcott
willeastcott previously approved these changes May 31, 2022
@willeastcott
Copy link
Contributor

willeastcott commented May 31, 2022

The mouse module sets the third parameter of removeEventListener as well as addEventListener. Presumably, touch should do the same?

@willeastcott willeastcott dismissed their stale review May 31, 2022 00:54

PR might need to change calls to removeEventListener

@erikdubbelboer
Copy link
Contributor Author

That's giving me linting errors as passive is not a valid option for removeEventListener. See: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#options
You want me to still add it?

I'm also getting this linting error in the mouse module:
Screenshot 2022-05-31 at 10 04 59

@willeastcott
Copy link
Contributor

Ah yeah, you're right. I just read this: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
I'm wondering whether the best solution would be to completely drop the third parameter from the calls to removeEventListener.

@erikdubbelboer
Copy link
Contributor Author

I would keep the false there just for clarity.

@willeastcott
Copy link
Contributor

OK, sounds good. 😄

@willeastcott willeastcott merged commit 1ebfd36 into playcanvas:main May 31, 2022
slimbuck added a commit to slimbuck/engine that referenced this pull request Jun 16, 2022
slimbuck added a commit to slimbuck/engine that referenced this pull request Aug 1, 2022
slimbuck added a commit that referenced this pull request Aug 1, 2022
slimbuck added a commit that referenced this pull request Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants