Skip to content

Commit 6059bce

Browse files
thebuilderwardpeet
authored andcommitted
fix(gatsby-image): ensure that currentSrc exists (#13287)
* 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
1 parent 494ad07 commit 6059bce

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/gatsby-image/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Image extends React.Component {
224224
this.setState({ isVisible: true }, () =>
225225
this.setState({
226226
imgLoaded: imageInCache,
227-
imgCached: this.imageRef.current.currentSrc.length > 0,
227+
imgCached: !!this.imageRef.current.currentSrc,
228228
})
229229
)
230230
})

0 commit comments

Comments
 (0)