microsoft / react-native-code-push

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

Codepush not applying downloaded bundle #2582

Closed mohitarora777 closed 1 year ago

mohitarora777 commented 1 year ago

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Steps to Reproduce

  1. Open App
  2. Wait for codepush to download bundle
  3. Kill the app and restart

Expected Behavior

CodePush Bundle should be loaded

Actual Behavior

Default Bundle is getting Loaded

Screenshot 2023-09-13 at 7 14 33 PM

Reproducible Demo

const CodepushWrappedAppComponent = (props: Props) => {
    const data = safeJsonParse(props.data) || {};
    const { isDebug = false, buildEnvironment = 'production' } = data as dataType;
    const labelRef = useRef('');
    config.setActiveEnv(buildEnvironment);
    config.setIsDebug(isDebug);
    errorHandler.startErrorHandling();
    facade.setBaseUrlFromConfig();
    const deploymentKey =
        Platform.OS === 'ios'
            ? config.activeConfig.iosCodePushDeploymentKey
            : config.activeConfig.androidCodePushDeploymentKey;
    let rollbackRetryOptions = {
        delayInHours: 4,
        maxRetryAttempts: 3,
    };
    if (isDebug) {
        rollbackRetryOptions = {
            delayInHours: 0,
            maxRetryAttempts: 999,
        };
    }
    const codepushConfig = {
        checkFrequency: CodePush.CheckFrequency.MANUAL,
        installMode: CodePush.InstallMode.ON_NEXT_RESTART,
        mandatoryInstallMode: CodePush.InstallMode.ON_NEXT_RESTART,
        deploymentKey,
        rollbackRetryOptions,
    };

    const fetchCodepushUpdate = async () => {
        try {
            const updateAvailable = await CodePush.checkForUpdate();
            if (updateAvailable) {
                labelRef.current = updateAvailable?.label;
                codepushSync(); // only calling sync when the update is available
            } else {
                sendEvent('UP_TO_DATE');
            }
        } catch (error) {
            errorHandler.reportStringError(`[CodePush]: Error in checking for update`, error);
        }
    };

    const onCodepushStatusChange = (status: CodePush.SyncStatus) => {
        switch (status) {
            case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
                sendEvent('CHECKING_FOR_UPDATE');
                break;
            case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
                sendEvent('DOWNLOADING_PACKAGE');
                break;
            case CodePush.SyncStatus.INSTALLING_UPDATE:
                sendEvent('INSTALLING_UPDATE');
                break;
            case CodePush.SyncStatus.UP_TO_DATE:
                sendEvent('UP_TO_DATE');
                break;
            case CodePush.SyncStatus.UPDATE_INSTALLED:
                sendEvent('UPDATE_INSTALLED');
                break;
            case CodePush.SyncStatus.UNKNOWN_ERROR:
                sendEvent('UNKNOWN_ERROR');
                break;
        }
    };

    const onBinaryMismatch = () => {
        sendEvent('BINARY_MISMATCH');
    };

    const codepushSync = () => {
        CodePush.sync(codepushConfig, onCodepushStatusChange, undefined, onBinaryMismatch);
    };

    useEffect(() => {
        fetchCodepushUpdate();
    }, []);

    const sendEvent = (action: string) => {
        if (!isDebug) {
            EventModule.trackEvent({
                eventId: 1397824909, // codepush_event
                action,
                sessionId: getSessionId(),
                newCodepushLabel: labelRef.current ? labelRef.current : `v${codepushLabel}`,
            });
        }
    };

    const Comp = CodePush(codepushConfig)(App);

    return (
        <Provider>
            <Comp data={data} tag={props.rootTag} />
        </Provider>
    );
};

export default CodepushWrappedAppComponent;

In Index.android.js we are registering this component

import { AppRegistry } from 'react-native';
import CodepushWrappedAppComponent from './src/CodepushWrapper';

AppRegistry.registerComponent('moj', () => CodepushWrappedAppComponent);

Environment

MikhailSuendukov commented 1 year ago

Hello @mohitarora777 and thanks for reaching out to us. Could you please clarify in what context to use the demo you provided? Because apparently it doesn't work out of the box. Also, could you please provide more application logs?

MikhailSuendukov commented 1 year ago

I'm closing this issue for now due to inactivity. But if you have any other questions, feel free to contact us.

alihamza1729 commented 1 year ago

I am facing same issue bundle downloaded but does not apply immediately. It says that changes will apply on next restart

react-native:"0.71.1" react-native-code-push:"8.1.0"

DmitriyKirakosyan commented 1 year ago

@alihamza1729 , could you share logs and/or a minimal demo app that we can use to replicate the issue?

alihamza1729 commented 1 year ago

@alihamza1729 , could you share logs and/or a minimal demo app that we can use to replicate the issue?

Upon reviewing my code, I discovered that I am using Higher Order Components (HOC) and the CodePush sync function in different files. While this setup has provided the desired functionality, a new issue has arisen where CodePush installs the new version, but it gets rolled back after a restart of the application.