Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does this support a fallback image if the img is not loaded?

See original GitHub issue

I think it should roll back to placeholderSrc if src is not found…

I can check at my end if there is no property, but if its set to black; the library before would just try to load a broken image; instead it should return something that makes the placeholderSrc render.

I used this

src={img_url ? img_url : placeholderImg}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

rainecommented, Jul 12, 2020

If src is defined but loading the image fails for some reason, the onload event is not fired so the placeholder image would still be visible.

This is not what I’m seeing. <img> element is there even if loading the image fails.

mydearxymcommented, Apr 24, 2020

i think a fallback props or onError callback is needed,take the README examle:

const Article = ({ articleId }) => (
    <ArticleContent id={articleId} />
    <LazyLoadComponent placeholder={LoadingComp} fallback={ErrorHint}>
      <ArticleComments id={articleId} />

if the Comments Comp is load failed for some reason, i can show the ErrorHint Comp

another realworld example is the net::ERR_CONNECTION_REFUSED error when load image fails can not fallback to placeholder, and i have to do very ugly staff to do that


Read more comments on GitHub >

github_iconTop Results From Across the Web

Inputting a default image in case the src attribute of an html ...
when an error occurs, all srcset's are set to the fallback version. a broken link image is not showing up. it does not...
Read more >
Handling <img /> fallback. - Medium
Our first problem is when an image URL is stored in DB and that URL can be broken due to any reason. we...
Read more >
HTML only image fallback - DEV Community ‍ ‍
Below an image is embedded in an 'object' tag. If that image is not loaded correctly (e.g. inexistent image) the 'img' inside it...
Read more >
Native Lazy Image Loading With JavaScript Fallback
Until recently, lazy image loading required JavaScript - typically by reconfiguring <img> s with a placeholder and then detecting when each image comes...
Read more >
HTML fallback images on error - Daily Dev Tips
So what can we do when this happens? We can use the onerror attribute on the image to set a fallback. It works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found