[react-events] Remove lastNativeEvent in favor of SystemFlags (#17585)
Dominic Gannaway committed
Dec 13, 2019 at 17:03 UTC
be603f5a51be33027193d9e5ae35a0e572d8ad5d
3 files changed
+14
-11
packages/legacy-events/EventSystemFlags.js
+1
@@ -15,3 +15,4 @@ export const IS_PASSIVE = 1 << 2;
15
export const IS_ACTIVE = 1 << 3;
16
export const PASSIVE_NOT_SUPPORTED = 1 << 4;
17
export const IS_REPLAYED = 1 << 5;
18
+export const IS_FIRST_ANCESTOR = 1 << 6;
packages/react-dom/src/events/EnterLeaveEventPlugin.js
+5
-10
@@ -13,7 +13,7 @@ import {
13
TOP_POINTER_OUT,
14
TOP_POINTER_OVER,
15
} from './DOMTopLevelEventTypes';
16
-import {IS_REPLAYED} from 'legacy-events/EventSystemFlags';
16
+import {IS_REPLAYED, IS_FIRST_ANCESTOR} from 'legacy-events/EventSystemFlags';
17
import SyntheticMouseEvent from './SyntheticMouseEvent';
18
import SyntheticPointerEvent from './SyntheticPointerEvent';
19
import {
@@ -42,12 +42,6 @@ const eventTypes = {
42
},
43
};
44
45
-// We track the lastNativeEvent to ensure that when we encounter
46
-// cases where we process the same nativeEvent multiple times,
47
-// which can happen when have multiple ancestors, that we don't
48
-// duplicate enter
49
-let lastNativeEvent;
50
-
45
const EnterLeaveEventPlugin = {
46
eventTypes: eventTypes,
47
@@ -169,11 +163,12 @@ const EnterLeaveEventPlugin = {
163
164
accumulateEnterLeaveDispatches(leave, enter, from, to);
165
172
- if (nativeEvent === lastNativeEvent) {
173
- lastNativeEvent = null;
166
+ // If we are not processing the first ancestor, then we
167
+ // should not process the same nativeEvent again, as we
168
+ // will have already processed it in the first ancestor.
169
+ if ((eventSystemFlags & IS_FIRST_ANCESTOR) === 0) {
170
return [leave];
171
}
176
- lastNativeEvent = nativeEvent;
172
173
return [leave, enter];
174
},
packages/react-dom/src/events/ReactDOMEventListener.js
+8
-1
@@ -49,6 +49,7 @@ import {
49
IS_PASSIVE,
50
IS_ACTIVE,
51
PASSIVE_NOT_SUPPORTED,
52
+ IS_FIRST_ANCESTOR,
53
} from 'legacy-events/EventSystemFlags';
54
55
import {
@@ -175,13 +176,19 @@ function handleTopLevel(bookKeeping: BookKeepingInstance) {
176
const eventTarget = getEventTarget(bookKeeping.nativeEvent);
177
const topLevelType = ((bookKeeping.topLevelType: any): DOMTopLevelEventType);
178
const nativeEvent = ((bookKeeping.nativeEvent: any): AnyNativeEvent);
179
+ let eventSystemFlags = bookKeeping.eventSystemFlags;
180
+
181
+ // If this is the first ancestor, we mark it on the system flags
182
+ if (i === 0) {
183
+ eventSystemFlags |= IS_FIRST_ANCESTOR;
184
+ }
185
186
runExtractedPluginEventsInBatch(
187
topLevelType,
188
targetInst,
189
nativeEvent,
190
eventTarget,
184
- bookKeeping.eventSystemFlags,
191
+ eventSystemFlags,
192
);
193
}
194
}