ctrlplusb / react-tree-walker

Walk a React (or Preact) element tree, executing a "visitor" function against each element.
MIT License
345 stars 34 forks source link

issue with connect, outdated props when rendered #43

Open CosticaPuntaru opened 5 years ago

CosticaPuntaru commented 5 years ago

here is a repo to reproduce the issue but i will try to summarise it here https://github.com/CosticaPuntaru/react-walk-tree--redux-bug

tl:dr; in order for nested component to render properly the component instance needs to recalculate props after the "visitor" function is run and before render is called.

what i understand from what happens: case: we have two components that want to lazy load data from server, one sibling of the other (i call them first and second), both of them are decorated with redux connect

running steps: reactWalkTree gets the App and walks it runs the connector component, binds the store props to the component props, then runs by "bootstrap" function, waits for it to finish and then runs the render,

the issue is that the render function is called with the props that were bind to the component before the "bootstrap" function was called. and having a if(!ready) return (<div>Loading</div>); will never give a change to the secondComponent.bootstrap to run and gather the data. thus not not getting the correct ssr,

hope this is clear enough,

oyeanuj commented 5 years ago

FWIW, I'm seeing the same issue with parent & child components