From eae062a23a8047ac8f70d0503ad85023a3511752 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 8 Feb 2026 22:28:53 +0100 Subject: [PATCH] Fixed issues --- src/app/runs/[runId]/components/Editor.tsx | 60 +++++----------------- 1 file changed, 14 insertions(+), 46 deletions(-) diff --git a/src/app/runs/[runId]/components/Editor.tsx b/src/app/runs/[runId]/components/Editor.tsx index ff63e0c..c82da63 100644 --- a/src/app/runs/[runId]/components/Editor.tsx +++ b/src/app/runs/[runId]/components/Editor.tsx @@ -41,10 +41,6 @@ function getLanguageExtension(lang: Language) { export default function Editor({ run }: { run: LiveRun | null | undefined }) { const [editorView, setEditorView] = useState(); - const [isConnected, setConnected] = useState(false); - - const [rawMoves, setRawMoves] = useState([]); - const [movesLoading, setMovesLoading] = useState(false); const scheduledTimeouts = useRef([]); // WebSocket connection @@ -59,53 +55,25 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) { ws.onmessage = (m) => { const data: LiveRunMove[] = JSON.parse(m.data); - setRawMoves(data); + + data.forEach((move) => { + const timeout = setTimeout(() => { + if (!editorView) return; + + editorView.dispatch({ + selection: { anchor: move.cursor }, + scrollIntoView: true, + changes: move.changes, + }); + }, move.latency); + + scheduledTimeouts.current.push(timeout); + }); }; 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) => { - const timeout = setTimeout(() => { - if (!editorView) return; - - editorView.dispatch({ - selection: { anchor: move.cursor }, - scrollIntoView: true, - changes: move.changes, - }); - }, move.latency); - - 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 (