question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`onMouseLeave` can be unreliable in Chrome

See original GitHub issue

See this jsfiddle: https://jsfiddle.net/tvxderw3/

In Chrome, as you quickly move your mouse up and down the list, you’ll notice that some get stuck in the hover state. This works fine in Safari, and works in Chrome if you use a stable key between the hover states. I think mouseout somehow isn’t firing if the underlying DOM node is replaced by a new one in the same tick, but it’s odd that this is a Chrome-only bug.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:23 (6 by maintainers)

github_iconTop GitHub Comments

49reactions
DamianDobrevcommented, Oct 2, 2018

I managed to “fix” this. I’m doing two things:

  1. Added the listener to element which is not display: inline;, rather block/inline-block.
  2. Added pointer-events: none to any containers of SVGs inside the element with the listener.

Seems to work fine now, the event is fired properly. I do not know why though.

17reactions
yardenappcommented, Dec 28, 2019

I fixed this by invalidating the hover state between renders

// Inside your component
const divRef = useRef();
const [hovered, setHovered] = useState();
 
if(hovered && divRef.current && divRef.current.matches(':hover') === false)
    setHovered(false);

return (
    <div ref={divRef} onMouseEnter={()=>setHovered(true)} onMouseLeave={()=>setHovered(false)}/>
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent mouseleave from firing on right-click in Chrome?
To inspect you can use f12 then select your element by hovering over it. You could stop the onMouseLeave event possible by using ......
Read more >
Element: mouseleave event - Web APIs | MDN
The mouseleave event is fired at an Element when the cursor of a pointing device (usually a mouse) is moved out of it....
Read more >
Mouseleave only triggering as expected in Chrome
Hello, The following seems to work only in Chrome, and it does not seem ... is not hovering over any ".widget", you will...
Read more >
mouseenter and mouseleave events don't fire when an ...
I'm only having problems with mouseleave (mouseenter doesn't concern me as much). If an element is resized to be smaller and the mouse...
Read more >
onmouseleave does not fire if you have mutiple elements react
Custom elements can be lazily upgraded on the page and some PRPL patterns rely on this technique. During the upgrade process, a custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found