1
- import React , { PropsWithChildren , useEffect , useLayoutEffect , useRef } from 'react' ;
1
+ import React , { PropsWithChildren , useEffect , useRef } from 'react' ;
2
2
import type { PaginatorProps } from '../../types/types' ;
3
3
import { deprecationAndReplacementWarning } from '../../utils/deprecationWarning' ;
4
4
import { DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD } from '../../constants/limits' ;
@@ -73,6 +73,8 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
73
73
const hasPreviousPageFlag = hasPreviousPage || hasMore ;
74
74
75
75
const scrollComponent = useRef < HTMLElement > ( ) ;
76
+ const previousOffset = useRef < number | undefined > ( ) ;
77
+ const previousReverseOffset = useRef < number | undefined > ( ) ;
76
78
77
79
const scrollListenerRef = useRef < ( ) => void > ( ) ;
78
80
scrollListenerRef . current = ( ) => {
@@ -93,7 +95,12 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
93
95
}
94
96
95
97
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
97
104
if (
98
105
reverseOffset < Number ( threshold ) &&
99
106
typeof loadPreviousPageFn === 'function' &&
@@ -120,7 +127,7 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
120
127
// eslint-disable-next-line react-hooks/exhaustive-deps
121
128
} , [ ] ) ;
122
129
123
- useLayoutEffect ( ( ) => {
130
+ useEffect ( ( ) => {
124
131
const scrollElement = scrollComponent . current ?. parentNode ;
125
132
if ( ! scrollElement ) return ;
126
133
0 commit comments