Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 09883dd

Browse files
Prevent removing ReactNativeDevBundle in LiveReload (#1332)
1 parent 19b1a5e commit 09883dd

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.facebook.react.bridge.JavaScriptModule;
1212
import com.facebook.react.bridge.NativeModule;
1313
import com.facebook.react.bridge.ReactApplicationContext;
14+
import com.facebook.react.devsupport.DevInternalSettings;
15+
import com.facebook.react.devsupport.interfaces.DevSupportManager;
1416
import com.facebook.react.uimanager.ViewManager;
1517

1618
import org.json.JSONException;
@@ -76,7 +78,7 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
7678

7779
mCurrentInstance = this;
7880

79-
clearDebugCacheIfNeeded();
81+
clearDebugCacheIfNeeded(null);
8082
initializeUpdateAfterRestart();
8183
}
8284

@@ -119,8 +121,20 @@ private String getPublicKeyByResourceDescriptor(int publicKeyResourceDescriptor)
119121
return publicKey;
120122
}
121123

122-
public void clearDebugCacheIfNeeded() {
123-
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null)) {
124+
public void clearDebugCacheIfNeeded(ReactInstanceManager instanceManager) {
125+
boolean isLiveReloadEnabled = false;
126+
127+
// Use instanceManager for checking if we use LiveRelaod mode. In this case we should not remove ReactNativeDevBundle.js file
128+
// because we get error with trying to get this after reloading. Issue: https://github.com/Microsoft/react-native-code-push/issues/1272
129+
if (instanceManager != null) {
130+
DevSupportManager devSupportManager = instanceManager.getDevSupportManager();
131+
if (devSupportManager != null) {
132+
DevInternalSettings devInternalSettings = (DevInternalSettings)devSupportManager.getDevSettings();
133+
isLiveReloadEnabled = devInternalSettings.isReloadOnJSChangeEnabled();
134+
}
135+
}
136+
137+
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled) {
124138
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
125139
File cachedDevBundle = new File(mContext.getFilesDir(), "ReactNativeDevBundle.js");
126140
if (cachedDevBundle.exists()) {

android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ private void setJSBundle(ReactInstanceManager instanceManager, String latestJSBu
118118

119119
private void loadBundle() {
120120
clearLifecycleEventListener();
121-
mCodePush.clearDebugCacheIfNeeded();
121+
try {
122+
mCodePush.clearDebugCacheIfNeeded(resolveInstanceManager());
123+
} catch(Exception e) {
124+
// If we got error in out reflection we should clear debug cache anyway.
125+
mCodePush.clearDebugCacheIfNeeded(null);
126+
}
127+
122128
try {
123129
// #1) Get the ReactInstanceManager instance, which is what includes the
124130
// logic to reload the current React context.

0 commit comments

Comments
 (0)