mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-05 06:57:35 -04:00
fix: codemirror does not vanish anymore on hot reload
This commit is contained in:
@@ -323,6 +323,7 @@ export class StrudelMirror {
|
||||
this.editor.dispatch({ changes });
|
||||
}
|
||||
clear() {
|
||||
this.stop();
|
||||
this.onStartRepl && document.removeEventListener('start-repl', this.onStartRepl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,16 @@ export function Repl({ embedded = false }) {
|
||||
});
|
||||
|
||||
editorRef.current = editor;
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.dispose(() => {
|
||||
editorRef.current.clear();
|
||||
setTimeout(() => {
|
||||
delete editorRef.current;
|
||||
delete containerRef.current;
|
||||
});
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
const [replState, setReplState] = useState({});
|
||||
@@ -199,7 +209,7 @@ export function Repl({ embedded = false }) {
|
||||
id="code"
|
||||
ref={(el) => {
|
||||
containerRef.current = el;
|
||||
if (!editorRef.current) {
|
||||
if (!editorRef.current && containerRef.current) {
|
||||
init();
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user