Skip to content

[Android][0.22.2] Possible Unhandled Promise Rejection after reopening app from minimized/background state #6700

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

Closed
jorgemichael024 opened this issue Mar 29, 2016 · 26 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@jorgemichael024
Copy link

React Native Version: 0.22.2
Platform: Android
System: Ubuntu 15.04
Device: Samsung Note 3 (5.0)

Hi guys, after upgrading from 0.21 to 0.22.2, I'm experiencing the warning below every time I reopen my app from minimized/background state.

'Possible Unhandled Promise Rejection (id: 0): Tried to change the status bar while not attached to an Activity'

But when I remove the StatusBar component from my view, the warning goes away (obviously).

This is my snippet:

<View style={ {flex: 1, backgroundColor: 'white'} }>
<StatusBar
  backgroundColor={this.props.statusbarBGColor}
          barStyle={"light-content"}
         />
        {toolbar}
    <View style={[styles.container, this.props.overrideStyle]}>
        {this.props.children}
    </View>            
</View>
@satya164
Copy link
Contributor

Is there anything which re-renders the component in which you've the statusbar? e.g. - some event which updates state in parent component.

cc @janicduplessis

@janicduplessis
Copy link
Contributor

Do you use AppState and setState when the app state changes?

Also the warning should not happen in 0.23.0-rc1 as I've changed the implementation to be smarter and not update the status bar values if they didn't change.

@jorgemichael024
Copy link
Author

@satya164 , yes. The snippet is my BaseContainer which is used by Home screen that updates a lot. I'm also using AppState in my Home screen.

cc @janicduplessis

@cablegunmaster
Copy link

OS: Ubuntu 15.10
Emulator: Genymotions.
React: 0.14.8
React-native: 0.22.2

I have this issue with the emulator Geny motions. When I'm saving the file it will say "Hot loading..." and give me the same error below. I would like to give a log, but no idea where the log is saved from either genymotion or react-native.

Any specific code this happens? no, it happens with any code.

@arild-jacobsen
Copy link

I am having the same issue, but for me it happens only on device, not on emulator (I am using the new standard emulator from build tools 25.1.1 rather than GenyMotion emulator, so that may be related). Whenever I make a change in my editor and cause a Hot Reload on device (Samsung Galaxy S7, haven't tested on other devices yet), I get the Promise Rejection warning. Output from logcat is:

04-11 16:28:56.384  1175  1507 I ReactNativeJS: [React Transform HMR] Patching ReactTest
04-11 16:28:56.504  1175  1507 W ReactNativeJS: Possible Unhandled Promise Rejection (id: 7):
04-11 16:28:56.504  1175  1507 W ReactNativeJS: Network request failed
04-11 16:28:56.504  1175  1507 W ReactNativeJS: onload@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:14486:21
04-11 16:28:56.504  1175  1507 W ReactNativeJS: _sendLoad@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:14079:7
04-11 16:28:56.504  1175  1507 W ReactNativeJS: setReadyState@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:14069:15
04-11 16:28:56.504  1175  1507 W ReactNativeJS: _didCompleteResponse@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:13964:19
04-11 16:28:56.504  1175  1507 W ReactNativeJS: call@[native code]
04-11 16:28:56.504  1175  1507 W ReactNativeJS: http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:13902:110
04-11 16:28:56.504  1175  1507 W ReactNativeJS: emit@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:9481:28
04-11 16:28:56.504  1175  1507 W ReactNativeJS: __callFunction@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7817:28
04-11 16:28:56.504  1175  1507 W ReactNativeJS: http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7721:22
04-11 16:28:56.504  1175  1507 W ReactNativeJS: guard@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7675:3
04-11 16:28:56.504  1175  1507 W ReactNativeJS: callFunctionReturnFlushedQueue@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7720:6
04-11 16:28:56.504  1175  1507 W ReactNativeJS: callFunctionReturnFlushedQueue@[native code]
04-11 16:28:56.504  1175  1507 W ReactNativeJS: global code

@cpsubrian
Copy link

I saw this warning and in my case it was because I was calling StatusBar.setTranslucent(true) before my main App component was actually mounted. (not sure if relevant to OP's problem since I am using the static method rather than the component).

@nilptr
Copy link

nilptr commented Aug 20, 2016

I got the same warning occasional on startup. (react-native: 0.28.0, react: 15.0.0, Android):

08-19 14:40:09.528 20791-21076/com.bee W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 0):
                                                        Tried to change the status bar while not attached to an Activity
                                                        createErrorFromErrorData@http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4698:20
                                                        http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4649:35
                                                        __invokeCallback@http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4515:15
                                                        http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4401:24
                                                        guard@http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4343:3
                                                        invokeCallbackAndReturnFlushedQueue@http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4400:6
                                                        invokeCallbackAndReturnFlushedQueue@[native code]
                                                        global code

I found the rejection in the native implementation:

@ReactMethod
public void setHidden(final boolean hidden, final Promise res) {
  final Activity activity = getCurrentActivity();
  if (activity == null) {
    // res.reject("E_NO_ACTIVITY", "Tried to change the status bar while not attached to an Activity");
    res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
    return;
  }
  // ...
}

However, the rejection is not handled in the JavaScript implementation:

// react-native/Libraries/Components/StatusBar/StatusBar.js

const StatusBarManager = require('NativeModules').StatusBarManager;

setHidden(hidden: boolean, animation?: StatusBarAnimation) {
  animation = animation || 'none';
  StatusBar._defaultProps.hidden.value = hidden;
  if (Platform.OS === 'ios') {
    StatusBarManager.setHidden(hidden, animation);
  } else if (Platform.OS === 'android') {
    StatusBarManager.setHidden(hidden);
  }
},

Is there any way to pend the setXXX call till the value which getCurrentActivity returns is not null?

Sorry for my broken English.

@janicduplessis
Copy link
Contributor

I think this happens methods on statusbar before react-native is attached to an activity. The best way to avoid this is either to use the component or call methods in componentDidMount of your main component.

We should probably improve the error message to make this less confusing and maybe catch the promise to avoid the unhandled promise rejection.

@nilptr
Copy link

nilptr commented Aug 25, 2016

It seems that componentDidMount of the main component may happen before react-native is attached to an activity.

class RNTest extends Component {
  componentDidMount() {
    StatusBar.setHidden(true);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
      </View>
    );
  }
}

// ...

AppRegistry.registerComponent('RNTest', () => RNTest);

screenshot_2016-08-23-19-31-11_com rntest

@smallpath
Copy link

+1, v0.32

I get the same WARNING message on device when the app is starting and then make it background by press HOME key. After switch to the app, the StatusBar has no effect and I'm running to the same issue.

Why there should be a WARNING messege? If it can't be setHidden, so it is. I think taking away the reject message makes sense

@alzuma
Copy link

alzuma commented Sep 18, 2016

+1, v0.33 same problem as @smallpath

@alexHlebnikov
Copy link

+1 RN.0.34.0.RC.0

@nodegin
Copy link

nodegin commented Sep 24, 2016

+1RN.0.34.0

@Richard-Cao
Copy link

+1 RN 0.34.1

@antoinerousseau
Copy link
Contributor

hey guys, how did you work around this issue?

@janicduplessis
Copy link
Contributor

#10421 should fix this, the warning will be moved to a native log.

@bezenson
Copy link

Fresh 0.36 too. Is it possible that it is related to router-flux somehow? Or you don't use it?

@WatcherDing
Copy link

+1 RN 0.36.1

@marcshilling
Copy link

This also happens to me and when I reopen the app the status bar is permanently hidden :/

@mattisx
Copy link

mattisx commented Nov 13, 2016

Getting this with RN 0.37 (Android, Windows) on emulator (have not tried an actual device) when I return to the app from a background state, but only when I exit the app with the Android hardware back button.

All I'm doing is:

<StatusBar
    backgroundColor='#FF8B8B'
    barStyle='light-content'
/>

and:

componentDidMount() {
    AppState.addEventListener('change', this._handleAppState);
}

componentWillUnmount() {
    AppState.removeEventListener('change', this._handleAppState);
}

_handleAppState(appState) {
    console.log('Application state change: '+appState);
}

@277850318
Copy link

+1 RN 0.37

@cinder92
Copy link

+1 RN 0.38

@Rhysjc
Copy link

Rhysjc commented Dec 7, 2016

+1 RN 0.38

I don't get the orange error message, but my translucent status bar loses all of it's styling. I'm using the component rather than the API.

This issue only occurs sometimes, specifically when:

  • Bringing the app back from the background
  • Opening the app from a push notification

@iamcco
Copy link

iamcco commented Jan 13, 2017

same here

@erie-e9
Copy link

erie-e9 commented Feb 9, 2017

Can I connect a Node API with a Exponent's project on localhost and watch the result on my iPad? I'm trying but show me the error: "Possible Unhandled Promise Rejection (id:0) Network request failed"

@hramos
Copy link
Contributor

hramos commented Mar 10, 2017

This issue has been open for a year. My understanding is that the issue that was originally reported was addressed in 0.23. Afterwards, other similar but unrelated issues have been reported on this same thread by different people. I don't think we'll be able to troubleshoot every single issue individually in this thread.

I am going to go ahead and close this issue as resolved. If you believe this is done in error, please open a new issue and make sure to fill out the template when doing so. Thanks!

@hramos hramos closed this as completed Mar 10, 2017
@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests