From e910dd80ee51902dc1cfbb8eade3d77880ecb0c2 Mon Sep 17 00:00:00 2001 From: Marco Schumacher Date: Fri, 19 Jul 2024 14:07:23 +0200 Subject: [PATCH] fix: optimize row height calculation in Row component --- src/components/row.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/row.tsx b/src/components/row.tsx index eaa0d47..946d434 100644 --- a/src/components/row.tsx +++ b/src/components/row.tsx @@ -60,13 +60,18 @@ export const Row = memo(function Row({ }; }); - useEffect(() => { + useLayoutEffect(() => { function update() { table.update((state) => { - const h1 = document.contains(divRef.current) ? divRef.current?.offsetHeight ?? 0 : 0; - const h2 = document.contains(detailsDivRef.current) - ? detailsDivRef.current?.offsetHeight ?? 0 - : 0; + if (!divRef.current) { + return; + } + + const h1 = divRef.current.offsetHeight; + const h2 = + detailsDivRef.current && document.contains(detailsDivRef.current) + ? detailsDivRef.current.offsetHeight + : 0; state.rowHeights.set(itemId, h1 + h2); });