Skip to content

Commit d2071f7

Browse files
committed
Add back teardown function
1 parent f8a57d5 commit d2071f7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

client/modules/IDE/components/Editor/codemirror.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ export default function useCodeMirror({
9494
});
9595
}
9696

97+
// When the component unmounts, we want to clean up the CodeMirror instance.
98+
function teardownCodeMirror() {
99+
if (cmView.current) {
100+
cmView.current.destroy();
101+
cmView.current = null;
102+
}
103+
}
104+
97105
// When settings change, we pass those changes into CodeMirror.
98106
// TODO: There should be a useEffect hook for when the theme changes.
99107
useEffect(() => {
@@ -201,6 +209,7 @@ export default function useCodeMirror({
201209

202210
return {
203211
setupCodeMirrorOnContainerMounted,
212+
teardownCodeMirror,
204213
getContent,
205214
tidyCode
206215
// showFind,

client/modules/IDE/components/Editor/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function Editor({
8484
// a reference to the actual CM instance.
8585
const {
8686
setupCodeMirrorOnContainerMounted,
87+
teardownCodeMirror,
8788
// cmInstance,
8889
getContent,
8990
tidyCode
@@ -130,6 +131,7 @@ function Editor({
130131

131132
return () => {
132133
provideController(null);
134+
teardownCodeMirror();
133135
};
134136
}, []);
135137

0 commit comments

Comments
 (0)