Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat: topic message swr cache (#10886)

Shinji-Li613a404bf537
diff --git a/src/features/Conversation/store/slices/data/action.ts b/src/features/Conversation/store/slices/data/action.ts
index b3f2a58dfe1..422b6353a91 100644
--- a/src/features/Conversation/store/slices/data/action.ts
+++ b/src/features/Conversation/store/slices/data/action.ts
@@ -3,7 +3,7 @@ import type { ConversationContext, UIChatMessage } from '@lobechat/types';
import type { SWRResponse } from 'swr';
import type { StateCreator } from 'zustand/vanilla';
-import { useClientDataSWR } from '@/libs/swr';
+import { useClientDataSWRWithSync } from '@/libs/swr';
import { messageService } from '@/services/message';
import type { Store as ConversationStore } from '../../action';
@@ -105,14 +105,14 @@ export const dataSlice: StateCreator<
// This is used when external messages are provided (e.g., creating new thread)
const shouldFetch = !skipFetch && !!context.agentId;
- return useClientDataSWR<UIChatMessage[]>(
+ return useClientDataSWRWithSync<UIChatMessage[]>(
shouldFetch ? ['CONVERSATION_FETCH_MESSAGES', context] : null,
- async ([, key]: [string, ConversationContext]) => {
- return messageService.getMessages(key as any);
+ async () => {
+ return messageService.getMessages(context as any);
},
{
- onSuccess: (data) => {
+ onData: (data) => {
if (!data) return;
// Parse messages using conversation-flow
diff --git a/src/libs/swr/localStorageProvider.ts b/src/libs/swr/localStorageProvider.ts
index eb82aa67bce..a5f5bf5abdb 100644
--- a/src/libs/swr/localStorageProvider.ts
+++ b/src/libs/swr/localStorageProvider.ts
@@ -276,6 +276,7 @@ const SWR_CACHEABLE_PATTERNS = [
// Chat page data
'SWR_USE_FETCH_TOPIC', // Topic list (cached per agentId/groupId)
'fetchGroupDetail', // Group detail (cached per groupId)
+ 'CONVERSATION_FETCH_MESSAGES', // Messages (cached per agentId/topicId)
];
/**