A stuck scroll's report checks again, and knows when a swipe last moved the reader (#488, #450)

All three scroll_stuck reports since 9035306 said "slid 0s ago". The swipe
code's touchend runs before the stuck-scroll watcher's and calls slide(0)
on every touch in the reader that is not a swipe, and slide set slidAt
whatever dx was. It is now set only for a move across.

The watcher read scrollTop on touchend. iOS scrolls off the main thread,
and two of the three reports were fast flicks of 2-4 touchmoves, which can
end before the page knows the new position. It looks again 300 ms later
and reports only a reader that still has not moved, with the drag's time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVBuJRne2JAhFpaDV2U
This commit is contained in:
2026-11-22 08:38:54 -05:00
parent 520c8bf8ff
commit 8afa79b022
2 changed files with 16 additions and 7 deletions

View File

@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- A report of a reader that would not scroll no longer comes from a quick flick that did scroll, and says when the reader was last swiped across, not that it was just now (#488).
- The headers of Currently Listening, Up Next, Playlists and Signals start where a podcast's does, rather than twice as far in and further down (#485).
- On a phone, a pinned item's pin in the reader's floating actions is on its accent disc again, rather than nearly invisible on a light theme (#480).
- Swiping between items on a phone no longer flashes: the pictures of the items either side are loaded ahead, so the preview under your finger shows its picture with its text, and the swipe ends only once the new item's pictures are ready (#471).

View File

@@ -118,7 +118,8 @@ function beside(dx: number){
/// beside it with it.
function slide(dx: number, ms = 160){
const d = $('#detail'); if(!d) return;
slidAt = Date.now();
// Only a move across: every touch in the reader that is not a swipe ends in slide(0) (#488).
if(dx) slidAt = Date.now();
dx = Math.round(dx); // whole pixels, or the seam between the reader and its neighbour blurs
const w = d.clientWidth || 1, tr = ms ? `transform ${ms}ms ease-out, opacity ${ms}ms ease-out` : 'none';
d.style.transition = tr;
@@ -209,7 +210,7 @@ document.addEventListener('touchcancel', () => { if(touch?.pane === 'list') pull
// What #450's three reports could not say (#450): where the finger began, whether the page saw it
// move at all (none means the browser kept the drag for itself), whether the page cancelled the
// touch, and how long since the reader was last slid across, the one thing a swipe changes on it.
let drag: {x: number, y: number, top: number, on: string, moves: number, cancelled: boolean} | null = null,
let drag: {x: number, y: number, t: number, top: number, on: string, moves: number, cancelled: boolean} | null = null,
shownAt = Date.now(), slidAt = 0;
document.addEventListener('visibilitychange', () => { if(!document.hidden) shownAt = Date.now(); });
const named = (el: Element | null) => !el ? 'nothing'
@@ -225,7 +226,7 @@ document.addEventListener('touchstart', ev => {
if(ev.touches.length !== 1 || !d || !S.sel) return;
const r = d.getBoundingClientRect();
if(t.clientX < r.left || t.clientX > r.right || t.clientY < r.top || t.clientY > r.bottom) return;
drag = {x: t.clientX, y: t.clientY, top: d.scrollTop, on: named(ev.target as Element), moves: 0, cancelled: false};
drag = {x: t.clientX, y: t.clientY, t: Date.now(), top: d.scrollTop, on: named(ev.target as Element), moves: 0, cancelled: false};
// After the swipe's own touchstart, which may cancel it, has run.
queueMicrotask(() => { if(drag) drag.cancelled = ev.defaultPrevented; });
}, {passive: true});
@@ -234,8 +235,15 @@ document.addEventListener('touchend', ev => {
const d = $('#detail'), t = ev.changedTouches[0], g = drag;
drag = null;
if(!g || !d || !t) return;
const dy = t.clientY - g.y, room = d.scrollHeight - d.clientHeight;
if(!stuckDrag(dy, t.clientX - g.x, g.top, d.scrollTop, room)) return;
const dy = t.clientY - g.y, dx = t.clientX - g.x, room = d.scrollHeight - d.clientHeight, ms = Date.now() - g.t;
if(!stuckDrag(dy, dx, g.top, d.scrollTop, room)) return;
// Looked at again a moment later: iOS scrolls off the main thread, and a fast flick can end
// before the page has been told where it went (#488).
setTimeout(() => {
if(stuckDrag(dy, dx, g.top, d.scrollTop, room)) stuck(d, t, g, dy, room, ms);
}, 300);
});
function stuck(d: HTMLElement, t: Touch, g: NonNullable<typeof drag>, dy: number, room: number, ms: number){
const inert = ([...document.body.children] as HTMLElement[]).filter(el => el.inert).map(named).join(' ');
report('scroll_stuck', {feed: S.feed, state: [
`top ${g.top} of ${room}`, `drag ${Math.round(dy)}px`, `started on ${g.on}`,
@@ -244,6 +252,6 @@ document.addEventListener('touchend', ev => {
`transform ${d.style.transform || 'none'}`, `peek ${$('#dpeek') ? 'left behind' : 'gone'}`,
`overflow ${getComputedStyle(d).overflowY}`, `reading ${document.body.classList.contains('reading')}`,
`shown ${Math.round((Date.now() - shownAt) / 1000)}s ago`, `${S.entries.length} loaded`,
`from x ${Math.round(g.x)}`, `${g.moves} moves seen`, `touch ${g.cancelled ? 'cancelled' : 'left alone'}`,
`from x ${Math.round(g.x)}`, `${g.moves} moves seen in ${ms}ms`, `touch ${g.cancelled ? 'cancelled' : 'left alone'}`,
`slid ${slidAt ? Math.round((Date.now() - slidAt) / 1000) + 's ago' : 'never'}`].join(', ')});
});
}