Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-modeling): stabilize overview table height (#110031)

Jovan Sakoviceee7ed0d0ad2
diff --git a/products/data_modeling/frontend/ModelsOverviewTable.test.tsx b/products/data_modeling/frontend/ModelsOverviewTable.test.tsx
new file mode 100644
index 000000000000..05c366bd9c13
--- /dev/null
+++ b/products/data_modeling/frontend/ModelsOverviewTable.test.tsx
@@ -0,0 +1,46 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render } from '@testing-library/react'
+
+import { ModelsOverviewTable } from './ModelsOverviewTable'
+
+const DATA = Array.from({ length: 12 }, (_, index) => ({ id: index, name: `Model ${index}` }))
+const COLUMNS = [{ title: 'Name', dataIndex: 'name' as const }]
+
+describe('ModelsOverviewTable', () => {
+ afterEach(() => {
+ cleanup()
+ jest.restoreAllMocks()
+ })
+
+ it('keeps the settled height while loading refreshes a short page', () => {
+ let measuredHeight = 500
+ jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(
+ () => ({ height: measuredHeight }) as DOMRect
+ )
+ jest.spyOn(globalThis, 'ResizeObserver').mockImplementation(
+ () => ({ observe: () => null, unobserve: () => null, disconnect: () => null }) as ResizeObserver
+ )
+
+ const table = (loading: boolean): JSX.Element => (
+ <ModelsOverviewTable
+ columns={COLUMNS}
+ dataSource={DATA}
+ loading={loading}
+ rowKey="id"
+ data-attr="models-overview-test"
+ />
+ )
+ const { container, rerender } = render(table(false))
+ const wrapper = container.querySelector<HTMLElement>('[data-attr="models-overview-test"]')!
+
+ expect(wrapper).toHaveStyle({ minHeight: '500px' })
+
+ measuredHeight = 100
+ rerender(table(true))
+ expect(wrapper).toHaveStyle({ minHeight: '500px' })
+
+ rerender(table(false))
+ expect(wrapper).toHaveStyle({ minHeight: '500px' })
+ })
+})
diff --git a/products/data_modeling/frontend/ModelsOverviewTable.tsx b/products/data_modeling/frontend/ModelsOverviewTable.tsx
index 670f47e7ba2d..3016fc132031 100644
--- a/products/data_modeling/frontend/ModelsOverviewTable.tsx
+++ b/products/data_modeling/frontend/ModelsOverviewTable.tsx
@@ -8,26 +8,30 @@ export function ModelsOverviewTable<T extends Record<string, any>>({
}: LemonTableProps<T>): JSX.Element {
const containerRef = useRef<HTMLDivElement>(null)
const contentRef = useRef<HTMLDivElement>(null)
+ const preservedHeightRef = useRef(0)
const hasMultiplePages = props.dataSource.length > 10
useLayoutEffect(() => {
const container = containerRef.current
const content = contentRef.current
- if (!container || !content || !hasMultiplePages) {
- container?.style.removeProperty('min-height')
+ if (!container || !content || props.loading) {
+ return
+ }
+ if (!hasMultiplePages) {
+ preservedHeightRef.current = 0
+ container.style.removeProperty('min-height')
return
}
- let height = 0
const preserveHeight = (): void => {
const bounds = content.getBoundingClientRect()
- height = Math.max(height, bounds.height)
- container.style.minHeight = `${height}px`
+ preservedHeightRef.current = Math.max(preservedHeightRef.current, bounds.height)
+ container.style.minHeight = `${preservedHeightRef.current}px`
}
preserveHeight()
const observer = new ResizeObserver(preserveHeight)
observer.observe(content)
return () => observer.disconnect()
- }, [hasMultiplePages])
+ }, [hasMultiplePages, props.loading])
return (
<div ref={containerRef} data-attr={dataAttr}>