Skip to content

Commit 47f9798

Browse files
authored
fix(monaco-editor): avoid rendering Monaco Editor multiple times (#4971)
Refs #4970
1 parent 6315aaa commit 47f9798

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/plugins/editor-monaco/components/MonacoEditor/MonacoEditor.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ const MonacoEditor = ({
2929
const editorRef = useRef(null);
3030
const subscriptionRef = useRef(null);
3131
const valueRef = useRef(value);
32+
const preventCreation = useRef(false);
3233
const [isEditorReady, setIsEditorReady] = useState(false);
3334

3435
const createEditor = useCallback(() => {
36+
if (!containerRef.current) return;
37+
if (preventCreation.current) return;
38+
3539
editorRef.current = monaco.editor.create(containerRef.current, {
3640
value,
3741
language,
@@ -66,6 +70,7 @@ const MonacoEditor = ({
6670

6771
editorRef.current.getModel().updateOptions({ tabSize: 2 });
6872
setIsEditorReady(true);
73+
preventCreation.current = true;
6974
}, [value, language, theme, isReadOnly]);
7075

7176
const disposeEditor = useCallback(() => {

0 commit comments

Comments
 (0)