Skip to content

Commit

Permalink
fix(gatsby-image): ensure that currentSrc exists (gatsbyjs#13287)
Browse files Browse the repository at this point in the history
* Ensure that currentSrc exists

Trying to read `currentSrc` before it has been set throws an `Unable to get property 'length' of undefined or null reference` error.
It should be an empty string, but IE11 can return `undefined`.

* Check if the `currentSrc` has a value

Instead of reading the `length`, we can just check to see if it's a value. This ensures it's not `undefined` and that it has a valid `src` URL
  • Loading branch information
thebuilder authored and wardpeet committed Apr 11, 2019
1 parent 494ad07 commit 6059bce
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/gatsby-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class Image extends React.Component {
this.setState({ isVisible: true }, () =>
this.setState({
imgLoaded: imageInCache,
imgCached: this.imageRef.current.currentSrc.length > 0,
imgCached: !!this.imageRef.current.currentSrc,
})
)
})
Expand Down

0 comments on commit 6059bce

Please sign in to comment.