Skip to content

Commit

Permalink
Clean up Monaco models of deleted schemata
Browse files Browse the repository at this point in the history
  • Loading branch information
syimyuzya committed Aug 22, 2024
1 parent b61a99e commit c769478
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Components/SchemaEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from "@emotion/styled";
import { faFileCode } from "@fortawesome/free-regular-svg-icons";
import { faChevronDown, faChevronUp, faPlus, faRotateLeft, faXmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Editor from "@monaco-editor/react";
import Editor, { useMonaco } from "@monaco-editor/react";

import CreateSchemaDialog from "./CreateSchemaDialog";
import Spinner from "./Spinner";
Expand Down Expand Up @@ -224,6 +224,18 @@ export default function SchemaEditor({ state, setState, commonOptions }: SchemaE
[schemas, activeSchemaName],
);

const monaco = useMonaco();
useEffect(() => {
if (!monaco) return;
// Clean up deleted schemata
const schemaUris = new Set(schemas.map(({ name }) => monaco.Uri.parse(name).toString()));
monaco.editor.getModels().forEach(model => {
if (!schemaUris.has(model.uri.toString())) {
model.dispose();
}
});
}, [monaco, schemas]);

const getDefaultFileName: (sample: Sample | "") => string = useMemo(
() =>
memoize((sample: string) => {
Expand Down

0 comments on commit c769478

Please sign in to comment.