From f63daf16a816d56d3d3b07d7835c21c0204eafe5 Mon Sep 17 00:00:00 2001 From: Claudio Date: Sun, 10 May 2026 23:25:48 +0200 Subject: [PATCH] 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) --- frontend/src/components/timeline/Timeline.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/src/components/timeline/Timeline.tsx b/frontend/src/components/timeline/Timeline.tsx index b6971f9..d33d621 100644 --- a/frontend/src/components/timeline/Timeline.tsx +++ b/frontend/src/components/timeline/Timeline.tsx @@ -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