mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-06 20:42:52 +08:00
fix(chat): 修复 ChatPanel 无限重渲染导致的 Maximum update depth exceeded
- useTaskStore 选择器内调用 getCurrentTask() 每次返回新对象引用, 改为分别选取 currentTaskId + tasks 后用 useMemo 派生 - chatHistory[taskId] || [] 在选择器内每次创建新空数组引用, 改为选择器返回原始值,外部用 ?? [] 兜底 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -49,11 +49,16 @@ export default function ChatPanel({ taskId }: ChatPanelProps) {
|
||||
const [indexing, setIndexing] = useState(false)
|
||||
const [indexed, setIndexed] = useState<boolean | null>(null)
|
||||
|
||||
const messages = useChatStore(state => state.chatHistory[taskId] || [])
|
||||
const messages = useChatStore(state => state.chatHistory[taskId]) ?? []
|
||||
const addMessage = useChatStore(state => state.addMessage)
|
||||
const clearChat = useChatStore(state => state.clearChat)
|
||||
|
||||
const currentTask = useTaskStore(state => state.getCurrentTask())
|
||||
const currentTaskId = useTaskStore(state => state.currentTaskId)
|
||||
const tasks = useTaskStore(state => state.tasks)
|
||||
const currentTask = useMemo(
|
||||
() => tasks.find(t => t.id === currentTaskId) ?? null,
|
||||
[tasks, currentTaskId],
|
||||
)
|
||||
|
||||
// 检查索引状态
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user