Skip to content

Commit 05344fa

Browse files
authored
Follow up fix to 19452 (facebook#19454)
1 parent d29bf59 commit 05344fa

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

packages/react-dom/src/__tests__/ReactDOMEventListener-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ describe('ReactDOMEventListener', () => {
595595
const container = document.createElement('div');
596596
const innerRef = React.createRef();
597597
const outerRef = React.createRef();
598-
const onPlayCapture = jest.fn();
598+
const onPlayCapture = jest.fn(e => log.push(e.currentTarget));
599+
const log = [];
599600
document.body.appendChild(container);
600601
try {
601602
ReactDOM.render(
@@ -612,12 +613,23 @@ describe('ReactDOMEventListener', () => {
612613
}),
613614
);
614615
expect(onPlayCapture).toHaveBeenCalledTimes(3);
616+
expect(log).toEqual([
617+
outerRef.current,
618+
outerRef.current.firstChild,
619+
innerRef.current,
620+
]);
615621
outerRef.current.dispatchEvent(
616622
new Event('play', {
617623
bubbles: false,
618624
}),
619625
);
620626
expect(onPlayCapture).toHaveBeenCalledTimes(4);
627+
expect(log).toEqual([
628+
outerRef.current,
629+
outerRef.current.firstChild,
630+
innerRef.current,
631+
outerRef.current,
632+
]);
621633
} finally {
622634
document.body.removeChild(container);
623635
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,6 @@ export function accumulateSinglePhaseListeners(
718718
const captured = bubbled !== null ? bubbled + 'Capture' : null;
719719
const listeners: Array<DispatchListener> = [];
720720

721-
// If we are not handling EventTarget only phase, then we're doing the
722-
// usual two phase accumulation using the React fiber tree to pick up
723-
// all relevant useEvent and on* prop events.
724721
let instance = targetFiber;
725722
let lastHostComponent = null;
726723
const targetType = event.type;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import getEventCharCode from '../getEventCharCode';
4343
import {IS_CAPTURE_PHASE, IS_NON_DELEGATED} from '../EventSystemFlags';
4444

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

4748
function extractEvents(
4849
dispatchQueue: DispatchQueue,
@@ -174,6 +175,13 @@ function extractEvents(
174175
// TODO: We may also want to re-use the accumulateTargetOnly flag to
175176
// special case bubbling for onScroll/media events at a later point.
176177
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+
}
177185

178186
// We traverse only capture or bubble phase listeners
179187
accumulateSinglePhaseListeners(

0 commit comments

Comments
 (0)