-
Notifications
You must be signed in to change notification settings - Fork 3.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
Fix passive event warning in chrome #9777
Fix passive event warning in chrome #9777
Conversation
Thanks for that! I am all for fixing warnings. We are still supporting IE11, will that not fail when running the code in IE? IE (seems to me, at least?) doesn't support an object as options (and only a boolean). |
That needs to be tested but I'm confident as an object can be converted to true @kaliatech : Do you mind testing on IE to be sure? |
I'm attempting to test, but having problems getting a babylonjs dev setup that works for testing IE11. Will use forums to discuss if I'm unable to get it working. |
RE: IE11Testing the original change worked, as it was, in IE11 without any obvious issue. However, it is not obvious if IE11 is internally setting I suspect that changing from the default would not affect anyone. The difference between event capturing and bubbling is very esoteric. (More info here.) But just-in-case, I added another commit with feature detection to handle IE11 and make sure it works exactly the way it did previously. Up to you if the extra code is worthwhile. RE: Passive and CameraInputsManager.noPreventDefaultAs I mentioned in original comment, I set passive to false because of Bablyon's handling of
...as expected. In theory, if noPreventDefault = true, then passive could be set to true and maybe there would be a small browser performance improvement. I didn't see any easy to handle that with existing code organization though, and I think unlikely it actually matters. (As an aside, unclear why ExampleIn case not obvious, all of this revolves around the scenario where there is a babylon.js canvas on the page, babylon is setup with a camera that makes use of the mouse wheel, and the page itself is scrollable. In this example, Setting noPreventDefault = false fixes this so that wheel controls camera if pointer is on top of canvas, otherwise it scrolls page. And in that case, passive could have been set to true. |
I'm fine with the changes then LGTM |
Summary
On chrome, initializing babylon.js with standard camera input controls causes a warning in the console about a non-passive event listener related to wheel events. The warning reads like this:
This happens with Babylon 5.x, 4.2.x, etc, and has likely been happening in Chrome for some time now. The warning can seemingly be safely ignored, but it is annoying and likely causes new users to wonder if something is wrong.
History
Around Chrome 52, support for passive event listeners was added. At some point later, Chrome started showing warnings when certain event listeners are added without an explicit passive setting. In this case, the warning is due to Babylon cameras listening to mouse wheel events. The intent by the chrome team is to notify web devs via warning so that unless
preventDefault
handling is actually needed, then passive=true can be used which allows optimization for default page scroll handling.Passive Decision
I debated setting
passive
totrue
orfalse
. I set it to false because that seems like a safer option. However, it be might be acceptable to set it to true depending on how/where the wheel event listener is attached in the DOM, AND how it relates to theCameraInputsManager.noPreventDefault
setting.The exceptional case is around expectations when using a mouse wheel on a scrollable page and with a Babylon camera. I would guess that most users expect the mouse wheel to control camera when mouse pointer is over the Babylon canvas, else wheel should scroll the page.
Setting passive to false replicates existing functionality (because that is the default), whatever that is. Making it explicit seems to be enough to prevent the warning in chrome.
Related Links
Related discussion in the three.js project:
Related forum post
Supporting info: