diff --git a/src/renderers/__tests__/ReactCompositeComponentState-test.js b/src/renderers/__tests__/ReactCompositeComponentState-test.js
index 9018953438..2d9351da1e 100644
--- a/src/renderers/__tests__/ReactCompositeComponentState-test.js
+++ b/src/renderers/__tests__/ReactCompositeComponentState-test.js
@@ -414,4 +414,30 @@ describe('ReactCompositeComponent-state', () => {
'scu from a,b to a,b,c',
]);
});
+
+ it('should treat assigning to this.state inside cWRP as a replaceState, with a warning', () => {
+ let ops = [];
+ class Test extends React.Component {
+ state = { step: 1, extra: true };
+ componentWillReceiveProps() {
+ this.setState({ step: 2 }, () => {
+ // Tests that earlier setState callbacks are not dropped
+ ops.push(`step: ${this.state.step}, extra: ${!!this.state.extra}`);
+ });
+ // Treat like replaceState
+ this.state = { step: 3 };
+ }
+ render() {
+ return null;
+ }
+ }
+
+ // Mount
+ const container = document.createElement('div');
+ ReactDOM.render(, container);
+ // Update
+ ReactDOM.render(, container);
+
+ expect(ops).toEqual(['step: 3, extra: false']);
+ });
});
diff --git a/src/renderers/shared/fiber/ReactFiberClassComponent.js b/src/renderers/shared/fiber/ReactFiberClassComponent.js
index 87f3426099..13b6d78010 100644
--- a/src/renderers/shared/fiber/ReactFiberClassComponent.js
+++ b/src/renderers/shared/fiber/ReactFiberClassComponent.js
@@ -408,6 +408,10 @@ module.exports = function(
if (oldProps !== newProps || oldContext !== newContext) {
if (typeof instance.componentWillReceiveProps === 'function') {
instance.componentWillReceiveProps(newProps, newContext);
+
+ if (instance.state !== workInProgress.memoizedState) {
+ updater.enqueueReplaceState(instance, instance.state, null);
+ }
}
}