Skip to content

Conversation

@sujitha-saranam
Copy link
Contributor

@sujitha-saranam sujitha-saranam commented Aug 13, 2025

Overview

This PR addresses #54174. It fixes the default scroll to the most recent logs and ensures that jump-to-start/end buttons scroll instantly.

Root Cause:

Jumping to the end is slow because the virtualizer has to compute/measure positions for a large number of rows before it can accurately place the scroll. For very long logs, this causes the temporary slow scroll effect.

Solution

  • Implemented precise offset calculation for hash-based navigation to jump directly to a target log.
  • Enhanced jump-to-start and jump-to-end logic to bypass gradual virtualizer measurement, allowing instant scrolling.
  • Updated highlight calculation to work correctly with the reversed order, ensuring the selected log is always visually marked.

Changes Made

  • Updated useLayoutEffect to compute exact scroll offsets based on virtual item positions.
  • Modified handleScrollTo to combine scrollToIndex with scrollTop via requestAnimationFrame for instant jumps.
  • Adjusted the bgColor calculation for virtualized items to correctly highlight the log matching the hash.
  • Tweak Code and VStack container styling to match virtualized content height and improve scroll behavior.

closes: #54174
related: #54174

closes: #51788

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request.

I wouldn't reverse the logs in the frontend because it will cause many different problem, maybe we can just scroll to bottom on loading. (log reverse should be done in the backend, because if we start paginating / streaming logs reversing just in the UI will not work)

With the current implementation I see a few issues:
Groups are weird
Screenshot 2025-08-18 at 18 06 02
First line is truncated
Screenshot 2025-08-18 at 18 06 22

Once I click on the "scroll to bottom" button, I cannot scroll up.

Screen.Recording.2025-08-18.at.18.07.14.mov

@sujitha-saranam
Copy link
Contributor Author

Hi @pierrejeambrun

Screencast.from.2025-08-20.18-59-02.mp4

I have fixed the logs reversal from the backend and also addressed the UI issues. I’ve attached a screen recording of my local setup showing these updates. Could you please check and let me know if everything looks fine, or if there are any external changes I should also make?

Thanks!

@sujitha-saranam sujitha-saranam marked this pull request as draft August 20, 2025 17:02
@sujitha-saranam sujitha-saranam marked this pull request as ready for review August 21, 2025 08:03
@sujitha-saranam sujitha-saranam marked this pull request as draft August 21, 2025 08:04
@sujitha-saranam sujitha-saranam marked this pull request as ready for review August 21, 2025 08:30
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to update the backend ordering there? Also I didn't take a closer look but we most probably can't do that because that should be at the reader lvl to reverse order. (start from the end of the file and cursor back to the beginning)

Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even we have the another UI endpoint for this feature, the builit-in reversed will still cause the OOM problem for API server when the log is large.

@jscheffl
Copy link
Contributor

Iactually would not like to read logs in reverse order. I this is made then it would need to be an optional feature, should not require all users to read logs in reverse order.

log_stream = task_log_reader.read_log_stream(ti, try_number, metadata) # type: ignore[arg-type]
ndjson_log_stream = list(task_log_reader.read_log_stream(ti, try_number, metadata)) # type: ignore[arg-type]
reversed_stream = reversed(ndjson_log_stream)
log_stream = (line for line in reversed_stream)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t this just iter(reversed_stream)?

@sujitha-saranam sujitha-saranam marked this pull request as draft August 26, 2025 09:14
@sujitha-saranam sujitha-saranam marked this pull request as ready for review August 26, 2025 10:56
@sujitha-saranam
Copy link
Contributor Author

sujitha-saranam commented Aug 26, 2025

I am reverting the back-end changes as they were optional. Please let me know if any other changes i should do.

@pierrejeambrun pierrejeambrun added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Sep 2, 2025
@pierrejeambrun pierrejeambrun added this to the Airflow 3.0.7 milestone Sep 2, 2025
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Tested locally and working.

A few adjustments/cleaning/simplification suggestions before we can merge.

Comment on lines +100 to +107
return;
}

const targetIndex = Math.max(0, Math.min(parsedLogs.length - 1, Number(hash) || 0));
const el = parentRef.current;

const total = rowVirtualizer.getTotalSize();
const clientH = el?.clientHeight ?? 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the direct link to lines. We used to add 5 more lines so it wouldn't be on the edge of the container, f screenshot.

Screenshot 2025-09-02 at 14 06 18

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both clicking on a log line, or refreshing the page with a URL with a line number specified will not land where we want. http://localhost:28080/dags/big_logs/runs/manual__2025-09-02T12:02:44.060539+00:00/tasks/my_task?try_number=1#4806

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return;
}

// === bottom === (instant jump even for huge lists)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a comment for bottom, but not for top. Remove it

Suggested change
// === bottom === (instant jump even for huge lists)

Comment on lines +172 to +176
try {
rowVirtualizer.scrollToOffset(offset);
} catch {
rowVirtualizer.scrollToIndex(parsedLogs.length - 1, { align: "end" });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be enough. We can remove the typeof check. (undefined is not callable) (same above)

Comment on lines +183 to +195
requestAnimationFrame(() => {
el.scrollTop = offset;
requestAnimationFrame(() => {
el.scrollTop = offset;
const lastItem = el.querySelector<HTMLElement>(
`[data-testid="virtualized-item-${parsedLogs.length - 1}"]`,
);

if (lastItem) {
lastItem.scrollIntoView({ behavior: "auto", block: "end" });
}
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are those requestAnimationFrame achieving? I Tried without them and it still look fine.

@kaxil kaxil removed the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Sep 14, 2025
@eladkal
Copy link
Contributor

eladkal commented Sep 15, 2025

@sujitha-saranam can you address above comments?

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Nov 20, 2025
@github-actions github-actions bot closed this Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers. stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix jump to most recent logs and jump by default Scrolling in logs does not work properly.

8 participants