React-native-code-push: [Android] RN0.33+ Android doesn't use the code-pushed JS bundle immediately

Created on 25 Sep 2016  路  10Comments  路  Source: microsoft/react-native-code-push

  • react-native-code-push version: 1.13.2-beta
  • react-native version: 0.33+
  • iOS/Android version: 4.4
  • Does this repro on a simulator, or only on a physical device? Both
  • Repro steps:
// index.android.js

import React, { Component } from "react";
import { View, AppRegistry } from "react-native";

import codePush from "react-native-code-push";

const backgroundColor = "green";
console.log(`backgroundColor: ${backgroundColor}`);

class Example extends Component {
  componentWillMount = () => {
    codePush.sync({
      deploymentKey: "<code>",
      updateDialog: true,
      installMode: codePush.InstallMode.IMMEDIATE,
    });
  };

  render() {
    return (
      <View style={{ flex: 1, backgroundColor }}>
      </View>
    );
  }
}

AppRegistry.registerComponent("grainApp", () => Example);

  1. The first run will print backgroundColor: "green"
  2. Change the backgroundColor, and do a code-push
  3. Click update when the update dialog appear
  4. Screen flashes, but the app will not use the new JS bundle (Also console.log(backgroundColor: ${backgroundColor}); is not printed)
  5. The updated bundle will be used after we killed the app via app switcher

I think this relates to https://github.com/facebook/react-native/issues/10089 but I might be wrong

All 10 comments

The attached issue is not related, rather this is (yet another) breaking API change to JsBundleLoader.createFileLoader in RN 0.33 (it no longer requires a Context to be passed to it). See the related commit: https://github.com/facebook/react-native/commit/0c2fdf4b6af3c4193d351ed615b9fc12c941173a#diff-e110fa648a5e434c9533e8e35b5b1f6dR50

We need to change this line https://github.com/Microsoft/react-native-code-push/blob/master/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java#L116 in our code.

Thanks for the response!
I think we'll just downgrade to the more stable RN 0.32 atm

@geof90 - Just a heads up, I tested it and I don't think this is it... Turns out that change made it into 0.34 but not 0.33

Hi @sbycrosz, I'm unable to reproduce this on RN 0.33. Are you sure you got this on RN 0.33? And the problem went away when you used RN 0.32?

My RN version was 033 and 032.1 respectively. But let me try it again with a minimal sample project..

Hi! I have the same problem. Any updates?

@DanDance, @sbycrosz - are you seeing this in debug mode only? Is it possible that what you're seeing is this? https://github.com/Microsoft/react-native-code-push/issues/438

Hi @silhouettes
I'm positive I'm using a release build.

Here's the repro repo https://github.com/sbycrosz/rn33codepush
which I build & install using ./gradlew assembleRelease && adb install -r app/build/outputs/apk/app-release.apk

And here's the adb logcat ReactNativeJS:I *:S that I think would be helpful

------------ First run
10-03 00:03:39.302  3592  3609 I ReactNativeJS: backgroundColor: red
10-03 00:03:39.351  3592  3609 I ReactNativeJS: Running application "example" with appParams: {"initialProps":{},"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
10-03 00:03:39.355  3592  3609 I ReactNativeJS: componentWillMount
10-03 00:03:39.368  3592  3609 I ReactNativeJS: rendering red
10-03 00:03:39.398  3592  3609 I ReactNativeJS: [CodePush] Checking for update.
10-03 00:03:39.415  3592  3609 I ReactNativeJS: [CodePush] Reporting binary update (1.0)
10-03 00:03:40.343  3592  3609 I ReactNativeJS: [CodePush] Report status failed: {"appVersion":"1.0"}
10-03 00:03:40.482  3592  3609 I ReactNativeJS: [CodePush] Awaiting user action.
10-03 00:03:42.846  3592  3609 I ReactNativeJS: [CodePush] Downloading package.
10-03 00:03:44.340  3592  3609 I ReactNativeJS: [CodePush] Installing update.
10-03 00:03:44.398  3592  3609 I ReactNativeJS: [CodePush] Restarting app
10-03 00:03:44.412  3592  3609 I ReactNativeJS: componentWillUnmount


------------ After accepting updateDialog
10-03 00:03:44.422  3592  3609 I ReactNativeJS: [CodePush] Reporting binary update (1.0)
10-03 00:03:44.481  3592  3609 I ReactNativeJS: Running application "example" with appParams: {"initialProps":{},"rootTag":11}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
10-03 00:03:44.501  3592  3609 I ReactNativeJS: componentWillMount
10-03 00:03:44.513  3592  3609 I ReactNativeJS: rendering red
10-03 00:03:44.519  3592  3609 I ReactNativeJS: [CodePush] Checking for update.
10-03 00:03:44.644  3592  3609 I ReactNativeJS: [CodePush] Report status failed: {"appVersion":"1.0"}
10-03 00:03:44.766  3592  3609 I ReactNativeJS: [CodePush] App is up to date.
10-03 00:03:56.684  3592  3609 I ReactNativeJS: componentWillUnmount


------------ After closing the app via back button then opening it via launcher
10-03 00:03:58.397  3592  3609 I ReactNativeJS: [CodePush] Reporting binary update (1.0)
10-03 00:03:58.519  3592  3609 I ReactNativeJS: Running application "example" with appParams: {"initialProps":{},"rootTag":21}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
10-03 00:03:58.522  3592  3609 I ReactNativeJS: componentWillMount
10-03 00:03:58.523  3592  3609 I ReactNativeJS: rendering red
10-03 00:03:58.524  3592  3609 I ReactNativeJS: [CodePush] Checking for update.
10-03 00:03:58.794  3592  3609 I ReactNativeJS: [CodePush] Report status failed: {"appVersion":"1.0"}
10-03 00:03:58.957  3592  3609 I ReactNativeJS: [CodePush] App is up to date.
10-03 00:04:04.963  3592  3609 I ReactNativeJS: componentWillUnmount

------------ After closing the app via app switcher then opening it via launcher
10-03 00:04:12.720  3652  3669 I ReactNativeJS: backgroundColor: black  <<- Update applied
10-03 00:04:12.762  3652  3669 I ReactNativeJS: Running application "example" with appParams: {"initialProps":{},"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
10-03 00:04:12.779  3652  3669 I ReactNativeJS: componentWillMount
10-03 00:04:12.787  3652  3669 I ReactNativeJS: rendering black
10-03 00:04:12.861  3652  3669 I ReactNativeJS: [CodePush] Checking for update.
10-03 00:04:12.863  3652  3669 I ReactNativeJS: [CodePush] Reporting CodePush update success (v5)
10-03 00:04:13.715  3652  3669 I ReactNativeJS: [CodePush] App is up to date.

My concern is that RN doesn't reload the JS bundle because ReactNativeJS: backgroundColor: is only printed when the task is killed (not on activity restarts)

@sbycrosz - thanks so much for the stripped down repro. I was able to reproduce it, and upgrading to react-native-code-push 1.14.6-beta actually fixed the problem. I'm not sure which release fixed this as we have had many releases since 1.13.2-beta, but it's possible that it was the loader fix that was shipped in 1.14.6-beta (release notes).

Please let me know if that works for you! If you'd like RN 34 compat, we will also be making a new release in a day or two.

@DanDance also!

Thanks @silhouettes!
I'll make note to upgrade code-push whenever we upgrade RN!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ninjz picture ninjz  路  4Comments

Fuhrmann picture Fuhrmann  路  3Comments

osdnk picture osdnk  路  3Comments

vira-khdr picture vira-khdr  路  3Comments

jaysig picture jaysig  路  3Comments