question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-image: WebP image sources do not generate PNG fallback

See original GitHub issue

Description

Using a WebP image, only .webp files are generated.

Steps to reproduce

const Image = () => {
  const data = useStaticQuery(graphql`
    query {
      placeholderImage: file(relativePath: { eq: "sample.webp" }) {
        childImageSharp {
          fluid(maxWidth: 300) {
            ...GatsbyImageSharpFluid_withWebp
          }
        }
      }
    }
  `);

  return <Img fluid={data.placeholderImage.childImageSharp.fluid} />;
};

How to Make a Minimal Reproduction: https://www.gatsbyjs.org/contributing/how-to-make-a-reproducible-test-case/

Expected result

A fallback type should be generated, ideally PNG since WebP supports transparency.

Actual result

Only WebP images are created.

Environment

Run gatsby info --clipboard in your project directory and paste the output here.

  System:
    OS: macOS 11.0
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.12.0 - /usr/local/bin/node
    npm: 6.14.8 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 85.0.4183.121
    Edge: 85.0.564.63
    Firefox: 80.0.1
    Safari: 14.0.1
  npmGlobalPackages:
    gatsby-cli: 2.12.101

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ascorbiccommented, Oct 22, 2020
0reactions
cpboydcommented, Oct 22, 2020

@ascorbic Should there perhaps be documentation added to https://www.gatsbyjs.com/docs/working-with-images/ in this regard?

Especially as there’s more prevalence of new image containers with better compression like WebP and HEIF? For example, iPhones now default to HEIF which has led to known issues with systems unprepared to handle that (e.g. SAT testing)

I still think Gatsby should, ideally, focus on being user-friendly with good defaults out of the box. Gatsby already provides default support for polyfills, so I’m not sure how a default preferring an image fallback to a format with good cross-browser support is any different from that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsbyjs image with Webp and fallback to jpg using picture ...
Wrapping the Gatsby Image inside a <picture> tag is not as useful as you ... WebP, gatsby-image will fall back to the default...
Read more >
Gatsby Image plugin
The Gatsby Image plugin supports four output formats: JPEG, PNG, WebP and AVIF. By default, the plugin generates images in the same format...
Read more >
Using WebP images with React - Josh W Comeau
In this tutorial, we'll see how we can leverage "next-gen" image formats like WebP. These images are often 2-3x smaller than the legacy...
Read more >
gatsby-plugin-image - npm
The Gatsby Image plugin handles the hard parts of producing images in multiple ... Errors don't cause the build to fail, but instead...
Read more >
@gromy/gatsby-plugin-image - npm package | Snyk
This plugin is a replacement for gatsby-image. ... Note that src will be undefined if a .png or .jpg image is not available....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found