microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

The update not installed, keeps rolled back or throwing an exception #2639

Closed mununki closed 9 months ago

mununki commented 10 months ago

Every updates are not installed and keep rolled back or throwing an exception on iOS. I started facing this issue after upgrading RN 0.68.7 -> 0.72.7 and code-push 7.1.0 -> 8.1.0.

Steps to Reproduce

  1. RN v0.72.7 and code-push v8.1.0, might be relavant "react-native-reanimated": "^3.4.0"
  2. Wrap the app
    export default codePush({
    checkFrequency: codePush.CheckFrequency.MANUAL,
    installMode: codePush.InstallMode.ON_NEXT_RESTART,
    })(App);
  3. Release the update

Expected Behavior

The update is installed

Actual Behavior

The update keeps rolled back, not installed on iOS. AOS is fine. I observed symptoms in two cases. It works fine on the previous versions.

1. Auto update

{
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
  installMode: codePush.InstallMode.IMMEDIATE,
}

This case cause the exception when I ran the app through the xcode to get an error stack. Thread 3: "Error when sending event: CodePushDownloadProgress with body: {\n receivedBytes = 8914917;\n totalBytes = 8914917;\n}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in CodePush, even though it's inherited from RCTEventEmitter."

2. Manual update

{
  checkFrequency: codePush.CheckFrequency.MANUAL,
  installMode: codePush.InstallMode.ON_NEXT_RESTART,
}

This case doesn't cause the exception, but the sync call is not working as intended. When the sync is called, it logs

[CodePush] Checking for update.
[CodePush] An update is available, but it is being ignored due to having been previously rolled back.

Even if you check the app center dashboard, all updates are rolled back and not installed.

Reproducible Demo

Environment

WilliamWelsh commented 10 months ago

I have the exact same issue.

Did you ever have expo-updates installed?

mununki commented 10 months ago

I have the exact same issue.

Did you ever have expo-updates installed?

No, I'm not using expo. It is configured with react-native-cli.

mununki commented 10 months ago

Similar issue: https://github.com/microsoft/react-native-code-push/issues/2598

mununki commented 9 months ago

I finally fix this issue.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:self.moduleName
                                               initialProperties:self.initialProps
                                                   launchOptions:launchOptions];
...
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
...
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

I suspect the cause of the issue is that it creates a new rootView again during the process of checking for codepush updates, downloading the latest jsbundle, and installing it, causing an interruption in the middle. So I made the following modification and codepush update installed normally and works as intended.

  1. Call super in the first part of the function.
  2. Remove the part of initializing RCTRootView rootView that is already done inside super
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [super application:application didFinishLaunchingWithOptions:launchOptions];

  # NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  # RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
  #                                                     moduleName:self.moduleName
  #                                              initialProperties:self.initialProps
  #                                                  launchOptions:launchOptions];

  #  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  #  UIViewController *rootViewController = [UIViewController new];
  #  rootViewController.view = rootView;
  #  self.window.rootViewController = rootViewController;
  #  [self.window makeKeyAndVisible];
...
return YES;
}
Gautham495 commented 8 months ago

Can you share the full snippet of AppDelegate.mm please.

amanthegreatone commented 6 months ago

pls check this i had this issue which was solved. https://github.com/microsoft/react-native-code-push/issues/2529#issuecomment-1968788585