@@ -33,6 +33,11 @@ export default class HTMLImage extends PureComponent {
33
33
34
34
componentDidMount ( ) {
35
35
this . getImageSize ( ) ;
36
+ this . mounted = true ;
37
+ }
38
+
39
+ componentWillUnmount ( ) {
40
+ this . mounted = false ;
36
41
}
37
42
38
43
componentWillReceiveProps ( nextProps ) {
@@ -75,7 +80,7 @@ export default class HTMLImage extends PureComponent {
75
80
const { styleWidth, styleHeight } = this . getDimensionsFromStyle ( style , height , width ) ;
76
81
77
82
if ( styleWidth && styleHeight ) {
78
- return this . setState ( {
83
+ return this . mounted && this . setState ( {
79
84
width : typeof styleWidth === 'string' && styleWidth . search ( '%' ) !== - 1 ? styleWidth : parseInt ( styleWidth , 10 ) ,
80
85
height : typeof styleHeight === 'string' && styleHeight . search ( '%' ) !== - 1 ? styleHeight : parseInt ( styleHeight , 10 )
81
86
} ) ;
@@ -85,14 +90,14 @@ export default class HTMLImage extends PureComponent {
85
90
source . uri ,
86
91
( originalWidth , originalHeight ) => {
87
92
if ( ! imagesMaxWidth ) {
88
- return this . setState ( { width : originalWidth , height : originalHeight } ) ;
93
+ return this . mounted && this . setState ( { width : originalWidth , height : originalHeight } ) ;
89
94
}
90
95
const optimalWidth = imagesMaxWidth <= originalWidth ? imagesMaxWidth : originalWidth ;
91
96
const optimalHeight = ( optimalWidth * originalHeight ) / originalWidth ;
92
- this . setState ( { width : optimalWidth , height : optimalHeight , error : false } ) ;
97
+ this . mounted && this . setState ( { width : optimalWidth , height : optimalHeight , error : false } ) ;
93
98
} ,
94
99
( ) => {
95
- this . setState ( { error : true } ) ;
100
+ this . mounted && this . setState ( { error : true } ) ;
96
101
}
97
102
) ;
98
103
}
0 commit comments