onLoad event doesn't trigger
Hello everyone. I ran into the issue, that the onLoad event on an <img> does not trigger.
Here is the code in question: https://stackblitz.com/edit/github-a9ukgq-25tgxa?file=src%2Fpages%2FHome.tsx,src%2Fcomponents%2Fcomp.tsx,src%2Fcomponents%2Fcomp.css
StackBlitz
Solid-start Basic Example (forked) - StackBlitz
Run official live example code for Solid-start Basic, created by Solidjs on StackBlitz
3 Replies
It looks like it works the very first time.
However once the image is cached by the browser the image is already loaded (and complete is
true
) by the time the event listener is added, so onLoad
never fires.MDN Web Docs
HTMLImageElement: complete property - Web APIs | MDN
The read-only HTMLImageElement interface's
complete attribute is a Boolean value which indicates
whether or not the image has completely loaded.
I see, thanks!
One possible workaround:
Another one
Combining the ideas: