-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Root component sometimes mounted twice on Android in development #19377
Comments
This comment has been minimized.
This comment has been minimized.
Uhm so it seems to be related to Android "interfering" with the React lifecycle or at least not properly unmounting when going in the background? 🤔 Could it be related to the version of Android the app is running on / being targetted against (ex. v23 VS v27)? Weirdly reminds me of this old issue react-navigation/react-navigation#2599 which was fixed by this react-navigation/react-navigation#3224 (just linking for reference) |
This comment has been minimized.
This comment has been minimized.
I couldn't get your cloned app to build using those instructions, but I've run into a similar error in the past. In your
to
|
I can reproduce this easily. Clicking the home button of the android phone, does not trigger "unmount", however subsequently clicking the app-icon from the home screen triggers my root component's "constructor" and "mount", leaving the old instance of these objects still running. Have tried @Meandmybadself 's suggestion which doesn't change this behavior. |
We get this constantly in our app. We're using react-native 0.57.4, react 16.6.0 and react-navigation 2.18.2 in production. We have |
Experiencing the exact same thing, ends up double instantiation of our router and horrible performance |
We have noticed that we especially get it when we open the app through a push notification grouped by the OS (Android >8) As in there are multiple push notifications and the OS automatically groups them by app. When we click these something weird happens with the instantiation. |
Not sure if it is relevant for this issue, but I hope it helps someone debug: When we removed our splash screen the issue disappeared! We had
and this caused the main activity to reinstantiate when the app came to foreground through OS grouped push notifications. We set up react-native-splash-screen instead and the problem went away |
Be sure to add |
It still happens even with |
still occurring even though I have all the changes mentioned by @Meandmybadself
|
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Android users reported an issue on react-navigation that is caused by a component being mounted twice where we only expect it to be mounted once (react-navigation/react-navigation#4196). I dug into the root (no pun intended) cause and found that the problem was caused by the app root component mounting twice.
Environment
Environment:
OS: macOS High Sierra 10.13.4
Node: 9.2.0
Yarn: 1.5.1
npm: 5.7.0
Watchman: 4.7.0
Xcode: Xcode 9.3 Build version 9E145
Android Studio: 3.0 AI-171.4408382
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4 => 0.55.4
Steps to Reproduce
componentDidMount
andcomponentWillUnmount
on the root component of a newreact-native init
app.react-native run-android
componentDidMount
componentDidMount
log twice, butcomponentWillUnmount
does not ever get logged.Expected Behavior
Root component should only ever be mounted once on app start
Actual Behavior
Root component is mounted twice on app start
The text was updated successfully, but these errors were encountered: