fix(audio): resume ctx in toggle + unconditional unlock#356
Merged
Conversation
…sture The previous autoplay unlock bailed early when Howler.ctx was null — but Howler.ctx is lazy-initialized on the first Howl construction, so on first mount the effect ran before the first playback effect and never registered listeners. Toggle off/on also silently failed because resume() was only called from the deferred effect, which some browsers treat as outside the gesture window. - Register unlock listeners unconditionally when soundEnabled - Call Howler.ctx.resume() synchronously inside toggleSound (the click handler IS a user gesture) - In the unlock handler, also re-play the active Howl if it isn't currently playing — Howler's own flush doesn't always restart queued Howls after ctx resume Tests: 23 passing, including new cases for toggle resume and replay fallback. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ambient music wasn't playing on hard refresh on beta, and toggling sound off/on didn't recover. Root cause was a timing bug in the autoplay unlock:
Howler.ctxis lazy-initialized on the first Howl construction, so on first mount the unlock effect ran BEFORE the first playback effect and bailed early (ctx was null) — listeners were never registered.Howler.ctx.resume()synchronously insidetoggleSound(the click handler IS a user gesture)Test plan
pnpm --filter client test -- SoundContext— 23/23 passingpnpm --filter client build— clean🤖 Generated with Claude Code