avishayil / react-native-restart

React Native Package With One Purpose: To Restart Your React Native Project
MIT License
926 stars 145 forks source link

App crash when RN.restart() use on IOS #239

Open Sekiro-kost opened 1 year ago

Sekiro-kost commented 1 year ago

Hello

I'v a crash issue with IOS build (with metro and release build), when I use RN.restart()

Here is my thread about my issue

https://github.com/facebook/react-native/issues/36776

Thank you very much

Orange9000 commented 1 year ago

Are you using react-native-reanimated in your project?

Sekiro-kost commented 1 year ago

Are you using react-native-reanimated in your project?

Yes. And I have the same issue both v3 version or below

Orange9000 commented 1 year ago

Are you using react-native-reanimated in your project?

Yes. And I have the same issue both v3 version or below

Same here. I traced my crashes to reanimated. If you're using v3, could you try adding a delay before restart like this?

setTimeout(() => RNRestart.Restart(), 1000)

This seems to have helped in my case, although I'm still investigating.

Sekiro-kost commented 1 year ago

I have already.

setTimeout(()=>{
      RNRestart.restart();
    },300)

I will try with 1000 like you.

By the way, Restart is deprecated; restart must be use.

Sekiro-kost commented 1 year ago

I just tried, still the same problem.

Devojha408 commented 1 year ago

I'm currently using React Native version 0.68 and the react-native-restart library version 0.0.24. I've tried adding a delay to my code, but I'm still experiencing crashes with the iOS build of my app. @Sekiro-kost you still experiencing the issue.

MohsinaliEMed commented 1 year ago

the same problem

Sekiro-kost commented 1 year ago

Always the same for me. Any idea @avishayil ?

rocket13011 commented 1 year ago

Same problem

ShepSims commented 1 year ago

Same problem, adding a timeout does not help

ArturKalach commented 1 year ago

It seems that this problem related to runOnJS function from react-native-reanimated.

Like an example, when you use reanimated with gesture-hangler, using runOnJS can lead to crash.

If you use something like that:

    const tapGesture = Gesture.Tap().onStart(() => {
      runOnJS(onPress)()
    })

You can avoid issue with

    const tapGesture = Gesture.Tap()
      .runOnJS(true)
      .onStart(() => {
        onPress()
      })

But when we talk about worklets it gets difficult, I haven't find any solution yet.

Lidobix commented 1 year ago

Hello, on my side I solved the problem by enabling hermes in podfile + pod install. Tested on device & simulator.

Simoon-F commented 1 year ago

same。

ludwig-pro commented 1 year ago

I have exactly the same problem. at first i suspected reanimated, but after patching it, i still get the bug.

Only in "release", according to sentry tracking, it's a RAM problem:

WatchdogTermination: The OS watchdog terminated your app, possibly because it overused RAM.

I try to replace react-native-restart by code-push and I have the same issue, also reported by other here

reanimated patch for react-native-reanimated 3.1.0 =>

diff --git a/node_modules/react-native-reanimated/ios/LayoutReanimation/REAAnimationsManager.m b/node_modules/react-native-reanimated/ios/LayoutReanimation/REAAnimationsManager.m
index 365ae4f..6290823 100644
--- a/node_modules/react-native-reanimated/ios/LayoutReanimation/REAAnimationsManager.m
+++ b/node_modules/react-native-reanimated/ios/LayoutReanimation/REAAnimationsManager.m
@@ -396,7 +396,7 @@ BOOL REANodeFind(id<RCTComponent> view, int (^block)(id<RCTComponent>))
     return NO;
   }

-  BOOL hasExitAnimation = _hasAnimationForTag(view.reactTag, EXITING) || [_exitingViews objectForKey:view.reactTag];
+  BOOL hasExitAnimation = [self hasAnimationForTag:view.reactTag type:EXITING] || [_exitingViews objectForKey:view.reactTag];
   BOOL hasAnimatedChildren = NO;
   shouldRemoveSubviewsWithoutAnimations = shouldRemoveSubviewsWithoutAnimations && !hasExitAnimation;
   NSMutableArray *toBeRemoved = [[NSMutableArray alloc] init];
@@ -521,7 +521,7 @@ BOOL REANodeFind(id<RCTComponent> view, int (^block)(id<RCTComponent>))
 {
   LayoutAnimationType type = before == nil ? ENTERING : LAYOUT;
   NSNumber *viewTag = view.reactTag;
-  if (_hasAnimationForTag(viewTag, type)) {
+  if ([self hasAnimationForTag:viewTag type:type]) {
     REASnapshot *after = [[REASnapshot alloc] init:view];
     if (before == nil) {
       [self onViewCreate:view after:after];
@@ -533,7 +533,7 @@ BOOL REANodeFind(id<RCTComponent> view, int (^block)(id<RCTComponent>))
     [self setNewProps:before.values forView:view];
   }

-  if (_hasAnimationForTag(viewTag, SHARED_ELEMENT_TRANSITION)) {
+  if ([self hasAnimationForTag:viewTag type:SHARED_ELEMENT_TRANSITION]) {
     if (type == ENTERING) {
       [_sharedTransitionManager notifyAboutNewView:view];
     } else {
diff --git a/node_modules/react-native-reanimated/src/reanimated2/mappers.ts b/node_modules/react-native-reanimated/src/reanimated2/mappers.ts
index 4e66106..bc8712f 100644
--- a/node_modules/react-native-reanimated/src/reanimated2/mappers.ts
+++ b/node_modules/react-native-reanimated/src/reanimated2/mappers.ts
@@ -80,8 +80,11 @@ export function createMapperRegistry() {
   }

   function mapperRun() {
-    processingMappers = true;
     runRequested = false;
+    if (processingMappers) {
+      return;
+    }
+    processingMappers = true;
     if (mappers.size !== sortedMappers.length) {
       updateMappersOrder();
     }
ludwig-pro commented 1 year ago

BTW I use Xcode_14.3.1.app to build the app

jpangan commented 1 year ago

This happens to me in Android. my setup is RN version 0.68.5, installed "react-native-restart": "0.0.24". I followed what's stated in the README.md but still getting the issue on Android.

serhiiharbo commented 1 year ago

The same. Any solution so far?

bviebahn commented 11 months ago

In my case I'm doing the restart when selecting a value from a dropdown which also results in this crash. I just removed the reanimated animation from the dropdown which seems to fix it.

ghost commented 11 months ago

Getting a similar issue with the following: "react-native-code-push": "^8.0.0", "react-native": "0.71.13", "react-native-reanimated": "3.5.4",

From Xcode logs: 2023-10-17 12:04:34.002039-0700 app[5567:35772] [native] Invalidating <RCTCxxBridge: 0x7fb2a5a08dc0> (parent: <RCTBridge: 0x6000028acbd0>, executor: (null)) Assertion failed: (objectCounter_ == 0 && "JSCRuntime destroyed with a dangling API object"), function ~JSCRuntime, file JSCRuntime.cpp, line 412.

NguyenHoangMinhkkkk commented 10 months ago

i just facing the issue for now, any update ?

VadymBezsmertnyi commented 9 months ago

My app crashes on iOS 17 when using RNRestart.restart() or RNRestart.Restart(). When will the bug be fixed?

vasylnahuliak commented 7 months ago

This issue is caused by react-native-reanimated with disabled Hermes

https://github.com/software-mansion/react-native-reanimated/issues/1424

ThadeusRonnThomas commented 7 months ago

I Commented out the following assertions for the time being. from react jsc

//#ifndef NDEBUG // assert( // objectCounter == 0 && "JSCRuntime destroyed with a dangling API object"); // assert( // stringCounter == 0 && "JSCRuntime destroyed with a dangling API string"); //#endif

NguyenHoangMinhkkkk commented 7 months ago

I Commented out the following assertions for the time being. from react jsc

//#ifndef NDEBUG // assert( // objectCounter == 0 && "JSCRuntime destroyed with a dangling API object"); // assert( // stringCounter == 0 && "JSCRuntime destroyed with a dangling API string"); //#endif

hello, is this a workaround ?

ThadeusRonnThomas commented 7 months ago

You can use it as a temporary workaround. This just disables the check for objectCounter and stringCounter. This is not a fix for the issue.

malikzype commented 7 months ago

+1

Pankajjajra commented 6 months ago

Same problem !! anyone get any solution ?

malikzype commented 6 months ago

@ThadeusRonnThomas Tried commenting the same but didnt work for me. Can you help us with a temporary workaround?

GwiYeong commented 2 months ago

Same problem!! is there any workaround??

Kozlove3 commented 1 month ago

+1

Sekiro-kost commented 1 month ago

I solve the problem with :

"react-native-restart": "0.0.27" , "react-native-reanimated": "3.5.2", on my package.json

import RNRestart from 'react-native-restart';

RNRestart.restart();

Ahsanabid27 commented 3 weeks ago

Hey I'm using "react-native-restart" but getting an error on the ios release build App got stuck on the change language screen sometimes it's working smoothly sometimes it's stuck i've try to debug this run on the debuging mode it gives an error when i close the metro on Ios Error: "Timed out waiting for modules to be invalidated" (in debug mode working fine)