Skip to content

Fix scroll position stability when items resize#12264

Merged
mtsgrd merged 1 commit intomasterfrom
mg-branch-35
Feb 6, 2026
Merged

Fix scroll position stability when items resize#12264
mtsgrd merged 1 commit intomasterfrom
mg-branch-35

Conversation

@mtsgrd
Copy link
Contributor

@mtsgrd mtsgrd commented Feb 6, 2026

  • Stick to bottom when the last visible item expands (e.g. expanding a
    collapsed diff), not just when stickToBottom is enabled
  • Compensate scroll position only when the topmost visible element
    resizes, fixing jitter when scrolling up
  • Remove scroll thumb position transition that caused lag during
    fast scrolling

Copilot AI review requested due to automatic review settings February 6, 2026 20:01
@vercel
Copy link

vercel bot commented Feb 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gitbutler-web Ready Ready Preview, Comment Feb 6, 2026 9:11pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves scroll position stability in the UI’s virtualized scrolling components, focusing on preventing scroll “jumps” and lag when list items resize (e.g., expanding diffs) and when scrolling quickly.

Changes:

  • Removes the scrollbar thumb “top” transition to reduce lag during fast scrolling.
  • Updates VirtualList resize handling to (a) stick to bottom when the last visible item expands near the bottom and (b) only compensate scroll position when the topmost visible element resizes while scrolling up.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/ui/src/lib/components/scroll/Scrollbar.svelte Removes top transition on the scrollbar thumb to avoid lag/jitter during rapid scroll updates.
packages/ui/src/lib/components/VirtualList.svelte Refines resize compensation logic to reduce jitter when scrolling up and improve bottom-sticking behavior when near bottom.

Comment on lines 176 to 195
// When scrolling up, compensate for the height change of the topmost
// visible element to prevent content from jumping downward.
viewport.scrollBy({ top: heightMap[index] - oldHeight });
} else if (
(lastJumpToIndex !== undefined || startIndex) &&
lastScrollDirection === undefined
) {
const newScrollTop = calculateHeightSum(0, lastJumpToIndex || startIndex || 0);
viewport.scrollTop = newScrollTop;
// After jumping to an index, maintain position as off-viewport elements
// resize. Scroll direction is undefined during jumps.
viewport.scrollTop = calculateHeightSum(0, lastJumpToIndex || startIndex || 0);
skipNextScrollEvent = true;
} else if (stickToBottom && previousDistance < STICKY_DISTANCE) {
} else if (
(stickToBottom || index === visibleRange.end - 1) &&
previousDistance < STICKY_DISTANCE
) {
// Maintain bottom position when near bottom and either stickToBottom
// is enabled or the last visible item resizes.
skipNextScrollEvent = true;
scrollToBottom();
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The new scroll-stability behavior (auto-sticking to bottom when the last visible item resizes, and only compensating for the topmost visible item while scrolling up) isn’t covered by the existing VirtualList Playwright CT tests. Since packages/ui/tests/VirtualList.spec.ts exists, please add/adjust tests to exercise these resize scenarios (e.g., expand the last visible row via the wrapper’s “Expand Last” control and assert the scroll position remains stable both with and without stickToBottom).

Copilot uses AI. Check for mistakes.
- Stick to bottom when the last visible item expands (e.g. expanding a
  collapsed diff), not just when stickToBottom is enabled
- Compensate scroll position only when the topmost visible element
  resizes, fixing jitter when scrolling up
- Remove scroll thumb position transition that caused lag during
  fast scrolling
@mtsgrd mtsgrd merged commit 08c8e50 into master Feb 6, 2026
25 checks passed
@mtsgrd mtsgrd deleted the mg-branch-35 branch February 6, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant