File tree Expand file tree Collapse file tree
packages/gatsby-image/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -395,14 +395,18 @@ class Image extends React.Component {
395395 // Once isVisible is true, imageRef becomes accessible, which imgCached needs access to.
396396 // imgLoaded and imgCached are in a 2nd setState call to be changed together,
397397 // avoiding initiating unnecessary animation frames from style changes.
398- this . setState ( { isVisible : true } , ( ) =>
398+ this . setState ( { isVisible : true } , ( ) => {
399399 this . setState ( {
400400 imgLoaded : imageInCache ,
401401 // `currentSrc` should be a string, but can be `undefined` in IE,
402402 // !! operator validates the value is not undefined/null/""
403- imgCached : ! ! this . imageRef . current . currentSrc ,
403+ // for lazyloaded components this might be null
404+ // TODO fix imgCached behaviour as it's now false when it's lazyloaded
405+ imgCached : ! ! (
406+ this . imageRef . current && this . imageRef . current . currentSrc
407+ ) ,
404408 } )
405- )
409+ } )
406410 } )
407411 }
408412 }
You can’t perform that action at this time.
0 commit comments