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.

🐛 fix: set context before replaceMessages in StoreUpdater layout effect (#13421)

Inneiee8cab83053c
diff --git a/src/features/Conversation/StoreUpdater.tsx b/src/features/Conversation/StoreUpdater.tsx
index 9a589bb667f..552f27e1412 100644
--- a/src/features/Conversation/StoreUpdater.tsx
+++ b/src/features/Conversation/StoreUpdater.tsx
@@ -81,9 +81,10 @@ const StoreUpdater = memo<StoreUpdaterProps>(
prevContextKeyRef.current = contextKey;
prevMessagesRef.current = undefined;
- // Atomically reset all stale data so ChatList shows skeleton (messagesInit=false)
- // instead of old topic messages during the transition
+ // Update context first so replaceMessages uses the correct context
+ // when calling onMessagesChange (otherwise writes to the old topic key)
storeApi.setState({
+ context,
dbMessages: messages ?? [],
displayMessages: [],
messagesInit: false,