diff --git a/website/src/components/Chat/ChatConversationTree.tsx b/website/src/components/Chat/ChatConversationTree.tsx index afaffe2509..c83ec1f133 100644 --- a/website/src/components/Chat/ChatConversationTree.tsx +++ b/website/src/components/Chat/ChatConversationTree.tsx @@ -56,7 +56,7 @@ const TreeChildren = ({ } & StrictOmit) => { const sortedTrees = useMemo(() => trees.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at)), [trees]); const [index, setIndex] = useState(0); - const currentTree = sortedTrees[index]; + const currentTree = sortedTrees[Math.min(index, trees.length - 1)]; const length = trees.length; const hasSibling = length > 1;