@@ -39,6 +39,7 @@ import {
39
39
HostRoot ,
40
40
HostPortal ,
41
41
HostComponent ,
42
+ HostText ,
42
43
} from 'react-reconciler/src/ReactWorkTags' ;
43
44
44
45
import getEventTarget from './getEventTarget' ;
@@ -420,19 +421,21 @@ export function dispatchEventForPluginEventSystem(
420
421
if ( node === null ) {
421
422
return ;
422
423
}
423
- if ( node . tag === HostRoot || node . tag === HostPortal ) {
424
+ const nodeTag = node . tag ;
425
+ if ( nodeTag === HostRoot || nodeTag === HostPortal ) {
424
426
const container = node . stateNode . containerInfo ;
425
427
if ( isMatchingRootContainer ( container , targetContainerNode ) ) {
426
428
break ;
427
429
}
428
- if ( node . tag === HostPortal ) {
430
+ if ( nodeTag === HostPortal ) {
429
431
// The target is a portal, but it's not the rootContainer we're looking for.
430
432
// Normally portals handle their own events all the way down to the root.
431
433
// So we should be able to stop now. However, we don't know if this portal
432
434
// was part of *our* root.
433
435
let grandNode = node . return ;
434
436
while ( grandNode !== null ) {
435
- if ( grandNode . tag === HostRoot || grandNode . tag === HostPortal ) {
437
+ const grandTag = grandNode . tag ;
438
+ if ( grandTag === HostRoot || grandTag === HostPortal ) {
436
439
const grandContainer = grandNode . stateNode . containerInfo ;
437
440
if (
438
441
isMatchingRootContainer ( grandContainer , targetContainerNode )
@@ -450,7 +453,13 @@ export function dispatchEventForPluginEventSystem(
450
453
if ( parentSubtreeInst === null ) {
451
454
return ;
452
455
}
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 ;
454
463
continue ;
455
464
}
456
465
node = node . return ;
0 commit comments