Easy-peasy: react: state mapper and render are called with stale props

Created on 25 Mar 2019  路  11Comments  路  Source: ctrlplusb/easy-peasy

Hi,

not sure if you are following the discussions about the official react-redux hooks, but one major issue we are trying to solve there is what has been called the "zombie child problem". Basically, it means that the selector in useStore and worst case even the render of the component happens with an inconsistent store and props. Sadly, your library suffers from the same issue with both cases happening, i.e. useStore and the render are executed with inconsistent state and props. You can see an example that causes a crash here and another example that logs what is happening to the console more clearly here.

All 11 comments

Thanks for reporting this @MrWolfZ - I really appreciate the time you took to create a reproducible example for me.

I have given this some thought and I believe I _may_ have a solution that will work in the context of easy-peasy. I will let you know if and when I have a demoable solution, and if it works I sincerely hope we can take the ideas over to the official react-redux hooks. 馃憤

@MrWolfZ my initial naive implementation appears to be work in principle, however, it needs more work.

https://codesandbox.io/s/pm39mzn13m

@ctrlplusb there is an error a warning printed to the console when I hit the "Delete B" button.

Also, I can't find the branch with your 2.2.0-alpha.1 version. Have you pushed it here? I'd like to see the changes you made to fix the issue.

@MrWolfZ yeah, it's still a work in progress. I'll ping you the branch when I have something semi-decent to push up. Very POC at this stage.

Ok, seems like the warning has gone away with latest effort...

@MrWolfZ see #137

@ctrlplusb That code still has some issues. On the surface, this seems to work, but in reality a hidden error is thrown in the event handler. I refactored the example a little bit to make it clearer what is happening.

Thanks for that 馃憤

@MrWolfZ thanks for giving me a deeper insight into this problem. I am looking at a temporary solution to this where the mapState error is caught, and I then allow a window of opportunity where a new registration is started (i.e. props updated) or the component unmounts. If none of these cases occur I then throw the error.

It's not working right now, but could possibly be a temporary workaround.

https://github.com/ctrlplusb/easy-peasy/pull/138

Hoping to explore this direction a bit more whilst doing more research and tracking the conversation with react-redux 馃憤

Ok, workaround is "working.

https://codesandbox.io/s/p3nywxx37q

Needs more robust testing though.

Fixed by #138

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raul-madrigal picture raul-madrigal  路  3Comments

positimo picture positimo  路  3Comments

djgrant picture djgrant  路  6Comments

vincentjames501 picture vincentjames501  路  6Comments

gino8080 picture gino8080  路  5Comments