-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
next/image - onLoad event work incorrect #20368
Comments
|
But there is no any method to handle when image start/finish Rendering. |
I'm trying to implement a simple placeholder, but I can't remove the background's animation without |
I think this deserves a second review by NextJs, currently image loading using next/image is very jarring visually. An onLoad event would allow us to have animated loads and css transitions. Is there a different way we're supposed to do this? |
I agree... can't the |
It looks like I was wrong as If anyone's interested, here's my current workaround: <Image
src={img.url}
onLoad={(e) => {
e.target.src.indexOf('data:image/gif;base64') < 0 && handleLoad()
}}
/> We only want to trigger the load handler when the actual image is loaded, hence making sure the source of the target element triggering the event is not base64. This obviously has limitations but this is my best attempt atm. Ideally, the lib would expose both |
Thanks @dbismut! That helps a lot. One thing to note is that the |
I can confirm that onLoad doesn't work with |
I've just had exactly this issue, has anyone dug into why that onload isn't firing? |
Use @timneutkens was correct that image components don't support An onLoad event isn't always triggered in react because react might bind the event handler after an image has already loaded. See the following comment in the next/image source: next.js/packages/next/client/image.tsx Lines 251 to 252 in 80ec93d
|
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
onLoad event on image fires not when user scroll until image, but when page loads, so that's impossible to add any spinner to next/image
To Reproduce
Add next/image component with onLoad event to long page bottom and just reload page, after page load you will see onLoad runs without scroll
Expected behavior
onLoad should work when image on user view port i think, or maybe there is should be onRender method for that.
System information
The text was updated successfully, but these errors were encountered: