Stop passing prevContext param to componentDidUpdate (#8631)
Brian Vaughn committed
Apr 21, 2017 at 13:15 UTC
9d225b5a444490136e4e5d2b23724ba5a7ea0fb0
5 files changed
+7
-39
scripts/fiber/tests-failing.txt
-3
@@ -1,6 +1,3 @@
1
-src/isomorphic/classic/__tests__/ReactContextValidator-test.js
2
-* should pass previous context to lifecycles
3
-
1
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
2
* gives source code refs for unknown prop warning (ssr)
3
* gives source code refs for unknown prop warning for exact elements (ssr)
scripts/fiber/tests-passing.txt
+1
@@ -89,6 +89,7 @@ src/isomorphic/children/__tests__/onlyChild-test.js
89
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
90
* should filter out context not in contextTypes
91
* should pass next context to lifecycles
92
+* should not pass previous context to lifecycles
93
* should check context types
94
* should check child context types
95
* should warn (but not error) if getChildContext method is missing
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
+4
-6
@@ -125,14 +125,13 @@ describe('ReactContextValidator', () => {
125
expect(actualComponentWillUpdate).toEqual({foo: 'def'});
126
});
127
128
- it('should pass previous context to lifecycles', () => {
128
+ it('should not pass previous context to lifecycles', () => {
129
var actualComponentDidUpdate;
130
131
class Parent extends React.Component {
132
getChildContext() {
133
return {
134
foo: this.props.foo,
135
- bar: 'bar',
135
};
136
}
137
@@ -142,12 +141,11 @@ describe('ReactContextValidator', () => {
141
}
142
Parent.childContextTypes = {
143
foo: PropTypes.string.isRequired,
145
- bar: PropTypes.string.isRequired,
144
};
145
146
class Component extends React.Component {
149
- componentDidUpdate(prevProps, prevState, prevContext) {
150
- actualComponentDidUpdate = prevContext;
147
+ componentDidUpdate(...args) {
148
+ actualComponentDidUpdate = args;
149
}
150
151
render() {
@@ -161,7 +159,7 @@ describe('ReactContextValidator', () => {
159
var container = document.createElement('div');
160
ReactDOM.render(<Parent foo="abc" />, container);
161
ReactDOM.render(<Parent foo="def" />, container);
164
- expect(actualComponentDidUpdate).toEqual({foo: 'abc'});
162
+ expect(actualComponentDidUpdate).toHaveLength(2);
163
});
164
165
it('should check context types', () => {
src/renderers/__tests__/ReactCompositeComponent-test.js
-16
@@ -15,7 +15,6 @@ var ChildUpdates;
15
var MorphingComponent;
16
var React;
17
var ReactDOM;
18
-var ReactDOMFeatureFlags;
18
var ReactDOMServer;
19
var ReactCurrentOwner;
20
var ReactPropTypes;
@@ -28,7 +27,6 @@ describe('ReactCompositeComponent', () => {
27
jest.resetModules();
28
React = require('react');
29
ReactDOM = require('react-dom');
31
- ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
30
ReactDOMServer = require('react-dom/server');
31
ReactCurrentOwner = require('ReactCurrentOwner');
32
ReactPropTypes = require('ReactPropTypes');
@@ -806,13 +804,6 @@ describe('ReactCompositeComponent', () => {
804
expect('foo' in nextContext).toBe(true);
805
}
806
809
- componentDidUpdate(prevProps, prevState, prevContext) {
810
- if (!ReactDOMFeatureFlags.useFiber) {
811
- // Fiber does not pass the previous context.
812
- expect('foo' in prevContext).toBe(true);
813
- }
814
- }
815
-
807
shouldComponentUpdate(nextProps, nextState, nextContext) {
808
expect('foo' in nextContext).toBe(true);
809
return true;
@@ -828,13 +819,6 @@ describe('ReactCompositeComponent', () => {
819
expect('foo' in nextContext).toBe(false);
820
}
821
831
- componentDidUpdate(prevProps, prevState, prevContext) {
832
- if (!ReactDOMFeatureFlags.useFiber) {
833
- // Fiber does not pass the previous context.
834
- expect('foo' in prevContext).toBe(false);
835
- }
836
- }
837
-
822
shouldComponentUpdate(nextProps, nextState, nextContext) {
823
expect('foo' in nextContext).toBe(false);
824
return true;
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+2
-14
@@ -1022,11 +1022,9 @@ var ReactCompositeComponent = {
1022
var hasComponentDidUpdate = !!inst.componentDidUpdate;
1023
var prevProps;
1024
var prevState;
1025
- var prevContext;
1025
if (hasComponentDidUpdate) {
1026
prevProps = inst.props;
1027
prevState = inst.state;
1029
- prevContext = inst.context;
1028
}
1029
1030
if (inst.componentWillUpdate) {
@@ -1060,12 +1058,7 @@ var ReactCompositeComponent = {
1058
if (__DEV__) {
1059
transaction.getReactMountReady().enqueue(() => {
1060
measureLifeCyclePerf(
1063
- inst.componentDidUpdate.bind(
1064
- inst,
1065
- prevProps,
1066
- prevState,
1067
- prevContext,
1068
- ),
1061
+ inst.componentDidUpdate.bind(inst, prevProps, prevState),
1062
this._debugID,
1063
'componentDidUpdate',
1064
);
@@ -1074,12 +1067,7 @@ var ReactCompositeComponent = {
1067
transaction
1068
.getReactMountReady()
1069
.enqueue(
1077
- inst.componentDidUpdate.bind(
1078
- inst,
1079
- prevProps,
1080
- prevState,
1081
- prevContext,
1082
- ),
1070
+ inst.componentDidUpdate.bind(inst, prevProps, prevState),
1071
inst,
1072
);
1073
}