Skip to content

Commit

Permalink
🚩 fix: Initialize Conversation Only when Necessary Data is Fetched (#…
Browse files Browse the repository at this point in the history
…1379)

* fix(ChatRoute): only initialize conversation after all data is fetched (models, endpoints, initialConversationQuery if not `new`)

* chore: remove unnecessary packages for rolling up api

* chore: bump data-provider package.json
  • Loading branch information
danny-avila authored Dec 17, 2023
1 parent 7c2134f commit c9d3e0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 86 deletions.
23 changes: 19 additions & 4 deletions client/src/routes/ChatRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useRecoilValue } from 'recoil';
import { useEffect, useRef } from 'react';
import { useParams } from 'react-router-dom';
import { useGetConvoIdQuery, useGetModelsQuery } from 'librechat-data-provider/react-query';
import {
useGetConvoIdQuery,
useGetModelsQuery,
useGetEndpointsQuery,
} from 'librechat-data-provider/react-query';
import { useNewConvo, useConfigOverride } from '~/hooks';
import ChatView from '~/components/Chat/ChatView';
import useAuthRedirect from './useAuthRedirect';
Expand All @@ -21,20 +25,31 @@ export default function ChatRoute() {
const initialConvoQuery = useGetConvoIdQuery(conversationId ?? '', {
enabled: isAuthenticated && conversationId !== 'new',
});
const endpointsQuery = useGetEndpointsQuery({ enabled: isAuthenticated && modelsQueryEnabled });

useEffect(() => {
if (conversationId === 'new' && modelsQuery.data && !hasSetConversation.current) {
if (
conversationId === 'new' &&
endpointsQuery.data &&
modelsQuery.data &&
!hasSetConversation.current
) {
newConversation({ modelsData: modelsQuery.data });
hasSetConversation.current = true;
} else if (initialConvoQuery.data && modelsQuery.data && !hasSetConversation.current) {
} else if (
initialConvoQuery.data &&
endpointsQuery.data &&
modelsQuery.data &&
!hasSetConversation.current
) {
newConversation({
template: initialConvoQuery.data,
modelsData: modelsQuery.data,
});
hasSetConversation.current = true;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialConvoQuery.data, modelsQuery.data]);
}, [initialConvoQuery.data, modelsQuery.data, endpointsQuery.data]);

if (!isAuthenticated) {
return null;
Expand Down
64 changes: 0 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions packages/data-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "librechat-data-provider",
"version": "0.3.2",
"version": "0.3.3",
"description": "data services for librechat apps",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down Expand Up @@ -44,13 +44,10 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.1.0",
Expand Down
14 changes: 0 additions & 14 deletions packages/data-provider/server-rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import babel from '@rollup/plugin-babel';

const rootPath = path.resolve(__dirname, '../../');
const rootServerPath = path.resolve(__dirname, '../../api');
Expand All @@ -30,19 +29,6 @@ export default {
}),
commonjs(),
json(),
babel({
exclude: 'node_modules/**',
babelHelpers: 'bundled',
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
],
}),
],
external: (id) => {
// More selective external function
Expand Down

0 comments on commit c9d3e0a

Please sign in to comment.