Skip to content

fix(audio): resume ctx in toggle + unconditional unlock#356

Merged
mokn merged 1 commit intodevfrom
feat/audio-zones
Apr 13, 2026
Merged

fix(audio): resume ctx in toggle + unconditional unlock#356
mokn merged 1 commit intodevfrom
feat/audio-zones

Conversation

@mokn
Copy link
Copy Markdown
Collaborator

@mokn mokn commented Apr 13, 2026

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.ctx is 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.

  • Register unlock listeners unconditionally when soundEnabled
  • Call Howler.ctx.resume() synchronously inside toggleSound (the click handler IS a user gesture)
  • Re-play active Howl on first unlock gesture if it isn't currently playing — Howler's built-in flush doesn't always restart queued Howls

Test plan

  • pnpm --filter client test -- SoundContext — 23/23 passing
  • pnpm --filter client build — clean
  • Beta: hard refresh in Dark Cave, wait, then click anywhere → ambient plays
  • Beta: mute mid-combat, unmute → battle track resumes

🤖 Generated with Claude Code

…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]>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Building Building Preview, Comment Apr 13, 2026 9:27pm
ud Building Building Preview, Comment Apr 13, 2026 9:27pm
ud-api Building Building Preview, Comment Apr 13, 2026 9:27pm
ud-api-beta Building Building Preview, Comment Apr 13, 2026 9:27pm

Request Review

@mokn mokn merged commit 75122cf into dev Apr 13, 2026
2 of 6 checks passed
@mokn mokn deleted the feat/audio-zones branch April 13, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant