Skip to content

Commit 556a2aa

Browse files
committed
refactor(conversation): streamline onLoad callback handling for conversation list loading
1 parent 06107cf commit 556a2aa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/kit/src/vue/conversation/useConversation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,13 @@ export const useConversation = (options: UseConversationOptions): UseConversatio
118118
.then((list) => {
119119
// 如果加载的列表为空,直接返回
120120
if (!list?.length) {
121-
options.onLoad?.([])
122-
return
121+
return []
123122
}
124123

125124
// 如果当前内存中的会话列表为空,直接使用加载的列表
126125
if (conversations.value.length === 0) {
127126
conversations.value = list
128-
options.onLoad?.(conversations.value)
129-
return
127+
return conversations.value
130128
}
131129

132130
// 合并策略:内存数据优先于存储数据
@@ -140,11 +138,14 @@ export const useConversation = (options: UseConversationOptions): UseConversatio
140138
}
141139
})
142140
conversations.value = Array.from(merged.values())
143-
options.onLoad?.(conversations.value)
144141

145142
// 确保 activeConversation 对应的会话在合并后的列表中
146143
// 如果 activeConversationId 存在但对应的会话不在列表中,说明可能被意外删除
147144
// 这种情况下,activeConversation 会自动变为 null(通过 computed 属性)
145+
return conversations.value
146+
})
147+
.then((loadedList) => {
148+
options.onLoad?.(loadedList)
148149
})
149150
.catch((error) => {
150151
console.error('[useConversation] loadConversations failed:', error)

0 commit comments

Comments
 (0)