Skip to content

Commit

Permalink
Fix android reload reentrant issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo authored and vonovak committed Feb 25, 2025
1 parent eac0fbb commit d0f3174
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.facebook.react.devsupport.interfaces.StackFrame;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
import com.facebook.react.packagerconnection.JSPackagerClient;
import com.facebook.react.packagerconnection.RequestHandler;
import java.io.File;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -357,6 +358,12 @@ private int getExponentActivityId() {
@Override
public void reloadExpoApp() {
try {
if (mDevServerHelper.mPackagerClient != null) {
// In Expo Go's multi-Activity structure, reloading means destroying the current Activity and creating a new one with a fresh React instance.
// To prevent reentrant `reloadExpoApp` from being triggered by a long press of the "r" key in the CLI, which could lead to an unexpected state,
// we must terminate the packager connection immediately. This is done without waiting a worker thread by using `mDevServerHelper.closePackagerConnection()`.
mDevServerHelper.mPackagerClient.close();
}
Class.forName("host.exp.exponent.ReactNativeStaticHelpers").getMethod("reloadFromManifest", int.class).invoke(null, getExponentActivityId());
} catch (Exception expoHandleErrorException) {
expoHandleErrorException.printStackTrace();
Expand Down

0 comments on commit d0f3174

Please sign in to comment.