Aljullu / react-lazy-load-image-component

React Component to lazy load images and components using a HOC to track window scroll position.
https://www.npmjs.com/package/react-lazy-load-image-component
MIT License
1.44k stars 109 forks source link

Lazyloading stops working beyond 5K images #48

Open vamzz1 opened 5 years ago

vamzz1 commented 5 years ago

Bug description I have a use case where I have to show the user more than 100K images. My API returns images in batches of 3K images. The lazyloading works on the first batch, i.e, when I render 3K images using the lazyloadcomponent. But when I append the next batch and the batch size increases to 6K. The browser hangs and in the network tab I see that all the images are fetched instead of only the images in the viewport. I see more than 4K requests made in the network tab.

To Reproduce

class ImageGrid extends React.Component {

  render() {
      const { results, imageGridSuffix, scrollPosition } = this.props;

      const imagePlaceholder = <div style={{ width: 224, height: 224, background: "#c9c9c9" }}/>

      let divs = [];

      for (var index=0;index < results.length/3;index++) {
        const result = results[index];
        divs.push(
        <div
          key={`result-${index}`}
          className={styles.canvasRoot}
        >
          <LazyLoadComponent placeholder={imagePlaceholder} delayTime={0} scrollPosition={scrollPosition} >
            <Canvas />
          </LazyLoadComponent>
        </div>);
      }
      return divs;
    }
}

export default trackWindowScroll(ImageGrid);

Also one thing I noticed is this issue kicks in only once the total batch size of images exceed 5K. before that everything renders as expected.

Expected behavior I expected the component to lazy load irrespective of the array size it's using.

Technical details: