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

App crash when RN.restart() use on IOS

Open Sekiro-kost opened this issue 2 years ago • 36 comments

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

Sekiro-kost avatar Apr 04 '23 12:04 Sekiro-kost

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

Orange9000 avatar Apr 18 '23 06:04 Orange9000

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

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

Sekiro-kost avatar Apr 18 '23 06:04 Sekiro-kost

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.

Orange9000 avatar Apr 18 '23 07:04 Orange9000

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 avatar Apr 18 '23 07:04 Sekiro-kost

I just tried, still the same problem.

Sekiro-kost avatar Apr 18 '23 07:04 Sekiro-kost

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.

Devojha408 avatar May 07 '23 13:05 Devojha408

the same problem

MohsinaliEMed avatar May 23 '23 13:05 MohsinaliEMed

Always the same for me. Any idea @avishayil ?

Sekiro-kost avatar May 23 '23 13:05 Sekiro-kost

Same problem

rocket13011 avatar May 30 '23 13:05 rocket13011

Same problem, adding a timeout does not help

ShepSims avatar Jun 05 '23 15:06 ShepSims

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.

ArturKalach avatar Jun 06 '23 09:06 ArturKalach

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

Lidobix avatar Jun 06 '23 14:06 Lidobix

same。

Simoon-F avatar Jul 03 '23 01:07 Simoon-F

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 avatar Aug 09 '23 06:08 ludwig-pro

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

ludwig-pro avatar Aug 09 '23 12:08 ludwig-pro

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.

jpangan avatar Sep 06 '23 13:09 jpangan

The same. Any solution so far?

serhiiharbo avatar Sep 07 '23 08:09 serhiiharbo

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.

bviebahn avatar Oct 16 '23 08:10 bviebahn

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.

ghost avatar Oct 17 '23 19:10 ghost

i just facing the issue for now, any update ?

NguyenHoangMinhkkkk avatar Oct 30 '23 12:10 NguyenHoangMinhkkkk

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

VadymBezsmertnyi avatar Dec 11 '23 05:12 VadymBezsmertnyi

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

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

vasylnahuliak avatar Jan 25 '24 07:01 vasylnahuliak

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

ThadeusRonnThomas avatar Jan 31 '24 12:01 ThadeusRonnThomas

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 ?

NguyenHoangMinhkkkk avatar Feb 01 '24 07:02 NguyenHoangMinhkkkk

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.

ThadeusRonnThomas avatar Feb 01 '24 08:02 ThadeusRonnThomas

+1

malikzype avatar Feb 15 '24 12:02 malikzype

Same problem !! anyone get any solution ?

Pankajjajra avatar Feb 19 '24 09:02 Pankajjajra

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

malikzype avatar Feb 19 '24 10:02 malikzype

Same problem!! is there any workaround??

GwiYeong avatar Jun 30 '24 06:06 GwiYeong

+1

Kozlove3 avatar Jul 31 '24 14:07 Kozlove3