Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code push - Bundle changes are not reflected once the App closes and reopens #2529

Open
karthinidc opened this issue Jun 2, 2023 · 35 comments

Comments

@karthinidc
Copy link

Code push - Bundle changes are not reflected once the App closes and reopens only. (iOS Platform), Android working fine.

Steps to Reproduce

  1. Installed build on the device
  2. Released code push with changes
  3. Code push bundle installed on the device - New release available on the screen.
  4. App closes and reopens - New change from bundle release will not be reflected - Older IPA file changes alone available in screen

Expected Behavior

Always available the new bundle release on the screen

Actual Behavior

Always not available the new bundle release on the screen

Environment

  • react-native-code-push version: 7.0.4
  • react-native version:0.69.0
  • iOS/Android/Windows version: iOS 15.7.1
  • Does this reproduce on a debug build or release build? : release build and App Store release
  • Does this reproduce on a simulator, or only on a physical device? - Both

(The more info the faster we will be able to address it!)

@namcancode
Copy link

namcancode commented Jun 3, 2023

same here

@Venulapog
Copy link

Venulapog commented Jun 3, 2023

same here,
"react-native": "0.69.1", "react-native-code-push": "^7.0.5", are the verisons

I'm not sure if this information is relevant, but the code push was functioning correctly for me when the "react-native" version was 0.68.2. However, I needed to add a new feature that required upgrading "react-native" to at least version 0.69.1. To perform the upgrade, I used the upgrade helper provided by https://react-native-community.github.io/upgrade-helper/?from=0.68.2&to=0.69.1. After publishing the app about 2 months ago, when I tried to do the code push last week, the code push is no longer working as expected. The issue is that after a successful code push, the app prompts for an upgrade, and upon installation, it functions properly. However, when I close and reopen the app, it reverts back to the previous version.
I am not sure if this might be the reason.
How can I confirm what might be causing this issue?
Please note code push version was the same "7.0.5"

@DmitriyKirakosyan
Copy link
Contributor

@karthinidc , @namcancode , can you also confirm if the issues started to happen after RN upgrade?

@karthinidc
Copy link
Author

@DmitriyKirakosyan It's a new project, Created the React Native version with 0.69.0. -- Not did any RN upgrade

@BCT-Barney
Copy link

Same here,
"react-native": "0.71.6",
"react-native-code-push": "^8.0.2",

@BCT-Barney
Copy link

@DmitriyKirakosyan kindly ask if there is any thought of this issue?

@DmitriyKirakosyan
Copy link
Contributor

Please make sure you have correctly set up CodePush in AppDelegate.mm, see https://learn.microsoft.com/en-us/appcenter/distribution/codepush/rn-get-started#ios-setup.
Also make sure the #import <CodePush/CodePush.h> line is placed above the #if block.

Let me know if it helps.

@uncoolclub
Copy link

uncoolclub commented Jun 14, 2023

@DmitriyKirakosyan Facing the same issue on only iOS. Is there any way?

Environment

react-native-code-push version: ^8.0.1
react-native version:0.71.6
iOS/Android/Windows version: iOS 16.5
Does this reproduce on a debug build or release build? : It's a release build and it's an app that was run on Testflight.
Does this reproduce on a simulator, or only on a physical device? - physical device
using hermes engine

AppDelegate.mm

#import "AppDelegate.h"
#import "SDImageCodersManager.h"

#import <SDWebImageWebPCoder/SDImageWebPCoder.h>
#import <React/RCTAppSetupUtils.h>
#import <React/RCTBundleURLProvider.h>

#import <CodePush/CodePush.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  self.moduleName = @"";
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [CodePush bundleURL];
#endif
}

- (BOOL)concurrentRootEnabled
{
  return true;
}

@end

@DmitriyKirakosyan
Copy link
Contributor

DmitriyKirakosyan commented Jun 15, 2023

Hi @uncoolclub , may I ask you to reproduce the issue on an empty app and share it with us if possible?
App logs would also be helpful.

@uncoolclub
Copy link

uncoolclub commented Jun 19, 2023

@DmitriyKirakosyan

I apologize, but I cannot spend much time on this due to other tasks, so I cannot test in an empty app. Instead, I'll tell you more about the current environment.

The issue is the same as the following issue: (2436)
When receiving a code push update only on iOS, if the app is closed and restarted, the code push update is not received. After this bug appears, re-distributing with the same code will work normally. However, the strange thing is that if you distribute it with the same code, it should not be distributed originally. (No changed logic, so I throw an error in the code push.)

The log I observed in the Xcode console is as follows, and along with this log, the app stays on the previous version without receiving the latest update:
Also, I took a picture of console.log in LoadingScreen as below, but it could not be checked in the Xcode console.

[CodePush] Loading JS bundle from file:///var/mobile/Containers/Data/Application/A90206B2-BDA2-4527-8E1F-A1F643C499D1/Library/Application%20Support/CodePush/36f844ae1b550aa78f08b8b60db98b3c2f6fae660950830df0cb5f2a5e390f69/CodePush/main.jsbundle
// App.jsx
import React, { lazy, Suspense, useEffect } from 'react';
import LoadingScreen from '@Loading/LoadingScreen';

// import other modules

const codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };
const screenOptions = {
  headerShown: false,
  gestureEnabled: PLATFORM.CURRENT === PLATFORM.IOS,
  cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
};

const queryClient = new QueryClient();
const Stack = createNativeStackNavigator();

const App = () => {
  ...

  return (
    <Provider store={store}>
      <QueryClientProvider client={queryClient}>
        <Suspense fallback={<View />}>
          <NavigationContainer>
            <Stack.Navigator screenOptions={screenOptions}>
              ...
            </Stack.Navigator>
          </NavigationContainer>
        </Suspense>
      </QueryClientProvider>
    </Provider>
  );
};

export default codePush(codePushOptions)(App);
// LoadingScreen.jsx
...
  syncWithCodePush = async () => {
    const [isTester, isBetaTester] = await Promise.all([getIsTester(true), getIsBetaTester()]);
    this.setRandomProcessText();

    return new Promise((resolve) => {
      const option = { installMode: InstallMode.IMMEDIATE };

      if (isTester) {
        option.deploymentKey = TEST_DEPLOYMENT_KEY;
      } else if (isBetaTester) {
        option.deploymentKey = BETA_TEST_DEPLOYMENT_KEY;
      } else {
        option.deploymentKey = PROD_DEPLOYMENT_KEY;
      }

      const loadingTimeout = setTimeout(() => {
        this.setState({ isCodeUpdated: true, isOnSync: false });
        resolve(true);
      }, 13000);

      sync(
        option,
        (status) => {
          switch (status) {
            case SyncStatus.CHECKING_FOR_UPDATE:
              console.log('[CodePush] Checking for updates.');
              break;

            case SyncStatus.UP_TO_DATE:
              console.log('[CodePush] Up-to-date.');

              this.setState({
                isOnSync: false,
                isCodeUpdated: true,
                totalBytes: 100,
                receivedBytes: 100,
              });
              clearTimeout(loadingTimeout);
              resolve(true);
              break;

            case SyncStatus.UPDATE_INSTALLED:
              console.log('[CodePush] Update installed.');

              this.setState({
                isOnSync: false,
                isCodeUpdated: true,
                totalBytes: 100,
                receivedBytes: 100,
              });
              clearTimeout(loadingTimeout);
              break;

            case SyncStatus.INSTALLING_UPDATE:
              console.log('[CodePush] Installing update.');

              this.setState({
                isOnSync: false,
                isCodeUpdated: true,
                totalBytes: 100,
                receivedBytes: 100,
              });
              clearTimeout(loadingTimeout);
              break;

            case SyncStatus.DOWNLOADING_PACKAGE:
              console.log('[CodePush] Downloading package.');

              this.setState({ isOnSync: true });
              clearTimeout(loadingTimeout);
              break;

            default:
              break;
          }
        },
        ({ receivedBytes, totalBytes }) => {
          this.setState({ receivedBytes, totalBytes, isOnSync: true });

          if (receivedBytes >= totalBytes) {
            this.setRandomProcessText();
          }
        },
      );
    });
  };

Also, there was no problem when I used the version below, but there was an issue while upgrading the version.

// prev version
"react": "17.0.2",
"react-native": "0.68.0",
"react-native-code-push": "^7.0.5"
// current version
"react": "18.2.0",
"react-native": "0.71.6",
"react-native-code-push": "^8.0.1"

If you have a plan to work on this bug, can I know when it can be fixed?

@uncoolclub
Copy link

uncoolclub commented Jun 19, 2023

@DmitriyKirakosyan

A bug has just been reproduced and recorded. I will attach it additionally. The flow is as follows.

  1. I went into the credit in the previous version app and checked the code push version. (CODE_PUSH: v44/v44)

  2. The latest version has been distributed through code push and after exiting the app, I enter the app again, there is an update, but I don't get it.

  3. After exiting the app, I need to get the latest version when I go back in, but I haven't and I'm still stuck with the previous version. (CODE_PUSH: v44/v44)

If this bug occurs, the only solution I found is to reinstall the app in the direction of clearing its cache. This bug happens quite often. 😭

Below is the latest version available through the App Center. (v45)
스크린샷 2023-06-19 오후 2 19 51

The commands used are as follows.

const { command } = require('./common');
const { CURRENT_VERSION, SERVICE, SERVICE_NAME_KOR, MINIMUM_VERSION } = require('./constant');

const main = async () => {
  const result = await command(
    `appcenter codepush release-react -a ${SERVICE}/ios -m -d Beta -t "${MINIMUM_VERSION} - ${CURRENT_VERSION}"`,
  );
};

main()
  .then((result) => console.log(result))
  .catch(() => require('process').exit(1));

@uncoolclub
Copy link

@DmitriyKirakosyan Hi, Can you check it ASAP? It's about to be released, so I need to check it quickly. Help me, please. 🥺🥺

@DmitriyKirakosyan
Copy link
Contributor

@uncoolclub ,

I will attach it additionally

I can't see any additional attachments. Or you meant the video?
I checked your code and the video and it is still hard to say why it doesn't work for you..

A couple of additional questions:

  • Have you upgraded react-native or started the project from version 0.71?
  • Have you started seeing this issue with code-push just recently or it was happening from the time you integrated it?

@uncoolclub
Copy link

@DmitriyKirakosyan
It means video.
Upgraded react-native to 0.71. No such bugs were found in previous versions. The problem was identified by code push.

@DmitriyKirakosyan
Copy link
Contributor

@uncoolclub Unfortunately the video and the flow steps didn't help me to find the root cause.
Try to remove code-push and integrate it again using the docs.
Have you done react-native migration from older version? Did the code-push work well before or you face the issue from the very beginning of adding it?

@HeronicKnight
Copy link

HeronicKnight commented Jul 4, 2023

Hi I'm having the same issues except mine is a complete starter application. When new update is released to codepush the app prompts with the install button, once I click install no changes happen, but on the appcenter it shows its been downloaded and installed. Already reinstalled twice double checking correct gradle and java getJSBundleFile override.

import React from 'react';
import type {PropsWithChildren} from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';

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

const codePushOptions = {
  updateDialog: true,
  checkFrequency: codePush.CheckFrequency.ON_APP_START,
  installMode: codePush.InstallMode.IMMEDIATE,
};

type SectionProps = PropsWithChildren<{
  title: string;
}>;

function Section({children, title}: SectionProps): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';
  return (
    <View style={styles.sectionContainer}>
      <Text
        style={[
          styles.sectionTitle,
          {
            color: isDarkMode ? 'white' : 'black',
          },
        ]}>
        {title}
      </Text>
      <Text
        style={[
          styles.sectionDescription,
          {
            color: isDarkMode ? 'lightgray' : 'gray',
          },
        ]}>
        {children}
      </Text>
    </View>
  );
}

function App(): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? 'black' : 'white',
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <View
          style={{
            backgroundColor: isDarkMode ? 'black' : 'white',
          }}>
          <Section title="Driver App">
            <Text style={styles.highlight}>
              Over-The-Air Updates Mockup{'\n'}
            </Text>
            <Text style={styles.baseText}>This is version 2.0.0</Text>
          </Section>
          <Section title="Testing Changes">
            <Text style={styles.highlight}>
              I added text here for version 2.0.0
            </Text>
          </Section>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  baseText: {
    fontFamily: 'Cochin',
    fontStyle: 'italic',
  },
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
  },
  highlight: {
    fontWeight: '700',
  },
});

export default codePush(codePushOptions)(App);
"react-native": "^0.71.11",
"react-native-code-push": "^8.0.2"

@skdev24
Copy link

skdev24 commented Jul 6, 2023

This helped me #2195 (comment). I had a similar issue.

@DSoliz
Copy link

DSoliz commented Aug 3, 2023

Hello, facing the same issue on iOS only

"react": "17.0.2",
"react-native": "0.68.6",
"react-native-code-push": "^7.1.0",

iPad OS Version 16.5.1

Update: In our case this seems to have fixed it

#2195 (comment)

@mhatami-ecotrak
Copy link

Same here Latest React native & code push

@DmitriyKirakosyan
Copy link
Contributor

@mhatami-ecotrak , have you tried the fix from #2195 (comment)?
Have you updated/migrated react-native recently?

@vkyscen
Copy link

vkyscen commented Jan 24, 2024

I'm still facing the same issue in 2k24. Any solutions or workaround for this?

@DmitriyKirakosyan
Copy link
Contributor

@vkyscen Please try the workaround mentioned above.

@ishiharas
Copy link

I am facing the same issue on iOS right now. (Android works without a problem.)

( -> Codepush is loading the update after starting the app, restarting and showing the changes. After restarting the app manually, the original bundle is showing again. No information in xCode logs. )

I am not using react-native-navigation by wix. Therefore the workaround doesn't work for me.

"react-native": "0.73.2",
"appcenter": "5.0.1",
"react-native-code-push": "^8.2.1",

My AppDelegate.mm looks like the following:

#import "AppDelegate.h"
#import "RNBootSplash.h"
#import <Firebase.h>

#import <AppCenterReactNative.h>
#import <AppCenterReactNativeAnalytics.h>
#import <AppCenterReactNativeCrashes.h>
#import <CodePush/CodePush.h>

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  self.moduleName = @"AppNameRN";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  [FIRApp configure];
  [AppCenterReactNative register];
  [AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true];
  [AppCenterReactNativeCrashes registerWithAutomaticProcessing];

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  return [self getBundleURL];
}

- (NSURL *)getBundleURL
{
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  #else
    return [CodePush bundleURL];
  #endif
}

// ⬇️ Add this before file @end
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
                          moduleName:(NSString *)moduleName
                           initProps:(NSDictionary *)initProps {
  UIView *rootView = [super createRootViewWithBridge:bridge
                                          moduleName:moduleName
                                           initProps:initProps];

  [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // ⬅️ initialize the splash screen

  return rootView;
}

@end

@DmitriyKirakosyan Do you see anything out of the ordinary here? Maybe it is the RNBootSplash implementation?

The rest of my code is fairly simple: main.tsx (which is called by index.js with AppRegistry.registerComponent)

const codePushOptions: CodePushOptions = {
  checkFrequency: CodePush.CheckFrequency.MANUAL,
};

function Main() {
  return (
    <Provider store={store}>
      <PersistGate persistor={persistor}>
        <SafeAreaProvider>
          <NavigationContainer ref={navigationRef}>
            <PaperProvider theme={appTheme}>
              <RootStack />
              <LoadingView />
            </PaperProvider>
          </NavigationContainer>
        </SafeAreaProvider>
      </PersistGate>
    </Provider>
  );
}

export default CodePush(codePushOptions)(Main);

and inside my loading-component:

  useEffect(() => {
    const codePushSync = async () => {
      await CodePush.sync(
        {
          installMode: CodePush.InstallMode.IMMEDIATE,
        },
        (cb) => {
          if (
            cb == CodePush.SyncStatus.UP_TO_DATE ||
            cb == CodePush.SyncStatus.UPDATE_INSTALLED ||
            cb == CodePush.SyncStatus.UNKNOWN_ERROR
          ) {
            setCodePushFinished(true);
          }
        }
      );
    };

    codePushSync();
  }, []);

@ishiharas
Copy link

ishiharas commented Feb 28, 2024

For everyone looking here in 2k24:

I found the issue in my previous setup.
I made my staging scheme a copy of my debug scheme.
That's why the preprocessor macro was set to DEBUG=1 for staging as well.
While the first sync works, after a restart, it would catch the default-bundleURL.

Bildschirmfoto 2024-02-28 um 12 24 41

Deleting the preprocessor macro for staging fixed the issue.

@tgp-fk
Copy link

tgp-fk commented Mar 21, 2024

Any update on this? facing the same on Android. It's loading the bundle from codepush index.bundle.js but not reflecting the changes in android.

@DmitriyKirakosyan
Copy link
Contributor

@ishiharas, your code snippet appears fine. Could you please create a minimal demo application to replicate the issue? @tgp-fk, I have the same request for you.

@amanthegreatone
Copy link

For everyone looking here in 2k24:

I found the issue in my previous setup. I made my staging scheme a copy of my debug scheme. That's why the preprocessor macro was set to DEBUG=1 for staging as well. While the first sync works, after a restart, it would catch the default-bundleURL.

Bildschirmfoto 2024-02-28 um 12 24 41 Deleting the preprocessor macro for staging fixed the issue.

this fixed the issue for me

@anhnguyen123
Copy link

For everyone looking here in 2k24:

I found the issue in my previous setup. I made my staging scheme a copy of my debug scheme. That's why the preprocessor macro was set to DEBUG=1 for staging as well. While the first sync works, after a restart, it would catch the default-bundleURL.

Bildschirmfoto 2024-02-28 um 12 24 41 Deleting the preprocessor macro for staging fixed the issue.

For everyone looking here in 2k24:

I found the issue in my previous setup. I made my staging scheme a copy of my debug scheme. That's why the preprocessor macro was set to DEBUG=1 for staging as well. While the first sync works, after a restart, it would catch the default-bundleURL.

Bildschirmfoto 2024-02-28 um 12 24 41 Deleting the preprocessor macro for staging fixed the issue.

My situation is like this now, what should I do?

image

@Bruce-Ming
Copy link

same here
"react": "18.2.0",
"react-native": "0.72.4"
"react-native-code-push": "^8.1.0",

@tgp-fk
Copy link

tgp-fk commented Jun 14, 2024

hey @Bruce-Ming it's better to leave this code push now as it will be deprecated next year. It's Better to wait for a standalone version by MS.

@sufian1999
Copy link

sufian1999 commented Aug 9, 2024

"react": "17.0.2",
"react-native": "0.68.2",
"react-native-code-push": "^7.1.0"

I pushed code with this:
appcenter codepush release-react -a owner-email/app-name -d Production -m --disabled

When the 'Just Now' changes to the Date Time. I Enabled the release and when I open the TestFlight, it downloads the update after 1-2 minutes and changes reflect on the next restart.

Today, I tested it 2 times on my TestFlight, it's working.

Suppose any issue comes up once my app is uploaded via the App Store. I will let you people know.

  • I update my live app via codePush for iOS. The first time, it updates the app. But the second time I push changes, it's not updating the app. So, I'm finding a solution for it.

@nguyenductoan1995
Copy link

"react": "18.3.1",
"react-native": "0.74.5",
"react-native-code-push": "^9.0.0",

i got same issue. The first time it worked but i don't understand why when i close the app and reopen it it goes back to the original

@DmitriyKirakosyan
Copy link
Contributor

@nguyenductoan1995 please share the app logs and a demo app to reproduce the issue on if possible.

@nguyenductoan1995
Copy link

@DmitriyKirakosyan
pls see this log:
1 .process of opening the app
2. code push download
3. install new bundle
4. close the app and reopen it
5. back to the original bundle
log.txt

@DordeDimitrijev
Copy link
Contributor

Hi @nguyenductoan1995 i can't reproduce the issue you are experiencing could you please share a small demo app in which this issue is reproducable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests