Skip to content

Commit

Permalink
call .destroy on ace when react component unmounts (#78132) (#78150)
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Sep 22, 2020
1 parent 44e75ba commit 949cb6a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ function EditorUI({ initialTextValue }: EditorProps) {
unsubscribeResizer();
clearSubscriptions();
window.removeEventListener('hashchange', onHashChange);
if (editorInstanceRef.current) {
editorInstanceRef.current.getCoreEditor().destroy();
}
};
}, [saveCurrentTextObject, initialTextValue, history, setInputEditor, settingsService]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,8 @@ export class LegacyCoreEditor implements CoreEditor {
},
]);
}

destroy() {
this.editor.destroy();
}
}
5 changes: 5 additions & 0 deletions src/plugins/console/public/types/core_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,9 @@ export interface CoreEditor {
* detects a change
*/
registerAutocompleter(autocompleter: AutoCompleterFunction): void;

/**
* Release any resources in use by the editor.
*/
destroy(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export const Editor = memo(({ licenseEnabled, initialValue, onEditorReady }: Pro
setTextArea(licenseEnabled ? containerRef.current!.querySelector('textarea') : null);

onEditorReady(createEditorShim(editorInstanceRef.current));

return () => {
if (editorInstanceRef.current) {
editorInstanceRef.current.destroy();
}
};
}, [initialValue, onEditorReady, licenseEnabled]);

return (
Expand Down

0 comments on commit 949cb6a

Please sign in to comment.