From 84639ab53fcb83c5d4806b5d791bb07992c40bf1 Mon Sep 17 00:00:00 2001 From: Timothy Yung Date: Thu, 8 Jul 2021 16:01:51 -0700 Subject: [PATCH] Guard against reused fibers in React Native commands (#21837) --- .../react-native-renderer/src/ReactFabric.js | 22 +++++++++---------- .../src/ReactNativeRenderer.js | 21 +++++++++--------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index c79868af51f0e..6fe3eeb12d244 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -160,16 +160,14 @@ function dispatchCommand(handle: any, command: string, args: Array) { 'native component. Use React.forwardRef to get access to the underlying native component', ); } - return; } - if (handle._internalInstanceHandle) { - nativeFabricUIManager.dispatchCommand( - handle._internalInstanceHandle.stateNode.node, - command, - args, - ); + if (handle._internalInstanceHandle != null) { + const {stateNode} = handle._internalInstanceHandle; + if (stateNode != null) { + nativeFabricUIManager.dispatchCommand(stateNode.node, command, args); + } } else { UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args); } @@ -186,11 +184,11 @@ function sendAccessibilityEvent(handle: any, eventType: string) { return; } - if (handle._internalInstanceHandle) { - nativeFabricUIManager.sendAccessibilityEvent( - handle._internalInstanceHandle.stateNode.node, - eventType, - ); + if (handle._internalInstanceHandle != null) { + const {stateNode} = handle._internalInstanceHandle; + if (stateNode != null) { + nativeFabricUIManager.sendAccessibilityEvent(stateNode.node, eventType); + } } else { legacySendAccessibilityEvent(handle._nativeTag, eventType); } diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index fdb1c05fed94f..3c3f234e0cb66 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -160,12 +160,11 @@ function dispatchCommand(handle: any, command: string, args: Array) { return; } - if (handle._internalInstanceHandle) { - nativeFabricUIManager.dispatchCommand( - handle._internalInstanceHandle.stateNode.node, - command, - args, - ); + if (handle._internalInstanceHandle != null) { + const {stateNode} = handle._internalInstanceHandle; + if (stateNode != null) { + nativeFabricUIManager.dispatchCommand(stateNode.node, command, args); + } } else { UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args); } @@ -182,11 +181,11 @@ function sendAccessibilityEvent(handle: any, eventType: string) { return; } - if (handle._internalInstanceHandle) { - nativeFabricUIManager.sendAccessibilityEvent( - handle._internalInstanceHandle.stateNode.node, - eventType, - ); + if (handle._internalInstanceHandle != null) { + const {stateNode} = handle._internalInstanceHandle; + if (stateNode != null) { + nativeFabricUIManager.sendAccessibilityEvent(stateNode.node, eventType); + } } else { legacySendAccessibilityEvent(handle._nativeTag, eventType); }