fix(audio): module-scope Howl cache survives provider remounts#358
Merged
Conversation
…unts MUDProvider swaps its internal component type when setupPromise resolves (MUDContext.Provider → MUDProviderInner), which unmounts the entire SoundProvider subtree. The previous ref-based Howl cache was destroyed mid-load, producing "Decoding audio data failed" on the first Howl and leaving the second mount's Howl in a silent state even though Howler reported playback. Moving the cache, activeTrack, and missingZoneWarned set to module scope means the second mount sees the Howl already playing and no-ops via the keyEq early return. Also strips the diagnostic console.logs now that the root cause is identified, and adds __resetSoundForTests so the test suite can reset module state between runs. All 23 SoundContext tests pass against the new implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
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
ambientHowls,battleHowls,activeTrack, andmissingZoneWarnedto module scope so they survive React provider remountsMUDProviderswaps component types whensetupPromiseresolves (MUDContext.Provider→MUDProviderInner), which unmounts the entireSoundProvidersubtree. The old ref-based cache was destroyed mid-load, producing "Decoding audio data failed" on the first Howl and leaving the second mount silent despite Howler reportingplayingconsole.logs shipped in chore(audio): diagnostic logging for silent ambient bug #357 now that the root cause is identified__resetSoundForTestsfor the test suite to reset module state between runsWhy the old fix didn't work
PR #356 resumed the audio context synchronously inside
toggleSoundand registered unlock listeners unconditionally. That part was correct — the logs from #357 confirmedctxState: 'running'on the second mount andHowl playingfiring. But the Howl being "played" was a fresh instance from the second mount, racing against the first mount's unload cleanup. The shared Web Audio state ended up in a silent mode even though Howler's state machine said otherwise.Module-scope cache means the second mount sees
keyEq(activeTrack, desired) === trueand early-returns without touching the live Howl at all.Test plan
pnpm --filter client test src/contexts/SoundContext.test.tsx— 23/23 passingpnpm --filter client build— clean🤖 Generated with Claude Code