From 22448283076530783576a938896be1a4b363724d Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 8 Jul 2021 13:28:47 -0700 Subject: [PATCH] Guard against reused fibers in React Native commands --- .../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 040e02e093e47..bc0ffc92ea9f4 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -161,16 +161,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); } @@ -187,11 +185,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 6f12fd5d8d445..8227c5eee01cf 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -161,12 +161,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); } @@ -183,11 +182,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); }