1- import React , { PropsWithChildren , useEffect , useLayoutEffect , useRef } from 'react' ;
1+ import React , { PropsWithChildren , useEffect , useRef } from 'react' ;
22import type { PaginatorProps } from '../../types/types' ;
33import { deprecationAndReplacementWarning } from '../../utils/deprecationWarning' ;
44import { DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD } from '../../constants/limits' ;
@@ -73,6 +73,8 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
7373 const hasPreviousPageFlag = hasPreviousPage || hasMore ;
7474
7575 const scrollComponent = useRef < HTMLElement > ( ) ;
76+ const previousOffset = useRef < number | undefined > ( ) ;
77+ const previousReverseOffset = useRef < number | undefined > ( ) ;
7678
7779 const scrollListenerRef = useRef < ( ) => void > ( ) ;
7880 scrollListenerRef . current = ( ) => {
@@ -93,7 +95,12 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
9395 }
9496
9597 if ( isLoading ) return ;
96- // FIXME: this triggers loadMore call when a user types messages in thread and the scroll container container expands
98+ if ( previousOffset . current === offset && previousReverseOffset . current === reverseOffset )
99+ return ;
100+ previousOffset . current = offset ;
101+ previousReverseOffset . current = reverseOffset ;
102+
103+ // FIXME: this triggers loadMore call when a user types messages in thread and the scroll container expands
97104 if (
98105 reverseOffset < Number ( threshold ) &&
99106 typeof loadPreviousPageFn === 'function' &&
@@ -120,7 +127,7 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
120127 // eslint-disable-next-line react-hooks/exhaustive-deps
121128 } , [ ] ) ;
122129
123- useLayoutEffect ( ( ) => {
130+ useEffect ( ( ) => {
124131 const scrollElement = scrollComponent . current ?. parentNode ;
125132 if ( ! scrollElement ) return ;
126133
0 commit comments