-
Notifications
You must be signed in to change notification settings - Fork 47.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
React 18 not passive wheel / touch event listeners support #22794
Comments
I have zoom/pan board element in my app. In v18 render I have two renders instead one,
here is a piece of my active native mousewheel event listener: //...
e.preventDefault();
let newScale =
scale + Math.sign(e.deltaY || e.deltaX || e.deltaZ) * -diagramDefaults.wheelStep;
if (newScale < minScale) newScale = minScale;
else if (newScale > diagramDefaults.maxScale) newScale = diagramDefaults.maxScale;
// below scroll changes happen immediately
containerRef.current.scrollTop =
((containerRef.current.scrollTop + e.clientY) * newScale) / scale - e.clientY;
containerRef.current.scrollLeft =
((containerRef.current.scrollLeft + e.clientX) * newScale) / scale - e.clientX;
// ref.current.style.transform = `scale(${newScale})`; // here I tried to dirty fix this issue but with low effect
// triggered scale prop update comes to render with delay in v18, while in v17 it was in same js event loop cycle.
onScale(newScale);
//... |
Gotcha. Thanks for explaining your use case. React DevTools (written with React DOM v18) has some "wheel" events code but it is just added in an event so that it can I'm not really up to date with the latest thinking around this event decision. @gaearon may know more (or it may be that his most recent update– linked above– still reflects our current thinking). |
Yes, I remember that discussion, I implemented my current solution inspired by comments there.
..so react will just check Browser gives this choice, why react takes it away from me, it does not help at all 😢 |
What log spam are you seeing? |
I think there is a misunderstanding. This issue is about support for marking events as not passive because they are passive by default. The warning you're showing is the exact opposite. Can you please show which callsite the warning highlights? I have a suspicion that it's either not React, or it's some older version. |
You're right, it's not React. It's in fact Kefir (inside Really sorry for wasting your time! Thanks for your work. :) |
No problem! |
Same issue, I need to call |
I am working on a carousel component that sometimes needs to prevent vertical scrolling of the window, and this design decision is apparently going to force me to add the listener manually as well. This is fine, but I do wonder how the React team thinks nobody would ever want to use |
Any workaround for this? If I want to handle mousewheels in a special way within a component (e.g. in a game or UI with special requirements), then I need to be able to do Would a safe workaround be to use |
@callumlocke You probably want to use a ref callback on the JSX element instead passing an actual ref. https://react.dev/reference/react-dom/components/common#ref-callback Also, make sure to clean up the listeners when they are no longer needed. In newer versions of React I think you can return a cleanup function like |
|
Same problem with me, need to have to use an active Wheel event in a div component. Only way I've found right now is using react-event-injector or using refs to attach event manually |
Hi all, is there any chances React 18 will support not passive wheel / touch event listeners?
In React 17 they are passive so no way to preventDefault and I had to add active listeners manually by ref.
So maybe in v18 there will be some option to make them not passive in react?
I just tested my code with React 18 beta and found some internal order of useEffect calls was changed, so my approach is failing because of desync of changes made in active listener vs other props changes.
The text was updated successfully, but these errors were encountered: