Skip to content

Commit

Permalink
fix(monaco-editor): avoid rendering Monaco Editor multiple times (#4971)
Browse files Browse the repository at this point in the history
Refs #4970
  • Loading branch information
char0n authored Apr 24, 2024
1 parent 6315aaa commit 47f9798
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,6 +70,7 @@ const MonacoEditor = ({

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

const disposeEditor = useCallback(() => {
Expand Down

0 comments on commit 47f9798

Please sign in to comment.