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

fix(gatsby-plugin-image): Hide placeholder on hydrated components with loaded images #29333

Merged
merged 3 commits into from
Feb 5, 2021

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Feb 4, 2021

We need to allow handling of "loaded" tracking when already hydrated. We also need to pass loading=lazy to browser components, not just server. Fixes an issue where navigating between pages that shared images was causing the placeholder to never be hidden.

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 4, 2021
@ascorbic ascorbic added topic: media Related to gatsby-plugin-image, or general image/media processing topics and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Feb 4, 2021
@ascorbic ascorbic added this to To cherry-pick in V2 Release hotfixes via automation Feb 4, 2021
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.

It fixes the issue but it's actually a little bit of a sideEffect, none the less I don't see any issues with it. I would like to see tests to actually catch this in the future.

Something to consider to not have these sideEffects anymore is to wrap the GatsbyImage component in gatsby-image.browser.tsx with React.memo so we don't re-trigger the component when we don't have to.

To reproduce what this PR fixes is to simply add a React.useState & React.useEffect to your page.

  const [data, setData] = React.useState(null)

  React.useEffect(() => {
    setTimeout(() => {
      setData("test")
    }, 1000)
  },)

@ascorbic ascorbic merged commit 1443ecd into master Feb 5, 2021
@ascorbic ascorbic deleted the fix/blurry-placeholder branch February 5, 2021 16:15
ascorbic added a commit that referenced this pull request Feb 5, 2021
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
(cherry picked from commit 1443ecd)
@ascorbic ascorbic moved this from To cherry-pick to Backport PR opened in V2 Release hotfixes Feb 5, 2021
ascorbic added a commit that referenced this pull request Feb 5, 2021
)

Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
(cherry picked from commit 1443ecd)

Co-authored-by: Matt Kane <matt@gatsbyjs.com>
@ascorbic ascorbic moved this from Backport PR opened to Backported in V2 Release hotfixes Feb 5, 2021
@ascorbic
Copy link
Contributor Author

ascorbic commented Feb 5, 2021

Published in gatsby-plugin-image@0.7.1

@t2ca
Copy link
Contributor

t2ca commented Feb 5, 2021

Published in gatsby-plugin-image@0.7.1

Thank you @ascorbic, this fixed the issue for me.

@sandren
Copy link

sandren commented Feb 7, 2021

@ascorbic Is this supposed to be fixed in gatsby-plugin-image@1.0.0.next as well?

I'm still experiencing the same issue when using gatsby@3.0.0.next, gatsby-plugin-sharp@3.0.0.next, gatsby-transformer-sharp@3.0.0.next, and gatsby-plugin-image@1.0.0.next together.

@ascorbic
Copy link
Contributor Author

ascorbic commented Feb 7, 2021

@sandren It's not in next yet. I'll do a release tomorrow

@laurenskling
Copy link
Contributor

This feature (and release 0.7.1) didn't end up in the changelog?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: media Related to gatsby-plugin-image, or general image/media processing topics
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants