-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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-source-contentful): Correct supported image formats #29562
Conversation
94cfe3e
to
628edce
Compare
628edce
to
2ce9ce4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a small nit.
@@ -33,6 +34,8 @@ const { | |||
// cache is more likely to go stale than the images (which never go stale) | |||
// Note that the same image might be requested multiple times in the same run | |||
|
|||
const validImageFormats = new Set([`jpg`, `png`, `webp`]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why a set is needed here.
const validImageFormats = new Set([`jpg`, `png`, `webp`]) | |
const validImageFormats = [`jpg`, `png`, `webp`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that set.has was significantly faster than array.includes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably is but it doesn't matter on a 3 items list. For me when I read Sets I expect things to get added to it and making sure things are unique and that makes it more complex in my head.
Sets are fine, that's why I approved it but wanted to get the reason on the why :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a pattern I always use for this sort of check, particularly when dealing with potentially large numbers of nodes, with a constant Set.
@@ -200,6 +203,13 @@ const generateImageSource = ( | |||
height = CONTENTFUL_IMAGE_MAX_SIZE | |||
} | |||
|
|||
if (!validImageFormats.has(toFormat)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!validImageFormats.has(toFormat)) { | |
if (!validImageFormats.includes(toFormat)) { |
(cherry picked from commit 3b4d32f)
Published in |
Contentful doesn't support AVIF. This fixes the resolver, and adds a check in the url builder