-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
onPress
Issue - Click Through Component When it Unmounts
#7993
Comments
This is a duplicate of When selecting a Menu item, element behind popup receives pointer event In addition, I cannot reproduce it in my Chrome, the browser fix for this was very recently rolled out. What version of Chrome are you on? I am on 134.0.6998.89 |
Version 134.0.6998.166 |
@snowystinger it looks like the chrome fix was merged Mar 10. I can also repro the same issue in Chrome Canary (nightly) which should include this change. Is it possible there's another underlying issue unrelated to the Chromium bug? |
For some reason I can reproduce it if I pull down the codesandbox and build it locally or if I show the codesandbox preview in a new window instead of the iframe. So the iframe is messing with it somehow. That aside, I see we are indeed calling stopPropagation. Which should work, according to this test: I also tried adding to our onClick handler in usePress
to no effect. I am not sure what is going on right now, we'll need to dive deeper into it. |
Thinking about this further, these elements are not nested. It's unlikely to be an issue tied to event propagation since there would be no event bubbling shared between them. What if this is just an issue with timing? Perhaps the |
Ah, good point, I glossed over the nesting/propagation. |
onPress
Event Propagation Issue When Component UnmountsonPress
Issue - Click Through Component When it Unmounts
This behavior can also be experienced in more common situations such as Modals. For example, when closing a modal in It can also happen when content is not initially overlapping. For example, a route change. The user can click on a react aria Button that changes the route and end up triggering Reading through the usePress refactor PR, one of the notes is:
The description and linked issues seems to describe this issue pretty well. Perhaps this issue was not fully resolved by delaying the firing of (Also, updated issue title to be more accurate.) |
I have a similar issue where clicking option in select using |
I think it might be a separate issue, because I had |
I traced it down to |
Thanks for sharing your reproduction and findings as well. I'm a little confused as to how I think this has an issue if the Select is inside a Modal, see GridList (in Popover) closes containing Modal on select |
@snowystinger I was wondering if it's possible to share any prioritization or timeline details around this issue. The issue is fairly high impact, and that information would help us to plan how to mitigate things in the meantime. |
Right now, there isn't prioritization on this bug. The fastest way to get prioritization is to submit a PR addressing it. Another way to get priority is to determine the root cause. So answering if the original issue was fully resolved:
Why would delaying to fire onPress during onClick not resolve this? It seems like it should have. So what about that isn't working? If we know the answers to this, then we can more easily come up with possible solutions. Otherwise, I have to ask for patience. |
Understood, and thank you for the transparency and the detailed explanation. I'll see if we can get any spare cycles to help dig into the root cause. |
Looks like due to the click event being delayed by android, and therefore this timer gets hit: react-spectrum/packages/@react-aria/interactions/src/usePress.ts Lines 544 to 553 in cfe79d3
If you add |
@devongovett we initially had |
Oh that's strange. It should be firing Edit: looks like https://bugs.webkit.org/show_bug.cgi?id=240917 According to that, setting |
That does indeed fix the issues posted above in both iOS Safari and Chrome on Android 🎉 Because we are using What would be the best approach to handling this for |
Provide a general summary of the issue here
In a certain case,
onPress
is sometimes firingonClick
event handlers for elements beneath the target. This occurs when theonPress
handler updates state which results in the component being unmounted.🤔 Expected Behavior?
When using a touch device to press a react-aria-components
Button
(which usesusePress
internally), it is expected that theButton
will prevent propagation of that event.This is usually the case as you can see below. In this case, we have two buttons. The top button is a react-aria-components
Button
usingonPress
. The element beneath is a standard HTML button with anonClick
handler that fires an alert if clicked.😯 Current Behavior
However, if the onPress handler results in the component being unmounted, the event sometimes propagates to the element beneath (seems to be inconsistent - maybe a race condition?).
Below is the same situation as before, but we conditionally render the react-aria-components
Button
based on React state, and in theonPress
handler we toggle that state.https://codesandbox.io/p/sandbox/suspicious-wilbur-k6v4l6
💁 Possible Solution
No response
🔦 Context
No response
🖥️ Steps to Reproduce
Code sandbox repro link: https://codesandbox.io/p/sandbox/suspicious-wilbur-k6v4l6
onPress
Event handler fires for top button, and top button is removed due to state update.onClick
Event handler fires for button underneath.This might take a few tries as it is inconsistent.
Version
Latest react-aria-components 1.7.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
Mac OS 15.3.1
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: