Desktop: Fix crash when closing a secondary window with the Rich Text Editor open (#11737)

pull/11582/merge
Henry Heino 2025-02-03 16:09:12 -08:00 committed by GitHub
parent 67d1dd36be
commit f90e642f43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 1 deletions

View File

@ -1387,7 +1387,17 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
useEffect(() => {
return () => {
if (editorRef.current) editorRef.current.remove();
if (!editorRef.current) return;
const ownerDocument = editorRef.current.getContainer().ownerDocument;
const parentWindow = ownerDocument.defaultView;
// Calling .remove after the parent window is closed throws an Error
// related to DOM API access. Since closing the window also removes the editor,
// it shouldn't be necessary to call .remove in this case:
if (parentWindow) {
editorRef.current.remove();
}
};
}, []);