react-lazy-load-image-component
react-lazy-load-image-component copied to clipboard
When rendered isomorphically it's possible for the `afterLoad` callback to never get called
Bug description
If you render LazyLoadImage component isomorphically, it's possible that the image is downloaded by the browser before the component mounts. When this happens, the afterLoad callback never gets called.
Expected behavior
LazyLoadImage should check if the img DOM node has loaded or errored upon mounting and trigger the appropriate callbacks. Currently, I have the LazyLoadImage component wrapped in a HOC that implements the following componentDidMount logic which seems to fix the issue
componentDidMount() {
const img = findDOMNode(this) as HTMLImageElement;
if (img && img.complete && img.naturalWidth !== 0) {
this.onLoad();
}
}
Technical details:
- Package version 1.5.0
- Server Side Rendering? Yes
- Device any
- Operating System any
- Browser? Chrome, iOS Safari
Hi @jkkjonah, thanks for reporting this! I didn't test it yet, but if you open a PR I would try to review it as soon as possible.
Thanks in advance!