Commit 3f615474 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Fix jaggy lyric transitions, screen cutoffs, and broken swipe gestures in FullPlayer

Three real-device bugs reported after the lyrics overlay rebuild: the live
line swapped text with no transition (now keyed + animated via CSS), the
full lyrics screen's fade mask was too narrow for the larger font and had
no safe-area bottom padding (widened + padded), and swipe-up-to-open did
nothing on a real touchscreen (ad-hoc pointer handlers lacked move/cancel
handling and touchAction: none - replaced with a shared useVerticalSwipe
hook).

Verifying the swipe fix in a real browser surfaced two further bugs
invisible in jsdom: every focus() call in FullPlayer scrolls its target
into view by default, firing while panels are still off-screen/mid-
transition and dragging documentElement's scroll position around (fixed
with preventScroll: true everywhere, plus locking documentElement's
overflow alongside body's). And the lyrics header is only 64px tall, so a
downward swipe crosses its bottom edge before the hook's deferred pointer
capture can engage - useVerticalSwipe now tracks drags via window-level
listeners instead of ones scoped to the dragged element.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 435c86a2
Pipeline #1165 passed with stage
in 8 minutes and 19 seconds
...@@ -214,9 +214,13 @@ describe('FullPlayer', () => { ...@@ -214,9 +214,13 @@ describe('FullPlayer', () => {
// distinctive layout classes since it has no role/label of its own. // distinctive layout classes since it has no role/label of its own.
const cover = document.querySelector('.flex-1.items-center.justify-center') as HTMLElement const cover = document.querySelector('.flex-1.items-center.justify-center') as HTMLElement
verticalSwipe(cover, 400, 300) verticalSwipe(cover, 400, 300)
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' }) await screen.findByRole('region', { name: 'Lyrics' })
verticalSwipe(lyricsRegion.parentElement as HTMLElement, 300, 400) // The close-swipe handlers live on the lyrics screen's header specifically (not the whole
// screen, which would otherwise fight the lyrics list's own vertical scroll) - identified
// via the back button it contains, same as the cover is identified by its own layout above.
const lyricsHeader = screen.getByRole('button', { name: 'Back to now playing' }).parentElement as HTMLElement
verticalSwipe(lyricsHeader, 300, 400)
await waitFor(() => expect(screen.queryByRole('region', { name: 'Lyrics' })).not.toBeInTheDocument()) await waitFor(() => expect(screen.queryByRole('region', { name: 'Lyrics' })).not.toBeInTheDocument())
}) })
......
This diff is collapsed.
import { fireEvent, render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { useVerticalSwipe } from './useVerticalSwipe'
function SwipeTarget({ direction, onSwipe }: { direction: 'up' | 'down'; onSwipe: () => void }) {
const handlers = useVerticalSwipe({ direction, onSwipe })
return (
<div data-testid="target" {...handlers}>
target
</div>
)
}
function drag(el: HTMLElement, points: number[]) {
fireEvent.pointerDown(el, { clientY: points[0], pointerId: 1 })
for (const y of points.slice(1)) {
fireEvent.pointerMove(el, { clientY: y, pointerId: 1 })
}
}
describe('useVerticalSwipe', () => {
it('fires onSwipe when dragged up past the threshold and released', () => {
const onSwipe = vi.fn()
render(<SwipeTarget direction="up" onSwipe={onSwipe} />)
const target = screen.getByTestId('target')
drag(target, [200, 100])
fireEvent.pointerUp(target, { clientY: 100, pointerId: 1 })
expect(onSwipe).toHaveBeenCalledTimes(1)
})
it('fires onSwipe when dragged down past the threshold and released', () => {
const onSwipe = vi.fn()
render(<SwipeTarget direction="down" onSwipe={onSwipe} />)
const target = screen.getByTestId('target')
drag(target, [100, 200])
fireEvent.pointerUp(target, { clientY: 200, pointerId: 1 })
expect(onSwipe).toHaveBeenCalledTimes(1)
})
it('does not fire for an upward drag when configured for down', () => {
const onSwipe = vi.fn()
render(<SwipeTarget direction="down" onSwipe={onSwipe} />)
const target = screen.getByTestId('target')
drag(target, [200, 100])
fireEvent.pointerUp(target, { clientY: 100, pointerId: 1 })
expect(onSwipe).not.toHaveBeenCalled()
})
it('does not fire when released short of the threshold', () => {
const onSwipe = vi.fn()
render(<SwipeTarget direction="up" onSwipe={onSwipe} />)
const target = screen.getByTestId('target')
drag(target, [200, 170])
fireEvent.pointerUp(target, { clientY: 170, pointerId: 1 })
expect(onSwipe).not.toHaveBeenCalled()
})
it('a cancelled gesture does not fire onSwipe', () => {
const onSwipe = vi.fn()
render(<SwipeTarget direction="up" onSwipe={onSwipe} />)
const target = screen.getByTestId('target')
drag(target, [200, 100])
fireEvent.pointerCancel(target, { clientY: 100, pointerId: 1 })
fireEvent.pointerUp(target, { clientY: 100, pointerId: 1 })
expect(onSwipe).not.toHaveBeenCalled()
})
it('ignores move/up events from an unrelated pointer id', () => {
const onSwipe = vi.fn()
render(<SwipeTarget direction="up" onSwipe={onSwipe} />)
const target = screen.getByTestId('target')
fireEvent.pointerDown(target, { clientY: 200, pointerId: 1 })
fireEvent.pointerMove(target, { clientY: 100, pointerId: 2 })
fireEvent.pointerUp(target, { clientY: 100, pointerId: 2 })
expect(onSwipe).not.toHaveBeenCalled()
})
it('still fires when release happens away from the dragged element', () => {
// The actual bug this hook exists to fix: a short element (e.g. a compact header) dragged
// vertically has the pointer cross its own edge almost immediately, after which a plain
// onPointerUp attached to the element itself would never see the matching pointerup at
// all - it lands on whatever's underneath instead. Tracking via window listeners means the
// release is still caught regardless of where it lands.
const onSwipe = vi.fn()
render(
<div>
<SwipeTarget direction="down" onSwipe={onSwipe} />
<div data-testid="elsewhere">elsewhere</div>
</div>,
)
const target = screen.getByTestId('target')
const elsewhere = screen.getByTestId('elsewhere')
fireEvent.pointerDown(target, { clientY: 100, pointerId: 1 })
fireEvent.pointerMove(elsewhere, { clientY: 200, pointerId: 1 })
fireEvent.pointerUp(elsewhere, { clientY: 200, pointerId: 1 })
expect(onSwipe).toHaveBeenCalledTimes(1)
})
})
import { useEffect, useRef } from 'react'
interface UseVerticalSwipeOptions {
/** 'up' fires when dragged upward past threshold; 'down' for downward. */
direction: 'up' | 'down'
onSwipe: () => void
/** Pixels the pointer must travel in `direction` before release counts as a swipe. */
threshold?: number
}
interface UseVerticalSwipeResult {
onPointerDown: (e: React.PointerEvent) => void
}
/** Single-direction vertical swipe gesture, no drag-visual tracking (unlike useSwipeAction,
* which follows the finger for a row reveal) - this is a plain threshold-and-release trigger
* for opening/closing a full-screen panel.
*
* Tracks the drag via window-level pointermove/pointerup/pointercancel listeners added on
* pointerdown, rather than relying on onPointerMove/onPointerUp handlers attached to the
* dragged element itself (the more obvious approach, and what useSwipeAction does). That
* works fine for useSwipeAction's row - wide enough that a horizontal drag stays within its
* bounds - but breaks down for a short element being dragged vertically (e.g. a compact
* header being swiped down to close a panel): the pointer crosses the element's own bottom
* edge almost immediately, and once it does, move/up events get hit-tested to whatever's
* underneath instead - they're never delivered to the element's own handlers at all, since it
* isn't an ancestor of the new target. Listening on window sidesteps the problem entirely:
* once a drag starts, events keep arriving regardless of where the pointer physically ends up. */
export function useVerticalSwipe({ direction, onSwipe, threshold = 60 }: UseVerticalSwipeOptions): UseVerticalSwipeResult {
const startYRef = useRef<number | null>(null)
const pointerIdRef = useRef<number | null>(null)
function cleanup() {
window.removeEventListener('pointermove', onWindowPointerMove)
window.removeEventListener('pointerup', onWindowPointerUp)
window.removeEventListener('pointercancel', onWindowPointerCancel)
startYRef.current = null
pointerIdRef.current = null
}
// No-op beyond identifying the right pointer - release is what decides whether this was a
// swipe, and there's no drag-visual to update along the way. Still needed so a listener
// exists to remove in cleanup(), and kept for parity/future use (e.g. a live drag indicator).
function onWindowPointerMove(e: PointerEvent) {
if (pointerIdRef.current !== e.pointerId) return
}
function onWindowPointerUp(e: PointerEvent) {
if (pointerIdRef.current !== e.pointerId) return
const startY = startYRef.current
cleanup()
if (startY === null) return
const dy = e.clientY - startY
if (direction === 'up' && -dy > threshold) onSwipe()
else if (direction === 'down' && dy > threshold) onSwipe()
}
function onWindowPointerCancel(e: PointerEvent) {
if (pointerIdRef.current !== e.pointerId) return
cleanup()
}
function onPointerDown(e: React.PointerEvent) {
if (e.pointerType === 'mouse' && e.button !== 0) return
startYRef.current = e.clientY
pointerIdRef.current = e.pointerId
window.addEventListener('pointermove', onWindowPointerMove)
window.addEventListener('pointerup', onWindowPointerUp)
window.addEventListener('pointercancel', onWindowPointerCancel)
}
// Drops the window listeners if the component unmounts mid-drag (e.g. the panel is closed
// by some other means while a gesture is in flight) - otherwise they'd sit there until a
// pointerup/cancel happens to arrive, harmlessly but pointlessly.
useEffect(() => cleanup, [])
return { onPointerDown }
}
...@@ -99,8 +99,29 @@ ...@@ -99,8 +99,29 @@
animation: page-enter 300ms ease-out; animation: page-enter 300ms ease-out;
} }
/* The live lyric line overlaid on FullPlayer's cover art used to swap text on every active-line
change with no transition at all - React just re-renders the new string in place, which reads
as a jaggy/instant jump rather than a line change. Applied to a freshly-keyed element (see
FullPlayer.tsx) so each change genuinely restarts the animation instead of interrupting an
in-flight one. */
@keyframes lyric-line-enter {
from {
opacity: 0;
transform: translateY(6px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animate-lyric-line {
animation: lyric-line-enter 250ms ease-out;
}
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
.animate-page-enter { .animate-page-enter,
.animate-lyric-line {
animation: none; animation: none;
} }
} }
......
...@@ -190,6 +190,7 @@ const FRONTEND_DONE: DoneGroup[] = [ ...@@ -190,6 +190,7 @@ const FRONTEND_DONE: DoneGroup[] = [
'Library page with playback', '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. 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', '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',
'Lyrics presentation rebuilt to match Spotify\'s actual current pattern, not the "tap a bar to swap cover for lyrics" one from 08-31 (2026-09-01, researched via web search rather than guessed at) - and then rebuilt again same day once the user shared real Spotify screenshots, since the first pass (live line as a small caption below the cover) still buried it. Spotify\'s own placement is a gradient-scrim overlay directly on the album art itself, inside a scrollable "Lyrics" preview card further down the Now Playing page; adapted rather than copied, since our player is a fixed panel that doesn\'t scroll: the live synced line (plus a one-line preview of what\'s coming next) sits overlaid on the bottom of the art with the same gradient-scrim treatment, with an explicit chevron button alongside the swipe-up gesture and the tap-the-line fallback - three independent ways to find the same action instead of one easy-to-miss caption. The full lyrics screen\'s typography also moved from centered/small to Spotify\'s actual large, bold, left-aligned style.', 'Lyrics presentation rebuilt to match Spotify\'s actual current pattern, not the "tap a bar to swap cover for lyrics" one from 08-31 (2026-09-01, researched via web search rather than guessed at) - and then rebuilt again same day once the user shared real Spotify screenshots, since the first pass (live line as a small caption below the cover) still buried it. Spotify\'s own placement is a gradient-scrim overlay directly on the album art itself, inside a scrollable "Lyrics" preview card further down the Now Playing page; adapted rather than copied, since our player is a fixed panel that doesn\'t scroll: the live synced line (plus a one-line preview of what\'s coming next) sits overlaid on the bottom of the art with the same gradient-scrim treatment, with an explicit chevron button alongside the swipe-up gesture and the tap-the-line fallback - three independent ways to find the same action instead of one easy-to-miss caption. The full lyrics screen\'s typography also moved from centered/small to Spotify\'s actual large, bold, left-aligned style.',
'Three real-device lyrics bugs fixed same day, found after the overlay rebuild above shipped (2026-09-02): (1) the live line swapped text on every change with no transition at all - now the overlay text is remounted via a React key on each change so a CSS fade/slide-up animation genuinely replays instead of interrupting mid-flight; (2) the full lyrics screen\'s top/bottom fade mask was narrower than the new larger line height, reading as an abrupt cut rather than a gentle fade, and had no `env(safe-area-inset-bottom)` padding for the home-indicator/gesture-bar on real devices - mask widened and safe-area padding added; (3) swipe-up-to-open silently did nothing on a real touchscreen - the ad-hoc handlers had no `onPointerMove`/`onPointerCancel` handling or `touchAction: none`, so the browser\'s native scroll/overscroll heuristics could cancel the gesture before pointerup ever fired, the same bug class already solved once for row-swipe actions. Fixed with a new shared `useVerticalSwipe` hook, used for both the open (swipe up on the cover) and close (swipe down on the lyrics header) gestures. Real-browser (Playwright) verification of (3) surfaced two further bugs invisible in jsdom: every `.focus()` call in FullPlayer (there are seven, one per panel-open/close transition) fires the instant its panel\'s state flips, while that panel is still off-screen or mid-CSS-transition - `focus()`\'s default scroll-into-view behavior doesn\'t know that, and scrolled `documentElement` to chase an off-screen target, which visibly shoved the lyrics header out of frame (all seven calls now pass `{ preventScroll: true }`, alongside a defensive `documentElement.style.overflow = \'hidden\'` lock next to the existing body one - locking body alone doesn\'t stop documentElement, the actual scrolling element in standards mode). Separately, the swipe-down-to-close gesture itself failed even after that fix: the lyrics header is only 64px tall, so a downward drag crosses its own bottom edge within the first couple of pixels, and the hook\'s deferred `setPointerCapture` (borrowed from `useSwipeAction`, needed so a plain tap on the header\'s own back button still reaches the button) never got the chance to fire before the pointer left the element\'s bounds - once outside the header entirely, follow-up move/up events silently hit-test to whatever\'s underneath instead of the header, and the swipe was dropped. `useSwipeAction` never hit this because its row targets are wide enough in the swipe direction to stay under the pointer for the whole gesture; `useVerticalSwipe` now tracks an active drag via `window`-level pointermove/pointerup/pointercancel listeners instead, which keep receiving events regardless of where the pointer physically ends up.',
'Universal search box: separate Songs and Albums result sections while searching - replaces the plain list rather than filtering it in place', 'Universal search box: separate Songs and Albums result sections while searching - replaces the plain list rather than filtering it in place',
'Spotify-style default (non-search) view (2026-09-01): an Albums grid of cover-art cards above an always-on All Songs list covering the full library. The (album, artist) grouping is derived client-side from the already-loaded song list (mirroring /library/search\'s own grouping) rather than adding a second backend endpoint that would return the same shape - deletions and new songs update both sections for free since All Songs and the album groups both derive from the same one songs array.', 'Spotify-style default (non-search) view (2026-09-01): an Albums grid of cover-art cards above an always-on All Songs list covering the full library. The (album, artist) grouping is derived client-side from the already-loaded song list (mirroring /library/search\'s own grouping) rather than adding a second backend endpoint that would return the same shape - deletions and new songs update both sections for free since All Songs and the album groups both derive from the same one songs array.',
'Dedicated album page at /library/album (2026-09-01), replacing the earlier same-day expand-in-place version - tapping an album (from either the default grid or a search result row) now navigates to a real page showing its tracks in genuine track order, not upload/discovery order. This closed a real gap: identify_audio() (and the IdentifiedTrack cache) always computed a track_number, but LibrarySong had no column to store it in, so it was silently discarded on every tag/upload - added the column, a migration, persistence in _identify_tag_and_store, and a new GET /library/album?album=&artist= endpoint that sorts by it (numberless tracks sort after numbered ones, then alphabetically). Starting playback from any track in the list queues the rest of the real album order behind it, not just that one song. The page originally repeated the album name twice (Layout\'s own page-title heading, plus a second large one in the header) - caught by a genuinely flaky test rather than a design review, since jsdom happily renders two <h1>s with identical text where a real glance at the screenshot would\'ve caught it sooner; now only the one from Layout remains.', 'Dedicated album page at /library/album (2026-09-01), replacing the earlier same-day expand-in-place version - tapping an album (from either the default grid or a search result row) now navigates to a real page showing its tracks in genuine track order, not upload/discovery order. This closed a real gap: identify_audio() (and the IdentifiedTrack cache) always computed a track_number, but LibrarySong had no column to store it in, so it was silently discarded on every tag/upload - added the column, a migration, persistence in _identify_tag_and_store, and a new GET /library/album?album=&artist= endpoint that sorts by it (numberless tracks sort after numbered ones, then alphabetically). Starting playback from any track in the list queues the rest of the real album order behind it, not just that one song. The page originally repeated the album name twice (Layout\'s own page-title heading, plus a second large one in the header) - caught by a genuinely flaky test rather than a design review, since jsdom happily renders two <h1>s with identical text where a real glance at the screenshot would\'ve caught it sooner; now only the one from Layout remains.',
......
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