fix(chat): preserve messages array during chat update
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Object.assign was overwriting the existing messages array before the ternary fallback could reference it. Capture the reference beforehand.
This commit is contained in:
@@ -152,10 +152,13 @@ Alpine.data('chatManager', () => ({
|
|||||||
chat = { ...chunk.chat, messages: chunk.chat.messages || [] };
|
chat = { ...chunk.chat, messages: chunk.chat.messages || [] };
|
||||||
this.chats.unshift(chat);
|
this.chats.unshift(chat);
|
||||||
} else {
|
} else {
|
||||||
|
// Preserve Messages - Object.assign would overwrite the existing
|
||||||
|
// messages array before we can check whether the chunk has any.
|
||||||
|
const existingMessages = chat.messages;
|
||||||
Object.assign(chat, chunk.chat);
|
Object.assign(chat, chunk.chat);
|
||||||
chat.messages = chunk.chat.messages?.length
|
chat.messages = chunk.chat.messages?.length
|
||||||
? chunk.chat.messages
|
? chunk.chat.messages
|
||||||
: chat.messages;
|
: existingMessages;
|
||||||
}
|
}
|
||||||
this.selectedChatID = chunk.chat.id;
|
this.selectedChatID = chunk.chat.id;
|
||||||
this.updateHash(chunk.chat.id);
|
this.updateHash(chunk.chat.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user