From 254051cf624cf43e62b9ba55b37ddeb11a3d8526 Mon Sep 17 00:00:00 2001 From: icarus Date: Thu, 16 Oct 2025 23:59:45 +0800 Subject: [PATCH] fix(InputBar): move focus logic into useEffect to prevent side effects fix: Error: Cannot access refs during render --- .../src/windows/mini/home/components/InputBar.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/windows/mini/home/components/InputBar.tsx b/src/renderer/src/windows/mini/home/components/InputBar.tsx index cfd7d29457..0a378b6343 100644 --- a/src/renderer/src/windows/mini/home/components/InputBar.tsx +++ b/src/renderer/src/windows/mini/home/components/InputBar.tsx @@ -3,7 +3,7 @@ import { useTimer } from '@renderer/hooks/useTimer' import { Assistant } from '@renderer/types' import { Input as AntdInput } from 'antd' import { InputRef } from 'rc-input/lib/interface' -import React, { useRef } from 'react' +import React, { useEffect, useRef } from 'react' import styled from 'styled-components' interface InputBarProps { @@ -27,9 +27,13 @@ const InputBar = ({ }: InputBarProps & { ref?: React.RefObject }) => { const inputRef = useRef(null) const { setTimeoutTimer } = useTimer() - if (!loading) { - setTimeoutTimer('focus', () => inputRef.current?.input?.focus(), 0) - } + + useEffect(() => { + if (!loading) { + setTimeoutTimer('focus', () => inputRef.current?.input?.focus(), 0) + } + }) + return ( {assistant.model && }