Skip to content

Bug: onMouseEnter triggered twice on target when there's space around it, and ReactDOM.createPortal is used to render something else #21049

@benoitgrelard

Description

@benoitgrelard

React version: 17

Steps To Reproduce

  1. Hover the button
  2. Note the double log produced

Link to code example: https://codesandbox.io/s/react-mouseenter-bug-uyswr?file=/src/App.js

The current behavior

The onMouseEnter is triggered twice.

The expected behavior

The onMouseEnter should be triggered only once.


A few more notes:

  • I've tested on React 16.14 and it seems that bug only appeared in 17. (I can see it in the first ever 17 rc as well).
  • It's specifically when something happens to be portalled on the page too (you'll see if you don't render in a portal, no issue)
  • It is also linked to the fact there's space around the target that gets moused over. You'll notice that if you comment out the heading below for example and you mouse-enter coming from the bottom, the bug won't be there. But it will be at the top. Similarly if we you keep the headings rendered, but override their margins to be 0 such that there's no gap between the heading and the button, it won't happen either.

I'm conscious this is all really odd but I haven't been able to find out exactly what's happening here…

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions