Skip to content

Commit 746cec9

Browse files
committed
fix: enforce element visibility if resizing while scrolling
1 parent 6fdee22 commit 746cec9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ export function VirtualElement({
116116
}
117117
}, [ref, inView, placeholderHeight])
118118

119+
// failsafe to ensure visible elements if resizing happens while scrolling
120+
useEffect(() => {
121+
if (inView && !isShowingChildren) {
122+
// If element is in view but showing placeholder, force show children
123+
const forceShowTimeout = setTimeout(() => {
124+
setIsShowingChildren(true)
125+
}, 400)
126+
127+
return () => {
128+
clearTimeout(forceShowTimeout)
129+
}
130+
}
131+
}, [inView, isShowingChildren])
132+
133+
useEffect(() => {
134+
const checkVisibilityOnScroll = () => {
135+
if (inView && !isShowingChildren) {
136+
setIsShowingChildren(true)
137+
}
138+
}
139+
140+
window.addEventListener('scroll', checkVisibilityOnScroll, { passive: true })
141+
142+
return () => {
143+
window.removeEventListener('scroll', checkVisibilityOnScroll)
144+
}
145+
}, [inView, isShowingChildren])
146+
119147
useEffect(() => {
120148
if (inView) {
121149
setIsShowingChildren(true)

0 commit comments

Comments
 (0)