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

navigationState duplicate key when restarting the app after an error #52

Closed
fabriziomoscon opened this issue Jun 10, 2016 · 4 comments
Closed

Comments

@fabriziomoscon
Copy link
Contributor

fabriziomoscon commented Jun 10, 2016

@jevakallio
I reproduced the scene stack error I mentioned to you at the meetup. This happens when I open the app after another error occurred. So I guess leaving some dirty state in the application.
Contacts is the name of the route. To clear this error I have to clean manually the data cache for the app.

Possible Unhandled Promise Rejection (id: 0):
navigationState.children[2].key "scene_Contacts" conflicts withanother child!
Invariant Violation: navigationState.children[2].key "scene_Contacts" conflicts withanother child!
    at invariant (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:2433:7)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:71833:1
    at Array.forEach (native)
    at NavigationScenesReducer (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:71825:20)
    at new NavigationAnimatedView (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:71457:8)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28503:19)
    at ReactCompositeComponentWrapper._constructComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28485:13)
    at ReactCompositeComponentWrapper.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28404:15)
    at Object.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:26913:29)
    at ReactCompositeComponentWrapper.performInitialMount (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28580:28)

UPDATE:

This happens when inside the NavigationState another children with the same key gets pushed

using the chrome debug console:

// prev state state
Object NavigationState = {
   MainNavigation: {
      routes: [
         {key: 'pageA'},
         {key: 'pageB'},
      ]
  }
}

// next state
Object NavigationState = {
   MainNavigation: {
      routes: [
         {key: 'pageA'},
         {key: 'pageB'},
         {key: 'pageB'},
      ]
  }
}

// NOTE: the key `routes` is called `children` with react-native < 0.28

navigationstate

@fabriziomoscon
Copy link
Contributor Author

fabriziomoscon commented Jun 28, 2016

I have narrowed down this issue to this line:
https://github.com/futurice/pepperoni-app-kit/blob/master/src/modules/navigation/NavigationState.js#L48

in react-native:
https://github.com/facebook/react-native/blob/master/Libraries/NavigationExperimental/Reducer/NavigationScenesReducer.js#L125

also found this related issues with a good description: jlyman/RN-NavigationExperimental-Redux-Example#10

proposed fix:

const getNewChildrenList = (children) => {
    const sameChildren = children.filter((child) => {
        return child.get('key') === (action.payload && action.payload.key);
    });
    if (sameChildren.isEmpty()) {
        children.push(fromJS(action.payload));
    }
    return children;
}
return state
    .set('isNavigating', true)
        .updateIn(['children', state.get('index')], tabState =>
            tabState
                .update('children', getNewChildrenList)
                .set('index', tabState.get('children').size);
        );

Basically it checks that the child is not already present before pushing it in.
At the moment this solution doesn't work 100%, because the index between NavigationState and Scenes goes out of sync.
But hopefully this will help help others with this same issue

@jevakallio
Copy link
Contributor

@fabriziomoscon is this issue solved by #89 or is there something more we need to do in your opinion?

@fabriziomoscon
Copy link
Contributor Author

@jevakallio I haven't see this issue at all after implementing the change in PR #89
I think this is the fix: https://github.com/futurice/pepperoni-app-kit/blob/master/src/modules/navigation/NavigationState.js#L61-L68

@jevakallio
Copy link
Contributor

Awesome 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants