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

Chrome/React mouse-wheel event issue [Workaround] #141

Closed
philLITERALLY opened this issue Mar 21, 2019 · 17 comments
Closed

Chrome/React mouse-wheel event issue [Workaround] #141

philLITERALLY opened this issue Mar 21, 2019 · 17 comments

Comments

@philLITERALLY
Copy link

Running Chrome Version 73.0.3683.86.

Trying to zoom in or out using the scroll wheel results in the page scrolling not only the image as expected.

And on the console inspector I see:
Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312

The url is slightly different to the one noted in this PR comment: #39 (comment)

The PR listed above seems to be related to touch specific actions Treat Document Level Touch Event Listeners as Passive, the one I am seeing in the console seems to be related to the wheel Treat Document Level Wheel/Mousewheel Event Listeners as Passive

I tested it in the examples listed on this page and it is reproducible on all the examples not just my code (one example I tested with: https://jsfiddle.net/chrvadala/f67qyfsd/)

I've already set touch-action: none; like most people suggest as the solution but had no luck.

Strangely this is only affecting Chrome and all other browsers work as expected.

Please let me know if you need anything else from me to help. Thanks!

@gaborvoros
Copy link

Same here :/

@byronwall
Copy link

This React issue has the relevant context. facebook/react#14856

Chrome 73 changed the behavior of wheel events to be "passive" by default. A passive event ignores any attempt to call preventDefault which means it not possible to dismiss the scrolling behavior after handling the zoom. Until React provides a way to control or disable the passive handling, this is going to be broken in Chrome unless you're willing to manually add event listeners with {passive: false} set.

@chrvadala chrvadala added the bug label Mar 29, 2019
@chrvadala
Copy link
Owner

chrvadala commented Apr 1, 2019

Hi guys, until React has an official fix, we have to use the workaround published here facebook/react#14856 (comment)
I made a sample and it seems to work https://jsfiddle.net/yrmdzwn8/

I hope that Facebook/Chrome will provide soon an official solution.

@gaborvoros
Copy link

Thanks @chrvadala you saved my day :)
The workaround works for me

@chrvadala chrvadala changed the title Bug - Unable to preventDefault inside passive event listener due to target being treated as passive Chrome/React mouse-wheel event issue [Workaround] Apr 8, 2019
@chrvadala chrvadala pinned this issue Apr 8, 2019
@chrvadala chrvadala added this to the v3.1 milestone Apr 27, 2019
@chrvadala
Copy link
Owner

Today there isn't still an official solution, but a developer released a better workaround facebook/react#14856

@krnlde
Copy link
Contributor

krnlde commented Nov 12, 2019

Instead of attaching the event via attributes why don't you use document.addEventListener when componentDidMount / useEffect? Since you're using refs already that would help the issue without a lot of hustle - as far as I understand it.

@chrvadala
Copy link
Owner

To be honest I thought that React would have released an official fix for this, but it seems that, after 6 months, it is better to patch this library.
I agree with your approach, Are you open to submit a PR?

krnlde pushed a commit to krnlde/react-svg-pan-zoom that referenced this issue Nov 13, 2019
@krnlde
Copy link
Contributor

krnlde commented Nov 13, 2019

There you go

@krnlde
Copy link
Contributor

krnlde commented Nov 15, 2019

Bump

@chrvadala
Copy link
Owner

A fix has been released with v3.5.0 (thanks to @krnlde )

Workaround code suggested few comments above is no more required. Don't forget to get it rid off.

@chrvadala chrvadala unpinned this issue Nov 16, 2019
@krnlde
Copy link
Contributor

krnlde commented Nov 18, 2019

Seems like I introduced a new bug with this fix. I don't get any events on Edge and IE, can anybody confirm? x-ref: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7134034/

edit: This example doesn't work either: https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event

@chrvadala
Copy link
Owner

Unfortunately now I don't have a Windows PC with me, but I should be able to test it tomorrow.

@chrvadala chrvadala reopened this Nov 18, 2019
@krnlde
Copy link
Contributor

krnlde commented Nov 19, 2019

The problem only occurs with "precision touchpads". The thinkpad nob and a mousewheel do work.

@chrvadala
Copy link
Owner

sounds good! Is there a way to detect a "precision mousepad"? Do we have some way to fix it?

@krnlde
Copy link
Contributor

krnlde commented Nov 20, 2019

Unfortunately no. I'm still wondering if it worked before, because if I read the bugtracker correctly it shouldn't work either way with the precision touchpad. Also this quote

We lost this argument. Microsoft has chosen not to fix this bug despite our years of begging.
(source)

makes me unhappy.

It looked like probably mousewheel and/or DOMMouseScroll events could help, but they didn't seem to work on my machine either.

These guys have the same problem it seems, maybe we can help each other out.

@chrvadala
Copy link
Owner

Can you check if plain React wheel event works better? Moreover, I'm going to create a new issue since the topic we are talking about is a bit different from this one.

@krnlde
Copy link
Contributor

krnlde commented Nov 25, 2019

I used the simplest codesandbox for this issue and don't get an event in the console on Edge. Which means it shouldn't either with synthetic nor with native events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants