@@ -747,15 +747,18 @@ export default function(
747747 const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
748748 const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
749749
750+ const hasNewLifecycles =
751+ typeof ctor . getDerivedStateFromProps === 'function' ||
752+ typeof instance . getSnapshotBeforeUpdate === 'function' ;
753+
750754 // Note: During these life-cycles, instance.props/instance.state are what
751755 // ever the previously attempted to render - not the "current". However,
752756 // during componentDidUpdate we pass the "current" props.
753757
754758 // In order to support react-lifecycles-compat polyfilled components,
755759 // Unsafe lifecycles should not be invoked for components using the new APIs.
756760 if (
757- typeof ctor . getDerivedStateFromProps !== 'function' &&
758- typeof instance . getSnapshotBeforeUpdate !== 'function' &&
761+ ! hasNewLifecycles &&
759762 ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
760763 typeof instance . componentWillReceiveProps === 'function' )
761764 ) {
@@ -866,8 +869,7 @@ export default function(
866869 // In order to support react-lifecycles-compat polyfilled components,
867870 // Unsafe lifecycles should not be invoked for components using the new APIs.
868871 if (
869- typeof ctor . getDerivedStateFromProps !== 'function' &&
870- typeof instance . getSnapshotBeforeUpdate !== 'function' &&
872+ ! hasNewLifecycles &&
871873 ( typeof instance . UNSAFE_componentWillMount === 'function' ||
872874 typeof instance . componentWillMount === 'function' )
873875 ) {
@@ -921,15 +923,18 @@ export default function(
921923 const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
922924 const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
923925
926+ const hasNewLifecycles =
927+ typeof ctor . getDerivedStateFromProps === 'function' ||
928+ typeof instance . getSnapshotBeforeUpdate === 'function' ;
929+
924930 // Note: During these life-cycles, instance.props/instance.state are what
925931 // ever the previously attempted to render - not the "current". However,
926932 // during componentDidUpdate we pass the "current" props.
927933
928934 // In order to support react-lifecycles-compat polyfilled components,
929935 // Unsafe lifecycles should not be invoked for components using the new APIs.
930936 if (
931- typeof ctor . getDerivedStateFromProps !== 'function' &&
932- typeof instance . getSnapshotBeforeUpdate !== 'function' &&
937+ ! hasNewLifecycles &&
933938 ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
934939 typeof instance . componentWillReceiveProps === 'function' )
935940 ) {
@@ -1054,8 +1059,7 @@ export default function(
10541059 // In order to support react-lifecycles-compat polyfilled components,
10551060 // Unsafe lifecycles should not be invoked for components using the new APIs.
10561061 if (
1057- typeof ctor . getDerivedStateFromProps !== 'function' &&
1058- typeof instance . getSnapshotBeforeUpdate !== 'function' &&
1062+ ! hasNewLifecycles &&
10591063 ( typeof instance . UNSAFE_componentWillUpdate === 'function' ||
10601064 typeof instance . componentWillUpdate === 'function' )
10611065 ) {
0 commit comments