Skip to content

Commit 6bb86fd

Browse files
authored
Delegated all capture events (facebook#19463)
1 parent 05344fa commit 6bb86fd

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

packages/react-dom/src/events/DOMPluginEventSystem.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,15 @@ export function listenToNativeEvent(
373373
if (topLevelType === TOP_SELECTION_CHANGE) {
374374
target = (rootContainerElement: any).ownerDocument;
375375
}
376-
// If the event can be delegated, we can register it to the root container.
377-
// Otherwise, we should register the event to the target element.
378-
if (targetElement !== null && nonDelegatedEvents.has(topLevelType)) {
376+
// If the event can be delegated (or is capture phase), we can
377+
// register it to the root container. Otherwise, we should
378+
// register the event to the target element and mark it as
379+
// a non-delegated event.
380+
if (
381+
targetElement !== null &&
382+
!isCapturePhaseListener &&
383+
nonDelegatedEvents.has(topLevelType)
384+
) {
379385
eventSystemFlags |= IS_NON_DELEGATED;
380386
target = targetElement;
381387
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ import {
4040
import {IS_EVENT_HANDLE_NON_MANAGED_NODE} from '../EventSystemFlags';
4141

4242
import getEventCharCode from '../getEventCharCode';
43-
import {IS_CAPTURE_PHASE, IS_NON_DELEGATED} from '../EventSystemFlags';
43+
import {IS_CAPTURE_PHASE} from '../EventSystemFlags';
4444

4545
import {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags';
46-
import {getClosestInstanceFromNode} from '../../client/ReactDOMComponentTree';
4746

4847
function extractEvents(
4948
dispatchQueue: DispatchQueue,
@@ -166,22 +165,11 @@ function extractEvents(
166165
inCapturePhase,
167166
);
168167
} else {
169-
// When we encounter a non-delegated event in the capture phase,
170-
// we shouldn't emuluate capture bubbling. This is because we'll
171-
// add a native capture event listener to each element directly,
172-
// not the root, and native capture listeners always fire even
173-
// if the event doesn't bubble.
174-
const isNonDelegatedEvent = (eventSystemFlags & IS_NON_DELEGATED) !== 0;
175168
// TODO: We may also want to re-use the accumulateTargetOnly flag to
176169
// special case bubbling for onScroll/media events at a later point.
177-
const accumulateTargetOnly = inCapturePhase && isNonDelegatedEvent;
178-
// If we are not handling accumulateTargetOnly, then we should traverse
179-
// through all React fiber tree, finding all relevant useEvent and
180-
// on* prop events as we traverse the tree. Otherwise, we should
181-
// only handle the target fiber and stop traversal straight after.
182-
if (accumulateTargetOnly) {
183-
targetInst = getClosestInstanceFromNode(((targetContainer: any): Node));
184-
}
170+
// In which case we will want to make this flag boolean and ensure
171+
// we change the targetInst to be of the container instance. Like:
172+
const accumulateTargetOnly = false;
185173

186174
// We traverse only capture or bubble phase listeners
187175
accumulateSinglePhaseListeners(

0 commit comments

Comments
 (0)