[Fabric] Fix targetAsInstance dispatchEvent "cannot read property of null" (#18156)
* Fix Fabric targetAsInstance dispatchEvent: targetFiber stateNode is null in some cases Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Joshua Gross committed
Feb 27, 2020 at 17:23 UTC
ae60caacfd7a6fd9f4ada943c7d04a782f1e9505
1 file changed
+5
-1
packages/react-native-renderer/src/ReactFabricEventEmitter.js
+5
-1
@@ -87,7 +87,11 @@ export function dispatchEvent(
87
let eventTarget = null;
88
if (enableNativeTargetAsInstance) {
89
if (targetFiber != null) {
90
- eventTarget = targetFiber.stateNode.canonical;
90
+ const stateNode = targetFiber.stateNode;
91
+ // Guard against Fiber being unmounted
92
+ if (stateNode != null) {
93
+ eventTarget = stateNode.canonical;
94
+ }
95
}
96
} else {
97
eventTarget = nativeEvent.target;