question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RNScreensNavigationController is pushing the same view controller instance more than once

See original GitHub issue

Description

We are seeing the following crash quite frequently on iOS since we started to use react-native-screens/createNativeStackNavigator. Any help would be much appreciated.

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 0

Application Specific Information:
<RNScreensNavigationController: 0x1038e6800> is pushing the same view controller instance (<RNSScreen: 0x12f123e20>) more than once which is not supported and is most likely an error in the application

Thread 0 Crashed:
0   CoreFoundation                  0x3259749d8         __exceptionPreprocess
1   libobjc.A.dylib                 0x34e15ab50         objc_exception_throw
2   UIKitCore                       0x3298bc6c0         -[UINavigationController pushViewController:transition:forceImmediate:]
3   UIKitCore                       0x32a4dbfb4         -[_UIAfterCACommitBlock run]
4   UIKitCore                       0x32a041a64         _runAfterCACommitDeferredBlocks
5   UIKitCore                       0x32a030f94         _cleanUpAfterCAFlushAndRunDeferredBlocks
6   UIKitCore                       0x32a062564         _afterCACommitHandler
7   CoreFoundation                  0x3258f3878         __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
8   CoreFoundation                  0x3258edf4c         __CFRunLoopDoObservers
9   CoreFoundation                  0x3258edbf0         CFRunLoopRunSpecific
10  GraphicsServices                0x3533f9594         GSEventRunModal
11  UIKitCore                       0x32a0323d4         -[UIApplication _run]
12  UIKitCore                       0x32a037954         UIApplicationMain
13  ########                        0x200d3d5d4         main (main.m:7)

Steps To Reproduce

We see this crash in our Sentry issues but don’t know how to reproduce it yet.

Package versions

  • React: 16.13.1
  • React Native: 0.63.3
  • React Native Screens: 2.16.1
  • React Navigation: 4.4.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
kacperkapusciakcommented, Feb 25, 2021

I’ve managed to reproduce this issue with the following code

import React, {useEffect} from 'react';
import {StyleSheet, Button, View, Text} from 'react-native';
import {enableScreens} from 'react-native-screens';
import {createNativeStackNavigator} from 'react-native-screens/native-stack';

enableScreens();

const MainScreen = ({navigation}) => {
  useEffect(() => {
    navigation.navigate('Modal')
  }, [])

  return (
    <View style={styles.screen}>
      <Text>Issue 791</Text>
    </View>
  )
}

const PushScreen = ({navigation}) => (
  <View style={styles.screen}>
    <Button onPress={() => navigation.push('Push')} title="Mash this button" />
  </View>
);

const Stack = createNativeStackNavigator();

const App = () => (
  <Stack.Navigator>
    <Stack.Screen
      name="Main"
      component={MainScreen}
    />
    <Stack.Screen
      name="Push"
      component={PushScreen}
    />
    <Stack.Screen
      name="Modal"
      component={PushScreen}
      options={{ stackPresentation: 'modal'}}
    />
  </Stack.Navigator>
);

const styles = StyleSheet.create({
  screen: {
    ...StyleSheet.absoluteFillObject,
    flex: 1,
    paddingTop: 200,
    alignItems: 'center',
  },
});

export default App;

This error occurs when you push a ‘normal’ screen under a modal. Inside modals only pushing modals is supported. Could you check if it’s the case within your app?

2reactions
birgernasscommented, Jan 27, 2021

I know my information is very limited at this point. Thanks for sharing your thoughts on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Pushing the same view controller instance more than once is ...
I believe when you do some actions really fast this can happens too. I build something in like this: if(![self.navigationController.
Read more >
Pushing the same view controller instance… - Apple Community
Pushing the same view controller instance more than once is not supported. i used the below line in three different methods. [viewController ......
Read more >
iOS : "Pushing the same view controller instance more than once is ...
iOS : "Pushing the same view controller instance more than once is not supported" exception [ Gift : Animated Se iOS : "Pushing...
Read more >
Pushing the same view controller instance more than once is ...
It means you are pushing the same viewcontroller object to stack again when it's already in there. [self.navigationController pushViewController: ...
Read more >
React Native with Existing Native App (iOS) — Part II - Medium
Create a global extension to get Top most ViewController ... One way would be to give first priority to react-nativation .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found