📢 fix: Invalid engineTTS and Conversation State on Navigation (#6904)

* fix: handle invalid engineTTS values and prevent VoiceDropdown render errors

* refactor: add verbose developer logging for debugging conversation state issues

* refactor: remove unnecessary effect for conversationId changes

* chore: imports

* fix: include model and entity IDs in conversation query selection

* feat: add fetchFreshData function to retrieve conversation data on navigation

* fix: remove unnecessary comment in fetchFreshData function

* chore: reorder imports in useNavigateToConvo for consistency

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Marco Beretta 2025-04-16 03:00:06 +02:00 committed by GitHub
parent d32f34e5d7
commit 000f3a3733
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 75 additions and 18 deletions

View file

@ -1,16 +1,16 @@
import { useEffect, useRef } from 'react';
import { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import { Constants, EModelEndpoint } from 'librechat-data-provider';
import { useGetModelsQuery } from 'librechat-data-provider/react-query';
import type { TPreset } from 'librechat-data-provider';
import {
useGetConvoIdQuery,
useHealthCheck,
useGetEndpointsQuery,
useGetConvoIdQuery,
useGetStartupConfig,
useGetEndpointsQuery,
} from '~/data-provider';
import { useNewConvo, useAppStartup, useAssistantListMap } from '~/hooks';
import { getDefaultModelSpec, getModelSpecIconURL } from '~/utils';
import { getDefaultModelSpec, getModelSpecIconURL, logger } from '~/utils';
import { ToolCallsMapProvider } from '~/Providers';
import ChatView from '~/components/Chat/ChatView';
import useAuthRedirect from './useAuthRedirect';
@ -38,11 +38,6 @@ export default function ChatRoute() {
const { hasSetConversation, conversation } = store.useCreateConversationAtom(index);
const { newConversation } = useNewConvo();
// Reset the guard flag whenever conversationId changes
useEffect(() => {
hasSetConversation.current = false;
}, [conversationId]);
const modelsQuery = useGetModelsQuery({
enabled: isAuthenticated,
refetchOnMount: 'always',
@ -53,6 +48,9 @@ export default function ChatRoute() {
const endpointsQuery = useGetEndpointsQuery({ enabled: isAuthenticated });
const assistantListMap = useAssistantListMap();
/** This effect is mainly for the first conversation state change on first load of the page.
* Adjusting this may have unintended consequences on the conversation state.
*/
useEffect(() => {
const shouldSetConvo =
(startupConfig && !hasSetConversation.current && !modelsQuery.data?.initial) ?? false;
@ -63,7 +61,7 @@ export default function ChatRoute() {
if (conversationId === Constants.NEW_CONVO && endpointsQuery.data && modelsQuery.data) {
const spec = getDefaultModelSpec(startupConfig);
logger.log('conversation', 'ChatRoute, new convo effect', conversation);
newConversation({
modelsData: modelsQuery.data,
template: conversation ? conversation : undefined,
@ -80,6 +78,7 @@ export default function ChatRoute() {
hasSetConversation.current = true;
} else if (initialConvoQuery.data && endpointsQuery.data && modelsQuery.data) {
logger.log('conversation', 'ChatRoute initialConvoQuery', initialConvoQuery.data);
newConversation({
template: initialConvoQuery.data,
/* this is necessary to load all existing settings */
@ -94,6 +93,7 @@ export default function ChatRoute() {
assistantListMap[EModelEndpoint.azureAssistants]
) {
const spec = getDefaultModelSpec(startupConfig);
logger.log('conversation', 'ChatRoute new convo, assistants effect', conversation);
newConversation({
modelsData: modelsQuery.data,
template: conversation ? conversation : undefined,
@ -112,6 +112,7 @@ export default function ChatRoute() {
assistantListMap[EModelEndpoint.assistants] &&
assistantListMap[EModelEndpoint.azureAssistants]
) {
logger.log('conversation', 'ChatRoute convo, assistants effect', initialConvoQuery.data);
newConversation({
template: initialConvoQuery.data,
preset: initialConvoQuery.data as TPreset,
@ -127,7 +128,6 @@ export default function ChatRoute() {
endpointsQuery.data,
modelsQuery.data,
assistantListMap,
conversationId,
]);
if (endpointsQuery.isLoading || modelsQuery.isLoading) {