diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx index e1739be61..1d1ccafe0 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx @@ -1,3 +1,4 @@ +import { useUtilityStore } from "@/stores/utilityStore"; import Convert from "ansi-to-html"; import { useEffect, useMemo, useRef, useState } from "react"; import Markdown from "react-markdown"; @@ -41,6 +42,13 @@ export default function ChatMessage({ const setErrorData = useAlertStore((state) => state.setErrorData); const chatMessageRef = useRef(chatMessage); + const playgroundScrollBehaves = useUtilityStore( + (state) => state.playgroundScrollBehaves, + ); + const setPlaygroundScrollBehaves = useUtilityStore( + (state) => state.setPlaygroundScrollBehaves, + ); + // Sync ref with state useEffect(() => { chatMessageRef.current = chatMessage; @@ -107,9 +115,14 @@ export default function ChatMessage({ useEffect(() => { const element = document.getElementById("last-chat-message"); if (element) { - setTimeout(() => { - element.scrollIntoView({ behavior: "smooth" }); - }, 200); + if (playgroundScrollBehaves === "instant") { + element.scrollIntoView({ behavior: playgroundScrollBehaves }); + setPlaygroundScrollBehaves("smooth"); + } else { + setTimeout(() => { + element.scrollIntoView({ behavior: playgroundScrollBehaves }); + }, 200); + } } }, [lastMessage]); diff --git a/src/frontend/src/modals/IOModal/index.tsx b/src/frontend/src/modals/IOModal/index.tsx index fca343fbf..3c42231ca 100644 --- a/src/frontend/src/modals/IOModal/index.tsx +++ b/src/frontend/src/modals/IOModal/index.tsx @@ -2,6 +2,7 @@ import { useDeleteMessages, useGetMessagesQuery, } from "@/controllers/API/queries/messages"; +import { useUtilityStore } from "@/stores/utilityStore"; import { useEffect, useState } from "react"; import AccordionComponent from "../../components/accordionComponent"; import IconComponent from "../../components/genericIconComponent"; @@ -172,6 +173,16 @@ export default function IOModal({ sessions; }, [messages]); + const setPlaygroundScrollBehaves = useUtilityStore( + (state) => state.setPlaygroundScrollBehaves, + ); + + useEffect(() => { + if (open) { + setPlaygroundScrollBehaves("instant"); + } + }, [open]); + return ( ((set, get) => ({ healthCheckTimeout: null, setHealthCheckTimeout: (timeout: string | null) => set({ healthCheckTimeout: timeout }), + playgroundScrollBehaves: "instant", + setPlaygroundScrollBehaves: (behaves: ScrollBehavior) => + set({ playgroundScrollBehaves: behaves }), })); diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index d3fe911f2..48af8f093 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -775,7 +775,7 @@ export type tabsArrayType = { }; export type codeTabsPropsType = { - open: boolean; + open?: boolean; tabs: Array; activeTab: string; setActiveTab: (value: string) => void; diff --git a/src/frontend/src/types/zustand/utility/index.ts b/src/frontend/src/types/zustand/utility/index.ts index f16a08021..a14f8bdf8 100644 --- a/src/frontend/src/types/zustand/utility/index.ts +++ b/src/frontend/src/types/zustand/utility/index.ts @@ -3,4 +3,6 @@ export type UtilityStoreType = { setSelectedItems: (itemId: any) => void; healthCheckTimeout: string | null; setHealthCheckTimeout: (timeout: string | null) => void; + playgroundScrollBehaves: ScrollBehavior; + setPlaygroundScrollBehaves: (behaves: ScrollBehavior) => void; };