Skip to content

Commit

Permalink
Fix android reload reentrant issue (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo authored Nov 5, 2024
1 parent ad958d4 commit 8e3acb6
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 com.facebook.react.packagerconnection.Responder;
import java.io.File;
Expand Down Expand Up @@ -363,6 +364,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 8e3acb6

Please sign in to comment.