Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e028ce2

Browse files
authored
Modern Event System: ensure target ancestors are only host nodes (facebook#18827)
1 parent 4d124a4 commit e028ce2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
HostRoot,
4040
HostPortal,
4141
HostComponent,
42+
HostText,
4243
} from 'react-reconciler/src/ReactWorkTags';
4344

4445
import getEventTarget from './getEventTarget';
@@ -420,19 +421,21 @@ export function dispatchEventForPluginEventSystem(
420421
if (node === null) {
421422
return;
422423
}
423-
if (node.tag === HostRoot || node.tag === HostPortal) {
424+
const nodeTag = node.tag;
425+
if (nodeTag === HostRoot || nodeTag === HostPortal) {
424426
const container = node.stateNode.containerInfo;
425427
if (isMatchingRootContainer(container, targetContainerNode)) {
426428
break;
427429
}
428-
if (node.tag === HostPortal) {
430+
if (nodeTag === HostPortal) {
429431
// The target is a portal, but it's not the rootContainer we're looking for.
430432
// Normally portals handle their own events all the way down to the root.
431433
// So we should be able to stop now. However, we don't know if this portal
432434
// was part of *our* root.
433435
let grandNode = node.return;
434436
while (grandNode !== null) {
435-
if (grandNode.tag === HostRoot || grandNode.tag === HostPortal) {
437+
const grandTag = grandNode.tag;
438+
if (grandTag === HostRoot || grandTag === HostPortal) {
436439
const grandContainer = grandNode.stateNode.containerInfo;
437440
if (
438441
isMatchingRootContainer(grandContainer, targetContainerNode)
@@ -450,7 +453,13 @@ export function dispatchEventForPluginEventSystem(
450453
if (parentSubtreeInst === null) {
451454
return;
452455
}
453-
node = ancestorInst = parentSubtreeInst;
456+
const parentTag = parentSubtreeInst.tag;
457+
// getClosestInstanceFromNode can return a HostRoot or SuspenseComponent.
458+
// So we need to ensure we only set the ancestor to a HostComponent or HostText.
459+
if (parentTag === HostComponent || parentTag === HostText) {
460+
ancestorInst = parentSubtreeInst;
461+
}
462+
node = parentSubtreeInst;
454463
continue;
455464
}
456465
node = node.return;

0 commit comments

Comments
 (0)