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

feat(gatsby-remark-images): Fix blur-up preview image not working on initial page load #14816

Merged
merged 14 commits into from Jul 4, 2019

Conversation

YoshiWalsh
Copy link
Contributor

@YoshiWalsh YoshiWalsh commented Jun 16, 2019

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:
blurUp

After:
gatsby-remark-images

Related Issues

These changes fix #14325.

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.
@YoshiWalsh YoshiWalsh requested a review from a team as a code owner June 16, 2019 05:59
@YoshiWalsh
Copy link
Contributor Author

YoshiWalsh commented Jun 17, 2019

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.

@YoshiWalsh YoshiWalsh changed the title Topic/issue 14325 Fix blur-up preview image not working on initial page load Jun 17, 2019
@lannonbr lannonbr added the status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response label Jun 29, 2019
@YoshiWalsh
Copy link
Contributor Author

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?

@wardpeet wardpeet self-assigned this Jul 4, 2019
wardpeet
wardpeet previously approved these changes Jul 4, 2019
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 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 = {
Copy link
Contributor

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.

Suggested change
exports.defaults = {
exports.DEFAULT_OPTIONS= {

@wardpeet wardpeet added status: awaiting author response Additional information has been requested from the author and removed status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response labels Jul 4, 2019
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.

looks good, thank you!

@YoshiWalsh
Copy link
Contributor Author

Thanks @wardpeet , checks are passing now. Looking forward to getting this merged! :)

@wardpeet wardpeet merged commit c4a7c40 into gatsbyjs:master Jul 4, 2019
@gatsbot
Copy link

gatsbot bot commented Jul 4, 2019

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:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. We’ve got Gatsby t-shirts, stickers, hats, scrunchies, and much more. (You can also unlock even more free swag with 5 contributions — wink wink nudge nudge.) See gatsby.dev/swag for details.
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

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!

@wardpeet wardpeet changed the title Fix blur-up preview image not working on initial page load feat(gatsby-remark-images): Fix blur-up preview image not working on initial page load Jul 4, 2019
@fionawhim
Copy link
Contributor

Is moving the styles to <head> required for functionality, or is it just a potential size optimization?

@YoshiWalsh
Copy link
Contributor Author

@fionawhim It's just an optimisation/cleanliness-improvement. It's not required for the functionality.

fionawhim added a commit to fionawhim/gatsby that referenced this pull request Nov 30, 2019
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.
gatsbybot pushed a commit that referenced this pull request Dec 9, 2019
* 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
gatsbybot pushed a commit to gatsbyjs/gatsby-starter-blog that referenced this pull request Dec 9, 2019
* 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
leonhiat added a commit to leonhiat/gatsby-starter-blog that referenced this pull request Oct 31, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting author response Additional information has been requested from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blurred image only shown briefly
4 participants