Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(gatsby-image): Placeholder Improvements #10944
feat(gatsby-image): Placeholder Improvements #10944
Changes from 8 commits
5865ef1
241c2f6
34bc962
43c971f
b06b9e0
c12ec40
5a62ede
142f484
ec0071b
7d961da
66d64d3
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
can't you just use
options.base64Width
? It should be always set because of the healOptions functionThere 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 am pretty sure I required it here but it's been a while since I wrote this so I'm not sure what situation required it.(EDIT: Answered)
Looking through the commits, this const was originally hardcoded with a value of 20. I then had
options.base64Width || 20
before moving the default value into a variable, and finally a function(to support a config option value ingatsby.config.js
, otherwise falling back to the default value of 20).options.base64Width
is an optional param that can be set on the node/graphql function, should you want to use a different base64 width than the default value of 20. If you want to override the default globally viagatsby.config.js
,defaultBase64Width()
will return that value instead of 20.At line 806,
base64Args
for thefixed()
variant,width
param is replaced with theoptions.base64Width
if provided.Went over the code, the
fluid()
andfixed()
functions initialize theoptions
object at the start with no default params passed in. OnlygenerateBase64()
does this, where it originally passed in the hard coded default width of 20, my PR replaced that withdefaultBase64Width()
accordingly. That method is called by both fluid and fixed methods when they callbase64()
which first checks for a cached base64 data else it creates a new base64 image assigning the default width.Fluid needs to know the width in advance for computing the height, this was the case prior to my PR as well.
Fixed derives it's height from the width during generation of base64 image afaik, I added a width param to it's base64 args only if a custom width was requested, otherwise it's provided a default width during base64 generation as mentioned above with
generateBase64
.TL;DR:
No,
options.base64Width
isn't handled byhealOptions()
, it's passed in from a param in the graphql query.For
fluid()
the width must be known to derive thebase64Height
, prior to this PR it was a fixed value, 20; now it can also be a configurable global value ingatsby.config.js
too.For
fixed()
, it's only interested in the graphql query param if available, otherwise it gets a default width from the 2ndhealOptions()
at a later stage ingenerateBase64()
(assuming no cached version exists).Should
options.base64Width
be changed toargs.base64Width
to avoid this confusion withhealOptions()
? Should any of what I've said be added as comments to document what is going on within the code more clearly?