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

🐛 fix: set context before replaceMessages in layout effect

replaceMessages calls onMessagesChange(messages, get().context) internally.
Without updating context first, it writes new topic's messages to the old
topic's key in ChatStore, corrupting cached data.
This commit is contained in:
Innei 2026-03-31 20:47:33 +08:00 committed by GitHub
parent 393653e20c
commit ee8cab8305
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,