Commit bf57f549 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Fix swipe rows swallowing clicks (real pointer capture bug)

useSwipeAction called setPointerCapture unconditionally on
pointerdown, which redirects the browser's synthesized click event to
the capturing row element instead of whatever was actually tapped -
silently breaking every button inside a Library row (Play, Add to
playlist) on a real device. Invisible in the unit suite since jsdom
stubs setPointerCapture as a no-op; found via real end-to-end
(Playwright) testing while verifying the synced-lyrics fix below.
Capture now only engages once a real drag is detected.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 7689db70
Pipeline #1148 failed with stage
in 19 minutes and 3 seconds
import { fireEvent, render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useSwipeAction } from './useSwipeAction'
function SwipeRow({ onSwipeLeft, onSwipeRight }: { onSwipeLeft?: () => void; onSwipeRight?: () => void }) {
......@@ -90,4 +90,41 @@ describe('useSwipeAction', () => {
fireEvent.pointerMove(row, { clientX: 100, pointerId: 2 })
expect(row.dataset.delta).toBe('0')
})
describe('pointer capture timing', () => {
// Regression: capturing unconditionally on pointerdown (rather than once a real drag is
// detected) redirects the browser's synthesized click event to this element instead of
// whatever was actually tapped underneath the finger - silently breaking every button
// inside a swipeable row in a real browser. jsdom stubs setPointerCapture as a no-op (see
// src/test/setup.ts), which is why this class of bug is invisible to every other test here
// and has to be asserted on directly via the mock instead.
beforeEach(() => {
vi.mocked(window.Element.prototype.setPointerCapture).mockClear()
})
it('does not capture the pointer on a plain tap with no movement', () => {
render(<SwipeRow onSwipeRight={vi.fn()} />)
const row = screen.getByTestId('row')
fireEvent.pointerDown(row, { clientX: 50, pointerId: 1 })
fireEvent.pointerUp(row, { clientX: 50, pointerId: 1 })
expect(window.Element.prototype.setPointerCapture).not.toHaveBeenCalled()
})
it('does not capture for a tiny move well under the drag-intent threshold', () => {
render(<SwipeRow onSwipeRight={vi.fn()} />)
const row = screen.getByTestId('row')
fireEvent.pointerDown(row, { clientX: 50, pointerId: 1 })
fireEvent.pointerMove(row, { clientX: 52, pointerId: 1 })
expect(window.Element.prototype.setPointerCapture).not.toHaveBeenCalled()
})
it('captures the pointer once real dragging is detected', () => {
render(<SwipeRow onSwipeRight={vi.fn()} />)
const row = screen.getByTestId('row')
fireEvent.pointerDown(row, { clientX: 50, pointerId: 1 })
fireEvent.pointerMove(row, { clientX: 70, pointerId: 1 })
expect(window.Element.prototype.setPointerCapture).toHaveBeenCalledTimes(1)
expect(window.Element.prototype.setPointerCapture).toHaveBeenCalledWith(1)
})
})
})
......@@ -42,18 +42,27 @@ export function useSwipeAction({ onSwipeLeft, onSwipeRight, threshold = 72 }: Us
if (e.pointerType === 'mouse' && e.button !== 0) return
startXRef.current = e.clientX
pointerIdRef.current = e.pointerId
// Keeps events targeting this element even once the finger moves past its edges -
// otherwise a fast swipe would stop reporting moves the instant it left the row's bounds.
e.currentTarget.setPointerCapture(e.pointerId)
setSwiping(true)
}
function onPointerMove(e: React.PointerEvent) {
if (pointerIdRef.current !== e.pointerId) return
let dx = e.clientX - startXRef.current
const rawDx = e.clientX - startXRef.current
// Capture only once real dragging is detected (never on pointerdown itself) - capturing
// unconditionally as soon as the pointer goes down, even for a plain tap with ~zero
// movement, redirects the browser's synthesized click event to this element instead of
// whatever was actually tapped underneath the finger. That silently broke every button
// inside a swipeable row (Play, Add to playlist, ...) in a real browser, invisibly in
// tests only because jsdom's setPointerCapture is a stubbed no-op there. Once we're sure
// this is a genuine drag (moved more than a few px), capturing is safe and keeps events
// targeting this element even once the finger moves past the row's edges.
if (Math.abs(rawDx) > 4 && !e.currentTarget.hasPointerCapture(e.pointerId)) {
e.currentTarget.setPointerCapture(e.pointerId)
}
// Clamped to zero (not just left unclamped) in whichever direction has no handler, so a
// row with only one action configured doesn't visually drag in the direction that does
// nothing on release.
let dx = rawDx
if (dx > 0 && !onSwipeRight) dx = 0
if (dx < 0 && !onSwipeLeft) dx = 0
setDeltaX(dx)
......
......@@ -182,7 +182,7 @@ const FRONTEND_DONE: DoneGroup[] = [
area: 'Library & Playlists',
items: [
'Library page with playback',
'Real-time synced lyrics in the full-screen player (2026-08-31): line-by-line highlight follows playback position (last line whose timestamp has passed), auto-scrolls the active line to center, tapping a line seeks there - Spotify\'s actual signature lyrics behavior, not an approximation. Falls back to the existing static full-text view when a song has plain lyrics but no synced timing, and to the empty state when it has neither',
'Real-time synced lyrics in the full-screen player (2026-08-31): line-by-line highlight follows playback position (last line whose timestamp has passed), auto-scrolls the active line to center, tapping a line seeks there - Spotify\'s actual signature lyrics behavior, not an approximation. Falls back to the existing static full-text view when a song has plain lyrics but no synced timing, and to the empty state when it has neither. Fixed same day: the synced-lyrics lookup was only attempted when the identification candidate itself had no plain lyrics already - but Shazam and Gemini can both independently return a plain snippet, which was silently skipping the sync fetch (and any real timing that existed) whenever that happened. Now always attempted, with synced data winning over the candidate\'s own plain text when found; existing library songs were backfilled',
'Universal search box: separate Songs and Albums result sections while searching (an album expands to show/play its tracks) - replaces the plain list rather than filtering it in place',
'Playlists page: list, create, view tracks, playback',
'Add-to-playlist modal from the Library page (add existing or create-and-add)',
......@@ -211,7 +211,7 @@ const FRONTEND_DONE: DoneGroup[] = [
'Installable as a real app (2026-08-31): vite-plugin-pwa generates a manifest.webmanifest + service worker at build time, standalone display, cobalt-themed icons (incl. maskable variants for Android\'s adaptive-icon safe zone) - "Add to Home Screen" on iOS/Android now launches Stax in its own window, not a browser tab. Deliberately no runtimeCaching config: only the built app shell is precached, so authenticated/streamed/API requests always hit the network fresh rather than risking a stale or cross-account cache hit',
'In-app "Install Stax" banner (2026-08-31): the browser\'s own install icon is easy to miss entirely, so useInstallPrompt captures beforeinstallprompt at module load (not inside a component effect - each page wraps its own <Layout>, so a component-scoped listener could miss the one-per-page-load event if it fires before that particular page happens to mount) and InstallBanner surfaces a real "Install" button from it; iOS Safari has no such event at all, so it shows manual Share -> Add to Home Screen instructions instead',
'System/Android back button closes overlays instead of leaving the page underneath them (2026-08-31): useBackButtonClose pushes one history entry per open overlay onto a shared stack (not one popstate listener per instance, since a single back press must close only the top-most of several nested overlays - e.g. FullPlayer\'s Queue screen on top of FullPlayer itself - not all of them at once) - wired into FullPlayer (+ its Queue screen as a second nested level), Layout\'s mobile More sheet, AddToPlaylistModal, SongPicker, and RemixSongPicker. Fixed same day: closing an overlay via an action that *also* navigates (e.g. a More-sheet item, which is both a route Link and calls onClose) was clobbering that navigation - the cleanup unconditionally called history.back() to consume its own entry, which by then was buried under the Link\'s own pushState, so it undid the navigation instead. Each pushed entry now carries a unique id and cleanup only consumes it if it\'s still the current one',
'Swipe gestures on Library rows (2026-08-31): useSwipeAction (pointer-events based, no gesture library) drives a swipe-right-to-queue / swipe-left-to-delete interaction, sharing the same PlayerContext.addToQueue used elsewhere - queueing appends without touching whatever is currently playing, unlike toggle() which replaces the whole queue and starts playback',
'Swipe gestures on Library rows (2026-08-31): useSwipeAction (pointer-events based, no gesture library) drives a swipe-right-to-queue / swipe-left-to-delete interaction, sharing the same PlayerContext.addToQueue used elsewhere - queueing appends without touching whatever is currently playing, unlike toggle() which replaces the whole queue and starts playback. Fixed same day, found via real end-to-end (Playwright) testing rather than the unit suite: pointer capture was engaged unconditionally on pointerdown, which redirects the browser\'s synthesized click to the capturing row instead of whatever was actually tapped - silently breaking every button inside a row (Play, Add to playlist) on a real device. Invisible in jsdom, which stubs setPointerCapture as a no-op. Now only captures once a real drag is detected (a few px of movement), leaving plain taps untouched',
],
},
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment