Skip to content

fix(gatsby-image): ensure that currentSrc exists#13287

Merged
wardpeet merged 2 commits into
gatsbyjs:masterfrom
thebuilder:patch-1
Apr 11, 2019
Merged

fix(gatsby-image): ensure that currentSrc exists#13287
wardpeet merged 2 commits into
gatsbyjs:masterfrom
thebuilder:patch-1

Conversation

@thebuilder
Copy link
Copy Markdown
Contributor

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.

The issue was introduced by #12468 - it's simply missing an extra guard to ensure the value is defined.

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`.
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
Comment thread packages/gatsby-image/src/index.js
Copy link
Copy Markdown
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this regression! works like a charm!

@wardpeet
Copy link
Copy Markdown
Contributor

I'm on ie11 and I don't get this issue as it's wrapped inside IOSupported which is never true on ie11. Nonetheless, it's an ok check

@wardpeet wardpeet merged commit 6059bce into gatsbyjs:master Apr 11, 2019
@gatsbot
Copy link
Copy Markdown

gatsbot Bot commented Apr 11, 2019

Holy buckets, @thebuilder — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@thebuilder
Copy link
Copy Markdown
Contributor Author

I'm on ie11 and I don't get this issue as it's wrapped inside IOSupported which is never true on ie11. Nonetheless, it's an ok check

The error i caught: https://sentry.io/share/issue/da7dc5b5859943e09889b2089f52ee3b/

There's a lot of moving parts, in gatsby-image - Most likely the issue is triggered by the stack i'm using it with, combining Contentful with an ObjectFit polyfill.

polarathene pushed a commit to polarathene/gatsby that referenced this pull request May 20, 2019
raffishquartan pushed a commit to raffishquartan/gatsby that referenced this pull request Apr 28, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants