expo / ex-navigation

Route-centric navigation for React Native
997 stars 201 forks source link

setState Warning with 3.0 and RN 0.44 #477

Open idibidiart opened 7 years ago

idibidiart commented 7 years ago

If I use navigator.immediatelyResetStack I get a warning that setState must be called only on mounted or mounting component. If I use navigator.push I do not get the warning. I have no setState calls in my test code.

Let me know if you want me to publish a reproduction of it on Expo.

rumax commented 7 years ago

The bug is in ExNavigationComponents.js. componentWillUnmount should trigger _unsubcribeFromStore and it does, but in redux/lib/createStore.js :

function dispatch(action) {
....
var listeners = currentListeners = nextListeners;
for (var i = 0; i < listeners.length; i++) {
      listeners[i]();
    }

listeners has old value of listeners (dispatch happens after immediatelyResetStack and before unsubscribe). The quick fix can be to

  componentWillUnmount() {
      this._unsubcribeFromStore && this._unsubcribeFromStore();
      this._handleStateUpdate = () => {};
    }

in ExNavigationComponents.js


Related bug #468