From 45a6ae8032750ef7d0f94024b853611bf09902c8 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Wed, 24 Apr 2024 10:20:12 +0200 Subject: [PATCH] fix(monaco-editor): avoid rendering Monaco Editor multiple times Refs #4970 --- .../editor-monaco/components/MonacoEditor/MonacoEditor.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/editor-monaco/components/MonacoEditor/MonacoEditor.jsx b/src/plugins/editor-monaco/components/MonacoEditor/MonacoEditor.jsx index bf7f7d2cf38..524f42e7dc6 100644 --- a/src/plugins/editor-monaco/components/MonacoEditor/MonacoEditor.jsx +++ b/src/plugins/editor-monaco/components/MonacoEditor/MonacoEditor.jsx @@ -29,9 +29,13 @@ const MonacoEditor = ({ const editorRef = useRef(null); const subscriptionRef = useRef(null); const valueRef = useRef(value); + const preventCreation = useRef(false); const [isEditorReady, setIsEditorReady] = useState(false); const createEditor = useCallback(() => { + if (!containerRef.current) return; + if (preventCreation.current) return; + editorRef.current = monaco.editor.create(containerRef.current, { value, language, @@ -66,6 +70,7 @@ const MonacoEditor = ({ editorRef.current.getModel().updateOptions({ tabSize: 2 }); setIsEditorReady(true); + preventCreation.current = true; }, [value, language, theme, isReadOnly]); const disposeEditor = useCallback(() => {