diff --git a/src/components/CodeEditor/index.tsx b/src/components/CodeEditor/index.tsx index 957542c64f..0f669a2c63 100644 --- a/src/components/CodeEditor/index.tsx +++ b/src/components/CodeEditor/index.tsx @@ -86,6 +86,7 @@ export function CodeEditor({ // default paste event handler type is just Event, which is inaccurate, hence we // are overriding it here, so we can use ClipboardEvent, which is more // accurate and allows us to access clipboardData safely + // @ts-ignore window.addEventListener("paste", (e: ClipboardEvent) => { if (editorWrapper.current?.id === document.activeElement?.id && monaco) { e.preventDefault(); @@ -123,7 +124,7 @@ export function CodeEditor({ return; } const schemaFileName = `${schemaFilePrefix}.spec.schema.json`; - configureMonacoYaml(monaco, { + const yaml = configureMonacoYaml(monaco, { enableSchemaRequest: true, hover: true, completion: true, @@ -138,6 +139,14 @@ export function CodeEditor({ } ] }); + + // on unmount, we need to remove the schema for the editor to avoid memory + // leak, as the schema is stored in the global monaco object + return () => { + yaml.update({ + schemas: [] + }); + }; }, [language, monaco, schemaFilePrefix]); useEffect(() => {