react-lazy-load-image-component icon indicating copy to clipboard operation
react-lazy-load-image-component copied to clipboard

When rendered isomorphically it's possible for the `afterLoad` callback to never get called

Open jkkjonah opened this issue 5 years ago • 1 comments

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

jkkjonah avatar Jul 21 '20 21:07 jkkjonah

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!

Aljullu avatar Jul 28 '20 16:07 Aljullu