@samitouri / QOS-React / commits / 5c927b902f

Should not re-render as the result of a null state update

Fiber already happens to behave this way; this just adds a test. TODO: Should we add this feature to Stack, too?

Andrew Clark committed Dec 29, 2016 at 23:31 UTC 5c927b902f0716aec1c1858834229758518c12c4
2 files changed +24 -1
scripts/fiber/tests-passing.txt
+1
@@ -1578,6 +1578,7 @@ src/renderers/shared/shared/__tests__/ReactUpdates-test.js
1578 * unmounts and remounts a root in the same batch
1579 * handles reentrant mounting in synchronous mode
1580 * mounts and unmounts are sync even in a batch
1581 +* does not re-render if state update is null
1582
1583 src/renderers/shared/shared/__tests__/refs-destruction-test.js
1584 * should remove refs when destroying the parent
src/renderers/shared/shared/__tests__/ReactUpdates-test.js
+23 -1
@@ -13,9 +13,9 @@
13
14 var React;
15 var ReactDOM;
16 -var ReactDOMFeatureFlags;
16 var ReactTestUtils;
17 var ReactUpdates;
18 +var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
19
20 describe('ReactUpdates', () => {
21 beforeEach(() => {
@@ -1164,4 +1164,26 @@ describe('ReactUpdates', () => {
1164 ReactDOM.render(<Foo />, container1);
1165 expect(called).toEqual(true);
1166 });
1167 +
1168 + if (ReactDOMFeatureFlags.useFiber) {
1169 + // TODO: Should we add this feature to stack, too?
1170 + it('does not re-render if state update is null', () => {
1171 + let container = document.createElement('div');
1172 +
1173 + let instance;
1174 + let ops = [];
1175 + class Foo extends React.Component {
1176 + render() {
1177 + instance = this;
1178 + ops.push('render');
1179 + return <div />;
1180 + }
1181 + }
1182 + ReactDOM.render(<Foo />, container);
1183 +
1184 + ops = [];
1185 + instance.setState(() => null);
1186 + expect(ops).toEqual([]);
1187 + });
1188 + }
1189 });