react-infinite-scroll-component icon indicating copy to clipboard operation
react-infinite-scroll-component copied to clipboard

Not calling next function on long screens

Open ardeshiir opened this issue 2 years ago • 15 comments

When the window is zoomed out and the component is initialized the component will stuck on loading wont call the next function

sample

ardeshiir avatar May 01 '23 14:05 ardeshiir

@finishedcoot I still have this issue. What's the fix?

tofiqquadri avatar May 31 '23 07:05 tofiqquadri

@finishedcoot I'm having the same issue? What's the fix?

techwithanirudh avatar Jun 03 '23 03:06 techwithanirudh

@finishedcoot How could I use your fork without having yarn installed?

techwithanirudh avatar Jun 03 '23 15:06 techwithanirudh

@techwithanirudh @tofiqquadri Temporarily you can install the package by changing your package.json to be like this and reinstall the module. But I recommend to change it back after the maintainer fixed this issue ASAP.

"react-infinite-scroll-component": "git+https://github.com/Stacrypt/react-infinite-scroll-component",

ardeshiir avatar Jun 06 '23 07:06 ardeshiir

hola yo pude resolver el hecho que no llame a la función "next", lo que me daba error era usar el componente dentro de una etiqueta que usara "Overflow: auto"

LibardoVega avatar Jun 07 '23 19:06 LibardoVega

acabe de revisar bien la documentación y hace falta el "scrollableTarget" con eso ya pude usar el "Overflow: auto"

LibardoVega avatar Jun 07 '23 20:06 LibardoVega

I avoided using this library since it has this major bug open and it has not yet solved.

Instead of this I used IntersectionObserver and implemented the functionality of this library myself.

tofiqquadri avatar Jun 08 '23 08:06 tofiqquadri

I am too waiting on this!

kimkong88 avatar Jun 30 '23 23:06 kimkong88

I'm having the same issue!

Fernando-Hooklab avatar Jul 12 '23 20:07 Fernando-Hooklab

I'm having the same issue!

my workaround was just to fetch enough data for single page OR have each item card large enough to fit scroll.. OR load more manually(not waiting for scroll to reach the bottom) based on height

kimkong88 avatar Jul 12 '23 20:07 kimkong88

Issue still persists. See this codepen for example: https://codesandbox.io/s/amazing-hermann-x2qw8m?file=/src/index.js

Unfortunately this cripples the library for anything besides simple/single-page infinite scroll apps.

ryanschiang avatar Jul 23 '23 20:07 ryanschiang

Here's my workaround InfiniteScroll component, using IntersectionObserver:

interface InfiniteScrollProps {
  load: () => void;
  hasMore: boolean;
  loader: React.ReactNode;
  children?: React.ReactNode;
  endMessage?: React.ReactNode;
}

export const InfiniteScroll: React.FC<InfiniteScrollProps> = ({
  load,
  hasMore,
  loader,
  children,
  endMessage,
}) => {
  const sentinelRef = useRef<HTMLDivElement>(null);
  const observerRef = useRef<IntersectionObserver | null>(null);

  const handleIntersect = useCallback(
    (
      entries: IntersectionObserverEntry[],
      observer: IntersectionObserver
    ) => {
      // Check if the sentinel element is intersecting, and if so, call the load function
      if (entries[0].isIntersecting && hasMore) {
        load();
      }
    },
    [load]
  );

  useEffect(() => {
    // Create a new IntersectionObserver when the component mounts
    observerRef.current = new IntersectionObserver(handleIntersect, {
      root: null,
      rootMargin: "0px",
      threshold: 1.0,
    });

    // Attach the observer to the sentinel element
    if (sentinelRef.current) {
      observerRef.current.observe(sentinelRef.current);
    }

    // Clean up the observer when the component unmounts
    return () => {
      if (observerRef.current) {
        observerRef.current.disconnect();
      }
    };
  }, [load]);

  useEffect(() => {
    // When the hasMore prop changes, disconnect the previous observer and reattach it to the new sentinel element
    if (observerRef.current && sentinelRef.current) {
      observerRef.current.disconnect();
      observerRef.current.observe(sentinelRef.current);
    }
  }, [hasMore]);

  return (
    <div>
      {children}
      <div ref={sentinelRef}>{hasMore && loader}</div>
      {!hasMore && endMessage}
    </div>
  );
};

ryanschiang avatar Jul 23 '23 22:07 ryanschiang

You can workaround this issue with a hook, check the following response

https://github.com/ankeetmaini/react-infinite-scroll-component/issues/391#issuecomment-1734154621

eamador avatar Sep 25 '23 17:09 eamador

IntersectionObserver

any chance you could expand on that a bit?

fridaystreet avatar Aug 08 '24 22:08 fridaystreet