Revanth14 commented on code in PR #64013:
URL: https://github.com/apache/airflow/pull/64013#discussion_r3309471314


##########
airflow/www/static/js/dag/details/taskInstance/Logs/LogBlock.tsx:
##########
@@ -35,25 +40,53 @@ const LogBlock = ({
   setUnfoldedLogGroup,
 }: Props) => {
   const [autoScroll, setAutoScroll] = useState(true);
+  const [logHeight, setLogHeight] = useState<number>();
 
   const logBoxRef = useRef<HTMLPreElement>(null);
-  const offsetTop = useOffsetTop(logBoxRef);
+
+  const resizeLogBlock = useCallback(() => {
+    requestAnimationFrame(() => {
+      const logBox = logBoxRef.current;
+      if (!logBox) return;
+
+      const footerHeight =
+        parseInt(getComputedStyle(document.body).paddingBottom, 10) || 0;
+      const viewportHeight = window.visualViewport?.height ?? 
window.innerHeight;
+      const { top } = logBox.getBoundingClientRect();
+
+      setLogHeight(Math.max(0, viewportHeight - top - footerHeight));
+    });
+  }, []);
 
   const scrollToBottom = () => {
-    if (logBoxRef.current) {
-      logBoxRef.current.scrollTop = logBoxRef.current.scrollHeight;
-    }
+    requestAnimationFrame(() => {
+      if (logBoxRef.current) {
+        logBoxRef.current.scrollTop = logBoxRef.current.scrollHeight;
+      }
+    });
   };
 
+  useLayoutEffect(() => {
+    resizeLogBlock();
+
+    window.addEventListener("resize", resizeLogBlock);
+    window.visualViewport?.addEventListener("resize", resizeLogBlock);
+
+    return () => {
+      window.removeEventListener("resize", resizeLogBlock);
+      window.visualViewport?.removeEventListener("resize", resizeLogBlock);
+    };
+  }, [resizeLogBlock, wrap, parsedLogs]);
+
   useEffect(() => {
     // Always scroll to bottom when wrap or tryNumber change
-    if (offsetTop) scrollToBottom();
-  }, [wrap, tryNumber, offsetTop]);
+    if (logBoxRef.current) scrollToBottom();
+  }, [wrap, tryNumber, logHeight]);

Review Comment:
   Addressed. `logHeight` was removed from the unconditional scroll-to-bottom 
effect. Height changes now only scroll when `autoScroll` is true, so users 
reading earlier logs are not pulled to the bottom on resize.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to