Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 11, 2019

Conversation

thebuilder
Copy link
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
Copy link
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
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

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
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
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.

None yet

4 participants