Skip to content

Commit

Permalink
fix: fix schema leaks across different editor version
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Oct 17, 2023
1 parent 1252268 commit be10cac
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/CodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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(() => {
Expand Down

0 comments on commit be10cac

Please sign in to comment.