Merge fix/list-scroll: QA round 2026-09-19 (dev team)
This commit is contained in:
commit
cb4fc99dcc
6 files changed
+122
-8
No files matched your search
@@ -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))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { keyboardOpen } from '../lib/viewport-guard.js'
|
||||
|
||||
// One bottom sheet (or centered dialog) with swipe-to-dismiss.
|
||||
function Sheet({ sheet }) {
|
||||
@@ -180,6 +181,12 @@ export default function Modals() {
|
||||
// iOS scrolls the page again while the keyboard dismisses — after the line above ran.
|
||||
// Ask once more when that animation is over. The window-level guard in
|
||||
// lib/viewport-guard.js covers the keyboard closing while a sheet stays open.
|
||||
// Only with the keyboard up, though: without one there is nothing to undo, and a late
|
||||
// restore would overwrite a scroll the page behind made on purpose because the sheet
|
||||
// closed — the workout list going to the current exercise after ⋯ → Layout → List
|
||||
// (issue #224). At this point the sheet's field is already out of the DOM but the
|
||||
// keyboard has not started to go, so the visual viewport still tells the truth.
|
||||
if (!keyboardOpen()) return
|
||||
window.setTimeout(() => { if (document.body.style.position !== 'fixed') window.scrollTo(0, y) }, 350)
|
||||
}
|
||||
}, [sheets.length > 0])
|
||||
|
||||
@@ -292,3 +292,38 @@ describe('Modals drag axis lock and dismiss', () => {
|
||||
expect(mocks.state.sheets).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Modals scroll restore on close', () => {
|
||||
// The body is pinned while a sheet is open and the page is put back where it was on close.
|
||||
// The second, delayed restore exists for one reason — iOS scrolling the page again while the
|
||||
// keyboard dismisses — so it must only be armed when the keyboard is actually up (QA C1).
|
||||
async function openAndClose() {
|
||||
dom.scrollY = 320
|
||||
await setSheets([sheet('menu')])
|
||||
expect(document.body.style.position).toBe('fixed')
|
||||
dom.scrollTo.mockClear()
|
||||
await setSheets([])
|
||||
}
|
||||
|
||||
it('restores the position once and leaves a scroll the page made afterwards alone', async () => {
|
||||
vi.useFakeTimers()
|
||||
await openAndClose()
|
||||
expect(dom.scrollTo).toHaveBeenCalledTimes(1)
|
||||
expect(dom.scrollTo).toHaveBeenCalledWith(0, 320)
|
||||
await act(async () => { vi.advanceTimersByTime(400) })
|
||||
expect(dom.scrollTo).toHaveBeenCalledTimes(1)
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('restores again after the keyboard dismiss animation when the sheet closed with the keyboard up', async () => {
|
||||
vi.useFakeTimers()
|
||||
dom.innerHeight = 800
|
||||
dom.visualViewport = { height: 460 }
|
||||
await openAndClose()
|
||||
expect(dom.scrollTo).toHaveBeenCalledTimes(1)
|
||||
await act(async () => { vi.advanceTimersByTime(400) })
|
||||
expect(dom.scrollTo).toHaveBeenCalledTimes(2)
|
||||
expect(dom.scrollTo).toHaveBeenLastCalledWith(0, 320)
|
||||
vi.useRealTimers()
|
||||
})
|
||||
})
|
||||
@@ -1165,8 +1165,10 @@ body.chips-dragging *{cursor:inherit}
|
||||
border-radius:var(--r-lg);padding:14px 14px 4px;
|
||||
background:var(--surface-2);
|
||||
}
|
||||
/* scrolled to when the list opens (#224): clear the sticky header above it */
|
||||
.wl-unit{scroll-margin-top:calc(var(--sat) + 96px)}
|
||||
/* scrolled to when the list opens (#224): clear the sticky header above it. Workout.jsx
|
||||
measures the header (--whdr-h on .workout-list, safe area included) because it grows when
|
||||
the session name wraps; the fallback is the height of a one-line header. */
|
||||
.wl-unit{scroll-margin-top:calc(var(--whdr-h, var(--sat) + 80px) + 16px)}
|
||||
.wl-unit.cur{box-shadow:inset 0 0 0 1.5px var(--acc-line)}
|
||||
.wl-hd{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px}
|
||||
@media (max-width:400px){
|
||||
|
||||
@@ -581,13 +581,36 @@ function ActiveWorkout() {
|
||||
// The list opens at the exercise you are on, not at the top of the session (issue #224): you
|
||||
// switch to it mid-workout to look at what comes before and after. Only on the way in — once
|
||||
// the list is open, "current" moves because you tick rows in it, and a list that scrolls
|
||||
// itself under your thumb is worse than one that stays put.
|
||||
// itself under your thumb is worse than one that stays put. List ↔ Compact counts as a way
|
||||
// in: the rows change height, so the same scroll offset lands somewhere else.
|
||||
//
|
||||
// The scroll waits for the next frame rather than running in the effect itself. App.jsx
|
||||
// restores the route's remembered position in a frame it asked for during the same commit
|
||||
// (a reload, a back navigation), and a sheet closing (⋯ → Layout → List) puts the page back
|
||||
// where it was before the sheet opened, in an effect cleanup that runs before this one —
|
||||
// both would win over a scroll made right here. A frame asked for now runs after theirs.
|
||||
const listRef = useRef(null)
|
||||
const hdrRef = useRef(null)
|
||||
useEffect(() => {
|
||||
if (!listMode) return
|
||||
const el = listRef.current?.querySelector('.wl-unit.cur')
|
||||
if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'start' })
|
||||
}, [listMode])
|
||||
const schedule = callback => window.requestAnimationFrame
|
||||
? window.requestAnimationFrame(callback)
|
||||
: window.setTimeout(callback, 0)
|
||||
const cancel = frame => window.cancelAnimationFrame
|
||||
? window.cancelAnimationFrame(frame)
|
||||
: window.clearTimeout(frame)
|
||||
const frame = schedule(() => {
|
||||
const list = listRef.current
|
||||
const el = list?.querySelector('.wl-unit.cur')
|
||||
if (!el || typeof el.scrollIntoView !== 'function') return
|
||||
// The sticky header grows when the workout name wraps; the unit's scroll margin (index.css)
|
||||
// clears whatever height it has right now, with a one-line height as the fallback.
|
||||
const hdrH = hdrRef.current?.offsetHeight
|
||||
if (hdrH) list.style.setProperty('--whdr-h', hdrH + 'px')
|
||||
el.scrollIntoView({ block: 'start' })
|
||||
})
|
||||
return () => cancel(frame)
|
||||
}, [workoutView])
|
||||
|
||||
const total = setUnitsTotal(A.entries)
|
||||
const done = setsDoneActive(A)
|
||||
@@ -942,7 +965,7 @@ function ActiveWorkout() {
|
||||
{/* In list mode the whole session scrolls under the header, so the header (name, clock,
|
||||
set counter, discard/finish, progress) stays pinned — the one thing you want in view
|
||||
while you are somewhere in the middle of a long stack. Cards mode never scrolls far. */}
|
||||
<div className={'whdr' + (listMode ? ' stick' : '')}>
|
||||
<div className={'whdr' + (listMode ? ' stick' : '')} ref={hdrRef}>
|
||||
<div className="hdr">
|
||||
<button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); stopWork(); nav('/home') } })}><Icon name="xmark" /></button>
|
||||
<div style={{ textAlign: 'center' }}><div style={{ fontWeight: 600 }}>{A.name}</div><div className="sub">{A.backfill ? fmtDate(A.d, true) : <Elapsed start={A.start} />} · {t('{0} sets', done + '/' + total)}</div></div>
|
||||
|
||||
@@ -20,6 +20,7 @@ const mocks = vi.hoisted(() => {
|
||||
exConfigSheet: vi.fn(),
|
||||
toast: vi.fn(),
|
||||
scrollCalls: [],
|
||||
headerHeight: 0,
|
||||
swapActiveWorkoutExercise: vi.fn(),
|
||||
menuSheet: vi.fn(),
|
||||
effortPickerSheet: vi.fn(),
|
||||
@@ -121,6 +122,10 @@ function installDom() {
|
||||
dom.Element.prototype.scrollIntoView = vi.fn(function (options) {
|
||||
mocks.scrollCalls.push({ node: this, options })
|
||||
})
|
||||
// linkedom has no layout; the sticky workout header reports the height a test gives it.
|
||||
Object.defineProperty(dom.HTMLElement.prototype, 'offsetHeight', {
|
||||
configurable: true, get() { return this.classList.contains('whdr') ? mocks.headerHeight : 0 },
|
||||
})
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
container = document.getElementById('root')
|
||||
root = createRoot(container)
|
||||
@@ -185,6 +190,11 @@ async function addExerciseThroughSheets(ex = { id: 'added-exercise' }, cfg = { m
|
||||
await act(async () => { configCall[2](cfg) })
|
||||
}
|
||||
|
||||
// The list's scroll-to-current waits for the next frame (linkedom has no rAF, so a 0 ms timer).
|
||||
async function flushFrame() {
|
||||
await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)) })
|
||||
}
|
||||
|
||||
async function rerenderAt(cur) {
|
||||
mocks.S.active.cur = cur
|
||||
await act(async () => { root.render(React.createElement(Workout)) })
|
||||
@@ -195,6 +205,7 @@ beforeEach(() => {
|
||||
mocks.timer = null
|
||||
mocks.work = null
|
||||
mocks.scrollCalls.length = 0
|
||||
mocks.headerHeight = 0
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -1014,11 +1025,39 @@ describe('workout list view', () => {
|
||||
|
||||
it('opens at the current exercise instead of the top of the session (#224)', async () => {
|
||||
await mount([exercise('plain-bench', [true]), exercise('plain-row', [true]), exercise('plain-curl', [false])], 2, { workoutView: 'list' })
|
||||
// Not in the mount's own effect pass: App restores the route's scroll position in a frame
|
||||
// of its own, so the list scrolls in the frame after it, or the restore would win.
|
||||
expect(mocks.scrollCalls.length).toBe(0)
|
||||
await flushFrame()
|
||||
expect(mocks.scrollCalls.length).toBe(1)
|
||||
expect(mocks.scrollCalls[0].node).toBe(units()[2])
|
||||
expect(mocks.scrollCalls[0].node.classList.contains('cur')).toBe(true)
|
||||
})
|
||||
|
||||
it('clears the sticky header at its measured height, not a one-line guess (QA C27)', async () => {
|
||||
mocks.headerHeight = 143 // a routine name that wraps to three lines at 368 px
|
||||
await mount([exercise('plain-bench', [true]), exercise('plain-row', [true]), exercise('plain-curl', [false])], 2, { workoutView: 'list' })
|
||||
await flushFrame()
|
||||
expect(mocks.scrollCalls.length).toBe(1)
|
||||
expect(container.querySelector('.workout-list').style.getPropertyValue('--whdr-h')).toBe('143px')
|
||||
})
|
||||
|
||||
it('re-anchors on the current exercise when the layout changes between list and compact (QA C1)', async () => {
|
||||
await mount([exercise('plain-bench', [true]), exercise('plain-row', [true]), exercise('plain-curl', [false])], 2, { workoutView: 'list' })
|
||||
await flushFrame()
|
||||
mocks.scrollCalls.length = 0
|
||||
mocks.S.active.workoutView = 'compact'
|
||||
await rerender()
|
||||
await flushFrame()
|
||||
expect(mocks.scrollCalls.length).toBe(1)
|
||||
expect(mocks.scrollCalls[0].node.classList.contains('cur')).toBe(true)
|
||||
// ...but not when "current" merely moves inside the open list (that was #224's rule).
|
||||
mocks.scrollCalls.length = 0
|
||||
await rerenderAt(1)
|
||||
await flushFrame()
|
||||
expect(mocks.scrollCalls.length).toBe(0)
|
||||
})
|
||||
|
||||
it('stacks every exercise, labels each unit, and hides card navigation', async () => {
|
||||
await mount([exercise('plain-bench', [false, false]), exercise('plain-row', [false])], 0, { workoutView: 'list' })
|
||||
|
||||
|
||||
Reference in new issue
Block a user