fix(mobile): stop the player re-rendering on every playback tick #104

Merged
joshuafhiggins merged 2 commits from t3/reduce-player-rerenders into main 2026-11-16 22:02:57 -05:00
Owner

The mobile player re-rendered twice a second while audio played. The 500 ms playback clock lived in the broad usePlayback() value, so the player, tablet player, queue and intent bridge all re-rendered on every tick. seekTo also depended on duration, so every playback action changed identity on each track change, which re-rendered every album row through useMediaMenuActions.

Fix

  • currentTime and duration move to usePlaybackProgress(). Only the new PlayerProgress (slider and time labels) reads it. usePlayback() is removed; seekTo and waitForPlaybackReady join usePlaybackActions().
  • seekTo reads duration from a ref, so all actions are stable.
  • Dismiss gestures, now playing colors, the queue header and the queue renderItem are memoized. AlbumTrackRow gets a stable onPlay.
  • The phone volume listener lives in a VolumeSlider child, so the tablet player no longer registers it twice.

One visible change: tablet time labels now highlight while scrubbing, matching the phone.

Render counts

Temporary counters, iPhone Duo simulator, per 10 s window while playing:

Scenario Before After
Player open PlayerScreen 20, SongMeta 20, AppIntentBridge 26 PlayerProgress 20, AppIntentBridge 6
Player with queue + NowPlayingQueue 20 PlayerProgress 20, AppIntentBridge 6
Album screen, play + 3 skips (30 s) AlbumTrackRow 144 AlbumTrackRow 0
Tablet player (unfolded Duo), with queue not measured PlayerProgress 20, AppIntentBridge 6

Verified

On the iPhone Duo simulator, folded (phone player) and unfolded (tablet player): playback, skip, auto-advance, seeking, tapping a queued song, the side-by-side queue, and swipe-to-dismiss from every gesture area. Android was not run. Mobile typecheck passes.

Model: Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code

The mobile player re-rendered twice a second while audio played. The 500 ms playback clock lived in the broad `usePlayback()` value, so the player, tablet player, queue and intent bridge all re-rendered on every tick. `seekTo` also depended on `duration`, so every playback action changed identity on each track change, which re-rendered every album row through `useMediaMenuActions`. ## Fix - `currentTime` and `duration` move to `usePlaybackProgress()`. Only the new `PlayerProgress` (slider and time labels) reads it. `usePlayback()` is removed; `seekTo` and `waitForPlaybackReady` join `usePlaybackActions()`. - `seekTo` reads duration from a ref, so all actions are stable. - Dismiss gestures, now playing colors, the queue header and the queue `renderItem` are memoized. `AlbumTrackRow` gets a stable `onPlay`. - The phone volume listener lives in a `VolumeSlider` child, so the tablet player no longer registers it twice. One visible change: tablet time labels now highlight while scrubbing, matching the phone. ## Render counts Temporary counters, iPhone Duo simulator, per 10 s window while playing: | Scenario | Before | After | | --- | --- | --- | | Player open | PlayerScreen 20, SongMeta 20, AppIntentBridge 26 | PlayerProgress 20, AppIntentBridge 6 | | Player with queue | + NowPlayingQueue 20 | PlayerProgress 20, AppIntentBridge 6 | | Album screen, play + 3 skips (30 s) | AlbumTrackRow 144 | AlbumTrackRow 0 | | Tablet player (unfolded Duo), with queue | not measured | PlayerProgress 20, AppIntentBridge 6 | ## Verified On the iPhone Duo simulator, folded (phone player) and unfolded (tablet player): playback, skip, auto-advance, seeking, tapping a queued song, the side-by-side queue, and swipe-to-dismiss from every gesture area. Android was not run. Mobile typecheck passes. Model: Claude Opus 5.5 via Claude Code in T3 Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
joshuafhiggins added 1 commit 2026-11-16 14:46:36 -05:00
The playback clock lived in the broad usePlayback() value, so the player,
tablet player, queue and intent bridge re-rendered twice a second. seekTo
also depended on duration, which changed every playback action's identity
on each track change and re-rendered every album row.

- Move currentTime and duration into usePlaybackProgress(), read only by
  the new PlayerProgress slider and time labels. Drop usePlayback().
- Read duration from a ref in seekTo so all actions stay stable.
- Memoize dismiss gestures, now playing colors, the queue header and the
  queue renderItem. Pass a stable onPlay to AlbumTrackRow.
- Keep the phone volume listener in its own VolumeSlider so the tablet
  player no longer registers it twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joshuafhiggins added 1 commit 2026-11-16 22:02:51 -05:00
# Conflicts:
#	apps/mobile/components/app-intent-bridge.tsx
#	apps/mobile/contexts/playback.tsx
joshuafhiggins merged commit f58342f64e into main 2026-11-16 22:02:57 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: joshuafhiggins/otunes#104