From beebf4a0a36c4ee9dc52631afdf2b25745a1b0f2 Mon Sep 17 00:00:00 2001 From: Sushant Sardeshpande Date: Thu, 8 Aug 2024 07:58:23 -0700 Subject: [PATCH] Fix for app restart on Android in case of remote debugging (#45775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Added a check in setRemoteJSDebugEnabled in DevSupportManagerBase.java to check for PREFS_REMOTE_JS_DEBUG_KEY to see if the value has changed. Fix for https://github.com/facebook/react-native/issues/45399 - App restarting when `NativeDevSettings.setIsDebuggingRemotely` is used in a landing component. If this was invoked from a component load or action that would fire on app start, it was creating an infinite loop where the app would keep on restart before eventually leading to a crash. ## Changelog: [ANDROID] [FIXED] - Fix issue with `NativeDevSettings.setIsDebuggingRemotely` where the app would keep on restarting if remote debugging was invoked from an action / component that was called on app start. Pull Request resolved: https://github.com/facebook/react-native/pull/45775 Test Plan: Create a new project using RN CLI. Set `newArchEnabled=false`.� Install modules using `yarn install`.� Build from source for Android by setting the following in `settings.gradle`-� ``` includeBuild('../node_modules/react-native') { dependencySubstitution { substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid")) substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid")) substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine")) substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine")) } } ``` Set the ANDROID_HOME and ANDROID_NDK_HOME environment variables required for react native.�Call `NativeDevSettings.setIsDebuggingRemotely` from App.tsx which is the landing component.� Test with both `hermesEnabled=true` and `hermesEnabled=false` and ensure that app does not keep on restarting after fix. Reviewed By: cipolleschi Differential Revision: D60377406 Pulled By: huntie fbshipit-source-id: c8faf184b50b67f50f8a4b6851df9d0ef3350949 --- .../react/devsupport/DevSupportManagerBase.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java index d02f9bb3b63..cc211ab0081 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java @@ -998,11 +998,13 @@ public abstract class DevSupportManagerBase implements DevSupportManager { return; } - UiThreadUtil.runOnUiThread( - () -> { - mDevSettings.setRemoteJSDebugEnabled(isRemoteJSDebugEnabled); - handleReloadJS(); - }); + if (mDevSettings.isRemoteJSDebugEnabled() != isRemoteJSDebugEnabled) { + UiThreadUtil.runOnUiThread( + () -> { + mDevSettings.setRemoteJSDebugEnabled(isRemoteJSDebugEnabled); + handleReloadJS(); + }); + } } @Override