From 6059bce2b2a602598e23021a7a52a76e1ad05200 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt <3764345+thebuilder@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:00:35 +0200 Subject: [PATCH] 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 --- packages/gatsby-image/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-image/src/index.js b/packages/gatsby-image/src/index.js index 6841a4392435e..6d82b4d0e1900 100644 --- a/packages/gatsby-image/src/index.js +++ b/packages/gatsby-image/src/index.js @@ -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, }) ) })