@@ -22,6 +22,7 @@ import {
2222import {
2323 getClosestInstanceFromNode ,
2424 getNodeFromInstance ,
25+ isContainerMarkedAsRoot ,
2526} from '../../client/ReactDOMComponentTree' ;
2627import { accumulateEnterLeaveTwoPhaseListeners } from '../DOMPluginEventSystem' ;
2728
@@ -57,15 +58,19 @@ function extractEvents(
5758 domEventName === 'mouseout' || domEventName === 'pointerout' ;
5859
5960 if ( isOverEvent && ( eventSystemFlags & IS_REPLAYED ) === 0 ) {
61+ // If this is an over event with a target, we might have already dispatched
62+ // the event in the out event of the other target. If this is replayed,
63+ // then it's because we couldn't dispatch against this target previously
64+ // so we have to do it now instead.
6065 const related =
6166 ( nativeEvent : any ) . relatedTarget || ( nativeEvent : any ) . fromElement ;
6267 if ( related ) {
63- // Due to the fact we don't add listeners to the document with the
64- // modern event system and instead attach listeners to roots, we
65- // need to handle the over event case. To ensure this, we just need to
66- // make sure the node that we're coming from is managed by React.
67- const inst = getClosestInstanceFromNode ( related ) ;
68- if ( inst !== null ) {
68+ // If the related node is managed by React, we can assume that we have
69+ // already dispatched the corresponding events during its mouseout.
70+ if (
71+ getClosestInstanceFromNode ( related ) ||
72+ isContainerMarkedAsRoot ( related )
73+ ) {
6974 return ;
7075 }
7176 }
0 commit comments