Skip to content

fix(player): a track change during a load cancels the auto-resume - #259

Merged
sydevs-bot merged 8 commits into
mainfrom
claude/fix-256-player-auto-resume
Nov 18, 2026
Merged

sydevs-bot merged 8 commits into
mainfrom
claude/fix-256-player-auto-resume

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The playlist player now auto-resumes from what the listener last asked for, so a track change arriving while a track is still loading no longer stops playback.

Change outline

Flow — what decides a newly loaded track's autoplay

The flag is written where intent is stated, and read where the track loads. Nothing in between samples the player.

 usePlaylistAudioPlayer()                        hooks/audio/usePlaylistAudioPlayer.ts
+  play()      → wantsPlaybackRef = true  → playerControls.play()
+  pause()     → wantsPlaybackRef = false → playerControls.pause()
+  togglePlayPause() → isPlaying ? pause() : play()
   previous() / next()
-    wasPlayingRef = playerState.isPlaying       # false for the width of a load
     setCurrentTrackIndex(…)
   selectTrack(i)   → wantsPlaybackRef = true  → #255's behaviour, kept
   effect [currentTrackIndex, currentTrack?.url]
     loadCurrentTrack()
-      load(url, { autoplay: wasPlayingRef })
+      load(url, { autoplay: wantsPlaybackRef })

Behaviour — the effect that used to heal the flag, and the state it wrote

Narrowing this effect to its one remaining statement showed that hasEnded had no reader
anywhere in the repo, so the state goes with the effect.

-effect [isPlaying, isLoading, isReady]
-  isPlaying
-    wasPlayingRef = true                        # re-raised the flag after every start
-    setHasEnded(false)
-  else if !isLoading && !isReady
-    wasPlayingRef = false                       # unreachable: a pause keeps isReady

-const [hasEnded, setHasEnded] = useState(false)
-handleTrackEnd() → setHasEnded(true)
-state.hasEnded                                  # composed, never read
-PlaylistAudioPlayerState.hasEnded               # components/molecules/AudioPlayer/types.ts

AudioPlayer.tsx is the hook's only consumer and never read the field. grep -rni hasended
returns nothing.

Components — the controls the hook hands out

play, pause and togglePlayPause stop being re-exports of the core hook's, which is what puts every path to playback through the flag.

 controls                                        hooks/audio/usePlaylistAudioPlayer.ts
-  play: playerControls.play
-  pause: playerControls.pause
-  togglePlayPause: playerControls.togglePlayPause
+  play, pause, togglePlayPause                  # this hook's own, declared above

selectTrack keeps the body #255 gave it, with two changes the merge made. Its in-place play
goes 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 its useCallback, matching
the three above: playerControls changes 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

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh on the branch merged with origin/main — lint 0 errors, tsc --noEmit clean, 117 files / 1139 tests pass
  • Targeted specs: 8 passed (hooks/audio/usePlaylistAudioPlayer.test.ts). Mutating autoplay back to playerState.isPlaying fails 4 of them; routing selectTrack's in-place play around play fails a 5th
  • Build: N/A — no build, server or Wrangler change
  • Browser: ✓ 7 scenarios in headless Chromium against the Ladle AudioPlayer and MusicLibrary stories, detailed below

Manual 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.

  1. pnpm ladle, open ?story=organisms--music-library, press play, then press next twice inside about a second. Audio must still be playing.
  2. Same story: press play, press pause, then press next. Nothing must start playing.
  3. Let a track run to its end. The next one must start on its own.
  4. Click a playlist row while the player is paused. That track must start playing — fix(playlist): a filtered playlist plays and highlights the wrong track #255's behaviour, which the reviewer chose over this ticket's third criterion.

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

  • fix(playlist): a filtered playlist plays and highlights the wrong track #255 merged, and the reviewer answered the question thread with B. A row click always starts playback, so selectTrack keeps 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.
  • The transport button lies for the width of a load, and the limit is now a shortcut: marker above togglePlayPause. Measured: after pressing next while playing, the button's label reads Play until the fetch completes, and a press inside that window calls play() against the listener's intent. Fixing it means state.isPlaying reporting 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 _queue and the manual play() resolves to the same sound id.
  • Dismissed — move the intent down into useAudioPlayer (the core hook), so load's autoplay would default to it. The core hook is the only layer that sees every transition, so the argument is real, but it changes a hook MeditationPlayer also uses and the default of a shared load, 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.
  • Dismissed — MeditationPlayer.tsx:417 reads the same lagging state.isPlaying. Checked: that effect lists state.isPlaying in 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 a load and could not.
  • Dismissed — drop useCallback from previous/next/toggleShuffle for consistency with the three new unmemoized controls. True that they pay no rent while controls is a fresh literal, but memoizing the new ones would be cargo cult (playerControls changes identity every render) and removing the old ones reaches toggleShuffle, which this ticket has no business in.
  • Review ran as /simplify + /code-review high; no routine has pr-review-toolkit. The correctness pass caught that my own /simplify commit had weakened the then source-scan guard to a write count, which a true in next and a false in previous would still satisfy. The behaviour specs that replaced it do not have that hole.
  • Security review skipped: no changed path matches securityReview.triggerPattern.
  • Docs checked, nothing stale — no guide or doc describes the auto-resume mechanism.
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 from Howler._howls[n].playing() rather than from the document.

Fetch delay Gap between the two next presses origin/main This branch
100ms 80ms stopped playing
300ms 150ms stopped playing
800ms 150ms stopped playing
800ms 1200ms playing playing
0ms 0ms playing playing

So the window is exactly as wide as the audio fetch and no wider — the ticket's guess was right. The two rows where main survives 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 after pause, the end of a track, and each selectTrack path.

Closes #256


Generated by Claude Code

…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 sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 question for the reviewer, one per thread.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread hooks/audio/usePlaylistAudioPlayer.ts Resolved
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot

sydevs-bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 21:16Z address-review · attempt 1 · session · done
  • 21:16Z address-review · attempt 1 · session
  • 20:07Z address-review · attempt 1 · session · done
  • 20:07Z address-review · attempt 1 · session
  • 20:00Z review-pr · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 18, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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 — hasEnded has no reader in the repo, and this diff narrows its effect to the one write that shows it. hooks/audio/usePlaylistAudioPlayer.ts:116
  • consider — the transport button always plays during a load and writes true to 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:97 passes the clicked index as initialTrackIndex, which AudioPlayer.tsx:73 feeds to useState alone.
  • Both dismissals in the body are accurate. MeditationPlayer.tsx:417 does list state.isPlaying in its deps.
  • Dropping useCallback from play, pause and togglePlayPause costs nothing: AudioPlayer.tsx is 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-scan is 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

Comment thread hooks/audio/usePlaylistAudioPlayer.ts Resolved
Comment thread hooks/audio/usePlaylistAudioPlayer.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 18, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 18, 2026
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

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, tsc clean, 1121 tests pass. Body refreshed — the outline described an effect this push removed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review November 18, 2026 20:14
@sydevs-bot
sydevs-bot requested a review from Ardnived November 18, 2026 20:14
@sydevs-bot
sydevs-bot enabled auto-merge November 18, 2026 20:14
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 18, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 18, 2026
…-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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Answered and merged. #255 is on main, so the branch carries it.

Lean gate green: 0 lint errors, tsc clean, 1139 tests. Body refreshed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 18, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 18, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 18, 2026
Merged via the queue into main with commit 0d92c9d Nov 18, 2026
35 of 36 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-256-player-auto-resume branch November 18, 2026 21:37
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 18, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 18, 2026
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(player): a track change during a load cancels the auto-resume

3 participants