Skip to content
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

ReactInstanceManager.recreateReactContextInBackground does not remove the stale root view group #41677

Closed
wschurman opened this issue Nov 28, 2023 · 1 comment
Labels
Needs: Triage 🔍 Type: Upgrade Issue Issues reported from upgrade issue form

Comments

@wschurman
Copy link
Contributor

wschurman commented Nov 28, 2023

New Version

0.73.0-rc.5

Old Version

0.72.5

Build Target(s)

Android in Release Build Variant

Output of react-native info

System:
  OS: macOS 14.1.1
  CPU: (12) arm64 Apple M2 Max
  Memory: 783.33 MB / 64.00 GB
  Shell:
    version: 3.2.57
    path: /bin/bash
Binaries:
  Node:
    version: 18.18.2
    path: /var/folders/6k/nxc22y0n12580hckvvt5dry80000gn/T/yarn--1701206323469-0.5141404886845193/node
  Yarn:
    version: 1.22.19
    path: /var/folders/6k/nxc22y0n12580hckvvt5dry80000gn/T/yarn--1701206323469-0.5141404886845193/yarn
  npm:
    version: 9.8.1
    path: ~/.volta/tools/image/node/18.18.2/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.14.3
    path: /opt/homebrew/lib/ruby/gems/2.7.0/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK:
    API Levels:
      - "26"
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 26.0.3
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-26 | Google APIs Intel x86 Atom_64
      - android-28 | Google Play Intel x86 Atom
      - android-30 | Google APIs Intel x86 Atom
      - android-30 | Google Play Intel x86 Atom
      - android-33 | Google Play ARM 64 v8a
    Android NDK: 21.4.7075529
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /opt/homebrew/opt/openjdk@17/bin/javac
  Ruby:
    version: 2.7.8
    path: /opt/homebrew/opt/ruby@2.7/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.0-rc.5
    wanted: 0.73.0-rc.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Issue and Reproduction Steps

Issue: calling recreateReactContextInBackground on the ReactInstanceManager instance no longer removes the old root view.

Suspected blame rev: #37004

Previously, tearDownReactContext would call clearReactRoot, but now it calls detachRootViewFromInstance.
In detachRootViewFromInstance, only the view ID is reset:
https://github.com/javache/react-native/blob/a63613ca7bffd54211985224a61300d5de0f5640/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java#L1295
as opposed to clearReactRoot which also removes the views from the root view group: https://github.com/javache/react-native/blob/a63613ca7bffd54211985224a61300d5de0f5640/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java#L847

This occurs in both fabric and non-fabric.

Repro: https://github.com/wschurman/rn-reload-repro

The repro repo does the following:

  1. Create app with a custom native module that calls recreateReactContextInBackground.
  2. To see it more clearly, it adds some code to the app that displays the timestamp on mount (so it can be seen that the old view isn't removed when the timestamp doesn't change):
const [startTime, setStartTime] = React.useState<number | null>(null);
React.useEffect(() => {
  setStartTime(Date.now());
}, []);
...
<Text>{startTime}<Text>
@wschurman wschurman added Needs: Triage 🔍 Type: Upgrade Issue Issues reported from upgrade issue form labels Nov 28, 2023
@github-actions github-actions bot added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Nov 28, 2023
@github-actions github-actions bot removed the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Nov 29, 2023
@lunaleaps
Copy link
Contributor

lunaleaps commented Nov 29, 2023

Should this have been closed? I'll re-open until someone corrects. Oh sorry I'm confused, this was fixed with #41678. Closing

@lunaleaps lunaleaps reopened this Nov 29, 2023
douglowder pushed a commit to react-native-tvos/react-native-tvos that referenced this issue Nov 30, 2023
Summary:
This is my proposed solution to facebook/react-native#41677.

Fixes facebook/react-native#41677.

## Changelog:

[ANDROID] [FIXED] - Fix android root view group removal during instance re-creation

Pull Request resolved: facebook/react-native#41678

Test Plan:
Both with fabric enabled and disabled (new architecture):

1. Clone repro repo: https://github.com/wschurman/rn-reload-repro
2. Build and run on android (I use android studio)
3. Click reload button, see timestamp doesn't change (indicating that the view is not removed)
4. Apply this PR as a patch.
5. Re-build and run.
6. Click reload button, see view is correctly disposed of and the new view is set.

Reviewed By: cortinico

Differential Revision: D51658524

Pulled By: javache

fbshipit-source-id: d9a026cde677ad1ec113230bc31bd9297bca8bfc
huntie pushed a commit that referenced this issue Dec 1, 2023
Summary:
This is my proposed solution to #41677.

Fixes #41677.

## Changelog:

[ANDROID] [FIXED] - Fix android root view group removal during instance re-creation

Pull Request resolved: #41678

Test Plan:
Both with fabric enabled and disabled (new architecture):

1. Clone repro repo: https://github.com/wschurman/rn-reload-repro
2. Build and run on android (I use android studio)
3. Click reload button, see timestamp doesn't change (indicating that the view is not removed)
4. Apply this PR as a patch.
5. Re-build and run.
6. Click reload button, see view is correctly disposed of and the new view is set.

Reviewed By: cortinico

Differential Revision: D51658524

Pulled By: javache

fbshipit-source-id: d9a026cde677ad1ec113230bc31bd9297bca8bfc
Othinn pushed a commit to Othinn/react-native that referenced this issue Jan 9, 2024
…book#41678)

Summary:
This is my proposed solution to facebook#41677.

Fixes facebook#41677.

## Changelog:

[ANDROID] [FIXED] - Fix android root view group removal during instance re-creation

Pull Request resolved: facebook#41678

Test Plan:
Both with fabric enabled and disabled (new architecture):

1. Clone repro repo: https://github.com/wschurman/rn-reload-repro
2. Build and run on android (I use android studio)
3. Click reload button, see timestamp doesn't change (indicating that the view is not removed)
4. Apply this PR as a patch.
5. Re-build and run.
6. Click reload button, see view is correctly disposed of and the new view is set.

Reviewed By: cortinico

Differential Revision: D51658524

Pulled By: javache

fbshipit-source-id: d9a026cde677ad1ec113230bc31bd9297bca8bfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Type: Upgrade Issue Issues reported from upgrade issue form
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants