fix(circular-waveform): stop instance recreation on prop changes - #168
Open
vincentdou wants to merge 1 commit into
Open
fix(circular-waveform): stop instance recreation on prop changes#168vincentdou wants to merge 1 commit into
vincentdou wants to merge 1 commit into
Conversation
CircularWaveform recreated its CircularWaveformCanvas instance whenever determineState changed identity (i.e. on every isThinking or audioTrack toggle, via the mount effect's [initializeWaveform] dependency). Each recreation leaked the previous instance (its requestAnimationFrame loop and AudioContext kept drawing the same canvas) and dropped the connected audio track, because the track-connect effect only runs on track changes — leaving the new instance without an analyser, so the waveform fell back to the static draw and appeared frozen. Fix: create the instance exactly once per mount and drive all prop changes imperatively through the existing setState / updateOptions / updateCanvasSize effects. The mount effect now disposes the instance in its cleanup, which also covers React StrictMode double-mounting. updateOptions rebuilds frequency bars when numBars changes so that structural option stays reactive without recreation.
|
@vincentdou is attempting to deploy a commit to the Daily Team on Vercel. A member of the Team first needs to authorize it. |
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.
What: CircularWaveform was recreating its CircularWaveformCanvas instance whenever isThinking/audioTrack toggled (the mount effect depended on initializeWaveform, whose deps included determineState). Each recreation leaked the old instance (its RAF loop + AudioContext kept running) and dropped the connected audio track — the new instance had no analyser, so the waveform fell back to the static draw and appeared frozen.
Fix: instance lifecycle now equals the canvas lifecycle. Props are applied imperatively via the existing setState/updateOptions/updateCanvasSize effects; the mount effect disposes the instance in cleanup (also covers StrictMode double-mount). updateOptions rebuilds frequency bars on numBars change so structural options stay reactive.
Verified: live-tested in a consumer app (patch-package) — no instance recreation across isThinking toggles, animation continuous. pnpm build + pnpm test green.
Note: no component-level regression test added — the package has no jsdom/testing-library setup (vitest is node-only, matches *.test.ts only); the correct seam for this bug is a jsdom component test.