Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

fix: fix infinite query failure when conversationId is not found

Daniel D Orlandofb7542c86520
diff --git a/client/src/data-provider/react-query-service.ts b/client/src/data-provider/react-query-service.ts
index c85660214c..91cb19740b 100644
--- a/client/src/data-provider/react-query-service.ts
+++ b/client/src/data-provider/react-query-service.ts
@@ -63,13 +63,11 @@ export const useGetConversationByIdQuery = (
//to make it work with how the Chat component is structured
export const useGetConversationByIdMutation = (
id: string,
- callback: (data: t.TConversation) => void
): UseMutationResult<t.TConversation> => {
const queryClient = useQueryClient();
return useMutation(() => dataService.getConversationById(id),
{
onSuccess: (res: t.TConversation) => {
- callback(res);
queryClient.invalidateQueries([QueryKeys.conversation, id]);
},
}
diff --git a/client/src/routes/Chat.jsx b/client/src/routes/Chat.jsx
index 88202b8221..3497799029 100644
--- a/client/src/routes/Chat.jsx
+++ b/client/src/routes/Chat.jsx
@@ -20,7 +20,7 @@ export default function Chat() {
//disabled by default, we only enable it when messagesTree is null
const messagesQuery = useGetMessagesByConvoId(conversationId, { enabled: false });
- const getConversationMutation = useGetConversationByIdMutation(conversationId, setConversation);
+ const getConversationMutation = useGetConversationByIdMutation(conversationId);
// when conversation changed or conversationId (in url) changed
useEffect(() => {
@@ -31,7 +31,17 @@ export default function Chat() {
newConversation();
} else if (conversationId) {
// fetch it from server
- getConversationMutation.mutate();
+ getConversationMutation.mutate(conversationId, {
+ onSuccess: (data) => {
+ setConversation(data);
+ },
+ onError: (error) => {
+ console.error('failed to fetch the conversation');
+ console.error(error);
+ navigate(`/chat/new`);
+ newConversation();
+ }
+ });
setMessages(null);
} else {
navigate(`/chat/new`);
@@ -45,15 +55,6 @@ export default function Chat() {
}
}, [conversation, conversationId]);
- useEffect(() => {
- if(getConversationMutation.isError) {
- console.error('failed to fetch the conversation');
- console.error(getConversationMutation.error);
- newConversation();
- }
- }, [getConversationMutation.isError, newConversation]);
-
-
useEffect(() => {
if (messagesTree === null && conversation?.conversationId) {
messagesQuery.refetch(conversation?.conversationId);