Skip to content

Commit db4e811

Browse files
limeburstclaude
andcommitted
control-plane: Explicitly dispose DiffEditor before model cleanup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7d07e8f commit db4e811

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

control-plane/src/components/Editor.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"use client";
22

3-
import React, { useCallback, useState } from "react";
3+
import React, { useCallback, useEffect, useRef, useState } from "react";
44
import MonacoEditor, { DiffEditor } from "@monaco-editor/react";
5+
import type { editor } from "monaco-editor";
56
import { useTheme } from "next-themes";
67
import { EDITABLE_FILE_EXTENSION_MAP } from "@/lib/const";
78
import { Button } from "@/components/ui/button";
@@ -37,6 +38,15 @@ export default function Editor({
3738
[setValue]
3839
);
3940

41+
const diffEditorRef = useRef<editor.IStandaloneDiffEditor | null>(null);
42+
43+
useEffect(() => {
44+
return () => {
45+
diffEditorRef.current?.dispose();
46+
diffEditorRef.current = null;
47+
};
48+
}, []);
49+
4050
const isDark = resolvedTheme === "dark";
4151
const ext = filename.split(".").pop() as string;
4252
const language = EDITABLE_FILE_EXTENSION_MAP[ext] ?? "plaintext";
@@ -87,8 +97,9 @@ export default function Editor({
8797
language={language}
8898
theme={theme}
8999
height="100%"
90-
onMount={(editor) => {
91-
const modifiedEditor = editor.getModifiedEditor();
100+
onMount={(diffEditor) => {
101+
diffEditorRef.current = diffEditor;
102+
const modifiedEditor = diffEditor.getModifiedEditor();
92103
modifiedEditor.onDidChangeModelContent(() => {
93104
onChange(modifiedEditor.getValue());
94105
});

0 commit comments

Comments
 (0)