From 555517c144f9f96912af52ec1e5dc8115f10baab Mon Sep 17 00:00:00 2001 From: Alex Blank Date: Tue, 26 May 2026 13:51:26 +0200 Subject: [PATCH] fix: font size buttons only worked once due to stale callback The changeFontSize callback passed to MobileTerminalWrapper was capturing the initial handleFontSizeChange function, so subsequent clicks used stale fontSize state. Fixed by wrapping handleFontSizeChange in a ref so the callback always calls the latest version. --- apps/web/src/components/terminal.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/terminal.tsx b/apps/web/src/components/terminal.tsx index 406aac7..5019995 100644 --- a/apps/web/src/components/terminal.tsx +++ b/apps/web/src/components/terminal.tsx @@ -42,6 +42,7 @@ export const TerminalComponent: React.FC = ({ const reconnectAttemptsRef = useRef(0); const onTerminalReadyRef = useRef(onTerminalReady); onTerminalReadyRef.current = onTerminalReady; + const handleFontSizeChangeRef = useRef<(delta: number) => void>(() => {}); const [status, setStatus] = useState< "connecting" | "connected" | "disconnected" | "error" | "resetting" >("connecting"); @@ -367,7 +368,7 @@ export const TerminalComponent: React.FC = ({ termRef.current?.focus(); }; const changeFontSize = (delta: number) => { - handleFontSizeChange(delta); + handleFontSizeChangeRef.current(delta); }; onTerminalReadyRef.current(sendData, status, focusInput, changeFontSize); } @@ -415,7 +416,7 @@ export const TerminalComponent: React.FC = ({ termRef.current?.focus(); }; const changeFontSize = (delta: number) => { - handleFontSizeChange(delta); + handleFontSizeChangeRef.current(delta); }; onTerminalReady(sendData, status, focusInput, changeFontSize); } @@ -448,6 +449,7 @@ export const TerminalComponent: React.FC = ({ }); } }; + handleFontSizeChangeRef.current = handleFontSizeChange; const handleCopy = async () => { if (!termRef.current) return;