From 63e4bd655a0020c8ea6d5db64cba6ad9ec9e325c Mon Sep 17 00:00:00 2001 From: jonathanmos Date: Thu, 24 Feb 2022 17:46:41 -0800 Subject: [PATCH] Fix Switch causing RetryableMountingLayerException (#32602) Summary: Added a null check to native.value in Switch to fix regression from RN 66 -> stuck operation in mViewCommandOperations list in Android Release on initial layout of a screen with Switch component. If approved, please incorporate this fix into an RN 66 release. ## Changelog [Android][Fixed] - Added a null check to native.value in Switch to fix https://github.com/facebook/react-native/issues/32594 Pull Request resolved: https://github.com/facebook/react-native/pull/32602 Test Plan: To reproduce, put a log in UIViewOperationQueue in dispatchViewUpdates you can see that the RetryableMountingException is no longer thrown for a screen with the Switch component on Android Release. As a result, mViewCommandOperations no longer has a stuck operation on initial layout. Reviewed By: charlesbdudley Differential Revision: D34397788 Pulled By: lunaleaps fbshipit-source-id: 1cee3516fb987942dfa50ad1f2d11c965a947f05 --- Libraries/Components/Switch/Switch.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/Switch/Switch.js b/Libraries/Components/Switch/Switch.js index 6c90f3d49c9..fcdc534c795 100644 --- a/Libraries/Components/Switch/Switch.js +++ b/Libraries/Components/Switch/Switch.js @@ -170,7 +170,8 @@ const SwitchWithForwardedRef: React.AbstractComponent< // that the update should be ignored and we should stick with the value // that we have in JS. const jsValue = value === true; - const shouldUpdateNativeSwitch = native.value !== jsValue; + const shouldUpdateNativeSwitch = + native.value != null && native.value !== jsValue; if ( shouldUpdateNativeSwitch && nativeSwitchRef.current?.setNativeProps != null