Error fallback image with loadEagerly?
See original GitHub issueI need an image that should be rendered asap (I’m using SSR with next.js), and currently I’m using the loadEagerly
prop in this image… However, I found interesting that if for some reason this image doesn’t exist, display the fallback image… Looks that with loadEagerly is only rendering the actual.
There is some another option to do it?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
HTML fallback images on error - Daily Dev Tips
So I decided to look into fallback images. And it's surprisingly easy. What we want to achieve: Load the image; If it doesn't...
Read more >Configure Fallback Images in React and Next.js
Therefore, I created a piece of state so I could rerender the component in case of an error: import fallback from "../public/fallback-image.png" ...
Read more >react-lazy-images - npm Package Health Analysis - Snyk
React utilities for lazy image loading For more information about how to use this package see README. Latest version published 4 years ago....
Read more >Embedded content - 4.8.1 - The picture element - HTML Spec
< script > function fallback ( video ) { // replace <video> with its contents ... The images load eagerly and delay the...
Read more >Native image lazy-loading for the web - Hacker News
The problem with the tech bubble these days is that people within it ... I would prefer to choose for myself whether images...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the workaround that you mention with
onError
is the best way to handle loadEagerly + error handling at the moment.The second scenario with
loadEagerly={!process.browser}
will have quirks, because the image will be re-rendered when the client sripts rehydrate. This is why you get the “blinking” behaviour even if there is no error - it’s the image entering the “Loading” state again.The reason the workaround only works sometimes, as far as I can tell, is that the event could fire before the client scripts have downloaded/parsed/executed. I don’t think it’s Next.js specific, but rather how hydration and events work. I could be wrong though!
A potential solution
This discussion does give me an idea:
loadEagerly
, then we move to a new state,Refreshing
Referesing
state, we would keep rendering theactual
, and also kick off an observed image loadLoaded
orError
states, as beforeIn theory, this means:
error
is usedI have some free time over the next few days, and was looking into tackling some leftover issues here. I’ll let you know if I manage to get a beta version out. No guarantees that it’ll work, but we can try it and get some feedback 😃
Better detailed:
hook:
Usage: