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): Fix blur-up preview image not working on initial page load #14816
Conversation
Previously this effect only worked for AJAX-based page loads. This change allows the effect to (mostly) work on initial load when the JS isn't yet loaded. If JS is already loaded then the original behaviour is preserved.
This increases the head size by 160 bytes but decreases the size of each image element by 103 bytes. The head is only downloaded on initial page load (not AJAX loads), so if the visitor encounters 2 or more images during their visit then this change was worth it.
Hi @KyleAMathews , could you provide me some guidance here? I'm having trouble with the tests. The gatsbygram e2e tests seem to be failing, but the gatsbygram example doesn't use gatsby-remark-images at all, so I can't see how I would've broken it. I'm also having trouble running the e2e tests locally. EDIT: After pulling the latest changes from master the tests are now passing. I think they just needed to be re-run, whatever issue was there must've been transient. |
Hey, I've updated my changes to match master, but now some of the tests are failing. I don't think the failures have anything to do with me, they seem transient. Could someone please re-run the CircleCI workflow? |
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 fixing this! I've added a small nit. I couldn't update your branch myself so can you also merge master in? This way our tests should work again.
Thank you for your patience and getting this out the door!
@@ -1,3 +1,13 @@ | |||
exports.defaults = { |
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.
exports.defaults
might be confused with export default
so maybe rename it to something verbose like DEFAULT_OPTIONS
.
exports.defaults = { | |
exports.DEFAULT_OPTIONS= { |
As @wardpeet pointed out, `exports.defaults` could be mistaken for `export default`
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.
looks good, thank you!
Thanks @wardpeet , checks are passing now. Looking forward to getting this merged! :) |
Holy buckets, @JoshuaWalsh — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Is moving the styles to |
@fionawhim It's just an optimisation/cleanliness-improvement. It's not required for the functionality. |
Fixes gatsbyjs#17593 This PR reverts a part of gatsbyjs#14816 that moved the image styles into a <style> tag in the head. Per this comment from @JoshuaWalsh, putting the styles in the <head> was just a cleanliness improvement, and did not affect the functionality that gatsbyjs#14816 was addressing: gatsbyjs#14816 (comment) Reverting this PR allows the responsive images to display correctly when the Remark HTML is displayed outside of the Gatsby layout, such as in an RSS feed.
* Moves responsive image CSS back into attribute Fixes #17593 This PR reverts a part of #14816 that moved the image styles into a <style> tag in the head. Per this comment from @JoshuaWalsh, putting the styles in the <head> was just a cleanliness improvement, and did not affect the functionality that #14816 was addressing: #14816 (comment) Reverting this PR allows the responsive images to display correctly when the Remark HTML is displayed outside of the Gatsby layout, such as in an RSS feed. * Updates Jest snapshots for image style changes
* Moves responsive image CSS back into attribute Fixes #17593 This PR reverts a part of #14816 that moved the image styles into a <style> tag in the head. Per this comment from @JoshuaWalsh, putting the styles in the <head> was just a cleanliness improvement, and did not affect the functionality that #14816 was addressing: gatsbyjs/gatsby#14816 (comment) Reverting this PR allows the responsive images to display correctly when the Remark HTML is displayed outside of the Gatsby layout, such as in an RSS feed. * Updates Jest snapshots for image style changes
* Moves responsive image CSS back into attribute Fixes #17593 This PR reverts a part of #14816 that moved the image styles into a <style> tag in the head. Per this comment from @JoshuaWalsh, putting the styles in the <head> was just a cleanliness improvement, and did not affect the functionality that #14816 was addressing: gatsbyjs/gatsby#14816 (comment) Reverting this PR allows the responsive images to display correctly when the Remark HTML is displayed outside of the Gatsby layout, such as in an RSS feed. * Updates Jest snapshots for image style changes
Description
This fixes a bug where the blur-up preview image would not work correctly on initial page load, because the image would load before the JavaScript necessary for the effect.
This change enables a simple blur-up effect (without the fade animation) to work even with JavaScript disabled. Once the JavaScript loads, the original fade effect is restored for any images that are still loading.
It's worth noting that this change does hide the alt text by setting the colour to transparent, and uses JavaScript to show the alt text once the image loading is completed (either due to failure or success) so for users with JavaScript disable the alt text will not appear. For this reason I have also made the alt text appear as the title of the image if the image didn't already have a title.
This change should not impact accessibility, as screen readers don't seem to care about the colour of image alt text.
Before:
After:
Related Issues
These changes fix #14325.