From 55b4f1873dab25af455ec3058abeab2cd769070d Mon Sep 17 00:00:00 2001 From: Owen Law Date: Thu, 15 Jun 2023 17:39:28 -0400 Subject: [PATCH] Fix out of bound index in chat paging --- website/src/components/Chat/ChatConversationTree.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/components/Chat/ChatConversationTree.tsx b/website/src/components/Chat/ChatConversationTree.tsx index afaffe250..c83ec1f13 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;