App component is re-rendered after navigating away and back again

This issue has been created since 2022-11-14.

Description

Summary

App is re-rendering after turning off screen or navigating to another app and back again. I reproduced this issue with the basic install of a fresh React Native app on IOS device. This issue was not present on v0.63.3.

Description

To me this is a bug causing the app to re-render after turning off the screen as shown in repo steps or if navigating away to home screen or another app and back again.

This causes the app component context to reset and I lose any values I might have in a user session via the useContext hook.

I confirmed that doing the above steps but with version 0.63.3 does not do this re-rendering. I was upgrading an app I had been working on and relied on the context for prop sharing in some long lived component sessions and this is causing me a lot of issues.

Version

0.70.5

Output of npx react-native info

System:
OS: macOS 12.6
CPU: (10) arm64 Apple M1 Pro
Memory: 86.05 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.3.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.11.0 - /opt/homebrew/bin/npm
Watchman: 2022.06.06.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
Android SDK:
API Levels: 30, 31, 32
Build Tools: 29.0.0, 29.0.1, 29.0.2, 29.0.3, 30.0.0, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0
System Images: android-31 | ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-31 | Google APIs Intel x86 Atom_64, android-31 | Google Play ARM 64 v8a, android-31 | Google Play Intel x86 Atom_64, android-32 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
Languages:
Java: 11.0.17 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Note: I'm having issues with my M1 mac and iOS simulator so I debug via my iPhone.

Steps to reproduce

Issue Repo Steps

  • npx react-native init AwesomeTSProject --template react-native-template-typescript
  • cd AwesomeTSProject/ios
  • pod install
  • Open App.tsx
  • Add log statement to app
const App = () => {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  console.error('App Loaded');
...
  • cd ..
  • npm start
  • Open ios folder in xcode
  • set signing certificates
  • debug to device / simulator
  • allow app to build and run on phone
  • observe debug error popup and close it
  • hit power button on phone / simulator
  • hit power button again to unlock phone and view app again
  • observe debug error popup

Works Correctly on v0.63.3

  • npx react-native init AwesomeProject --version 0.63.3
  • NOTE: due to my iphone version I needed to disable flipper and set the minimum ios version to 11 instead of 10 that is defaulted on this version.
  • cd AwesomeProject/ios
  • pod install
  • Open App.tsx
  • Add log statement to app
  • cd ..
  • npm start
  • Open ios folder in xcode
  • set signing certificates
  • debug to device / simulator
  • allow app to build and run on phone
  • observe debug error popup and close it
  • hit power button on phone / simulator
  • hit power button again to unlock phone and view app again
  • debug popup does not appear. App is not re-rendered

Snack, code example, screenshot, or link to a repository

const App = () => {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  console.error('App Loaded');
...
lucianobracco-geojam wrote this answer on 2022-11-20

Same here

lucianobracco-geojam wrote this answer on 2022-11-22

@kdowswell Hi there, I had the same issue with inside a Tab navigator and I fixed by supplying this detachInactiveScreens={false} (to the Tab.Navigator) for Android exclusively. If it is set to true or undefined, the issue persists. Hope this is helpful

More Details About Repo
Owner Name facebook
Repo Name react-native
Full Name facebook/react-native
Language JavaScript
Created Date 2015-01-09
Updated Date 2022-12-01
Star Count 106263
Watcher Count 3666
Fork Count 22655
Issue Count 2277

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
"Missing string id : " + string_id AssertionError: Missing string id : lightWidgetTitle 8 2022-06-15 2022-11-22
Add Isabel Costa as a codeowner 2 2021-05-15 2022-11-18
Update all references of systers used in the project to anitab.org 1 2021-05-11 2022-11-13
"Compose a message"-button does navigate correctly 0 2022-09-27 2022-10-31
How to fix "Элемент <value> может встречаться один раз в данном разделе." 2 2020-08-16 2022-11-13
Open Prompt for new scenes 0 2022-08-02 2022-11-20
Game stutters and becomes unplayable 7 2021-08-07 2022-10-13
Update firmware GPIO ports 1 2021-09-14 2022-11-14
Can't install this tool 2 2022-06-22 2022-11-21
Support for exposing `SendPort` like `StreamSink`? 3 2022-07-20 2022-09-04
这个 Swagger logo 可以替换吗?或者删除 5 2022-05-02 2022-11-18
BUG: ExternalSecret controller is force normalizing `refreshInterval` to `XmYs` 2 2022-06-30 2022-11-02
AttributeError: 'dict' object has no attribute '__NUMPY_SETUP__' 1 2022-07-07 2022-11-22
How difficult is to create an offline-first app? 14 2020-09-29 2022-11-10
MuseScore failed to build with "fatal error LNK1246: '/DYNAMICBASE:NO' not compatible with 'ARM64' target machine; link without '/DYNAMICBASE:NO'" with MSVC on Windows arm64ec 5 2022-09-21 2022-09-29
Comment/code inconsistency in utf8 decodeUtils 3 2021-12-15 2022-10-20
Touchpad Not working 2 2021-10-10 2022-11-22
SDL_Delay() requires a &mut TimerSubsystem? 5 2022-11-05 2022-12-01
Deployment documentation 2 2021-10-04 2022-11-22
Add lint for text overflow in say screen 2 2021-10-04 2022-11-19
The PCB does not fit 5 Pin Cherry MX switches 1 2022-04-08 2022-11-22
Setup a Service Principal : Unnecessary Powershell Parameter on instruction causes error 2 2022-04-23 2022-10-01
Remove event listener in onInvalidate 0 2022-08-24 2022-11-24
OpenTracing Shim: Proper handle tag/attribute ERROR 0 2022-11-02 2022-11-10
Release note for 1.19 2 2022-10-13 2022-11-06
s3 http-status 404 leads to imgproxy http-status 500 4 2022-03-15 2022-10-31
please rename the default branch of this repo from "master" to "main" 0 2021-09-24 2022-11-05
Cloning a team that was created using a template marks "Admin Center Template" as false and Team creation fails 1 2021-09-24 2022-11-21
Scene Tree and Node Editor Windows Not Updating Grouping Set Through Tool Script 3 2022-11-16 2022-11-11
After upgrading to 5.4.7 from 5.4.6, a blank page is rendered 2 2021-10-14 2022-11-27
exit code 1 even though all tests are passing 1 2021-11-19 2022-11-12
There should be an auxiliary switch option to control LED Brightness. 5 2022-01-21 2022-09-30
graphql id_salt causing 500 server errors 27 2022-08-02 2022-11-13
galaxy need an network devices name, if nodes' main network interfaces name are diff will not work 0 2022-04-26 2022-10-31
Append to manifest file when generating constraint databases 0 2022-11-28 2022-11-23
collision_detect is not valid in moveit when jog robot with teachpad tool 5 2022-11-15 2022-11-23
"ABORTED: Solution found but controller failed during execution" massage. 3 2022-11-10 2022-11-23
Give custom allowed start tolerance for each joints 1 2022-11-14 2022-11-23
bug about getCurrentPose in moveit::planning_interface::MoveGroupInterface 6 2022-11-01 2022-11-23
Can't put a div or other element in Checkbox label (labelElement) without it aligning poorly 6 2022-02-02 2022-10-23
Line continuation and split in Fortran 2 2021-08-20 2022-11-16
Update cats-effect to 3.2.3 1 2021-08-16 2022-11-15
ERROR: function "default" not defined 1 2022-07-01 2022-11-25
tarpc/tarpc/examples/compression.rs sends uncompressed messages 3 2021-08-12 2022-11-22
python调用mnn,多输入 3 2022-01-13 2022-01-15
onnx 模型一致性错误 0 2022-01-13 2022-01-15
format operator such as `+` or `-` into an identifier 1 2022-05-02 2022-11-22
Feature request: Allow conditional compilation of (at least) lexer mappings via #[cfg()] 0 2022-09-06 2022-11-12
IPC_NRF5340_NET_GPIO doesn't allow for more than a single pin value (?) 2 2021-06-23 2022-11-13
ExportPem_ExportEncryptedPkcs8PrivateKeyPem fails with 0 iteration count 1 2022-09-08 2022-10-17