Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(dictation): initialize onboarding event ref safely (#1756)

Chad Pihac5d515b95d61
diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.js
index 757c516f0..cc9241693 100644
--- a/src/hooks/useAudioRecording.js
+++ b/src/hooks/useAudioRecording.js
@@ -49,7 +49,7 @@ export const useAudioRecording = (toast, options = {}) => {
const wasRecordingRef = useRef(false);
const wasMicUnavailableRef = useRef(false);
const demoKindRef = useRef("dictation");
- const onDemoEventRef = useRef(onDemoEvent);
+ const onDemoEventRef = useRef(options.onDemoEvent);
const reportedLifecycleRef = useRef(null);
const lastStartOptionsRef = useRef({
voiceAgentRequested: false,
diff --git a/test/helpers/useAudioRecordingInitialization.test.js b/test/helpers/useAudioRecordingInitialization.test.js
new file mode 100644
index 000000000..b4cfdc604
--- /dev/null
+++ b/test/helpers/useAudioRecordingInitialization.test.js
@@ -0,0 +1,23 @@
+const assert = require("node:assert/strict");
+const test = require("node:test");
+const React = require("react");
+const { renderToStaticMarkup } = require("react-dom/server");
+const { createRendererServer, installBrowserGlobals } = require("../lib/rendererTestHarness");
+
+test("useAudioRecording accepts an onboarding event handler on its initial render", async (t) => {
+ installBrowserGlobals(t);
+ const vite = await createRendererServer(t, {
+ cachePrefix: "openwhispr-audio-recording-initialization-",
+ mockModules: {
+ "/helpers/audioManager": "export default class AudioManager {}",
+ },
+ });
+ const { useAudioRecording } = await vite.ssrLoadModule("/hooks/useAudioRecording.js");
+
+ function InitialRenderProbe() {
+ useAudioRecording(() => {}, { onDemoEvent: () => {} });
+ return React.createElement("div");
+ }
+
+ assert.doesNotThrow(() => renderToStaticMarkup(React.createElement(InitialRenderProbe)));
+});