Skip to content

Commit 199f105

Browse files
authored
fix: dispose editor on element unmount (#184)
this allow component to work in React.StrictMode where useEffect is called twice close #183
1 parent f3b0570 commit 199f105

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

core/src/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ function MonacoEditor(props: MonacoEditorProps, ref: React.ForwardedRef<RefEdito
8686
$editor.current.setValue(val);
8787
}
8888
}, [val])
89-
useEffect(() => {
90-
return () => {
91-
if($editor.current) {
92-
$editor.current.dispose()
93-
}
94-
}
95-
}, []);
9689

9790
useEffect(() => {
9891
if (options.theme) {
@@ -162,6 +155,11 @@ function MonacoEditor(props: MonacoEditorProps, ref: React.ForwardedRef<RefEdito
162155
throw new Error('Failed to load font codicon!!');
163156
}
164157
});
158+
} else {
159+
if ($editor.current) {
160+
$editor.current.dispose();
161+
$editor.current = undefined;
162+
}
165163
}
166164
}, []);
167165

0 commit comments

Comments
 (0)