**Do you want to request a _feature_ or report a _bug_?**
Report a bug

**What is the current behavior?**
Running `ReactTestUtils.createRenderer().render()` causes react to throw an exception:

```
Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (3 has parents 0 and 2).
Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (3 has parents 0 and 2).
```

I have the same issue when using both `Component` and `PureComponent`.
I do _not_ see the error when using `ReactTestUtils.renderToDocument()`.

**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).**
Could not figure out how to use `ReactTestUtils` in that JSFiddle example even though react-with-addons is loaded.

Here's the code I used in my project to reproduce it:

``` jsx
import React, { Component, PureComponent } from 'react'
import { render } from 'react-dom'
import ReactTestUtils from 'react-addons-test-utils'

class Root extends Component {
    componentWillMount() {
        this.testBreak()
        setTimeout(this.testBreak.bind(this), 10)
    }

    testBreak() {
        var i = 0, l = 50
        while(i <= l) {
            this.setState({ test: `this will break testing ${++i}` })
        }
    }

    render() {
        return (
            <div>
                {/* You need more than one nested element for this to break */}
                <div>First div</div>
                <div>Second div</div>
            </div>
        )
    }
}

render(
    <Root />
, document.getElementById('root'))

class TestReactElement extends PureComponent {
    render() { return (
        <div>{this.props.name}</div>
    )}
}

const testRender = (name) => {
    let renderer = ReactTestUtils.createRenderer()
    renderer.render(<TestReactElement name={name} />)
}

testRender('Test 1')
testRender('Test 2')
testRender('Test 3')
```

It works fine so long as I run `testRender()` once. As soon as it's run 2 or more times, the error pops up.

In my project, TAP output is being listened to from a `console.log` wrapper and `state` is being updated when a new one comes in. So while my reproducible example is contrived, it's real-world bug when running tests in my project.

**What is the expected behavior?**
The expected behavior is that no error occurs in the console when running multiple shallow test renders while at the same time React is updating the state of an element rendered to the DOM.

**Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?**
`15.3.0` and `15.3.2`. Windows 10 64-bit v1607 (and updates up to October 10th, 2016). I've not tried this in previous versions of React. Verified it displays the error in Chrome `54.0.2840.50 beta-m (64-bit)` and Firefox `50.0b5`.

/**
 * Copyright 2013-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @providesModule ReactShallowRenderer
 * @preventMunge
 */
'use strict';
var React = require('React');
var ReactDOMInjection = require('ReactDOMInjection');
var ReactDOMStackInjection = require('ReactDOMStackInjection');
var ReactCompositeComponent = require('ReactCompositeComponent');
var ReactReconciler = require('ReactReconciler');
var ReactUpdates = require('ReactUpdates');
var emptyObject = require('emptyObject');
var invariant = require('invariant');
var nextDebugID = 1;
class NoopInternalComponent {