From ad76b1174a10c20836cad2bbbf5fd67d65fc2021 Mon Sep 17 00:00:00 2001 From: OpenClaude Worker 3 Date: Wed, 8 Apr 2026 11:47:26 +0530 Subject: [PATCH] fix: move startup checks after submitCount declaration to avoid temporal dead zone Code quality bot flagged that submitCount was used before its declaration. Moved the entire startup checks block to after the submitCount useState declaration. Also added nullish coalescing (submitCount ?? 0) per bot suggestion. --- src/screens/REPL.tsx | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/screens/REPL.tsx b/src/screens/REPL.tsx index cb408d48..4a160d24 100644 --- a/src/screens/REPL.tsx +++ b/src/screens/REPL.tsx @@ -1337,34 +1337,6 @@ export function REPL({ const inputValueRef = useRef(inputValue); inputValueRef.current = inputValue; const promptTypingSuppressionActive = isPromptTypingSuppressionActive(isPromptInputActive, inputValue); - - // Defer startup checks until the user has interacted with the prompt. - // A pure timeout is insufficient (issue #363): if the user pauses >1.5s - // before typing, the timer can still fire and recommendation dialogs can - // steal focus. Instead, we gate on actual prompt readiness: - // - First message submitted (submitCount > 0) - // - Grace period elapsed + user is not actively typing - // - User is typing (deferred until they stop) - const startupChecksStartedRef = React.useRef(false); - const [startupGraceElapsed, setStartupGraceElapsed] = useState(false); - useEffect(() => { - const timer = setTimeout(() => setStartupGraceElapsed(true), STARTUP_GRACE_PERIOD_MS); - return () => clearTimeout(timer); - }, []); - const hasHadFirstSubmission = submitCount > 0; - useEffect(() => { - if (isRemoteSession) return; - if (startupChecksStartedRef.current) return; - if (!shouldRunStartupChecks({ - isRemoteSession, - hasStarted: startupChecksStartedRef.current, - promptTypingSuppressionActive, - hasHadFirstSubmission, - gracePeriodElapsed: startupGraceElapsed, - })) return; - startupChecksStartedRef.current = true; - void performStartupChecks(setAppState); - }, [setAppState, isRemoteSession, promptTypingSuppressionActive, hasHadFirstSubmission, startupGraceElapsed]); const insertTextRef = useRef<{ insert: (text: string) => void; setInputWithCursor: (value: string, cursor: number) => void; @@ -1456,6 +1428,34 @@ export function REPL({ const activeRemote = sshRemote.isRemoteMode ? sshRemote : directConnect.isRemoteMode ? directConnect : remoteSession; const [pastedContents, setPastedContents] = useState>({}); const [submitCount, setSubmitCount] = useState(0); + + // Defer startup checks until the user has interacted with the prompt. + // A pure timeout is insufficient (issue #363): if the user pauses >1.5s + // before typing, the timer can still fire and recommendation dialogs can + // steal focus. Instead, we gate on actual prompt readiness: + // - First message submitted (submitCount > 0) + // - Grace period elapsed + user is not actively typing + // - User is typing (deferred until they stop) + const startupChecksStartedRef = React.useRef(false); + const [startupGraceElapsed, setStartupGraceElapsed] = useState(false); + useEffect(() => { + const timer = setTimeout(() => setStartupGraceElapsed(true), STARTUP_GRACE_PERIOD_MS); + return () => clearTimeout(timer); + }, []); + const hasHadFirstSubmission = (submitCount ?? 0) > 0; + useEffect(() => { + if (isRemoteSession) return; + if (startupChecksStartedRef.current) return; + if (!shouldRunStartupChecks({ + isRemoteSession, + hasStarted: startupChecksStartedRef.current, + promptTypingSuppressionActive, + hasHadFirstSubmission, + gracePeriodElapsed: startupGraceElapsed, + })) return; + startupChecksStartedRef.current = true; + void performStartupChecks(setAppState); + }, [setAppState, isRemoteSession, promptTypingSuppressionActive, hasHadFirstSubmission, startupGraceElapsed]); // Ref instead of state to avoid triggering React re-renders on every // streaming text_delta. The spinner reads this via its animation timer. const responseLengthRef = useRef(0);