Fixed issues

This commit is contained in:
2026-02-08 22:28:53 +01:00
parent 01452e0e9f
commit eae062a23a
+4 -36
View File
@@ -41,10 +41,6 @@ function getLanguageExtension(lang: Language) {
export default function Editor({ run }: { run: LiveRun | null | undefined }) {
const [editorView, setEditorView] = useState<EditorView>();
const [isConnected, setConnected] = useState(false);
const [rawMoves, setRawMoves] = useState<LiveRunMove[]>([]);
const [movesLoading, setMovesLoading] = useState(false);
const scheduledTimeouts = useRef<NodeJS.Timeout[]>([]);
// WebSocket connection
@@ -59,25 +55,8 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) {
ws.onmessage = (m) => {
const data: LiveRunMove[] = JSON.parse(m.data);
setRawMoves(data);
};
return () => ws.close();
}, [run]);
// Scheduler
useEffect(() => {
if (!editorView || !rawMoves.length) return;
setMovesLoading(true);
// Clear any existing scheduled timeouts
scheduledTimeouts.current.forEach((t) => clearTimeout(t));
scheduledTimeouts.current = [];
const startTime = Date.now();
rawMoves.forEach((move) => {
data.forEach((move) => {
const timeout = setTimeout(() => {
if (!editorView) return;
@@ -90,21 +69,10 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) {
scheduledTimeouts.current.push(timeout);
});
// Stop loading after the last move
const lastMoveLatency = rawMoves[rawMoves.length - 1].latency;
const finishTimeout = setTimeout(
() => setMovesLoading(false),
lastMoveLatency + 50,
);
scheduledTimeouts.current.push(finishTimeout);
return () => {
scheduledTimeouts.current.forEach((t) => clearTimeout(t));
scheduledTimeouts.current = [];
setMovesLoading(false);
};
}, [rawMoves, editorView]);
return () => ws.close();
}, [run]);
return (
<CodeMirror