mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 03:31:24 +08:00
hotfix: enhance assistant topic validation in useActiveTopic hook (#8213)
fix: enhance assistant topic validation in useActiveTopic hook Updated the useActiveTopic hook to ensure that the assistant and its topics are properly validated before accessing properties. This prevents potential errors when data is not fully loaded.
This commit is contained in:
parent
720c5d6080
commit
7549972048
@ -34,7 +34,14 @@ export function useActiveTopic(assistantId: string, topic?: Topic) {
|
||||
|
||||
useEffect(() => {
|
||||
// activeTopic not in assistant.topics
|
||||
if (assistant && assistant.topics.length > 0 && !find(assistant.topics, { id: activeTopic?.id })) {
|
||||
// 确保 assistant 和 assistant.topics 存在,避免在数据未完全加载时访问属性
|
||||
if (
|
||||
assistant &&
|
||||
assistant.topics &&
|
||||
Array.isArray(assistant.topics) &&
|
||||
assistant.topics.length > 0 &&
|
||||
!find(assistant.topics, { id: activeTopic?.id })
|
||||
) {
|
||||
setActiveTopic(assistant.topics[0])
|
||||
}
|
||||
}, [activeTopic?.id, assistant])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user