Skip to content

Commit ce4b058

Browse files
authored
refactor(editor-monaco): enhance Monaco Editor integration with React (#4978)
1 parent e295eaa commit ce4b058

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ const MonacoEditor = ({
7474
}, [value, language, theme, isReadOnly]);
7575

7676
const disposeEditor = useCallback(() => {
77-
onWillUnmount(editorRef.current);
77+
onWillUnmount(editorRef.current, monaco);
7878
subscriptionRef.current?.dispose();
7979
editorRef.current.getModel()?.dispose();
8080
editorRef.current.dispose();
8181
}, [onWillUnmount]);
8282

8383
// disposing of Monaco Editor
84-
useMount(() => () => {
85-
if (editorRef.current) {
86-
disposeEditor();
87-
}
84+
useMount(() => {
85+
return () => {
86+
if (editorRef.current) disposeEditor();
87+
};
8888
});
8989

9090
// defining the custom themes and setting the active one
@@ -134,9 +134,13 @@ const MonacoEditor = ({
134134
);
135135

136136
// settings the theme if changed
137-
useEffect(() => {
138-
monaco.editor.setTheme(theme);
139-
}, [theme]);
137+
useUpdate(
138+
() => {
139+
monaco.editor.setTheme(theme);
140+
},
141+
[theme],
142+
isEditorReady
143+
);
140144

141145
// register listener for validation markers
142146
useEffect(() => {
@@ -188,7 +192,7 @@ const MonacoEditor = ({
188192

189193
// creating Editor instance as last effect
190194
useEffect(() => {
191-
if (!isEditorReady && containerRef.current) {
195+
if (!isEditorReady) {
192196
createEditor();
193197
}
194198
}, [isEditorReady, createEditor]);

0 commit comments

Comments
 (0)