Skip to content

Commit 4b73344

Browse files
committed
fix: ensure elements in view are always visible
1 parent 0b98431 commit 4b73344

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

packages/webui/src/client/lib/VirtualElement.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function VirtualElement({
7070
const [ref, setRef] = useState<HTMLDivElement | null>(null)
7171

7272
// Timers for visibility changes:
73+
const scrollTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
7374
const inViewChangeTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
7475
const skipInitialrunRef = useRef<boolean>(true)
7576
const isTransitioning = useRef(false)
@@ -130,17 +131,45 @@ export function VirtualElement({
130131
}
131132
}, [inView, isShowingChildren])
132133

134+
// Ensure elements are visible after a fast scroll:
133135
useEffect(() => {
134136
const checkVisibilityOnScroll = () => {
135137
if (inView && !isShowingChildren) {
136138
setIsShowingChildren(true)
137139
}
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)
138151
}
139152

140153
window.addEventListener('scroll', checkVisibilityOnScroll, { passive: true })
141154

142155
return () => {
143156
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)
144173
}
145174
}, [inView, isShowingChildren])
146175

@@ -191,7 +220,7 @@ export function VirtualElement({
191220
isTransitioning.current = false
192221
inViewChangeTimerRef.current = undefined
193222
}
194-
}, 50)
223+
}, 100)
195224
}, [inView, ref, handleResize, resizeObserverManager])
196225

197226
const onVisibleChanged = useCallback(

0 commit comments

Comments
 (0)