mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 09:37:28 +00:00
🐛 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:
parent
393653e20c
commit
ee8cab8305
1 changed files with 3 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue