Repository navigation
refactor(player): collapse the three MM:SS formatters into one - #254
Conversation
Three components each carried their own copy of this arithmetic, and the `!isFinite` guard was written in two of them and missed in the third. The guard survives into the shared copy because it is the stricter behaviour: howler reports `Infinity` for a stream of indeterminate length, which the bare arithmetic renders as `Infinity:NaN`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVux8To1yT9AEzJ8st
AudioPlayer and MeditationPlayer lose an identical copy each. Playlist loses the copy that had no `!isFinite` guard, so a non-finite track duration now reads `0:00` where it rendered `Infinity:NaN`. Rendered output is unchanged for every finite input, and the Playlist test pins both halves of that. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVux8To1yT9AEzJ8st
Removing `formatTime` from MeditationPlayer left its doc comment attached to the `MeditationFrame` interface below it. `Number.isFinite` replaces the bare global the three copies carried: the five other guards in this repo all use the namespaced form, and it is the stricter of the two. No finite input changes. The JSDoc drops its caller list, which a fourth consumer would silently falsify, and names both engines instead of one — `Infinity` from an indeterminate-length source, `NaN` from a media element before metadata. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVux8To1yT9AEzJ8st
|
🤖 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
Clean, and the simplest shape #240 allows. Of 88 added lines, 66 are the two tests; the product change is a 16-line helper and three imports. Nothing answers a question the ticket did not ask.
The new layer sits at the pole this repo prefers. Three callers in three atomic tiers leave no single caller to fold into, so lib/duration.ts is the generic-helper end, beside 20 lib/ modules that each carry their own .test.ts. Membership is complete: no sibling was left outside it. The exposure the body hands back rather than guards is the right call — useAudioPlayer.ts:235 is an uncounted harm, and a guard there would be permanent code against it.
Findings
None.
What was checked
- All five other
/ 60sites on the branch, for membership.Countdown.tsxsubtracts twoDates in milliseconds and takes no seconds input.VideoPlayerrenders no timestamp (vtt.tsserialises to the WebVTT spec).LectureTemplate.tsx:94,related-content.ts:23andcontent-blocks.ts:556convert seconds to whole minutes for aduration_minuteslabel.padStart(2now matches onlyCountdown.tsxandduration.ts. - The ladder. No
lib/module formatted a duration before, andIntl.DurationFormatgives a locale phrase, notM:SS. - The body's output evidence, recomputed. All eight
Playliststory durations format to the claimed set (196→3:16 … 305→5:05), and the five annotated fixtures match their comments. Number.isFinitefor the bare global. Identical on everynumber, and no call site passes a non-number —content-blocks.ts:661writes0,MeditationTemplate.tsx:193coerces.- The
shortcut:hour limit. Not crossed: these players carry songs and meditations only. - No contract surface, and no i18n gap —
no-restricted-syntaxtargets JSX text and props, not a returned string.
🤖 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 | 5f85d7a | Commit Preview URL Branch Preview URL |
Nov 18 2026, 07:24 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-design | 5f85d7a | Commit Preview URL Branch Preview URL |
Nov 18 2026, 07:23 PM |
`lib/duration.ts` becomes `lib/duration/index.ts`, so the module and its test sit together. The three call sites import `lib/duration` unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZTeCCP3QACFyTrhM9
|
Addressed the review. Pushed Adopted — the two duration files belong in a subfolder. They are now The review body was empty, so that thread was the whole ask.
Lean gate: ✓ lint + 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
The folder move left the spec importing './duration', a path that no longer exists beside it. tsc stopped the run before vitest reached the file, so the suite never reported it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWfFNKkYeWuhjoyRSn
…ontrast #254 collapsed the three M:SS formatters into lib/duration. This branch had retuned the colours around two of them, so both players conflicted. AudioPlayer and Playlist drop their local copies and read the shared formatter, which is main's whole point. The progress row keeps this branch's text-gray-700: main's side still read text-gray-600, at 2.71:1. Playlist's local copy had no !isFinite guard, so a non-finite track duration now reads 0:00 rather than Infinity:NaN — the behaviour main chose, and the one its Playlist.test.tsx pins. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjY2NtKzScDKCv7jxMW
`main` #254 replaced each player's own `formatTime` with the shared `formatDuration`, which keeps a `!isFinite` guard the Playlist copy lacked. This branch had already removed `AudioPlayer`'s `shuffle` prop, so both sides rewrote the same region. AudioPlayer keeps neither hunk: the local `formatTime` is dead now that the call sites read `formatDuration`, and `effectiveDisabledControls` referenced the `shuffle` prop this branch removed in favour of naming `'shuffle'` in `disabledControls`. Playlist.test.tsx keeps this branch's suite and folds in `main`'s non-finite case, which a row still renders as `0:00` — `Infinity > 0`, so the new "duration only when the track states one" guard lets it through. `main`'s finite case is already this branch's "prints the duration a track states". Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVbEVf4gdC6dKUYXeG
Summary
M:SSarithmetic collapse intolib/duration/, one import each.Playlistgains theNumber.isFiniteguard the other two already had, so a non-finite duration reads0:00instead ofInfinity:NaN.Change outline
A responsibility moved out of three components into one pure helper. Nothing else about the three changed.
Files
Behaviour — the one output change
Only the unguarded copy's non-finite path moves. Every finite input formats through identical arithmetic.
Preview
Preview pending — the Cloudflare alias does not exist until the build runs. Both previews build for this diff: it touches
components/*andlib/*, and only the two new test files fall under the Ladle trigger's exclude list.AudioPlayer,PlaylistandMeditationPlayerstories carry the timestamps this change must leave alone.Test results
.claude/skills/pr-prep/check.sh— lint +tsc --noEmit+ 106 files / 1038 testslib/duration/index.test.ts,Playlist.test.tsx,MeditationPlayer/)securityReview.triggerPatternManual verification
Playlist,AudioPlayerandMeditationPlayerstories and confirm the timestamps read as before.Notes for reviewer
hooks/audio/useAudioPlayer.ts:235passes howler'sdurationthrough under a type that saysnumber, so anInfinitywould also reachAudioPlayer.tsx:128(max={state.duration || 0}staysInfinity) andMeditationPlayer.tsx:372, whereInfinity > 0would suppress the SahajCloud duration fallback. I did not normalise at that boundary:Infinityneeds a source of indeterminate length, every track here is a finite file, and the ticket already settled that no live call site passes a non-finite value. Guarding it would be permanent code against an unmeasured harm, and it is outside this ticket. Say the word and it is a one-line change in the hook.Playlistnon-finite test is kept deliberately, though two reviewers called it a duplicate of the unit test. It is the only test that covers acceptance criterion 3 at the layer the criterion names — the unit test proves the helper guards, this provesPlaylist's rendered output moved offInfinity:NaN. I watched it fail againstmainfirst.-1:-30, but no call site can produce one (MeditationPlayerclamps withMath.max(0, …), the others read player state or a record field).Countdown.tsxstays as it is, per the ticket: it pads hours, minutes and seconds into three separate elements rather than building one string.VideoPlayer/vtt.tsalso stays — it serialisesHH:MM:SS.mmmto the WebVTT spec, not a human label.M:SSis a media-player convention, so it does not route throughuseT()orIntl.lib/content-blocks.ts:661hard-codesduration: 0on every song track, so every music-library playlist row renders0:00in production, while the story fixtures supply real durations — which is why Ladle looks right. The ticket asked me to confirm whether that stub was deliberate: it is, and documented, but its stated reason covers onlyAudioPlayer's progress bar, not the playlist rows. Fixing it needs an upstream SahajCloud schema decision, so it is a separate ticket. This PR does not change that behaviour either way.Detail
Why a new one-function file.
lib/slugify.tsis the existing one-function module in the same directory and the precedent the ticket cites (page-tag-labels.tsandatlas-embed.tsare others). With three callers in three different atomic tiers there is no single caller to fold into, so this is the generic-helper pole rather than a single-purpose middle layer.Why it sits in a folder. Review asked for the helper and its test grouped.
lib/duration/index.tsleaves the three import paths spelledlib/duration, as they were, and matcheslib/live-preview/, the one existinglib/subfolder.How "no rendered output changes for any finite input" was checked, rather than asserted:
duration: 196, // 3:16). The helper reproduces all five annotated values: 196→3:16, 242→4:02, 318→5:18, 281→4:41, 485→8:05.origin/mainin place. Both renders produce identical timestamp sets — Playlist3:16 4:02 5:18 4:41 3:44 4:27 3:13 5:05, AudioPlayer0:00 6:12, MeditationPlayer6:12— with no page errors either way.Changes taken from the review pass, each its own commit (
9bc0b8d):Number.isFinitereplaces the bare global the three copies carried. It is the only bareisFinitethe repo would have had; the five existing guards (FormBuilder.tsx:69,MeditationPlayer.tsx:548,559,lecture-shape.ts:72,submissions.ts:90) all use the namespaced form, and it is the stricter of the two. Identical on every finite input.Infinityfrom an indeterminate-length source,NaNfrom a media element before metadata loads.shortcut:line records that an hour or more reads61:40, not1:01:40— pre-existing in all three copies, and the function name alone over-promises.formatTimefromMeditationPlayerorphaned its/** Format time in seconds to MM:SS format */JSDoc onto theMeditationFrameinterface below it.Fixture pre-mortem.
Playlist.test.tsxbuilds aTrack, which assumes the shape incomponents/molecules/AudioPlayer/types.ts. I read that file:url,title,credit,creditURL,thumbnailURLanddurationare all required andtagsis optional, which is what the factory builds. It renders withrenderToStaticMarkupin thenodeenvironment perdocs/rules/testing.md;Link'suseLocaleowns the fallback for a bare unit render, soPlaylistneeds no page context. The local fixture duplicatesMeditationPlayer.test.tsx's by design — this repo has no shared component-test fixture location, and each story file builds its own.Efficiency, for the record. Two of the three removed copies allocated a closure per render —
AudioPlayer's on a 100 ms timer,Playlist's once per row. Now zero. Nanoseconds, so a dedup rather than a perf fix, but it moves the right way.lib/duration/index.tshas no imports, so it adds nothing to any bundle.Closes #240
Generated by Claude Code