Skip to content

Root component sometimes mounted twice on Android in development #19377

@brentvatne

Description

@brentvatne

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

  1. Clone https://github.com/brentvatne/android-double-mount-repro OR just add logs to componentDidMount and componentWillUnmount on the root component of a new react-native init app.
  2. Open the project on Android: react-native run-android
  3. Press the home button to go to the home screen, then tap on the app icon to open the app again
  4. Notice that in logs you will see the logs from componentDidMount
  5. Reload the app (r, r) and notice that you will see componentDidMount log twice, but componentWillUnmount 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPartnerPlatform: AndroidAndroid applications.StaleThere has been a lack of activity on this issue and it may be closed soon.p: ExpoPartner: Expo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions