Skip to content

Commit 63fa161

Browse files
committed
fix(react): detach Krisp processor on cancel
If the effect was cancelled while `track.setProcessor(processor)` was still in flight — e.g. the component unmounted with the track still alive via a caller-owned `trackRef` — setProcessor could resolve after the bailout, leaving the track with a Krisp processor attached that the hook no longer manages. When the track outlives the hook nothing was going to clean that up. Tear down the attachment inside the IIFE at each post-setProcessor cancellation check, so the track is left in the state the hook found it in.
1 parent 60a7d50 commit 63fa161

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/react/src/hooks/cloud/krisp/useKrispNoiseFilter.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,19 @@ export function useKrispNoiseFilter(options: useKrispNoiseFilterOptions = {}) {
100100
const processor = KrispNoiseFilter(options.filterOptions);
101101
try {
102102
await track.setProcessor(processor);
103-
if (cancelled) return;
103+
// If the effect was cancelled while setProcessor was in flight, the
104+
// processor landed on a track the hook no longer manages (e.g. the
105+
// component unmounted with the track still alive via a caller-owned
106+
// trackRef). Undo the attach so the track is left as we found it.
107+
if (cancelled) {
108+
await track.stopProcessor();
109+
return;
110+
}
104111
await processor.setEnabled(true);
105-
if (cancelled) return;
112+
if (cancelled) {
113+
await track.stopProcessor();
114+
return;
115+
}
106116
setIsNoiseFilterEnabled(true);
107117
} catch (e: any) {
108118
setIsNoiseFilterEnabled(false);

0 commit comments

Comments
 (0)