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

Added test to improve support of top-down update behaviour #1398

Closed
wants to merge 1 commit into from

Conversation

arhelmus
Copy link

@arhelmus arhelmus commented Sep 16, 2019

Hey, in recent issue we found test case which violates principle of top-down state update behaviour when state change propagates through mapStateToProps: #1397.

This PR is adding reproducible test-case to highlight this issue, I believe this is important due to statement in this part of codebase:

if (lastThrownError) {
    // It's possible that we caught an error due to a bad mapState function, but the
    // parent re-rendered without this component and we're about to unmount.
    // This shouldn't happen as long as we do top-down subscriptions correctly, but
    // if we ever do those wrong, this throw will surface the error in our tests.
    // In that case, throw the error from here so it doesn't get lost.
    throw lastThrownError
}

I would be grateful if you will help me to find how to fix this test case in react-redux or at least merge this test to make sure that issue will be fixed eventually.

@netlify
Copy link

netlify bot commented Sep 16, 2019

Deploy preview for react-redux-docs ready!

Built with commit 2a7c829

https://deploy-preview-1398--react-redux-docs.netlify.com

@RrNn
Copy link

RrNn commented Sep 24, 2019

hope this gets merged, so we can get a fix. I've been in a little hell because of this #1397 (comment) 👈 (first part) in an earlier version.

@markerikson
Copy link
Contributor

markerikson commented Sep 24, 2019

If this test case is truly showing a problem with our implementation, then I would really like someone to take some time to investigate the actual cause of the problem, and add that to this PR. The failing test case is helpful, but kind of useless on its own.

I unfortunately don't have time to investigate this issue myself right now.

@timdorr
Copy link
Member

timdorr commented Sep 25, 2019

I'm actually not sure what the problem is here. Why do we care if mSTP is called on a removed component? It should be a pure function, so there are no side effects to calling it an extra time. The actual render never happens, which is the important part.

@ykagan
Copy link

ykagan commented Oct 10, 2019

I'm actually not sure what the problem is here. Why do we care if mSTP is called on a removed component? It should be a pure function, so there are no side effects to calling it an extra time. The actual render never happens, which is the important part.

It becomes a problem when mSTP is written under the assumption that the props passed in are valid props for this component. For example its common to do something like

render () {
   ....
   state.items.map((item, i) => <WrappedComponent index={i} />)
}

in the parent component. and

const item = state.items[props.i];

in the child mSTP. This will cause an exception when item i is removed from items but mSTP is called anyway.

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

Successfully merging this pull request may close these issues.

5 participants