-
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): make images blur up #7800
Conversation
Looks promising! Instead of inlining the code however (which would cause a lot of code duplication), you can add the code using gatsby-ssr.js to the |
@KyleAMathews I've given this a go but under tests it would seem that |
This is for server rendering. Check out some of the other components that use this? Another option is to use https://www.gatsbyjs.org/docs/browser-apis/#onRouteUpdate |
Newest update moves script to |
Oh nice! Yeah, you need to change the package's babelrc to be like this so the browser code is transpiled https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-image/.babelrc |
Spot on 👍 all up to date now ready for another review round :) |
@KyleAMathews I've removed the [WIP] tag as I think we've gotten to a good point now. Final improvements:
I've updated the snapshot in line with the changes so we should be ready to go barring any feedback you guys have :) let me know if you want any tweaks. As a side note I found when using a for of loop, babel didn't seem to be transpiling this to valid es5 (it uses Symbol which is es2015) is this an issue that needs to be picked up separately? |
fc4ca3e
to
2116fff
Compare
left: 0; | ||
transition: opacity 0.5s; | ||
transition-delay: 0.5s; | ||
box-shadow: inset 0px 0px 0px 400px ${ |
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.
Was making this verbose intentional? This inflates outputted html with extra bytes. Perhaps we can keep it in readable form but actually output compressed code?
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.
Sure, my assumption was that this was minified down so shouldn't make a difference but much easier to understand what's going on.
>${imageTag}</span> | ||
<img | ||
class="${imageBackgroundClass}" | ||
style="width: 100%; height: 100%; position: relative; bottom: 0; left: 0; transition-delay: 0.5s; tranistion: opacity 0.5s; opacity: 1; 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.
typo in transition
property
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'm also not sure if it's good idea changing span to img here - there might be a11y implications if screenreader see 2 image tags instead of one for essentially same image?
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.
Hmmm... not sure to be honest I'll take your guidance on this one. Looking at gatsby-image
it seems that the actual image is wrapped in a Tag that's passed in as a prop. So would we put this back into the span and keep the background as is? As this would be similar to what's going on there.
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.
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.
From memory it was while I was working through a good way to implement it so went through several variations so I think this is probably just a side effect. I'll add it back in so essentially the below?
<img class="${imageBackgroundClass}" ... />
<span>${imageTag}</span>
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.
so previously it was
<span class="gatsby-resp-image-wrapper">
<span class="gatsby-resp-image-background-image">
<img>
</span>
</span>
which won't work if we won't to hide placeholder that previously was in .gatsby-resp-image-background-image
(as it would hide img too) maybe this:
<span class="gatsby-resp-image-wrapper">
<span class="gatsby-resp-image-background-image"></span>
<img>
</span>
to change as little as possible (limit potential regressions) in this PR?
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'll have a play around to see what works 👍 thanks for comments, appreciate it :)
exports.onRouteUpdate = () => { | ||
const imageWrappers = document.querySelectorAll(`.${imageWrapperClass}`) | ||
|
||
Array.prototype.forEach.call(imageWrappers, (imageWrapper) => { |
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 think it would be much more readable if you would use:
const imageWrappers = Array.from(document.querySelectorAll(`.${imageWrapperClass}`))
imageWrappers.forEach(imageWrapper => {
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 remember why I didn't do this. There is no polyfill currently loaded and felt probably wasn't worthwhile in this case since readability was similar. Do you think it's worth adding a polyfill or keep as is @pieh?
Yeah, IntersectionObserver is great as it's a cheap way to implement lazy loading — so definitely great but can come in a follow-up PR |
Hey @pieh, I've addressed all feedback apart from 2 points.
Let me know if there's anything else I can do or you have any questions :) |
But this was already working with
That is not correct - placeholder image in Main issue here is that you are applying unneeded changes that don't fix anything and potentially cause some problems :(
You are right, I should have check to see if it's safe to use. Might be worth commenting there that we are not using something easier to use because we would need to polyfill it? |
@pieh a) any guidance on where this should be done? |
I mean this could be just code comment right above you using it - it would be great if this would something like article we could link to (i.e. https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/ ). Which btw it seems like using classic |
true, I'll refactor to |
Think we're there @pieh :) not a |
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 @jamesadarich!
Holy buckets, @jamesadarich — 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! |
published |
Would be great if someone could make gatsby-remark-images-contentful compatible with this update. Thanks! |
thank you all for finalizing this. @jamesadarich do you intend on having a look at lazy loading for this? i am happy to give this a go IF you don't intend to / not have time. i don't use contentful so i won't touch that part sorry :/ |
This is awesome! Great work @jamesadarich! |
@KyleAMathews thanks, loving Gatsby glad I could give something back :) @pieh thanks for your patience and assistance with this one 👍 @t2ca I've just had a brief look at this package and has a lot of stuff in common so probably worth sharing some of the functionality for sure. Maybe we could talk about how to do that if it's something you're keen on doing? Feel free to contact me directly :) Like with @oorestisime it's not something I use but it'd be cool to refactor the code to have more shared stuff so it's interesting but I think lazy loading for me is higher priority @oorestisime I definitely did want to have a peek at this but maybe it's something we can collaborate on if that works for you? :) |
nah go ahead! my intention was just to make sure this gets done. it is not urgent, for me, so go for it. (i can have a look/test it once you have something :) ) |
BREAKING CHANGE: html markup has been changed, high resolution image (img.gatsby-resp-image-image) is no longer nested inside span with low resolution placeholder (span.gatsby-resp-image-wrapper) - it's sibling of that span now. This might affect any custom styling that is applied to inline images
Hey guys,
This is a proposal for adding functionality to mimic the blur up effect in
gatsby-image
forgatsby-remark-images
. This could be nicer I think but I can't see an obvious way to do that without a great deal of refactoring around how the remark plugins are integrating (but hopefully you guys can guide to an awesome solution :) )The pros and cons of this solution, I believe, are as follow;
Pros
Cons
Let me know what you guys think about the solution and any ideas you guys have