Fixes slow typing when long session (#1958)

This commit is contained in:
Zane
2025-04-01 08:06:40 -07:00
committed by GitHub
parent 22c968d20f
commit e0bd2d6763
2 changed files with 12 additions and 16 deletions
+1 -2
View File
@@ -442,8 +442,7 @@ export default function ChatView({
isLoading={isLoading} isLoading={isLoading}
onStop={onStopGoose} onStop={onStopGoose}
commandHistory={commandHistory} commandHistory={commandHistory}
value={_input} initialValue={_input}
onValueChange={_setInput}
/> />
<BottomMenu hasMessages={hasMessages} setView={setView} /> <BottomMenu hasMessages={hasMessages} setView={setView} />
</div> </div>
+11 -14
View File
@@ -8,8 +8,7 @@ interface InputProps {
isLoading?: boolean; isLoading?: boolean;
onStop?: () => void; onStop?: () => void;
commandHistory?: string[]; commandHistory?: string[];
value?: string; initialValue?: string;
onValueChange?: (value: string) => void;
} }
export default function Input({ export default function Input({
@@ -17,19 +16,17 @@ export default function Input({
isLoading = false, isLoading = false,
onStop, onStop,
commandHistory = [], commandHistory = [],
value: controlledValue, initialValue = '',
onValueChange,
}: InputProps) { }: InputProps) {
const [internalValue, setInternalValue] = useState(''); const [value, setValue] = useState(initialValue);
// Use controlled value if provided, otherwise use internal state
const value = controlledValue !== undefined ? controlledValue : internalValue; // Update internal value when initialValue changes
const setValue = (newValue: string) => { useEffect(() => {
if (controlledValue !== undefined && onValueChange) { if (initialValue) {
onValueChange(newValue); setValue(initialValue);
} else {
setInternalValue(newValue);
} }
}; }, [initialValue]);
// State to track if the IME is composing (i.e., in the middle of Japanese IME input) // State to track if the IME is composing (i.e., in the middle of Japanese IME input)
const [isComposing, setIsComposing] = useState(false); const [isComposing, setIsComposing] = useState(false);
const [historyIndex, setHistoryIndex] = useState(-1); const [historyIndex, setHistoryIndex] = useState(-1);
@@ -40,7 +37,7 @@ export default function Input({
if (textAreaRef.current) { if (textAreaRef.current) {
textAreaRef.current.focus(); textAreaRef.current.focus();
} }
}, [value]); }, []);
const useAutosizeTextArea = (textAreaRef: HTMLTextAreaElement | null, value: string) => { const useAutosizeTextArea = (textAreaRef: HTMLTextAreaElement | null, value: string) => {
useEffect(() => { useEffect(() => {