facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.49k stars 24.26k forks source link

App sometimes reloads the js bundle when switching from background to foreground. #29931

Open morph3ux opened 4 years ago

morph3ux commented 4 years ago

Description

App sometimes reloads the js bundle when switching from background to foreground.

React Native version:

0.63

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

Create a new react-native application. Install react-navigation. Create a stack navigator. Open app, go trough several screens. Switch app to another one in the background. Open as many apps as you can so you have a lot of them in the memory. Switch back and the react-native app reloads the bundle.

Expected Results

I should be able to manually disable this reaload. Since I don't kill the app I should go back to where I was. This is very annoying when you try to fill a form and you go to another application to copy and come back to paste.

github-actions[bot] commented 4 years ago
:warning: Missing Environment Information
:information_source: Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.
github-actions[bot] commented 4 years ago
:warning: Using Old Version
:information_source: It looks like you are using an older version of React Native. Please upgrade to the latest version, and verify if the issue persists. If it does not, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the current release.
github-actions[bot] commented 4 years ago
:warning: Missing Reproducible Example
:information_source: It looks like your issue is missing a reproducible example. Please provide a Snack or a repository that demonstrates the issue you are reporting in a minimal, complete, and reproducible manner.
nguyentuanit97 commented 3 years ago

Same issues with android

morph3ux commented 3 years ago

Meanwhile we've upgraded the app to use react-native 0.63 but the same issue was happening. After some research it turns out it was the react-navigation package to blame so after switching the entire application to use wix/react-native-navigation (took some time) everything now runs as it's supposed to run (also much much faster) - so thanks wix for the great work!

nguyentuanit97 commented 3 years ago

My app doesn't use react-navigation and also reloaded the app when switching from active to foreground.

morph3ux commented 3 years ago

My guess is that at some point the thread becomes too big to store the state in memory while switching the apps and this triggers a reload - it would be nice to see an option to disable this behaviour. It is really annoying when you have a half filled form for instance and you want to copy something from another app :) So yeah - maybe it is something that has to do with react-native itself

zombie6888 commented 3 years ago

Same issue, even with empty app, i see android splash screen while restarting, so i think it's not related to react navigation. You can easily reproduce this issue if select "1 process at most" option in developer options -> background process limit

alexhtcg commented 3 years ago

@morph3ux Any luck? I'm not using react-navigation and also reloaded the app when switching from active to foreground and background updating redux state frequently(timer).

joaosouz4dev commented 3 years ago

Same here

alexhtcg commented 3 years ago

change following files node_modules/react-native/React/Modules/RCTTiming.m


 - (void)markStartOfBackgroundTaskIfNeeded{
//  if (_backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
//    __weak typeof(self) weakSelf = self;
//    // Marks the beginning of a new long-running background task. We can run the timer in the background.
//    _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"rct.timing.gb.task" expirationHandler:^{
//      typeof(self) strongSelf = weakSelf;
//      if (!strongSelf) {
//        return;
//      }
//      // Mark the end of background task
//      [strongSelf markEndOfBackgroundTaskIfNeeded];
//    }];
//  }
 }
joaosouz4dev commented 3 years ago

@alexhtcg Which version of RN are u using?

alexhtcg commented 3 years ago

@alexhtcg Which version of RN are u using?

react-native 0.61.3

joaosouz4dev commented 3 years ago

@alexhtcg mine is 0.64.0 and I think that's why I haven't found your solution. 😕

alexhtcg commented 3 years ago

@alexhtcg mine is 0.64.0 and I think that's why I haven't found your solution. 😕

search xcode project [[UIApplication sharedApplication] beginBackgroundTaskWithName if any library are not using properly

for example react-native-background-timer this is not handle. should be invalid when app background more than 30 sec. but actual issue it not like this

jamesdunay commented 3 years ago

Seeing this problem as well. We're using react-navigation, but I feel like it would be more widely discussed if it was a problem on that specific package. Has anyone seen this issue brought up elsewhere?

morph3ux commented 3 years ago

@alexhtcg

@morph3ux Any luck? I'm not using react-navigation and also reloaded the app when switching from active to foreground and background updating redux state frequently(timer).

It's been 7 months since we've replaced react-navigation with wix/react-native-navigation and the issue is completely gone. Now, I can't tell if react-navigation is the problem or react-native itself in combination with react-native, but tbh since we didn't experience the issue after the switch, we've moved on and stopped investigating this.

srinu6 commented 3 years ago

I am having this issue when I enable Face ID in the app settings, the app is being reloaded. How can I disable the app from reloading?

aliraza-noon commented 1 year ago

It is very interesting we are using wix/react-native-navigation but still see this issue, I believe navigation is not the root cause of this, seems to be something else

github-actions[bot] commented 1 year ago

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.

aliraza-noon commented 1 year ago

not stale

sujaynaik commented 11 months ago

Even I'm facing the same issue.

If the user navigates to another app to copy some text (in order to fill up the form in my app). As soon as the user opens the app from background the existing screen is no longer shown, instead the home screen (landing screen) shows up.

| V "react": "16.13.1", "react-native": "0.63.4", "react-navigation": "4.4.0", "react-native-router-flux": "4.2.0",

CarlaSalHua commented 11 months ago

Im having the same issue in react native 0.64.2, with no solutions, so i don't know how to deal with this.

MalikMati98 commented 8 months ago

Im having the same issue in "react": "18.2.0", "react-native": "0.72.3". anyone find solution?

Nantris commented 8 months ago

I'm pretty sure this is an OS RAM limitation.

ElRaymond0 commented 6 months ago

We've noticed this issue also, it always happens without fail when we click to update notifications -> goes into the background -> disable notifications -> re-renders the app. It doesn't when you enable though which seems odd.

React: v18.2 React-native: v0.73.3

Lakston commented 3 months ago

Same here, the bundle reloads when going to settings and back, this is problematic because I cant debug the way we handle the permission changes

React: v18.2 React-native: v0.73.8

LucasLfs2004 commented 2 months ago

I have the same problem with the app, I still don't know what to do to solve it, it always restarts the app when I go to the ios home or change apps, nothing I've tried so far has worked.

I'm using react-native 0.69.12 and react-native-router-flux 4.3.1

Nantris commented 2 months ago

Reiterating that this is likely an OS RAM limitation... If someone can provide evidence otherwise, that would be beneficial. After upgrading to a device with more RAM and switching Firebase to React-Native-Firebase we no longer face this issue at all.

I'm not sure that React Native can work around this. Maybe some sort of rehydration of the entire app state is possible, but that seems a lot to ask.

Bauss9 commented 1 day ago

Any fixes guys would be appreciated at all, I am facing this issue and I have no idea what to do I am lost

LucasLfs2004 commented 1 day ago

Any fixes guys would be appreciated at all, I am facing this issue and I have no idea what to do I am lost

After a few more problems than this, I was forced to update the RN version to a more recent one. After updating react-native and the routing system to react-navigation, along with other libraries that were updated, this problem stopped happening. But I'm not sure if it was just updating the libraries that solved my problem.