@@ -70,6 +70,7 @@ export function VirtualElement({
70
70
const [ ref , setRef ] = useState < HTMLDivElement | null > ( null )
71
71
72
72
// Timers for visibility changes:
73
+ const scrollTimeoutRef = useRef < ReturnType < typeof setTimeout > | undefined > ( undefined )
73
74
const inViewChangeTimerRef = useRef < ReturnType < typeof setTimeout > | undefined > ( undefined )
74
75
const skipInitialrunRef = useRef < boolean > ( true )
75
76
const isTransitioning = useRef ( false )
@@ -130,17 +131,45 @@ export function VirtualElement({
130
131
}
131
132
} , [ inView , isShowingChildren ] )
132
133
134
+ // Ensure elements are visible after a fast scroll:
133
135
useEffect ( ( ) => {
134
136
const checkVisibilityOnScroll = ( ) => {
135
137
if ( inView && ! isShowingChildren ) {
136
138
setIsShowingChildren ( true )
137
139
}
140
+
141
+ // Add a check after scroll stops
142
+ if ( scrollTimeoutRef . current ) {
143
+ clearTimeout ( scrollTimeoutRef . current )
144
+ }
145
+ scrollTimeoutRef . current = setTimeout ( ( ) => {
146
+ // Recheck visibility after scroll appears to have stopped
147
+ if ( inView && ! isShowingChildren ) {
148
+ setIsShowingChildren ( true )
149
+ }
150
+ } , 400 )
138
151
}
139
152
140
153
window . addEventListener ( 'scroll' , checkVisibilityOnScroll , { passive : true } )
141
154
142
155
return ( ) => {
143
156
window . removeEventListener ( 'scroll' , checkVisibilityOnScroll )
157
+ if ( scrollTimeoutRef . current ) {
158
+ clearTimeout ( scrollTimeoutRef . current )
159
+ }
160
+ }
161
+ } , [ inView , isShowingChildren ] )
162
+
163
+ // Periodic check to ensure elements in view are shown
164
+ useEffect ( ( ) => {
165
+ const periodicCheckInterval = setInterval ( ( ) => {
166
+ if ( inView && ! isShowingChildren ) {
167
+ setIsShowingChildren ( true )
168
+ }
169
+ } , 1000 )
170
+
171
+ return ( ) => {
172
+ clearInterval ( periodicCheckInterval )
144
173
}
145
174
} , [ inView , isShowingChildren ] )
146
175
@@ -191,7 +220,7 @@ export function VirtualElement({
191
220
isTransitioning . current = false
192
221
inViewChangeTimerRef . current = undefined
193
222
}
194
- } , 50 )
223
+ } , 100 )
195
224
} , [ inView , ref , handleResize , resizeObserverManager ] )
196
225
197
226
const onVisibleChanged = useCallback (
0 commit comments