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 }}
Repository navigation
Parent refs are empty in child componentWillUnmount #1853
I ran into it when my child component called a passed-in handler to clean up during its componentWillUnmount, triggered while the parent was unmounting as well. This handler, belonging to the parent, tries to pause the parent's audio node, but this.refs.audioNode was already empty. (For what it's worth, when I inserted a breakpoint the DOM node is still there.)
I mentioned this on IRC and @zpao suggested it might be a bug, so here I am. :)
I'm assuming refs are cleaned up after componentWillUnmount, as opposed to after all life cycle methods in the current transaction have been called and the parent is apparently notified before the children. But this touches on another interesting question IMHO, shouldn't (notification of) unmounting occur from child to parent? (i.e, reverse of mounting)
Ah, did not realize that parents get notified of unmount before children. I'd agree that the order should be reversed, since the child may have prop dependencies on the parent (e.g. parent refs). Also, since in some sense child components do ultimately get unmounted before the parent (esp since the parent isn't always unmounted), notifying in that order seems to make more sense.
Well, I think the parent needs to be notified of the unmount before the child actually gets unmounted so you can clean up event handlers, etc. from a rendered child component? It might work to notify children first but wait for parents to be notified before actually unmounting the children.
@spicyj Yeah, I would expect notifications to flow from children to parents, once all affected instances have been notified they're all unmounted in some unspecified/undefined way.
Activity
syranide commentedon Jul 17, 2014
I'm assuming refs are cleaned up after
componentWillUnmount, as opposed to after all life cycle methods in the current transaction have been called and the parent is apparently notified before the children. But this touches on another interesting question IMHO, shouldn't (notification of) unmounting occur from child to parent? (i.e, reverse of mounting)joshma commentedon Jul 17, 2014
Ah, did not realize that parents get notified of unmount before children. I'd agree that the order should be reversed, since the child may have prop dependencies on the parent (e.g. parent refs). Also, since in some sense child components do ultimately get unmounted before the parent (esp since the parent isn't always unmounted), notifying in that order seems to make more sense.
sophiebits commentedon Jul 17, 2014
Well, I think the parent needs to be notified of the unmount before the child actually gets unmounted so you can clean up event handlers, etc. from a rendered child component? It might work to notify children first but wait for parents to be notified before actually unmounting the children.
syranide commentedon Jul 17, 2014
@spicyj Yeah, I would expect notifications to flow from children to parents, once all affected instances have been notified they're all unmounted in some unspecified/undefined way.
gaearon commentedon Oct 1, 2017
Closing as stale.
If you have a use case for which this makes a difference please file a new issue and describe it.