-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Image onLoad triggers late #64458
Comments
Here's a video demonstrating how this looks on my own site, after build and running You first see it with "Fast 3G," and then I refresh again with no throttling. Image.onLoad.problem.mp4 |
I've noticed this too, I was trying to fade in images once they had loaded by removing an |
I suspect it is due to the fact that Image component is using ref for the In a nutshell
To not over-engineer this with images having separate, smaller, high-priority bundles I suggest using plain CSS absolute element with lower z-index which gets overlapped by the image when loaded |
Ah that makes a lot of sense. I suppose people can always render an online |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/hardcore-keller-xt5l7m?file=/app/TestImage.tsx:18,29
To Reproduce
Current vs. Expected behavior
I expect "onLoad" to trigger immediately when the image has loaded. Thus, any kind of placeholder, skeleton, or such will cease when the image is fully visible, and any such effect would not continue to apply on the image.
But that's not what happens.
In this simplified code demonstration, the red background represents the loading state, and that (and any styles or classes) should be removed when the image is loaded. I like to add
animate-pulse
from Tailwind on my loading skeletons, but I stuck withopacity: 0.25
for simplicity. That red background gets replaced with the image, but any classes or styles are still applied to the image after the image has already loaded. So in this case, the image remains at 25% opacity. Then after a few seconds (on "Fast 3G"),onLoad
finally triggers and the change of state removes the styles and the image returns to full opacity.This happens in both
dev
andstart
.Provide environment information
Which area(s) are affected? (Select all that apply)
Image optimization (next/image, next/legacy/image)
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
I've experienced this since I started using Next.js with version 13. CodeSandbox is using 14.2.0-canary.9, but the problem still exists.
I've tried some crazy workarounds to this, but they are all unsatisfactory. I want this to just work.
The text was updated successfully, but these errors were encountered: