Skip to content

Commit 6778c53

Browse files
authored
Modern Event System: fix bug in EnterLeave (facebook#18849)
1 parent 7eaa1d7 commit 6778c53

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

packages/react-dom/src/events/plugins/ModernEnterLeaveEventPlugin.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ const EnterLeaveEventPlugin = {
6565
topLevelType === TOP_MOUSE_OVER || topLevelType === TOP_POINTER_OVER;
6666
const isOutEvent =
6767
topLevelType === TOP_MOUSE_OUT || topLevelType === TOP_POINTER_OUT;
68-
const related = nativeEvent.relatedTarget || nativeEvent.fromElement;
69-
70-
if (isOverEvent && (eventSystemFlags & IS_REPLAYED) === 0 && related) {
71-
// Due to the fact we don't add listeners to the document with the
72-
// modern event system and instead attach listeners to roots, we
73-
// need to handle the over event case. To ensure this, we just need to
74-
// make sure the node that we're coming from is managed by React.
75-
const inst = getClosestInstanceFromNode(related);
76-
if (inst !== null) {
77-
return;
68+
69+
if (isOverEvent && (eventSystemFlags & IS_REPLAYED) === 0) {
70+
const related = nativeEvent.relatedTarget || nativeEvent.fromElement;
71+
if (related) {
72+
// Due to the fact we don't add listeners to the document with the
73+
// modern event system and instead attach listeners to roots, we
74+
// need to handle the over event case. To ensure this, we just need to
75+
// make sure the node that we're coming from is managed by React.
76+
const inst = getClosestInstanceFromNode(related);
77+
if (inst !== null) {
78+
return;
79+
}
7880
}
7981
}
8082

@@ -100,6 +102,7 @@ const EnterLeaveEventPlugin = {
100102
let from;
101103
let to;
102104
if (isOutEvent) {
105+
const related = nativeEvent.relatedTarget || nativeEvent.toElement;
103106
from = targetInst;
104107
to = related ? getClosestInstanceFromNode(related) : null;
105108
if (to !== null) {

0 commit comments

Comments
 (0)