diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 6163fcd4..12ebba66 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -25,9 +25,9 @@ export default function Conversation() { const dispatch = useDispatch(); const endMessageRef = useRef(null); const inputRef = useRef(null); - const [isDarkTheme]= useDarkTheme(); + const [isDarkTheme] = useDarkTheme(); const [hasScrolledToLast, setHasScrolledToLast] = useState(true); - const fetchStream = useRef(new AbortController()) + const fetchStream = useRef(null) useEffect(() => { scrollIntoView(); }, [queries.length, queries[queries.length - 1]]); @@ -38,13 +38,13 @@ export default function Conversation() { element.focus(); } }, []); - useEffect(()=>{ - console.log('changed the conversation', conversationId) - return ()=>{ - console.log('i just did abortion !'); - fetchStream.current.abort(); + + useEffect(() => { + return () => { + fetchStream.current.abort(); //abort previous stream } - },[conversationId]) + }, [conversationId]) + useEffect(() => { const observerCallback: IntersectionObserverCallback = (entries) => { entries.forEach((entry) => { @@ -72,14 +72,10 @@ export default function Conversation() { }); }; - fetchStream.current != null && useEffect(()=>{ - return ()=>{fetchStream.current.abort()} - },[selectConversationId]) const handleQuestion = (question: string) => { question = question.trim(); if (question === '') return; dispatch(addQuery({ prompt: question })); - //@ts-ignore fetchStream.current = dispatch(fetchAnswer({ question })); }; diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index c6dd1b37..dd21c152 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -18,8 +18,6 @@ export const fetchAnswer = createAsyncThunk( 'fetchAnswer', async ({ question }, { dispatch, getState, signal }) => { const state = getState() as RootState; - console.log('signal', signal); - if (state.preference) { if (API_STREAMING) { await fetchAnswerSteaming( @@ -198,7 +196,11 @@ export const conversationSlice = createSlice({ state.status = 'loading'; }) .addCase(fetchAnswer.rejected, (state, action) => { - if(action.meta.aborted)return state; //ignore error + if(action.meta.aborted) + { + state.status = 'idle'; + return state; + } state.status = 'failed'; state.queries[state.queries.length - 1].error = 'Something went wrong. Please try again later.';