@@ -94,7 +94,8 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
9494 viewportSize : new Size ( ) ,
9595 scrollEndTime : 0 ,
9696 scrollTimeout : null as ReturnType < typeof setTimeout > | null ,
97- isScrolling : false
97+ isScrolling : false ,
98+ lastVisibleRect : new Rect ( )
9899 } ) . current ;
99100 let { direction} = useLocale ( ) ;
100101
@@ -105,15 +106,19 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
105106 // their sizes into account for performance reasons. Their scroll positions are accounted for in viewportOffset
106107 // though (due to getBoundingClientRect). This may result in more rows than absolutely necessary being rendered,
107108 // but no more than the entire height of the viewport which is good enough for virtualization use cases.
108- let visibleRect = allowsWindowScrolling
109+ let visibleRect = allowsWindowScrolling
109110 ? new Rect (
110111 state . viewportOffset . x + state . scrollPosition . x ,
111112 state . viewportOffset . y + state . scrollPosition . y ,
112113 Math . max ( 0 , Math . min ( state . size . width - state . viewportOffset . x , state . viewportSize . width ) ) ,
113114 Math . max ( 0 , Math . min ( state . size . height - state . viewportOffset . y , state . viewportSize . height ) )
114115 )
115116 : new Rect ( state . scrollPosition . x , state . scrollPosition . y , state . size . width , state . size . height ) ;
116- onVisibleRectChange ( visibleRect ) ;
117+ // Don't emit updates if the visible area is zero and the last emitted area was also zero.
118+ if ( visibleRect . area > 0 || state . lastVisibleRect . area > 0 ) {
119+ onVisibleRectChange ( visibleRect ) ;
120+ state . lastVisibleRect = visibleRect ;
121+ }
117122 } , [ state , allowsWindowScrolling , onVisibleRectChange ] ) ;
118123
119124 let [ isScrolling , setScrolling ] = useState ( false ) ;
0 commit comments