Skip to content

fix(web): scroll timeline and history views to selected target on URL load - #1254

Merged
kyasbal merged 3 commits into
mainfrom
push-pxmxkrmrtmxz
Nov 11, 2026
Merged

kyasbal merged 3 commits into
mainfrom
push-pxmxkrmrtmxz

Conversation

@kyasbal

@kyasbal kyasbal commented Nov 10, 2026

Copy link
Copy Markdown
Member

Part of #1193

Background

Opening a KHI session URL containing inspectionId along with timelineId, revisionIndex, or logId (such as jump links from render_timelines scenes) restored the active selection state, but the Timeline chart and History revision list often remained at their initial scroll positions or scrolled the target row underneath sticky/header elements:

  1. URL target selection ran before asynchronous TimelineView filtering, initial timeline scale calculation, and container resize measurements finished, causing early scroll effects to exit or be clamped against uninitialized .expander dimensions.
  2. Separate horizontal and vertical scrollTo({ behavior: 'smooth' }) calls and pixel-rounding feedback into viewportLeftTimeNs cancelled ongoing smooth scroll animations, while vertical Timeline auto-scroll did not reserve clearance for sticky ancestor headers.
  3. In the History pane, DiffListComponent conditionally unmounted CdkVirtualScrollViewport when empty so initial synchronous scrollToIndex calls fired before FixedSizeVirtualScrollStrategy attached and updated its spacer height. In addition, unrendered logIndex = -1 revisions and unconstrained row heights caused FixedSizeVirtualScrollStrategy offsets to overshoot and hide the selected revision behind the resource path header.

Approach

  • Wait for TimelineView.isFiltering() to complete in SessionUrlSyncService before applying timelineId, revisionIndex, or logId selection.
  • Gate Timeline cursor and row auto-scrolling on initialScaleApplied and measured viewport dimensions, coalesce horizontal and vertical smooth scroll targets on the next animation frame once .expander dimensions settle, and include ancestor sticky header height in the top scroll margin.
  • Keep DiffListComponent's CdkVirtualScrollViewport mounted, exclude non-renderable logIndex = -1 entries from virtual scroll rows while preserving original revision indices and diff status, align .revision-row height with DiffListScrollStrategy (13px border-box), and smoothly center off-screen selections inside the viewport once spacer layout is ready.
@kyasbal kyasbal added type:bug Something isn't working as expected area:frontend Web frontend application and UI components labels Nov 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves layout stability and scrolling behavior in the diff and timeline views. Key changes include refactoring the virtual scroll strategy in DiffListComponent to defer scrolling until layout metrics are ready, coalescing horizontal and vertical smooth scrolling in TimelineFrameComponent into a single animation frame-driven call that accounts for sticky ancestor headers, and ensuring that URL selection restoration waits for timeline filtering to complete. The reviewer pointed out a potential memory leak in SessionUrlSyncService.waitForFilteringComplete due to accumulating DestroyRef.onDestroy callbacks, suggesting a cleanup helper to unregister the callback upon completion.

Comment on lines +65 to +76
function waitAnimationFrames(count: number): Promise<void> {
return new Promise<void>((resolve) => {
const step = (remaining: number) => {
if (remaining <= 0) {
resolve();
return;
}
requestAnimationFrame(() => step(remaining - 1));
};
step(count);
});
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This method is duplicated.

* @param timelineID The unique identifier of the timeline.
* @returns True when the timeline is present in the displayed list.
*/
public hasTimeline(timelineID: number): boolean {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is O(N) but it can be O(1) and it wouldn't be a good practice to put this method in the class named scroll calculator.

* @returns Total height of ancestor sticky rows in pixels, or 0 if not found.
*/
public ancestorStickyHeight(timelineID: number): number {
const timeline = this.timelines.find((item) => item.id === timelineID);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is O(N) but it can be O(1) and the caller has timeline instance itself so we don't need to find it from ID.

@kyasbal
kyasbal added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit 462fbd6 Nov 11, 2026
21 checks passed
@kyasbal
kyasbal deleted the push-pxmxkrmrtmxz branch November 11, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Web frontend application and UI components type:bug Something isn't working as expected

1 participant