-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Bug: img element not dispatching error events when trying to get a non-existent resource from the same origin #8271
Comments
Your diagnosis...
...is correct. Unfortunately I'm not sure if there's a way to detect whether an image previously failed to load, which seems like a shocking omission on the part of the platform. I would love to be corrected here! |
Yeah, that was my diagnosis as well when I looked at this issue back when it was opened, but apparently I never commented on it. It was similar to a previous issue about 'how can I find out when an image was loaded', where the answer was 'write an action that checks whether it's already loaded and attach an event handler if not' - but in this case, I recall not being able to find a 'did this image already fail to load' property on the DOM, which seemed bizarre. |
In terms of what to actually do about this, what I would try is an old-fashioned |
You can also check if I'm going to close this as I don't think there's anything we could be doing differently here, this is just an unfortunate characteristic of the platform. |
fair enough. thanks @Conduitry and @Rich-Harris for looking at it. cheers |
I found a strange concoction of workarounds to make onerror work on sveltekit. {@html `<img src="${img}" alt="${name}" onerror="this.style.visibility = 'hidden'" />`} Works for my use case. |
Describe the bug
I have the following code in SvelteKit:
The
on:error
event callback is never called.However, if I change the source to
hello-there
, and I refresh the page, I get the following error in the console:GET http://localhost:5173/hello-there 404 (Not Found)
, but the callback is not called.However, if I make a change and let the HMR reload the contents, the error callback is called!!
Additionally, if I change the src to another domain, for example,
https://123thisshouldntexit.com/cdieo
, the error callback is always called, no matter if it's a new page load or HRM.I wonder if it's due to the svelte JS being loaded after the initial HTML is loaded, so all events are "lost" or "missed" by the runtime.
If that's the case, is there a way to know if an image didn't load? I usually use the
error
event, but I don't know if it's reliable with SvelteKit.Reproduction
https://github.com/charlie632/sveltkit-bug-image-repro/blob/main/src/routes/%2Bpage.svelte
Just go to the default localhost and open the console.
Do a change, and when the HMR hits, the console should have all three logs.
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: