Skip to content

Commit

Permalink
fix: old streaming answer gets appended to new conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
siiddhantt committed Nov 16, 2024
1 parent bd636d5 commit 47d687b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions frontend/src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SourceDropdown from './components/SourceDropdown';
import {
setConversation,
updateConversationId,
handleAbort,
} from './conversation/conversationSlice';
import ConversationTile from './conversation/ConversationTile';
import { useDarkTheme, useMediaQuery, useOutsideAlerter } from './hooks';
Expand Down Expand Up @@ -180,6 +181,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
};

const resetConversation = () => {
handleAbort();
dispatch(setConversation([]));
dispatch(
updateConversationId({
Expand Down
16 changes: 15 additions & 1 deletion frontend/src/conversation/conversationSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@ const initialState: ConversationState = {

const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';

let abortController: AbortController | null = null;
export function handleAbort() {
if (abortController) {
abortController.abort();
abortController = null;
}
}

export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
'fetchAnswer',
async ({ question }, { dispatch, getState, signal }) => {
async ({ question }, { dispatch, getState }) => {
if (abortController) {
abortController.abort();
}
abortController = new AbortController();
const { signal } = abortController;

let isSourceUpdated = false;
const state = getState() as RootState;
if (state.preference) {
Expand Down

0 comments on commit 47d687b

Please sign in to comment.