From d92ecda022e9038862e1864d5c9d0aa0d0bf4699 Mon Sep 17 00:00:00 2001 From: jonathanmos Date: Tue, 16 Nov 2021 11:24:36 +0200 Subject: [PATCH 1/2] Fix Switch causing RetryableMountingLayerException Summary: Changelog: Change useLayoutEffect to useEffect to fix #32594 - stuck operation in mViewCommandOperations list in Android Release --- Libraries/Components/Switch/Switch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Components/Switch/Switch.js b/Libraries/Components/Switch/Switch.js index abb7f00b761d..91ba3dec8549 100644 --- a/Libraries/Components/Switch/Switch.js +++ b/Libraries/Components/Switch/Switch.js @@ -165,7 +165,7 @@ const SwitchWithForwardedRef: React.AbstractComponent< setNative({value: event.nativeEvent.value}); }; - React.useLayoutEffect(() => { + React.useEffect(() => { // This is necessary in case native updates the switch and JS decides // that the update should be ignored and we should stick with the value // that we have in JS. From 71a588bc7cfb342c48a3534ee11b35020e4f125e Mon Sep 17 00:00:00 2001 From: jonathanmos Date: Sun, 20 Feb 2022 01:13:46 +0200 Subject: [PATCH 2/2] Fix Switch causing RetryableMountingLayerException --- Libraries/Components/Switch/Switch.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Libraries/Components/Switch/Switch.js b/Libraries/Components/Switch/Switch.js index 91ba3dec8549..16e7d20d5fd2 100644 --- a/Libraries/Components/Switch/Switch.js +++ b/Libraries/Components/Switch/Switch.js @@ -165,12 +165,13 @@ const SwitchWithForwardedRef: React.AbstractComponent< setNative({value: event.nativeEvent.value}); }; - React.useEffect(() => { + React.useLayoutEffect(() => { // This is necessary in case native updates the switch and JS decides // 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