fix(timeline): scroll to top on section / folder switch

Clicking a folder in the sidebar (or any section change) didn't
reset the timeline's scroll position. If the user was scrolled deep
into All Photos, the new folder loaded at the same y-offset, often
landing on empty space below the last row.

The section-change effect already cleared selection and reset the
auto-focus guard; just needed to also reset parentRef.current.scrollTop.
Synchronous so the first paint of the new section is anchored at
photo[0]; the auto-focus selectPhoto call still runs after render
to highlight the first photo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claudio
2026-05-10 23:25:48 +02:00
parent d580796dc8
commit f63daf16a8

View File

@@ -247,6 +247,18 @@ export function Timeline() {
prevSectionRef.current = currentSection
didAutoFocusRef.current = false
clearSelection()
// Reset scroll to the top of the new section. Without this the
// previous section's scroll offset (which can be tens of thousands
// of px in a long timeline) carries over to a freshly-loaded
// folder, leaving the user looking at empty space below the last
// row. The auto-focus effect below selects photos[0] on next
// render, but its "ensure visible" scroll only kicks in if the
// cell is out of view — by then the user has already seen the
// wrong scroll position. Doing this synchronously here keeps the
// first paint of the new section anchored at the top.
if (parentRef.current) {
parentRef.current.scrollTop = 0
}
}, [currentSection, clearSelection])
// Membership in the active heap (drives the green tint on each