Skip to content

Commit b8f6fb3

Browse files
authored
fix(Chat): correctly render when refreshing/visiting a conversation page (danny-avila#1037)
1 parent a9974ba commit b8f6fb3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

client/src/components/Nav/NewChat.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React from 'react';
1+
import { useNavigate } from 'react-router-dom';
22
import { useLocalize, useConversation } from '~/hooks';
33

44
export default function NewChat() {
55
const { newConversation } = useConversation();
6+
const navigate = useNavigate();
67
const localize = useLocalize();
78

89
const clickHandler = () => {
9-
// dispatch(setInputValue(''));
10-
// dispatch(setQuery(''));
1110
newConversation();
11+
navigate('/chat/new');
1212
};
1313

1414
return (

client/src/routes/Chat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function Chat() {
2727
const navigate = useNavigate();
2828

2929
//disabled by default, we only enable it when messagesTree is null
30-
const messagesQuery = useGetMessagesByConvoId(conversationId ?? '', { enabled: false });
30+
const messagesQuery = useGetMessagesByConvoId(conversationId ?? '', { enabled: !messagesTree });
3131
const getConversationMutation = useGetConversationByIdMutation(conversationId ?? '');
3232
const { data: config } = useGetStartupConfig();
3333

@@ -89,7 +89,8 @@ export default function Chat() {
8989
setShouldNavigate(false);
9090
}
9191
// conversationId (in url) should always follow conversation?.conversationId, unless conversation is null
92-
else if (conversation?.conversationId !== conversationId) {
92+
// messagesTree is null when user navigates, but not on page refresh, so we need to navigate in this case
93+
else if (conversation?.conversationId !== conversationId && !messagesTree) {
9394
if (shouldNavigate) {
9495
navigate(`/chat/${conversation?.conversationId}`);
9596
} else {

0 commit comments

Comments
 (0)