@@ -139,20 +139,18 @@ class ReactShallowRenderer {
139
139
) {
140
140
const beforeState = this . _newState ;
141
141
142
- if ( typeof this . _instance . componentWillMount === 'function' ) {
143
- // In order to support react-lifecycles-compat polyfilled components,
144
- // Unsafe lifecycles should not be invoked for any component with the new gDSFP.
145
- if ( typeof element . type . getDerivedStateFromProps !== 'function' ) {
146
- this . _instance . componentWillMount ( ) ;
147
- }
148
- }
142
+ // In order to support react-lifecycles-compat polyfilled components,
143
+ // Unsafe lifecycles should not be invoked for components using the new APIs.
149
144
if (
150
- typeof this . _instance . UNSAFE_componentWillMount = == 'function' &&
151
- typeof element . type . getDerivedStateFromProps !== 'function'
145
+ typeof element . type . getDerivedStateFromProps ! == 'function' &&
146
+ typeof this . _instance . getSnapshotBeforeUpdate !== 'function'
152
147
) {
153
- // In order to support react-lifecycles-compat polyfilled components,
154
- // Unsafe lifecycles should not be invoked for any component with the new gDSFP.
155
- this . _instance . UNSAFE_componentWillMount ( ) ;
148
+ if ( typeof this . _instance . componentWillMount === 'function' ) {
149
+ this . _instance . componentWillMount ( ) ;
150
+ }
151
+ if ( typeof this . _instance . UNSAFE_componentWillMount === 'function' ) {
152
+ this . _instance . UNSAFE_componentWillMount ( ) ;
153
+ }
156
154
}
157
155
158
156
// setState may have been called during cWM
@@ -173,20 +171,20 @@ class ReactShallowRenderer {
173
171
const oldProps = this . _instance . props ;
174
172
175
173
if ( oldProps !== props ) {
176
- if ( typeof this . _instance . componentWillReceiveProps === 'function' ) {
177
- // In order to support react-lifecycles-compat polyfilled components,
178
- // Unsafe lifecycles should not be invoked for any component with the new gDSFP.
179
- if ( typeof element . type . getDerivedStateFromProps !== 'function' ) {
180
- this . _instance . componentWillReceiveProps ( props , context ) ;
181
- }
182
- }
174
+ // In order to support react-lifecycles-compat polyfilled components,
175
+ // Unsafe lifecycles should not be invoked for components using the new APIs.
183
176
if (
184
- typeof this . _instance . UNSAFE_componentWillReceiveProps = == 'function' &&
185
- typeof element . type . getDerivedStateFromProps !== 'function'
177
+ typeof element . type . getDerivedStateFromProps ! == 'function' &&
178
+ typeof this . _instance . getSnapshotBeforeUpdate !== 'function'
186
179
) {
187
- // In order to support react-lifecycles-compat polyfilled components,
188
- // Unsafe lifecycles should not be invoked for any component with the new gDSFP.
189
- this . _instance . UNSAFE_componentWillReceiveProps ( props , context ) ;
180
+ if ( typeof this . _instance . componentWillReceiveProps === 'function' ) {
181
+ this . _instance . componentWillReceiveProps ( props , context ) ;
182
+ }
183
+ if (
184
+ typeof this . _instance . UNSAFE_componentWillReceiveProps === 'function'
185
+ ) {
186
+ this . _instance . UNSAFE_componentWillReceiveProps ( props , context ) ;
187
+ }
190
188
}
191
189
192
190
this . _updateStateFromStaticLifecycle ( props ) ;
@@ -211,20 +209,18 @@ class ReactShallowRenderer {
211
209
}
212
210
213
211
if ( shouldUpdate ) {
214
- if ( typeof this . _instance . componentWillUpdate === 'function' ) {
215
- // In order to support react-lifecycles-compat polyfilled components,
216
- // Unsafe lifecycles should not be invoked for any component with the new gDSFP.
217
- if ( typeof type . getDerivedStateFromProps !== 'function' ) {
218
- this . _instance . componentWillUpdate ( props , state , context ) ;
219
- }
220
- }
212
+ // In order to support react-lifecycles-compat polyfilled components,
213
+ // Unsafe lifecycles should not be invoked for components using the new APIs.
221
214
if (
222
- typeof this . _instance . UNSAFE_componentWillUpdate = == 'function' &&
223
- typeof type . getDerivedStateFromProps !== 'function'
215
+ typeof element . type . getDerivedStateFromProps ! == 'function' &&
216
+ typeof this . _instance . getSnapshotBeforeUpdate !== 'function'
224
217
) {
225
- // In order to support react-lifecycles-compat polyfilled components,
226
- // Unsafe lifecycles should not be invoked for any component with the new gDSFP.
227
- this . _instance . UNSAFE_componentWillUpdate ( props , state , context ) ;
218
+ if ( typeof this . _instance . componentWillUpdate === 'function' ) {
219
+ this . _instance . componentWillUpdate ( props , state , context ) ;
220
+ }
221
+ if ( typeof this . _instance . UNSAFE_componentWillUpdate === 'function' ) {
222
+ this . _instance . UNSAFE_componentWillUpdate ( props , state , context ) ;
223
+ }
228
224
}
229
225
}
230
226
0 commit comments