From ae60caacfd7a6fd9f4ada943c7d04a782f1e9505 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Thu, 27 Feb 2020 17:23:25 -0800 Subject: [PATCH] [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 --- .../react-native-renderer/src/ReactFabricEventEmitter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-native-renderer/src/ReactFabricEventEmitter.js b/packages/react-native-renderer/src/ReactFabricEventEmitter.js index 959df5bc48732..49abda74eb362 100644 --- a/packages/react-native-renderer/src/ReactFabricEventEmitter.js +++ b/packages/react-native-renderer/src/ReactFabricEventEmitter.js @@ -87,7 +87,11 @@ export function dispatchEvent( let eventTarget = null; if (enableNativeTargetAsInstance) { if (targetFiber != null) { - eventTarget = targetFiber.stateNode.canonical; + const stateNode = targetFiber.stateNode; + // Guard against Fiber being unmounted + if (stateNode != null) { + eventTarget = stateNode.canonical; + } } } else { eventTarget = nativeEvent.target;