react-native-restart icon indicating copy to clipboard operation
react-native-restart copied to clipboard

App randomly crashes in production

Open Wetsie opened this issue 3 years ago • 13 comments

It almost everytime crashes without any logs, but once I've managed to catch them:

E ReactNativeJS: TypeError: undefined is not a function, js engine: hermes
I ReactNativeJS: Unable to symbolicate stack trace: Bundle was not loaded from Metro.
E ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
E ReactNativeJS: This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
I ReactNativeJS: Unable to symbolicate stack trace: Bundle was not loaded from Metro.
E ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
E ReactNativeJS: This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
I ReactNativeJS: Unable to symbolicate stack trace: Bundle was not loaded from Metro.

It looks like the problem appeared after updating react native to version 0.64.0. Does this lib support new version or hermes engine?

Wetsie avatar Mar 25 '21 16:03 Wetsie

I'm not familiar with this issue, it happens only on production bundles?

avishayil avatar Apr 04 '21 08:04 avishayil

Hi everyone, I faced the same problem on both debug and release dist. I was calling RNRestart.Restart() at the top of RootNavigationStack function. I put the function call in my SplashScreen function (render when using classes) and it's working.

hichemBAALI avatar Apr 30 '21 13:04 hichemBAALI

As a workaround for this issue, I suggest adding the following code to the main activity class (the one that extends ReactFragmentActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
}

I have been using this in a production app for more than a year now. reference -> https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067

vikasverma92 avatar May 08 '21 15:05 vikasverma92

I'm checking compatibility issues with hermes

avishayil avatar May 10 '21 09:05 avishayil

Any news on this? Crashes on production build with React Native 0.63 / Android / Hermes.

saskaak avatar Jun 21 '21 14:06 saskaak

@saskaak does it still crash on production build? I'm considering using this library but these crashes make me nervous.

eddievlagea avatar Jul 28 '21 09:07 eddievlagea

@saskaak does it still crash on production build? I'm considering using this library but these crashes make me nervous.

For us, yes. Works just fine on iOS.

saskaak avatar Jul 28 '21 10:07 saskaak

I don't know if the issue is the same but I had crashes everytime on Android (mostly because of react-navigate-geture-handler).

A fix is instead of restarting as soon as the user press a button, just add some logic to unmount all your components.

RootNavigation.tsx:

const RootNavigation = () => {
	const { shouldRestart } = useShouldRestart()

    if (shouldRestart) {
        return <Restart />
    }
    
    // return your navigators
}

Restart.tsx:

import { useMount } from 'ahooks'
import { View } from 'react-native'

const Restart = () => {
    useMount(() => {
        // restartApp()
    })

    return <View />
}

export default Restart

useShouldRestart.ts:

import { atom, useRecoilState } from 'recoil'

export const shouldRestartAtom = atom({
    key: 'shouldRestart',
    default: false
})

const useShouldRestart = () => {
    const [shouldRestart, setShouldRestart] = useRecoilState(shouldRestartAtom)

    return { shouldRestart, setShouldRestart }
}

export default useShouldRestart

With this, you can simply set shouldRestart to true and the app should cleanly close itself. I still have SoftExceptionss popping on logcat but the app doesn't crash anymore.

francois-pasquier avatar Jan 11 '22 11:01 francois-pasquier

I solved the issue by https://github.com/avishayil/react-native-restart/issues/162#issuecomment-1038724027

saad-saadi avatar Feb 14 '22 07:02 saad-saadi

I solved the issue by #162 (comment)

Facing same issue in production build... I tried above solution but it's not working perfectly(shared video)

https://user-images.githubusercontent.com/75003713/160824634-26970880-f480-4319-b0d2-516b1fdacf47.mp4

  • app freezes for little-bit time & throw error,
  • there is not others things in my function

code:

    const setLanguage = async (code: string) => {
        if (code === 'ar') {
            await i18next.changeLanguage(code).then(() => {
                I18nManager.forceRTL(true);
                setTimeout(() => { RNRestart.Restart(); }, 150);
                setShowSelectionPopup(false);
            });
        } else {
            await i18next.changeLanguage(code).then(() => {
                I18nManager.forceRTL(false);
                setTimeout(() => { RNRestart.Restart(); }, 150);
                setShowSelectionPopup(false);
            });
        }
        console.log("code:", code);
    };

@avishayil

PrinceUBS avatar Mar 30 '22 11:03 PrinceUBS

I solved the issue by #162 (comment)

Facing same issue in production build... I tried above solution but it's not working perfectly(shared video)

RN-Restart-rec.mp4

  • app freezes for little-bit time & throw error,
  • there is not others things in my function

code:

    const setLanguage = async (code: string) => {
        if (code === 'ar') {
            await i18next.changeLanguage(code).then(() => {
                I18nManager.forceRTL(true);
                setTimeout(() => { RNRestart.Restart(); }, 150);
                setShowSelectionPopup(false);
            });
        } else {
            await i18next.changeLanguage(code).then(() => {
                I18nManager.forceRTL(false);
                setTimeout(() => { RNRestart.Restart(); }, 150);
                setShowSelectionPopup(false);
            });
        }
        console.log("code:", code);
    };

@avishayil

Where you able to fix this issue?

thanveershah avatar May 10 '22 03:05 thanveershah

Where you able to fix this issue?

Yep! by changing the Build configuration...

Open xCode > Product > Scheme > Edit Scheme... > Run(select from left panel) > Build configuration(info tab) = Release (this xCode 12.4 attached SS) image_2022_05_10T04_31_42_681Z

PrinceUBS avatar May 10 '22 04:05 PrinceUBS

I've made a PR for it #211, I've used ProcessPhoenix framework instead of the react-native-code-push code style

HammzaHM avatar Jun 13 '22 08:06 HammzaHM

Merged #211

avishayil avatar Jan 30 '23 08:01 avishayil