Skip to content

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

fix(notes): don't crash the note editor when Join & transcribe opens a meeting note (#2404)

Chad Pihaee0104e5c1e7
diff --git a/src/components/ui/RichTextEditorMenus.ts b/src/components/ui/RichTextEditorMenus.ts
index 394035093..48a049c99 100644
--- a/src/components/ui/RichTextEditorMenus.ts
+++ b/src/components/ui/RichTextEditorMenus.ts
@@ -22,6 +22,10 @@ export const editorHasFocus = (view: EditorView) =>
*/
export function useHideOnFocusLeave(editor: Editor, pluginKeys: readonly string[]) {
useEffect(() => {
+ // useEditor can hand over an editor it already destroyed: one it created while
+ // rendering, whose effect didn't run within 1 ms (a note opened by an IPC
+ // event). It re-renders with a new one, and this effect runs again for that.
+ if (editor.isDestroyed) return;
const scroller = editor.view.dom.parentElement;
if (!scroller) return;
const onFocusOut = (event: FocusEvent) => {
diff --git a/test/components/richTextEditor.test.js b/test/components/richTextEditor.test.js
index 7ad7931d6..fda2d47cd 100644
--- a/test/components/richTextEditor.test.js
+++ b/test/components/richTextEditor.test.js
@@ -965,3 +965,40 @@ for (const menu of ["selection", "empty line", "table"]) {
assert.deepEqual(notes.errors, []);
});
}
+
+test("the menus mount without error on an editor useEditor already destroyed", async (t) => {
+ // useEditor destroys the editor it created while rendering unless its effect
+ // runs within 1 ms, and replaces it once that effect runs. Opening a note from
+ // an IPC event (Join & transcribe) runs effects after paint, so the menus'
+ // effects, which run first, can get the destroyed one.
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
+ const React = require("react");
+ const { createRoot } = require("react-dom/client");
+ const vite = await createRendererServer(t);
+ const { RichTextEditorFormatMenu } = await vite.ssrLoadModule(
+ "/components/ui/RichTextEditorFormatMenu.tsx"
+ );
+ const { RichTextEditorTableMenu } = await vite.ssrLoadModule(
+ "/components/ui/RichTextEditorTableMenu.tsx"
+ );
+ const editor = createEditor("Meeting notes");
+ editor.destroy();
+ const host = happyWindow.document.createElement("div");
+ happyWindow.document.body.appendChild(host);
+ const root = createRoot(host);
+ t.after(async () => {
+ await React.act(async () => root.unmount());
+ host.remove();
+ });
+
+ await React.act(async () =>
+ root.render(
+ React.createElement(
+ React.Fragment,
+ null,
+ React.createElement(RichTextEditorFormatMenu, { editor }),
+ React.createElement(RichTextEditorTableMenu, { editor })
+ )
+ )
+ );
+});