From 070b4364feb819fcc70666861d49132b49cfba87 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 12 Jan 2024 19:31:10 +0100 Subject: [PATCH] fix: codemirror does not vanish anymore on hot reload --- packages/codemirror/codemirror.mjs | 1 + website/src/repl/Repl.jsx | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 0d095a4ed..349de2b0a 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -323,6 +323,7 @@ export class StrudelMirror { this.editor.dispatch({ changes }); } clear() { + this.stop(); this.onStartRepl && document.removeEventListener('start-repl', this.onStartRepl); } } diff --git a/website/src/repl/Repl.jsx b/website/src/repl/Repl.jsx index 7f8bd06ab..323376f41 100644 --- a/website/src/repl/Repl.jsx +++ b/website/src/repl/Repl.jsx @@ -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(); } }}