Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Fix unnecessary calls (Chat-input-panel) #565

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default function ChatInputPanel(props: ChatInputPanelProps) {
setReadyState(ReadyState.CLOSED);
}
})();
}, [appContext, state.modelsStatus, props]);
}, [appContext, props.session.id]); // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props was causing a new refresh on render. Instead it should refresh on a new session.


useEffect(() => {
const onWindowScroll = () => {
Expand Down
27 changes: 13 additions & 14 deletions lib/user-interface/react-app/src/components/chatbot/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import { CHATBOT_NAME } from "../../common/constants";
export default function Chat(props: { sessionId?: string }) {
const appContext = useContext(AppContext);
const [running, setRunning] = useState<boolean>(false);
const [session, setSession] = useState<{ id: string; loading: boolean }>({
id: props.sessionId ?? uuidv4(),
loading: typeof props.sessionId !== "undefined",
});
const [session, setSession] = useState<{ id: string; loading: boolean } | undefined>();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Session id was created twice.

const [initError, setInitError] = useState<string | undefined>(undefined);
const [configuration, setConfiguration] = useState<ChatBotConfiguration>(
() => ({
Expand Down Expand Up @@ -152,16 +149,18 @@ export default function Chat(props: { sessionId?: string }) {
)}
</div>
<div className={styles.input_container}>
<ChatInputPanel
session={session}
running={running}
setRunning={setRunning}
messageHistory={messageHistory}
setMessageHistory={(history) => setMessageHistory(history)}
setInitErrorMessage={(error) => setInitError(error)}
configuration={configuration}
setConfiguration={setConfiguration}
/>
{session &&
<ChatInputPanel
session={session}
running={running}
setRunning={setRunning}
messageHistory={messageHistory}
setMessageHistory={(history) => setMessageHistory(history)}
setInitErrorMessage={(error) => setInitError(error)}
configuration={configuration}
setConfiguration={setConfiguration}
/>
}
</div>
</div>
);
Expand Down
Loading