From 9b6c4d9479689b2df5e1902f2b87e04def916c85 Mon Sep 17 00:00:00 2001 From: Jordan Rome Date: Wed, 3 Dec 2025 16:22:07 -0500 Subject: [PATCH] Fix infinite fetch loop When loading content from the url param, we were entering an infinite loop because the `useEffect` to fetch the content was dependent upon a function that was getting re-created when the stored logs were getting updated. So every time we fetched, we updated the stored logs, and round and round we went. --- src/App.tsx | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 7feafcc..87a1519 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -277,21 +277,21 @@ function App({ testListHeight }: { testListHeight?: number }) { setStoredLogs(nextStoredLogs); }, []); - const addStoredLog = useCallback( - (lines: string[], name: string = "") => { - const now = new Date(); - const nextName = name - ? name - : `pasted log (${now.toDateString().toLowerCase()} - ${now.toLocaleTimeString().toLocaleLowerCase()})`; + const addStoredLog = useCallback((lines: string[], name: string = "") => { + const now = new Date(); + const nextName = name + ? name + : `pasted log (${now.toDateString().toLowerCase()} - ${now.toLocaleTimeString().toLocaleLowerCase()})`; + setStoredLogs((prevStoredLogs: StoredLogs) => { // Only keep 5 stored logs for now const nextStoredLogs: StoredLogs = [ [nextName, { rawLogLines: lines, pastedCLines: {} }], - ...storedLogs.slice(0, 5), + ...prevStoredLogs.slice(0, 5), ]; - updateStoredLogs(nextStoredLogs); - }, - [storedLogs], - ); + ldb.set(STORED_LOG_KEY, JSON.stringify(nextStoredLogs)); + return nextStoredLogs; + }); + }, []); const loadLog = useCallback((lines: string[]) => { const newVerifierLogState = processRawLines(lines); @@ -348,14 +348,11 @@ function App({ testListHeight }: { testListHeight?: number }) { [verifierLogState, storedLogs], ); - const loadInputText = useCallback( - (text: string) => { - const rawLines = text.split("\n"); - loadLog(rawLines); - addStoredLog(rawLines); - }, - [addStoredLog], - ); + const loadInputText = useCallback((text: string) => { + const rawLines = text.split("\n"); + loadLog(rawLines); + addStoredLog(rawLines); + }, []); const prepareNewLog = useCallback(() => { setSelectedState(getEmptyLogLineState()); @@ -443,7 +440,7 @@ function App({ testListHeight }: { testListHeight?: number }) { } }); } - }, [loadInputText]); + }, []); const handleLogLinesOver = useCallback( (e: React.MouseEvent) => {