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

Does mobx-react produces reactions in Unmounted Components? #94

Closed
jmaguirrei opened this issue Jul 31, 2016 · 5 comments
Closed

Does mobx-react produces reactions in Unmounted Components? #94

jmaguirrei opened this issue Jul 31, 2016 · 5 comments

Comments

@jmaguirrei
Copy link

Hello

I noticed reactions in components that are not rendered in the screen.
I putted a console.login render() function and get those logs.
Even though this components are observers of data that has mutated, they are not rendered, so (I think) they should not react...

Is it possible to prevent this?

@andykog
Copy link
Member

andykog commented Jul 31, 2016

@jmaguirrei, if render() is being called, then your components are being rendered somewhere

@andykog
Copy link
Member

andykog commented Jul 31, 2016

You can try placing console.log(this._reactInternalInstance._nativeParent._currentElement) in those render(). It might help you find out who is rendering your component (or might not).

@jmaguirrei
Copy link
Author

@andykog Thanks, I found in one case those components were hidden because they are animated from 0 to 1 scale...

But, I have another case that calls render() and I think they should not.

For example, I have this (simplified) component tree:

Main (observes and passes A & B)

  • Header (receives and observes 'A')
  • List (receives and observes 'B')

'A' changes, Main is re-rendered, Header is re-rendered, but List is also re-rendered (I mean render is called but no DOM is changed).

I can control List not to re-render with some 'ad-hoc' ShouldComponentUpdate, but I like to rely on mobx-react to do that.

How could achieve that?

@jmaguirrei
Copy link
Author

Closing this, no evidence that unmounted components are rendered, thans for the whole explanation

@andykog
Copy link
Member

andykog commented Aug 1, 2016

'A' changes, Main is re-rendered, Header is re-rendered, but List is also re-rendered (I mean render is called but no DOM is changed).

Removed misleading comments about forceUpdate. We have discovered, that this is happening because List doesn't have pure rendering implemented. That can be achieved either with decorating List with @observable (that implements pureRenderMixin), or just using something like https://www.npmjs.com/package/pure-render-decorator for LIst

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants