Skip to content

Bug: didPutListener tries to findDOMNode on unmounted component #7440

@joshma

Description

@joshma

I believe this is a bug and potentially related to #3298, but the specific details are different enough that I wanted to file a separate issue. Feel free to close if it's the same root cause.

I have a repro here: https://jsfiddle.net/7s6mwccu/2/

  • ClickMe is a component that runs causeError on click
  • causeError first renders components of type A and B (let's call them A0 and B0)
  • B0 has a componentDidMount function that calls setState (comes into play later)
  • causeError then updates A0 with a new prop
  • A.componentDidUpdate unmounts B0 and mounts a new B, B1
  • After causeError is all done, React's runtime performs some ops (presumably due to B0's setState) that leads to:

Warning: React can't find the root component node for data-reactid value .2. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.
Uncaught TypeError: Cannot read property 'firstChild' of undefined

Peeking at the stacktrace, it looks like didPutListener is trying to findDOMNode on an already-unmounted component.

Some weird details:

  • Leaving off onClick removes this error
  • Not calling setState in B.componentDidMount also removes this error

So it's a bit different from #3298 because it's not erroring if we only unmount B during a click; it's erroring if we have onClick and setState.

This is on React 0.14 - I tested it briefly on React 15 and got

Invariant Violation: React DOM tree root should always have a node reference.

which presumably is a better formed version of the same error.

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