Skip to content

Commit 6a9a40e

Browse files
committed
feat: prepare for dynamic resize observers based on inView
1 parent 32786bb commit 6a9a40e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export function VirtualElement({
105105
}
106106

107107
lastVisibilityChangeRef.current = now
108+
if (inView === visible) {
109+
//Setup resize observer and recalculations
110+
} else {
111+
// Stop resize observer:
112+
}
108113

109114
setInView(visible)
110115
},
@@ -147,14 +152,11 @@ export function VirtualElement({
147152
}
148153
}
149154
})
150-
}, 500)
155+
}, 200)
151156
}
152157
}
153158

154-
const findDashboardPanel = (el: HTMLElement | null): HTMLElement | null => {
155-
if (!el) {
156-
return null
157-
}
159+
const findDashboardPanel = (): HTMLElement | null => {
158160
const timelineWrapper = ref?.closest('.segment-timeline-wrapper--shelf')
159161
const dashboardPanel = timelineWrapper?.querySelector('.dashboard-panel')
160162
if (dashboardPanel) {
@@ -164,7 +166,7 @@ export function VirtualElement({
164166
}
165167

166168
const resizeObserver = new ResizeObserver(() => {
167-
const dashboardElement = findDashboardPanel(ref)
169+
const dashboardElement = findDashboardPanel()
168170
// Get heigth of timeline wrapper
169171
const containerHeight = dashboardElement?.clientHeight
170172

@@ -176,20 +178,17 @@ export function VirtualElement({
176178
})
177179

178180
if (ref) {
179-
// Delay the initial observer to allow the UI to render
180-
setTimeout(() => {
181-
const dashboardElement = findDashboardPanel(ref)
182-
if (dashboardElement) {
183-
oldDashboardHeight = dashboardElement?.clientHeight
184-
resizeObserver.observe(ref)
185-
}
186-
}, 2000)
181+
const dashboardElement = findDashboardPanel()
182+
if (dashboardElement) {
183+
oldDashboardHeight = dashboardElement?.clientHeight
184+
resizeObserver.observe(ref)
185+
}
187186
}
188187

189188
return () => {
190189
resizeObserver.disconnect()
191190
}
192-
}, [inView, ref, placeholderHeight])
191+
}, [ref, placeholderHeight])
193192

194193
useEffect(() => {
195194
if (inView === true) {
@@ -316,7 +315,7 @@ function measureElement(wrapperEl: HTMLDivElement, placeholderHeight?: number):
316315
totalHeight += panelRect.height
317316
}
318317

319-
if (totalHeight < 10) {
318+
if (totalHeight < 40) {
320319
totalHeight = placeholderHeight ?? el.clientHeight
321320
}
322321

0 commit comments

Comments
 (0)