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-transformer-sharp): Warn when using unsupported extension #20782

Merged
merged 5 commits into from
Feb 26, 2020

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Jan 22, 2020

Description

In the past people were (non surprisingly) confused when their image query e.g. from a CMS blew up and they couldn't figure out that it was cause by a .gif file they used.

Now a warning will be shown if a .gif file is queried and childImageSharp is used. I decided against an error and for a warning as people might guard themselves against that by checking childImageSharp for being null. It'll work then. Example query that shows an error:

export const query = graphql`
  query {
    normal: file(name: {eq: "shift"}) {
      name
      childImageSharp {
        fluid {
          src
        }
      }
    }
    gif: file(name: {eq: "killing-eve"}) {
      name
      childImageSharp {
        fluid {
          src
        }
      }
      publicURL
    }
  }
`

Output:

warn-on-gif

For now it doesn't specify the line + column as that would require a lot more additional work.

Documentation

Related Issues

Fixes #18699

childImageSharp: {
resolve: (parent, args, context, info) => {
if (parent.extension === `gif`) {
reporter.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

This has potential of spamming console. Do we need this warning for each instance of it?

Copy link
Contributor Author

@LekoArts LekoArts Feb 14, 2020

Choose a reason for hiding this comment

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

@pieh I guess we could also collect the paths (and counts) and print out only one warning with all paths at the end, e.g. with onPostBootstrap or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Printing it for every instance might be fine. I just wanted to raise potential problems it can cause.

I wouldn't recommend using onPostBootstrap (as this will result in non-warning cases for gatsby develop (local / preview) as people change their data or queries in source code).

Ideally we would have "sessions" for each "query running" step where we dedupe warnings for same files within those, but I don't think plugins can do something like that right now.

I'll try to find "prior art" in other plugins for similar warnings and if we have any - let's follow what we already do in other plugins

Copy link
Contributor Author

@LekoArts LekoArts Feb 19, 2020

Choose a reason for hiding this comment

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

Maybe we should shorten the warning (to two lines)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pieh shortened the message now

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.

This is great @LekoArts! I added 1 comment

packages/gatsby-transformer-sharp/src/create-resolvers.js Outdated Show resolved Hide resolved
@LekoArts LekoArts changed the title fix(gatsby-transformer-sharp): Warn when using .gif fix(gatsby-transformer-sharp): Warn when using unsupported extension Feb 19, 2020
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! Looks great, our users will be very happy.

@wardpeet wardpeet merged commit 4519c05 into gatsbyjs:master Feb 26, 2020
@LekoArts LekoArts deleted the sharp-gif branch February 26, 2020 10:35
@pieh
Copy link
Contributor

pieh commented Feb 26, 2020

Published gatsby-transformer-sharp@2.3.15

@CanRau
Copy link
Contributor

CanRau commented Feb 27, 2020

@LekoArts Is it supposed to warn for /jpe?g/ as well?
I get

warn You can't use childImageSharp together with can.jpeg — use publicURL instead. The childImageSharp
 portion of the query in this file will return null:

Yet the image shows as expected so all those warnings are pretty annoying 😢

@muescha
Copy link
Contributor

muescha commented Feb 27, 2020

jpeg is still supported in https://github.com/gatsbyjs/gatsby/pull/20782/files#diff-6ffe62631f12defe74d8bf931540b5e8R2

but i see the message is for this extension: can.jpeg``` 😕 🤔 ~~maybe there are 2 dots in your filename (/whatever.can.jpeg`)?

nevermind, the code says You can't use childImageSharp together with ${parent.name}.${parent.extension} - i was only looking at the screenshot where only You can't use childImageSharp together with .gif

@skovhus
Copy link
Contributor

skovhus commented Feb 27, 2020

This caused a regression where You can't use childImageSharp together with is shown for all file types, see:

@CanRau this is probably why you see the warning for jpeg.

@CanRau
Copy link
Contributor

CanRau commented Feb 27, 2020

Thanks for linking those 🙏 it's gone now 👍

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.

Image-sharp silently fails to process animated gifs
6 participants