diff --git a/packages/admin/dashboard/src/components/common/infinite-list/infinite-list.tsx b/packages/admin/dashboard/src/components/common/infinite-list/infinite-list.tsx index 612fb4503d..c2a7cf0740 100644 --- a/packages/admin/dashboard/src/components/common/infinite-list/infinite-list.tsx +++ b/packages/admin/dashboard/src/components/common/infinite-list/infinite-list.tsx @@ -77,6 +77,7 @@ export const InfiniteList = < startObserver.current = new IntersectionObserver( (entries) => { if (entries[0].isIntersecting && hasPreviousPage) { + startObserver.current?.disconnect() fetchPreviousPage() } }, @@ -88,6 +89,7 @@ export const InfiniteList = < endObserver.current = new IntersectionObserver( (entries) => { if (entries[0].isIntersecting && hasNextPage) { + endObserver.current?.disconnect() fetchNextPage() } }, @@ -97,8 +99,12 @@ export const InfiniteList = < ) // Register the new observers to observe the new first and last children - startObserver.current?.observe(parentRef.current!.firstChild as Element) - endObserver.current?.observe(parentRef.current!.lastChild as Element) + if (parentRef.current?.firstChild) { + startObserver.current?.observe(parentRef.current.firstChild as Element) + } + if (parentRef.current?.lastChild) { + endObserver.current?.observe(parentRef.current.lastChild as Element) + } } // Clear the old observers