diff --git a/src/renderers/shared/reconciler/ReactUpdateQueue.js b/src/renderers/shared/reconciler/ReactUpdateQueue.js index d293bc9bc3..73850a7cd5 100644 --- a/src/renderers/shared/reconciler/ReactUpdateQueue.js +++ b/src/renderers/shared/reconciler/ReactUpdateQueue.js @@ -32,7 +32,7 @@ function enqueueUpdate(internalInstance) { } function getInternalInstanceReadyForUpdate(publicInstance, callerName) { - invariant( + warning( ReactCurrentOwner.current == null, '%s(...): Cannot update during an existing state transition ' + '(such as within `render`). Render methods should be a pure function ' + diff --git a/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js b/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js index c23ea8c98f..1565aba035 100644 --- a/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js +++ b/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js @@ -346,6 +346,49 @@ describe('ReactCompositeComponent', function() { expect(cbCalled).toBe(false); }); + + it('should warn about `setState` in render', function() { + var container = document.createElement('div'); + + var renderedState = -1; + + var Component = React.createClass({ + getInitialState: function() { + return {value: 0}; + }, + render: function() { + renderedState = this.state.value; + if (this.state.value === 0) { + this.setState({ value: 1 }); + } + return
; + }, + }); + + expect(console.error.calls.length).toBe(0); + + var instance = React.render(