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:
SuYao 2025-07-17 11:48:25 +08:00 committed by GitHub
parent 720c5d6080
commit 7549972048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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])