Repository navigation
fix(player): a track change during a load cancels the auto-resume - #259
Conversation
…sPlaying `previous`, `next` and `selectTrack` each copied `playerState.isPlaying` into the auto-resume flag before moving the index. That reads the wrong thing: the flag has to survive a load, and `isPlaying` is false for exactly as long as one takes. A second track change inside that window loaded the next track with `autoplay: false`, and playback stopped (#256). Measured in Chromium against the Ladle AudioPlayer story, with every audio request served locally so the load has a known length: the window is as wide as the fetch and no wider. A 100ms fetch broke on presses 80ms apart; an 800ms fetch survived presses 1200ms apart. Over the public internet these mp3s are several megabytes, so the window is not narrow in practice. `wantsPlaybackRef` replaces the flag, and `play` and `pause` are its only writers — the two moments a listener states what they want. The navigation callbacks now move the index and nothing else, so each drops its `playerState.isPlaying` dependency, and the effect that re-raised the flag on every play is gone with the state it was healing. The hook's playlist-level `play`, `pause` and `togglePlayPause` wrap the core hook's rather than re-exporting them, which is what puts every path to playback through the flag. No DOM test environment exists here, so the test asserts where the flag is written rather than what the audio does. That is the defect exactly, and it fails four ways against the previous code. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWKdRAN3GtaQ1kXB8P
The test asserted the flag's spelling three ways and carried a brace matcher to scope them. One `matchAll` over the file answers the same question: the flag takes `true` and `false` and nothing else, which is the defect stated directly. `readSource` already pairs the read with the comment strip. `togglePlayPause` had copied the core hook's branch; it now composes this hook's own `play` and `pause` on one line. `selectTrack` had become an identity wrapper around `setCurrentTrackIndex`, so the controls object names that setter instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWKdRAN3GtaQ1kXB8P
Counting the writes leaves the original defect green: a `true` in `next` and a `false` in `previous` is still one of each. The guard has to say where each one sits, which is what the count replaced. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWKdRAN3GtaQ1kXB8P
sydevs-bot
left a comment
There was a problem hiding this comment.
1 question for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
This is the ticket's first shape and no bigger: two files, one hook, one test. Intent is written where a listener states it and read where a track loads, so the class is gone rather than the window narrowed. Nothing is smuggled in beside the fix.
The wrapper is the right owner because the sibling left outside it has no instance of the defect — MeditationPlayer.tsx:382 is the core hook's only other consumer, and it loads through the url option and never calls load a second time.
Two points on the file the diff grows, neither blocking.
Findings
should-fix—hasEndedhas no reader in the repo, and this diff narrows its effect to the one write that shows it.hooks/audio/usePlaylistAudioPlayer.ts:116consider— the transport button always plays during a load and writestrueto the flag against the listener's intent. The limit lives in this body, not in the file.hooks/audio/usePlaylistAudioPlayer.ts:132
What was checked
- Acceptance criteria 1, 3, 4 and 5 hold on the branch. Criterion 2 is unreachable here, as the body says:
MusicLibrary.tsx:97passes the clicked index asinitialTrackIndex, whichAudioPlayer.tsx:73feeds touseStatealone. - Both dismissals in the body are accurate.
MeditationPlayer.tsx:417does liststate.isPlayingin its deps. - Dropping
useCallbackfromplay,pauseandtogglePlayPausecosts nothing:AudioPlayer.tsxis the hook's only consumer and puts no control in a dependency array. - Ladder, on each new piece: no platform or installed API carries playback intent across a Howler load, and
tests/guards/_source-scanis the repo's own helper for a source assertion. - Read whole on the branch: both audio hooks,
AudioPlayer.tsx,MusicLibrary.tsx,types.ts, the new test.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`hasEnded` was written on track end and cleared on playback, exposed on the hook's state object and declared on the state type, and read nowhere in the repo. Narrowing its effect to the single write is what made that visible. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZDuwkv9EZSzRiSnVz
`togglePlayPause` branches on `playerState.isPlaying`, which is false for the width of a load, so a press meant to stop an auto-resuming track calls `play()` and writes `true` to the intent flag. Naming the limit only in the PR body loses it at merge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZDuwkv9EZSzRiSnVz
|
Both critic threads adopted. The question thread stays open.
Still waiting on you: should a row click start playback on a paused player? — the one point #255 and #256 contradict each other on. Lean gate green: 0 lint errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | 62641cf | Commit Preview URL Branch Preview URL |
Nov 18 2026, 09:22 PM |
…-auto-resume #255 landed on main and rewrote the same hook, so three hunks had a choice to make. The reviewer answered the question thread with **B**: a row click always starts playback. - `selectTrack` keeps #255's body — it raises the resume flag unconditionally, and plays in place when the picked row is already loaded. #256's third acceptance criterion is dropped, per that answer. - The in-place play goes through this hook's `play`, not `playerControls.play`. The core control sets no intent, so a skip arriving during that load would have gone silent — the defect #256 closes. - `selectTrack` drops its `useCallback`, matching the three controls this branch already unmemoized: `playerControls` changes identity every render, so the memo never held. - The hook test takes #255's jsdom harness. Its `carries playback across a skip` case asserted autoplay copied from `playerState.isPlaying`, which is the defect stated as a requirement, so it becomes two cases on what the listener last asked for, plus the two-skips-inside-one-load regression. The source-scan test it replaces is gone: the branch could not drive a DOM when it was written, and now can. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjY4Sv1i332csJS5sjt
#256's fourth criterion — a track that ends advances and keeps playing — had only a browser scenario behind it. The jsdom harness #255 brought reaches it: the recorder holds the `onEnd` the load registered. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjY4Sv1i332csJS5sjt
|
Answered and merged. #255 is on main, so the branch carries it.
Lean gate green: 0 lint errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-design | f277c66 | Commit Preview URL Branch Preview URL |
Nov 18 2026, 07:53 PM |
#259 and this branch rewrote neighbouring halves of usePlaylistAudioPlayer, so the two hunks resolve in opposite directions and both behaviours survive. Play order: this branch's `shuffledOrder` state and `playOrder` useMemo win. `hasEnded` goes with main, which dropped it from PlaylistAudioPlayerState; nothing reads it now. The branch's set-state-in-effect disable on `setHasEnded` dies with the call it annotated. Auto-resume: main's side wholesale. It replaced `wasPlayingRef` with `wantsPlaybackRef` and deleted the effect this branch had only annotated, so keeping that annotation would have resurrected a ref no longer declared. ssr-visibility imports the union: main hoisted the three component globs into `componentGlobs`, this branch hoisted `parse` and `walk`, and _source-scan carries both. The local SOURCE_GLOBS goes — the call site already reads componentGlobs after the auto-merge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVrp7hoPJLGB4XKncF
Summary
Change outline
Flow — what decides a newly loaded track's
autoplayThe flag is written where intent is stated, and read where the track loads. Nothing in between samples the player.
Behaviour — the effect that used to heal the flag, and the state it wrote
Narrowing this effect to its one remaining statement showed that
hasEndedhad no readeranywhere in the repo, so the state goes with the effect.
AudioPlayer.tsxis the hook's only consumer and never read the field.grep -rni hasendedreturns nothing.
Components — the controls the hook hands out
play,pauseandtogglePlayPausestop being re-exports of the core hook's, which is what puts every path to playback through the flag.selectTrackkeeps the body #255 gave it, with two changes the merge made. Its in-place playgoes through this hook's
play, so picking the loaded row states the intent a later skip reads —playerControls.play()would have left the flag down. And it drops itsuseCallback, matchingthe three above:
playerControlschanges identity every render, so the memo never held.Preview
Preview pending — the Cloudflare branch alias does not exist until the first build finishes. The change is a hook with no markup, so the pages to open are the two player stories on the Ladle playground preview: Molecules → AudioPlayer and Organisms → MusicLibrary.
Test results
.claude/skills/pr-prep/check.shon the branch merged withorigin/main— lint 0 errors,tsc --noEmitclean, 117 files / 1139 tests passhooks/audio/usePlaylistAudioPlayer.test.ts). Mutatingautoplayback toplayerState.isPlayingfails 4 of them; routingselectTrack's in-place play aroundplayfails a 5thManual verification
The ticket's checklist asks for audio played by hand. The scenarios below were run in headless Chromium with the audio served locally, which is not the same as listening to it.
pnpm ladle, open?story=organisms--music-library, press play, then press next twice inside about a second. Audio must still be playing.Scenarios 1 to 3 were run before #255 merged. Scenario 4 is only reachable since it, and is covered by the specs rather than by hand.
Notes for reviewer
selectTrackkeeps fix(playlist): a filtered playlist plays and highlights the wrong track #255's body and fix(player): a track change during a load cancels the auto-resume #256's third criterion is dropped — the ticket already says so, revised after fix(playlist): a filtered playlist plays and highlights the wrong track #255. The merge commit records the three hunks the conflict made a choice.shortcut:marker abovetogglePlayPause. Measured: after pressing next while playing, the button's label readsPlayuntil the fetch completes, and a press inside that window callsplay()against the listener's intent. Fixing it meansstate.isPlayingreporting intent rather than playback, which redefines the field for every consumer — a call I did not think was mine to make inside this ticket, so the marker names the upgrade trigger instead of this PR taking it. No overlapping audio: I chased a suspected double-play through Howler's_queueand the manualplay()resolves to the same sound id.useAudioPlayer(the core hook), soload'sautoplaywould default to it. The core hook is the only layer that sees every transition, so the argument is real, but it changes a hookMeditationPlayeralso uses and the default of a sharedload, which is wider than this ticket. The ticket's own Approach names the wrapper. Worth a follow-up ticket if you agree with the direction.MeditationPlayer.tsx:417reads the same laggingstate.isPlaying. Checked: that effect listsstate.isPlayingin its deps, so it re-runs and starts the music when playback actually begins. It self-heals; this hook's version baked the value into aloadand could not.useCallbackfromprevious/next/toggleShufflefor consistency with the three new unmemoized controls. True that they pay no rent whilecontrolsis a fresh literal, but memoizing the new ones would be cargo cult (playerControlschanges identity every render) and removing the old ones reachestoggleShuffle, which this ticket has no business in./simplify+/code-review high; no routine haspr-review-toolkit. The correctness pass caught that my own/simplifycommit had weakened the then source-scan guard to a write count, which atrueinnextand afalseinpreviouswould still satisfy. The behaviour specs that replaced it do not have that hole.securityReview.triggerPattern.Detail — reproducing the defect, and the window's measured width
The ticket was filed unverified, and asked for the load window to be measured first. It was, in headless Chromium against the running Ladle, with every audio request fulfilled locally after a controlled delay so the window has a known length. Two details were needed to get audio playing at all: the media element issues a
bytes=0-range request and needs a 206 response, and Howler's html5 mode builds detached<audio>elements, so playback has to be read fromHowler._howls[n].playing()rather than from the document.origin/mainSo the window is exactly as wide as the audio fetch and no wider — the ticket's guess was right. The two rows where
mainsurvives are the control: a gap longer than the fetch, and a fetch too fast for a second press to land inside. These mp3s are several megabytes over the public internet, so the window is not narrow in practice.Behaviour that had to stay unchanged, same harness, both before and after: one next keeps playing; pause then next does not start playing; a track reaching its end advances and keeps playing. Three next presses 60ms apart inside a 1000ms fetch also keep playing, as does the MusicLibrary story with a 2000ms fetch.
The harness lives outside the repo — it needs no repo change, so there is nothing here to review.
What the specs assert now. They were a source scan while this branch had no DOM to drive. #255 brought jsdom and
@testing-library/react, so the merge replaced the scan with the behaviour: two skips inside one load, a skip afterpause, the end of a track, and eachselectTrackpath.Closes #256
Generated by Claude Code