Skip to content

Parent refs are empty in child componentWillUnmount #1853

Closed

Description

@joshma

I believe I have a repro of this bug here: http://jsfiddle.net/joshma/t68Nv/5/

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

Activity

  1. syranide commented on Jul 17, 2014

    @syranide
    Contributor

    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)

  2. joshma commented on Jul 17, 2014

    @joshma
    ContributorAuthor

    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.

  3. sophiebits commented on Jul 17, 2014

    @sophiebits
    Collaborator

    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.

  4. syranide commented on Jul 17, 2014

    @syranide
    Contributor

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

  5. gaearon commented on Oct 1, 2017

    @gaearon
    Collaborator

    Closing as stale.
    If you have a use case for which this makes a difference please file a new issue and describe it.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions