Skip to content

Clamp section scroll offset to the scrollable range - #22741

Draft
francisrath wants to merge 4 commits into
desktop:developmentfrom
francisrath:fix-changes-list-stale-scroll-offset
Draft

francisrath wants to merge 4 commits into
desktop:developmentfrom
francisrath:fix-changes-list-stale-scroll-offset

Conversation

@francisrath

Copy link
Copy Markdown
Contributor

Closes #22619

Description

The Changes list could render a single row at the bottom of an otherwise empty pane while the header still reported the correct file count. The rows aren't drawn blank — they're never rendered at all, so there's nothing to click or uncheck, while the header count, the select-all checkbox and the commit button all still act on the full set.

setScrollTop restores a scroll position saved while the list was longer — repository.tsx passes changesListScrollTop back on the History → Changes transition. getSectionGridRenderer clamped that offset to the section's total height rather than to its scrollable range, so a restored position could land at or past the end of the content. react-virtualized resolves an offset past the end to a visible range of just the final row (_findNearestCell clamps to cellCount - 1, and the stop loop can't advance past it).

Nothing corrects it afterwards: a grid shorter than its viewport never scrolls, so no scroll event arrives to run react-virtualized's own clamp, and SectionList.onScroll stores the value unclamped and hands it back up to be saved again. That's also why switching to History and back doesn't help — that transition is what restores the offset in the first place.

Clamping to sectionHeight - visibleHeight yields 0 for a section that fits its viewport, so every row renders regardless of what was restored. For a section taller than the viewport the clamp only ever renders a superset of what's visible, so scrolling is unaffected.

Reproducing it (5/5 on 3.6.3, macOS):

  1. In any repo, get ~60 changed files so the Changes list scrolls.
  2. Scroll the Changes list to the bottom.
  3. Switch to the History tab.
  4. While on History, drop the changed-file count to a handful.
  5. Switch back to Changes.

Step 2 is the necessary ingredient — the identical sequence without scrolling first renders correctly every time, which I ran as a control. #22619 has a script that automates this.

Verified against a build of this branch. Where 3.6.3 renders one row, this renders all of them: 60→5, 40→3, 80→12 and 30→2. The stale offset is still being restored on the patched build (1319, 739, 1899, 449 before each transition), so the clamp is what's doing the work rather than some side effect of rebuilding. Scrolling still tracks correctly: on a 60-row list in a 421px viewport, offset 0 draws rows 0-18, 400 draws 13-32, 900 draws 31-49, and the bottom draws 45-59 ending on the true final row.

I also checked whether the History list has the same defect, since commit-list.tsx passes compareListScrollTop into List the same way and its only reset (scrollCompareListToTop) fires just on branch-created-from-commit. It doesn't reproduce — planting a stale compareListScrollTop and going Changes → History still renders every commit, because the commit list mounts empty while commits load and so passes through rowCount === 0, which react-virtualized explicitly zeroes the scroll offset for. SectionList's root grid never does, since its rowCount is the number of sections rather than the number of files.

The test case is added alongside the existing #22387 one in section-list-scroll-test.tsx: render a SectionList with a setScrollTop larger than its content, assert every row renders. It fails without the fix (expected all 5 rows to render, got 1) and passes with it.

Screenshots

The screenshot in #22619 shows the failure: "17 changed files" in the header, one row (OrderSummary.vue) at the bottom of an empty pane, and "Commit 17 files" on the button. With this change all 17 rows render in place.

Release notes

Notes: [Fixed] Show every changed file in the Changes list after returning from the History tab - #22619

A scrollTop saved while the Changes list was longer is replayed through
setScrollTop on the History -> Changes transition. Clamping it to the
section's total height rather than its scrollable range let it land at or
past the end of the content, which react-virtualized resolves to a visible
range of just the final row, so the list renders one row at the bottom of
an empty pane. A grid shorter than its viewport never scrolls, so no scroll
event ever fires to correct the offset.

Fixes desktop#22619
@github-actions github-actions Bot added external Pull request originating outside of the Desktop core team needs-triage labels Aug 17, 2026
francisrath and others added 2 commits October 13, 2026 14:48
The clamp and the grid's height prop computed the same value separately.
Sharing it makes it plain that the offset is clamped to what this grid
can actually scroll.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external Pull request originating outside of the Desktop core team needs-triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changes list renders blank, unclickable rows after bulk external file changes

1 participant