fix(voice): make stop() idempotent so a double tap can't throw

guard on the recorder's own state instead of react state, so a double tap or
the mic and send buttons both firing won't call stop() on an already-inactive
MediaRecorder.
This commit is contained in:
newsbubbles
2026-06-13 13:34:18 +01:00
parent 952ddb9eb7
commit 95a75aac47

View File

@@ -116,12 +116,15 @@ export function useVoiceInput(
}, [onTranscript, onError]);
// Stop recording. Pass { send: true } to auto-send the transcript once it's ready.
// Guard on the recorder's own state (not React state) so a double tap, or the mic
// and Send buttons both firing, can't call stop() on an already-inactive recorder.
const stop = useCallback((opts?: { send?: boolean }) => {
if (recorderRef.current && state === 'recording') {
const rec = recorderRef.current;
if (rec && rec.state !== 'inactive') {
sendRef.current = opts?.send ?? false;
recorderRef.current.stop();
rec.stop();
}
}, [state]);
}, []);
const toggle = useCallback(() => {
if (state === 'recording') stop();