🔧 fix: Immutability Issue in useChatFunctions (#7983)

* fix: Use mutable version of conversation in useChatFunctions

* fix: Use cloneDeep for conversation in useChatFunctions to ensure immutability

---------

Co-authored-by: lucioperca <lucioperca@users.noreply.github.com>
This commit is contained in:
Danny Avila 2025-06-19 19:21:38 -04:00 committed by GitHub
parent a5e8d009a1
commit d53cd1f391
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
import { v4 } from 'uuid';
import { cloneDeep } from 'lodash';
import { useQueryClient } from '@tanstack/react-query';
import {
Constants,
@ -51,10 +52,10 @@ export default function useChatFunctions({
getMessages,
setMessages,
isSubmitting,
conversation,
latestMessage,
setSubmission,
setLatestMessage,
conversation: immutableConversation,
}: {
index?: number;
isSubmitting: boolean;
@ -77,8 +78,8 @@ export default function useChatFunctions({
const isTemporary = useRecoilValue(store.isTemporary);
const codeArtifacts = useRecoilValue(store.codeArtifacts);
const includeShadcnui = useRecoilValue(store.includeShadcnui);
const { getExpiry } = useUserKey(conversation?.endpoint ?? '');
const customPromptMode = useRecoilValue(store.customPromptMode);
const { getExpiry } = useUserKey(immutableConversation?.endpoint ?? '');
const setShowStopButton = useSetRecoilState(store.showStopButtonByIndex(index));
const resetLatestMultiMessage = useResetRecoilState(store.latestMessageFamily(index + 1));
@ -108,6 +109,8 @@ export default function useChatFunctions({
return;
}
const conversation = cloneDeep(immutableConversation);
const endpoint = conversation?.endpoint;
if (endpoint === null) {
console.error('No endpoint available');