-
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
feat(gatsby-remark-images): Add option to use tracedSVG instead of blur up effect #9490
feat(gatsby-remark-images): Add option to use tracedSVG instead of blur up effect #9490
Conversation
#7800 seems like it will be fixing the issue with the effect not being visible unless If that PR is merged this PR should be changed to put |
547c436
to
ad9fbd8
Compare
Sorry for closing and reopening this. That was an attempt (unsuccessful) to get the CI checks to run again since they seem to keep timing out. Not sure what the issue is with the checks. |
I have now merged master including the changes from #7800. The issue where #7800 was changed back to using This PR should be ready to merge now. |
style="padding-bottom: ${ratio}; position: relative; bottom: 0; left: 0; background-image: url('${ | ||
fluidResult.base64 | ||
}'); background-size: cover; display: block;" | ||
style="padding-bottom: ${ratio}; position: relative; bottom: 0; left: 0; background-image: url("${placeholderImageData}"); background-size: cover; display: block;" |
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 don't think you can use a html entity here.
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.
This is the only way I have found to use the optimized SVG that traceSVG
returns within the style attribute. Based on this stackoverflow post and the HTML spec I believe the HTML entity is valid anywhere in an HTML document. It has worked as far as I have seen in my testing.
Using double quotes around the SVG data conflicts with the style attribute's quotes. Using single quotes around the SVG data conflicts with the single quotes in the optimized SVG encoding. Using single quotes for the style attribute as a whole with double quotes around the data also conflicts with the single quotes in the optimized SVG encoding. Using no quotes around the SVG data does not work (I believe because of spaces in the data). I have not thought of any other possible solution but I am open to suggestions.
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.
Thanks for the deep explanation.
What about escaping singles quotes in the SVG image?
const escapeSingleQuotes = (value) => value.replace(/'/g, '\\\'');
<div style="
background-image: url('${escapeSingleQuotes(placeholderImageData)}');
background-size: cover;
"
></div>
IMHO, it makes the code more self explanatory.
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.
Thanks for the suggestion. It definitely is a cleaner solution. I just pushed a commit along these lines. Apparently webpack or something else is optimizing it along the way, so to make things even better there was no increase in the number of bytes sent to the browser even with the escaped quotes.
Would be great to get this merged! |
I would love to see this approved as well! |
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.
Verified and works as expected. Thanks! And sorry @tlent for looong wait on this.
Published in [email protected] |
Works nicely! |
Closes #9414, #4624
Unfortunately due to #4510 the effect cannot currently be seen unless
{ backgroundColor: "transparent" }
is set in the gatsby-remark-images options. I will try looking into that issue soon.Please let me know if any changes need to be made. This is my first contribution to Gatsby.