Skip to content

PointerLeave event listener not fired across renders #21757

@dbismut

Description

@dbismut

This is a bit of an edge case and might be the logical expected behavior.

When adding two pointerleave events listeners to a ref interleaved with renders, the second pointerleave doesn't fire.

pointerleave.mov

The top square has a ref which gets two pointerenter and two pointerleave listeners that trigger a render by changing the component state. The listeners are added (and cleaned) on every render in a useEffect hook.

The bottom square has onPointerEnter and onPointerLeave props that also trigger a render by changing the component state.

As you can see from the video above, the behavior of the top square is different depending on whether the mouse exits to the background or to the bottom square.

React version: 17.0.2

Steps To Reproduce

From the demo below:

  1. Hover the top square
  2. Hover the bottom square

Link to code example:
https://codesandbox.io/s/use-gesture-react-use-hover-bug-forked-gpr0r

The current behavior

When hovering the bottom square, the top square has hovering1 set to false and hovering2 set to true.

The expected behavior

When hovering the bottom square, the top square should have both hovering1 and hovering2 set to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivityStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    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