-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Support passive event listeners in controls #10373
Comments
Usually the reason we use |
I'd like to bump this one, as I'm seeing a bunch of warnings in the Chrome (Canary) console. Passive event listeners could/should be applied to most mousewheel and touchstart events in many of the examples as well as:
I'm not sure how you would want to structure this, exactly, since it requires a bit of feature detection. You might want to place the feature detection code in a common utility file that you can reference from all the different control scripts. Here's the code I use in my own private repo. Feel free to adapt or use this: let eventOpts = false;
function nop() {}
try {
const opts = {};
Object.defineProperty(opts, 'passive', {
get () {
eventOpts = {
passive: true
};
}
});
window.addEventListener('test', nop, opts);
window.removeEventListener('test', nop, opts);
} catch (e) {}
module.exports = eventOpts; Then use it like this: element.addEventListener('touchstart', touchStart, eventOpts); |
I don't think those warnings apply to our case though... |
Why not? If I understand it correctly (which, admittedly, I may not), you don't need to set the option if you're calling |
I'm confused... |
Me too. It's gonna be okay. Let's all have some coffee, give it a think, read up on it and reconsider. I'm sure somewhere there's some data about the number of milliseconds of delay this is causing that will help us justify a change. |
This is a very confusing spec. If I'm getting it right, |
https://www.chromestatus.com/features/6662647093133312 Wheel events attached to the document or body are now automatically treated as being passive. Ps: (This was reported at https://stackoverflow.com/questions/58282573/ , I didn't check where you do attach such events, but it seems at least TrackballControls is affected). |
Yes, and |
Hi @Mugen87. I think that #17612 addresses the I believe @Kaiido's comment is correct.
By specifying them as The change to binding them to the canvas instead of to the body is also fine to have, but I wonder if anyone knows whether Chrome will honor it if we mark it |
I have done a test consisting of this commit: unphased@729ea92, and this cleans up all violation related messages in the console (aside from one related to a wheel event for the iframe, which i'm ignoring for the test). based on this, I think it shows that the api does not need to make specifying the domelement mandatory... |
@unphased can you share a jsfiddle that shows the violation? |
You can observe it on chrome on any of the controls examples, such as this: https://threejs.org/examples/misc_controls_orbit.html Just open console and reload. |
Should this issue be reopened? The trackball controls in |
@duhaime Not sure. |
Description of the feature
Since Chrome 51 and Firefox 49, passive event listeners have been supported. Marking the listeners in the controls as passive should greatly help perceived performance. A polyfill is available in the link if backwards-compatibility is important.
EDIT: I should note that this disables the ability to call
preventDefault()
. So listeners that callpreventDefault()
cannot be passive.Three.js version
All
The text was updated successfully, but these errors were encountered: