Repository navigation
fix(web): scroll timeline and history views to selected target on URL load - #1254
Conversation
There was a problem hiding this comment.
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.
| 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); | ||
| }); | ||
| } |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Part of #1193
Background
Opening a KHI session URL containing
inspectionIdalong withtimelineId,revisionIndex, orlogId(such as jump links fromrender_timelinesscenes) 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:TimelineViewfiltering, initial timeline scale calculation, and container resize measurements finished, causing early scroll effects to exit or be clamped against uninitialized.expanderdimensions.scrollTo({ behavior: 'smooth' })calls and pixel-rounding feedback intoviewportLeftTimeNscancelled ongoing smooth scroll animations, while vertical Timeline auto-scroll did not reserve clearance for sticky ancestor headers.DiffListComponentconditionally unmountedCdkVirtualScrollViewportwhen empty so initial synchronousscrollToIndexcalls fired beforeFixedSizeVirtualScrollStrategyattached and updated its spacer height. In addition, unrenderedlogIndex = -1revisions and unconstrained row heights causedFixedSizeVirtualScrollStrategyoffsets to overshoot and hide the selected revision behind the resource path header.Approach
TimelineView.isFiltering()to complete inSessionUrlSyncServicebefore applyingtimelineId,revisionIndex, orlogIdselection.initialScaleAppliedand measured viewport dimensions, coalesce horizontal and vertical smooth scroll targets on the next animation frame once.expanderdimensions settle, and include ancestor sticky header height in the top scroll margin.DiffListComponent'sCdkVirtualScrollViewportmounted, exclude non-renderablelogIndex = -1entries from virtual scroll rows while preserving original revision indices and diff status, align.revision-rowheight withDiffListScrollStrategy(13pxborder-box), and smoothly center off-screen selections inside the viewport once spacer layout is ready.