From 92675ddf9885a8c18e166bf08f39bce8bcfc6952 Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Tue, 16 Sep 2025 16:07:09 +0200 Subject: [PATCH] LogLine: mix observer with animation frame --- .../features/logs/components/panel/LogLine.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/app/features/logs/components/panel/LogLine.tsx b/public/app/features/logs/components/panel/LogLine.tsx index fce21d6c4a0..7b36cfdc737 100644 --- a/public/app/features/logs/components/panel/LogLine.tsx +++ b/public/app/features/logs/components/panel/LogLine.tsx @@ -149,11 +149,21 @@ const LogLineComponent = memo( if (!logLineRef.current) { return; } - const observer = new ResizeObserver(() => { - handleLogLineResize(); - }); + let frameId: number; + const handleResize = () => { + if (frameId) { + cancelAnimationFrame(frameId); + } + frameId = requestAnimationFrame(() => handleLogLineResize()); + }; + const observer = new ResizeObserver(handleResize); observer.observe(logLineRef.current); - return () => observer.disconnect(); + return () => { + observer.disconnect(); + if (frameId) { + cancelAnimationFrame(frameId); + } + } }, [handleLogLineResize]); useEffect(() => {