List view lands on the current exercise through the ⋯ menu too — two scroll restores were undoing it (QA C1)

Choosing List (or Compact) from ⋯ → Layout closes a sheet, and two things put the
page back where it was before that sheet opened, after the list had already scrolled
to the current unit (#224):

- Modals.jsx re-applied the pre-sheet scrollY a second time 350 ms after closing. That
  repeat exists for one case only — iOS scrolling the page again while the keyboard
  dismisses — so it is now armed only when the keyboard is up at close time. With no
  keyboard there is nothing to undo, and the late restore overwrote a scroll the view
  made on purpose.
- App.jsx treated the popstate from the sheet's history entry (Modals pushes one per
  sheet, #63) as a back-navigation: the pathname is the same, only the navigation type
  flips to POP after the PUSH that started the workout, and the effect restored the
  position it had recorded — read before the scroll event for the new position had
  been dispatched, so it was the old one. A POP that stays on the current route is
  not a navigation and is skipped now. That is also why the first sheet close after
  Start failed and later ones (POP → POP) did not.

The list's own scroll now runs in the next frame instead of in the effect: App.jsx
asks for its restore frame during the same commit (reload, back-navigation), so a
frame asked for afterwards runs after it. It also re-runs on List ↔ Compact, where
the rows change height and the old offset lands on a different exercise.

Measured at 368 px on the QA rig (scripts/opengym-qa/run/fix-list-scroll/measure.mjs,
current unit's top vs. sticky header bottom, 77 px):
  before  cards→list via menu: scrollY 2601 at 223 ms, back to 399 at 304 ms, unit
          2217 px below the fold (2/2); list→compact ok
  after   cards→list 93 px (gap 15) 2/2, list→compact 93 px 2/2, compact→list 93 px
          2/2, reload 89 px 6/6, reload with a current superset 89 px 4/4, back from
          Stats 89 px 2/2; verifier's own scripts 8/8 MENU OK at 368 and 412
This commit is contained in:
Duarte Santos committed 2026-09-19 21:23:26 +02:00
1 parent 83b2a140d6
commit 6e39fbd4b4
5 files changed
+98 -5

No files matched your search

+9 -1
View File
@@ -85,7 +85,7 @@ function Shell() {
// Forward navigation starts at the top; going back lands where you left off.
// The position is recorded from scroll events rather than read at route
// change, because by then a shorter page may already have clamped it.
const pathRef = useRef(loc.pathname)
const pathRef = useRef(null)
// iOS leaves the page displaced after the keyboard goes away (see lib/viewport-guard.js).
useEffect(() => installViewportGuard(), [])
// Click-drag a horizontal chip strip to scroll it sideways (lib/hchips.js) — on a desktop
@@ -108,8 +108,16 @@ function Shell() {
return () => window.removeEventListener('scroll', onScroll)
}, [])
useLayoutEffect(() => {
const samePath = pathRef.current === loc.pathname
pathRef.current = loc.pathname
if (navType !== 'POP') { window.scrollTo(0, 0); return }
// A POP that stays on the route we are on is not a back-navigation: it is the history
// entry a sheet pushed (Modals.jsx, #63) being unwound as the sheet closes. Nothing new
// mounted, Modals puts the page back where it was itself, and a view that scrolled on
// purpose because the sheet closed — the workout list going to the current exercise after
// ⋯ → Layout → List (#224) — must not be dragged back to a position recorded before that
// scroll's event had even been dispatched.
if (samePath) return
const y = scrollPositions.get(loc.pathname) || 0
// the restored view needs a layout pass before it is tall enough to scroll to y
const frame = window.requestAnimationFrame(() => window.scrollTo(0, y))