Revanth14 commented on code in PR #64013:
URL: https://github.com/apache/airflow/pull/64013#discussion_r3309481677
##########
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]);
useEffect(() => {
// When logs change, only scroll if autoScroll is enabled
- if (autoScroll && offsetTop) scrollToBottom();
- }, [parsedLogs, autoScroll, offsetTop]);
+ if (autoScroll && logBoxRef.current) scrollToBottom();
+ }, [parsedLogs, autoScroll]);
const onScroll = (e: React.UIEvent<HTMLDivElement>) => {
Review Comment:
Addressed in the same update: `Code as="pre"` is used with matching
`HTMLPreElement` ref and scroll event types.
--
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]