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.
This commit is contained in:
@@ -42,6 +42,7 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
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<TerminalProps> = ({
|
||||
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<TerminalProps> = ({
|
||||
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<TerminalProps> = ({
|
||||
});
|
||||
}
|
||||
};
|
||||
handleFontSizeChangeRef.current = handleFontSizeChange;
|
||||
|
||||
const handleCopy = async () => {
|
||||
if (!termRef.current) return;
|
||||
|
||||
Reference in New Issue
Block a user