You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
propTypes definitions cause unneeded component updates #56
I have a store with an observable list of items. Each item has an id and an observable value.
In the react part I have a List component and a ListItem component. The ListItem component renders the item’s id and value. Next to the value there is a +1 button that increases the item’s value by 1.
The List and ListItem components are observers.
Without propTypes definitions everything is working as expected. If I add a new item to the list only the List component is updated and if I click the +1 button only that specific item is updated.
If I add propTypes definitions to the List and ListItem components on each +1 button click the List component is also updated for some reason. But if I remove the observable properties from the propTypes definition of the ListItem component everything is working as expected.
changed the title [-]propTypes definitions cause not needed component updates[/-][+]propTypes definitions cause unneeded component updates[/+]on May 17, 2016
I don't think you are doing anything wrong: React does prop type checking in the parent component (in order to output meaningful error messages such as "Check render() method of component X").
These prop type checks result in these observables being reported observed, i.e. they are added as extra dependencies of the parent component (in addition to the child component).
I stumbled upon this issue myself a couple of days ago. Unfortunately, I don't have a solution for this.
It makes using the mobx-react devtools harder because parent components show as changed as well. It also hurts performance somewhat, since two re-renders have to happen: one for the actual component and one for the parent which only accidentally is added as observer (only due to prop type checking).
Made a change where using the propTypes provided by mobx-react will use untracked. This doesn't solve it for the general case though. Either using typescript 😉, or production will avoid this issue. So since this is only a dev problem, a further won't fix for now.
Activity
[-]propTypes definitions cause not needed component updates[/-][+]propTypes definitions cause unneeded component updates[/+]sgoll commentedon May 18, 2016
I don't think you are doing anything wrong: React does prop type checking in the parent component (in order to output meaningful error messages such as "Check render() method of component X").
These prop type checks result in these observables being reported observed, i.e. they are added as extra dependencies of the parent component (in addition to the child component).
I stumbled upon this issue myself a couple of days ago. Unfortunately, I don't have a solution for this.
It makes using the mobx-react devtools harder because parent components show as changed as well. It also hurts performance somewhat, since two re-renders have to happen: one for the actual component and one for the parent which only accidentally is added as observer (only due to prop type checking).
mattruby commentedon Jun 1, 2016
Will this be an issue running the prod build of React? I thought React only checks against the propTypes in dev mode?
mweststrate commentedon Jun 14, 2016
See also mobxjs/mobx#305
mweststrate commentedon Jun 20, 2016
I think this can be circumvented by having mobx-react provide it's own
propTypes, that leveragemobx.untracked, will investigatemweststrate commentedon Aug 6, 2016
Made a change where using the
propTypesprovided bymobx-reactwill useuntracked. This doesn't solve it for the general case though. Either using typescript 😉, or production will avoid this issue. So since this is only a dev problem, a further won't fix for now.Always do propType checking untracked, partially fixes #56, #305
vkartaviy commentedon Jan 16, 2018
Stumbled upon this issue today when used
PropTypes.arrayOf():(