Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
This repository was archived by the owner on Dec 31, 2020. It is now read-only.

propTypes definitions cause unneeded component updates #56

Closed

Description

@pnpetrov

Hi,

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.

Example: https://jsfiddle.net/ppetrov/e6ukjvxo/
Every component has a console.log in its render method.

Am I doing something wrong?

Best regards

Activity

  1. changed the title [-]propTypes definitions cause not needed component updates[/-] [+]propTypes definitions cause unneeded component updates[/+] on May 17, 2016
  2. sgoll commented on May 18, 2016

    @sgoll

    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).

  3. mattruby commented on Jun 1, 2016

    @mattruby
    Member

    Will this be an issue running the prod build of React? I thought React only checks against the propTypes in dev mode?

  4. mweststrate commented on Jun 14, 2016

    @mweststrate
    Member
  5. mweststrate commented on Jun 20, 2016

    @mweststrate
    Member

    I think this can be circumvented by having mobx-react provide it's own propTypes, that leverage mobx.untracked, will investigate

  6. mweststrate commented on Aug 6, 2016

    @mweststrate
    Member

    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.

  7. added a commit that references this issue on Aug 6, 2016
    3f0b751
  8. vkartaviy commented on Jan 16, 2018

    @vkartaviy

    Stumbled upon this issue today when used PropTypes.arrayOf() :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions