From 2cff24eb269ca3cb916f1f8f1e91e9786c22982a Mon Sep 17 00:00:00 2001 From: nielsbosma Date: Thu, 2 Apr 2026 11:47:19 +0200 Subject: [PATCH] [01484] Retry initial container measurement for nested flex layouts Replace synchronous getBoundingClientRect with a retry loop (up to 5 frames) so DataTables inside nested flex layouts get measured after the layout resolves instead of reading height=0 at mount time. --- .../dataTables/hooks/useContainerSize.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/widgets/dataTables/hooks/useContainerSize.ts b/src/frontend/src/widgets/dataTables/hooks/useContainerSize.ts index d85f8b05d..4aacdaf9d 100644 --- a/src/frontend/src/widgets/dataTables/hooks/useContainerSize.ts +++ b/src/frontend/src/widgets/dataTables/hooks/useContainerSize.ts @@ -58,13 +58,21 @@ export const useContainerSize = () => { resizeObserver.observe(containerRef.current); - // Synchronous initial measurement to avoid first render with height=0. - // Without this, the deferred requestAnimationFrame in the ResizeObserver callback - // causes DataEditor to render with height=undefined, showing only headers. - const { width: initWidth, height: initHeight } = containerRef.current.getBoundingClientRect(); - if ((initWidth > 0 || initHeight > 0) && !hasAppliedInitialRef.current) { - apply(initWidth, initHeight); - } + // Retry initial measurement until layout settles (max ~100ms). + // In nested flex layouts (e.g. HeaderLayout → Vertical → DataTable), the container + // may still have height=0 at mount time. Retrying across animation frames ensures + // we catch the moment the layout resolves. + let retries = 0; + const tryInit = () => { + if (hasAppliedInitialRef.current || !containerRef.current) return; + const { width, height } = containerRef.current.getBoundingClientRect(); + if (width > 0 || height > 0) { + apply(width, height); + } else if (retries++ < 5) { + requestAnimationFrame(tryInit); + } + }; + tryInit(); requestAnimationFrame(observeScrollArea);