Repository navigation
fix(playlist): a filtered playlist plays and highlights the wrong track - #255
Conversation
`currentTrackIndex` and `onTrackClick` index `tracks`, but the rendered rows carried their position in the filtered list. With a filter active the two disagreed, so the "now playing" highlight marked the wrong row and a click reported the wrong track. `visibleTracks` pairs each track with its index in `tracks` in the one place that knows both, leaving `PlaylistProps` unchanged. The row key becomes the track's own url, which the filter does not reshuffle. Refs #249 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWgyjsJfFMYcyqmLC
`AudioPlayer`'s `initialTrackIndex` seeded `usePlaylistAudioPlayer`'s state once, so `MusicLibrary` could show a new track's art and highlight while the previous one kept playing. A playlist click changed the audio never, filter or no filter, which is the other half of #249's symptom. The prop becomes `trackIndex`, which the hook follows through the same `selectTrack` path its own next and previous use, so playback resumes on the new track. The hook still owns the index, because it moves it itself on next, previous and track end. `MusicLibrary` is the only caller, and `MeditationPlayer` sits on `useAudioPlayer` instead, so no other consumer sees the rename. Refs #249 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWgyjsJfFMYcyqmLC
…ract
Applied from the /simplify pass and the altitude review:
- Playlist.test.tsx drops the assertions the render tests already pinned,
hoists `playingTitles`, and replaces a "set then clear a filter" name
with what a pure SSR render can actually show.
- `trackIndex` says in both JSDocs that it is followed but not fully
controlled, so a consumer must echo `onTrackChange`.
- `key={track.url}` carries a `shortcut:` marker: `Track` has no id, and
nothing upstream guarantees two songs cannot share an upload.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYWgyjsJfFMYcyqmLC
`MusicLibrary` feeds `onTrackChange` straight back as `trackIndex`, so the follow effect fired on the hook's own next, previous and track-end moves too. Each one re-entered `selectTrack` while the new track was still loading, where `isPlaying` reads false, clearing the auto-resume flag the move had just set. Comparing against the index the hook already holds leaves an echo alone and acts only on a real request. Found by the /code-review pass on this branch. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWgyjsJfFMYcyqmLC
sydevs-bot
left a comment
There was a problem hiding this comment.
2 questions for the reviewer, one per thread.
🤖 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 | fe86bc1 | Commit Preview URL Branch Preview URL |
Nov 18 2026, 08:06 PM |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | fe86bc1 | Commit Preview URL Branch Preview URL |
Nov 18 2026, 08:06 PM |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The index fix is right and no bigger than #249: visibleTracks is the one place that knows both index spaces, and four render tests fail against the old mapping. The joined player fix is what to weigh. It leaves two copies of one index — MusicLibrary's and the hook's — tied by an effect going down and onTrackChange coming up, plus a guard suppressing the hook's own echo. One owner needs none of that. My answer to the hook thread is C, which also retires disabledControls={['trackInfo']}; B if AudioPlayer's shape must stay. I have not duplicated the two question threads.
Findings
should-fix— a row click from a paused player selects without playing, against criterion 1.hooks/audio/usePlaylistAudioPlayer.ts:152should-fix—trackIndexnames a controlled prop that is not controlled.components/molecules/AudioPlayer/AudioPlayer.tsx:37consider— every playlist row renders0:00in production.contentIndexTrackreturnsduration: 0(lib/content-blocks.ts:665), nothing fills it,Playlist.tsx:107prints it. Fixtures all carry real durations, so Ladle and CI look right. Pre-existing: hide a zero, or file the upstream Song field.
What was checked
Criteria 1–5 hold; 6 unmeasurable, as the body says. Read whole on the branch: the five touched files plus useAudioPlayer.ts. Ladder: no index-pairing helper in lib/ or hooks/, and React has no prop-follow primitive, so both new pieces are the approach, not duplication; the visibleTracks export holds, because a node-env render cannot observe a click handler. git grep gives MusicLibrary.tsx:93 as the renamed prop's only caller, and no story or doc names initialTrackIndex. The body's two cited path ranges check out. preview-host.mjs could classify nothing: no previewUrl in this repo's .claude/workflow.json.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`selectTrack` copied the momentary `playerState.isPlaying` into `wasPlayingRef`, which `load` passes as `autoplay`. A click from a paused player therefore loaded the track and left it silent, against #249's first acceptance criterion. Picking a track is a request to hear it, so it now autoplays unconditionally; `next` and `previous` keep resume semantics, since they continue whatever the player was already doing. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWvtTogiAv1QB7tmQb
`trackIndex` is React's name for a fully controlled value, and this one is not: the player moves the index itself on next, previous and track end, which is why the JSDoc needed three lines telling the consumer to echo `onTrackChange` back. The name now says what the prop is — a request the player follows — and the caveat shrinks to the drift it still warns about. `MusicLibrary` is the only caller. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWvtTogiAv1QB7tmQb
`contentIndexTrack` hands every song `duration: 0`, because SahajCloud's Song type has no duration field, so each production playlist row printed `0:00`. Every fixture and story carries a real duration, which is why Ladle and CI always looked right. A row now prints a duration only when the track states one; filling it needs a duration field upstream. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWvtTogiAv1QB7tmQb
|
Three findings from the adversarial review, all built.
The two question threads still wait on you — who owns the player's index, and how player behaviour should be tested. A stands built in both. Lean gate ✓ 984 tests, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
The index lived twice — in MusicLibrary and in the player's hook — tied by a prop going down, onTrackChange coming up, and a guard suppressing the hook's own echo. That pairing is what played one track and highlighted another. usePlaylistAudioPlayer now owns the index outright, and the component that renders the player, the playlist and the album art holds the hook. A row click reaches it as controls.selectTrack, so the intent to hear a track travels as a call rather than as a number the player has to interpret. AudioPlayer renders what the hook holds. The sync channel goes with it: requestedTrackIndex, onTrackChange, the follow effect and the echo guard are all gone. The shuffle prop went too — it only hid the shuffle control, which disabledControls says outright. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWaSe8pi4pDfZm8qpv
|
Both answers are in, one built and one blocked.
No spec can click here, so the rework was measured in a browser. Picking Wind and clicking the second row left the art, the highlight and Howler all on Gate green: eslint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`main` #207 added `MusicLibrary.test.tsx` and `AudioPlayer.test.tsx` to pin the `sizes` each component advertises. This branch had already written a `MusicLibrary.test.tsx` of its own, and had replaced `AudioPlayerProps` `tracks` with the `state`/`controls` pair. MusicLibrary.test.tsx keeps both suites in one file. The album-art spec is unchanged beyond a fixture rename, and `renderToStaticMarkup` is a server render whatever environment holds it, so the file's jsdom opt-in leaves that markup contract where it was. AudioPlayer.test.tsx keeps `main`'s assertion and states the player pair the spec needs. `<AudioPlayer tracks={[track]} />` no longer type-checks, and the 48px box it measures is unaffected by who owns the track index. The component hunks merged clean: `MusicLibrary.tsx` carries the new `sizes` inside the hoisted hook, and `AudioPlayer.tsx` keeps its 48px thumbnail while reading `state.currentTrack`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZYuTjX2vtP6zEpMYz
|
Merged
Lean gate green: 1107 tests, eslint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Merging main brought in the thumbnail-sizes spec #207 added, written against the `tracks` prop this branch replaced. AudioPlayer is now presentational, so the spec builds the state and controls the hook would hand it. Its three assertions are unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYpgD65LmAMV3o2pLU
Two files conflicted, both against #199's contrast pass and main's reformat. Playlist.tsx keeps this branch's behaviour and main's colours: the duration still renders only when the track states one, now in text-teal-50 / text-gray-700; the row keeps aria-current and key={track.url}. AudioPlayer.stories.tsx takes main's structure with PlaylistPlayer in every slot, since AudioPlayer is presentational on this branch and needs the hook wiring. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXN8zWk1jS1XF5NBW3
|
Merged
Lean gate green: eslint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…-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
#255 landed on main and rewrote `selectTrack` in `hooks/audio/usePlaylistAudioPlayer.ts`. The merged body is main's, so the dependency array is main's too: this branch's `[playerState.isPlaying]` named a value the new body never reads. Everything else auto-merged. The branch's derived `playOrder` and stored shuffle survive beside main's index ownership. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZa1C7bwUKs2uxtdKu
Answers the eslint.config.js question thread on #265: option B, in this PR rather than a follow-up. #255 merged, so Playlist.tsx:152 is gone and no-array-index-key reports zero — the last thing blocking the promotion. All three report zero on this branch, so the ratchet closes with no new suppression. A rule left at warn records a violation nobody is stopped by: `eslint .` exits 0 on warnings and 1974 others are already there. Watched failing: a probe component with `key={index}`, a `setState` in an Effect and a dep array missing its read now produce three errors, one per rule. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXgmgR87TRD9NczmHe
Summary
tracks, so the right track plays and is highlighted.0:00, because no song states a duration.MusicLibraryholds the player hook, andAudioPlayerrenders what it holds.@testing-library/react, opted into per file.aria-current, so it is no longer marked by colour alone.Change outline
The index a playlist row reported and the index the player read were two different things, and there were two of the second one. Now there is one index, in one place, and every part reads it there.
Components — one owner for the playing track
Contract — who holds the track index
MusicLibraryisAudioPlayer's only consumer outside the stories, andMeditationPlayersits onuseAudioPlayerrather than this hook, so nothing else sees the new shape. The cost is that a consumer now wires the hook and theAudioPlayerProvideritself;AudioPlayer.stories.tsxcarries that wiring asPlaylistPlayer, which is the shape to copy.Preview
Both branch aliases, read from the Cloudflare Workers Builds check summaries. A branch alias follows the branch, so each serves this push once its build finishes.
onFilterChangesets a filter but never clears one. Its Without durations section is what a production row now looks likeMusicLibraryrenders only on a page carrying asongscontent-index block, and this run could not name one from the repo aloneTest results
.claude/skills/pr-prep/check.sh— eslint 0 errors,tsc --noEmitclean, 1050 testsMusicLibrary.test.tsx3,usePlaylistAudioPlayer.test.ts5,Playlist.test.tsx10 — all passpnpm build; no test dependency reachesdist/serverEach interaction spec fails against the defect it guards, measured by restoring the old code on the branch: the filtered-position index fails the filtered-click and filter-cleared specs,
selectTrackcopyingplayerState.isPlayingfails the filtered-click spec'sautoplay: true, and dropping the loaded-row branch failsplays the loaded track in place.Manual verification
All four steps were driven headlessly against the built playground after the ownership rework, reading both the DOM and Howler's own state. What stays for a human is that audio is audibly playing — the sample mp3s are remote and this environment could not play them.
Flute Meditation. ✓ art and highlight readFlute Meditation, andHowler._howlsheldSoundHelix-Song-5.mp3, which is that row's url.Flute Meditationacross the full list.String Symphonyand previous came back.SoundHelix-Song-1.mp3stopped; after the clickplaying()wastrueand the transport button read Pause. The highlighted-row case is covered by a spec, not yet by ear.Notes for reviewer
@testing-library/reactare dev dependencies; the default environment staysnode, and a file opts in with// @vitest-environment jsdom. The specs replacehooks/audio/useAudioPlayerwith a recorder, because Howler never plays under jsdom.docs/rules/testing.mdnow describes the opt-in in place of "do not reach for them".^29. jsdom 30 and 31 require Node^22.22.2, above the 22.17.0.node-versionpins for CI.happy-dom21 is already in the tree through@lexical/headless, and both new spec files pass under it unchanged — it was not taken because the thread asked for jsdom, but it is the lighter choice if you would rather not carry two DOM implementations.selectTrackonly changed the index, so the row already loaded — the first one, on a fresh paused player — never reached the load effect. That row now plays in place.MusicLibraryholds the hook,AudioPlayeris presentational. A row click now arrives ascontrols.selectTrack(index), so the intent to hear a track travels as a call rather than as a number the player has to interpret — the thing that broke twice.requestedTrackIndex,onTrackChange, the follow effect and the echo guard are all gone.initialTrackIndexseeded the player's state once: before this branch a playlist click never changed the audio at all, filter or no filter. Measured in the browser — the art readFlute Meditationwhile Howler still heldSoundHelix-Song-1.mp3.@eslint-react/no-array-index-keyreachedmainwith chore(deps): move off the end-of-life eslint 9 line #251: it reportskey={index}onmain'sPlaylist.tsx:157, and nothing on this branch.key={track.url}rests on an invariant nothing enforces. Non-empty is guaranteed (contentIndexTrackdrops a song with no url), uniqueness is not. It carries ashortcut:marker with its trigger.Trackhas no id;contentIndexTrackreceivesdoc.idand discards it, so giving it one is the deeper fix if duplicates ever appear.contentIndexTracksetsduration: 0because SahajCloud's Song type carries no duration field, and the player reads its own duration off the audio element, which a playlist row cannot. So a row now prints a duration only when the track states one, and every production row shows none until SahajCloud gains the field.Track.durationnow documents 0 as "unknown", the sentinelMeditationPlayeralready reads the same way.selectTrack, which always plays and has no follow effect. A run that builds it as written would revert the decision.tracksplays whatever now sits at the index, and a shrink below it throws inMusicLibrary. Holding the track (url ordoc.id) in the hook would remove both, and the filter fix above wants it first.AudioPlayerProvideris vestigial:react-use-audio-player4'suseAudioPlayernever reads its context, so each wrapper (here and inMeditationPlayer) mounts one unused player.Detail
Why
visibleTracksis still exported. It predates the jsdom lane, when a static render was the only way to reach the index a row reports. The interaction specs now cover the click through the real component, but the pure pairing stays the cheapest place to pin the mapping for untagged and unmatched tracks. It is exported fromPlaylist.tsxonly — neitherPlaylist/index.tsnor the molecules barrel re-exports it, so the design-system surface is unchanged. Precedent:buildLightboxSlideincomponents/atoms/Image/Image.tsx.The fixture's assumption, checked.
Track.tags[].idis the SongTag slug, and the same slug becomesMusicFilter.id. Verified againstcontentIndexTrack(lib/content-blocks.ts:633-663) andsongMusicFilters(components/organisms/RichText/blockConverters.tsx:80-94), both read on this branch. The five fixture tracks interleave two facets so that a filtered row's position never equals its index — the second visiblewindrow is index 4.Rejected:
useMemoaroundvisibleTracks.PlaylistItemis not memoized and takestrack/onTrackClickdirectly, so a stable array identity has no consumer; and on the Worker there is one render per request, whereuseMemois pure overhead. The pairs are a low single-digit fraction of what each row already allocates.Rejected for now:
memo(Playlist). Hoisting the hook moved the player's 10 HzcurrentTimepoll intoMusicLibrary, so each tick now re-renders every row. Measured at 0.22 ms per tick for 40 tracks and 0.42 ms for 100 (production React, jsdom), against 0.05 ms onmain;memo(Playlist)with a stablehandleFilterClickbrings it to 0.07 ms. Left out because the cost is small and the repo has nomemoyet, so it would set a precedent worth its own decision.Rejected: keeping
key={index}. With the fix,indexis the position intracksand would be stable across filter changes, so it would work. The ticket asks for the track's own value, and a content key lets React move surviving rows rather than patch them by position when a filter changes.Rejected: a
flatMapone-pass pairing. Saves an intermediate array and reads worse at this list size.Rejected: a controlled/uncontrolled
trackIndexprop — option B on the ownership thread. It keepsAudioPlayerself-contained, but an index arriving as a changed prop still cannot say whether the consumer means "show this" or "play this": a row click from a paused player would need a second ref to recover that intent, which is the guard again under another name. A method call carries it for free.Rejected: an
autoplayoption onselectTrack. A knob with one caller, and the only caller wants it on. Picking a track is a request to hear it, soselectTracknow always plays.nextandpreviouskeep resume semantics, because they continue whatever the player was doing.Dismissed findings. A review suggested dropping the
visibleTracksexport and covering untagged/unmatched tracks through the component by givingrender()atracksargument — declined, because the click target would then only be inferred from the highlight, and criterion 5 asks for both. Another suggested hoistingusePlaylistAudioPlayerintoMusicLibraryand makingAudioPlayerpresentational — asked as a question thread, and built once the reviewer chose it. This pass's/code-review highraised four more, declined:key={track.url}againstkey={index}(decided above, with itsshortcut:trigger);AudioPlayerno longer hiding shuffle by itself (MusicLibraryis its only consumer and names'shuffle'indisabledControls, per the contract above); thevisibleTracksexport costing Fast Refresh onPlaylist.tsx(the precedent above, and a dev-only reload); and makingTrack.durationoptional (0 is the shared sentinelMeditationPlayerreads too, and the real fix is the upstream field). ConvertingPlaylist.test.tsx's string parser to Testing Library was prototyped and declined: it saves nine lines and moves a markup contract off the server render the testing rule prefers.An anomaly worth recording. One headless run logged
Howl load error: 4while fetching asoundhelix.comsample; earlier and later runs did not. The sample host is remote and this sandbox's egress to it is not guaranteed. The index wiring still read correctly on that run.Closes #249
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code