Skip to content

React fails to unmount component from within event handler #3298

@slorber

Description

@slorber

Hi,

When trying to unmount my whole app, I got some error.

Uncaught TypeError: Cannot read property 'firstChild' of undefined
ReactMount.js:606ReactMount.findComponentRoot
ReactMount.js:606ReactMount.findReactNodeByID ReactMount.js:552getNode
ReactMount.js:128executeDispatch EventPluginUtils.js:109SimpleEventPlugin.executeDispatch
SimpleEventPlugin.js:305forEachEventDispatch EventPluginUtils.js:95executeDispatchesInOrder
EventPluginUtils.js:119executeDispatchesAndRelease EventPluginHub.js:46forEachAccumulated
forEachAccumulated.js:25EventPluginHub.processEventQueue
EventPluginHub.js:251runEventQueueInBatch
ReactEventEmitterMixin.js:18ReactEventEmitterMixin.handleTopLevel
ReactEventEmitterMixin.js:44handleTopLevelImpl ReactEventListener.js:80Mixin.perform
Transaction.js:134ReactDefaultBatchingStrategy.batchedUpdates
ReactDefaultBatchingStrategy.js:66batchedUpdates
ReactUpdates.js:109ReactEventListener.dispatchEvent ReactEventListener.js:175

I think it's not a big deal.

According to what I see with the debugger, it seems to be because a SyntheticMouseEvent is trying to get dispatched. And I guess the target has just been unmounted...

Note that my use case looks like this:

var Hello = React.createClass({
    render: function() {
        return <div onClick={unmount}>Hello {this.props.name}</div>;
    }
});

When using an unmount synchronous implementation, I get this error.
When adding a setTimeout 0 in the unmount code, I got no error.

I could not reproduce this in a jsfiddle, but I guess it's probably because I don't really know how batching work in React.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions