Skip to content

Commit e1ed96a

Browse files
authored
Fix out of bound index in chat paging (#3480)
closes #3478 `useIsomorphicLayoutEffect` wasn't being called until the first render meaning if the index could be out of bounds if the parent message was changed to a tree with less siblings than the previous. A simple min against the number of siblings prevents the out of bound index and then `useIsomorphicLayoutEffect ` is called the next frame, setting the correct thread.
1 parent 7885202 commit e1ed96a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

website/src/components/Chat/ChatConversationTree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const TreeChildren = ({
5656
} & StrictOmit<ChatMessageEntryProps, "message" | "canRetry">) => {
5757
const sortedTrees = useMemo(() => trees.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at)), [trees]);
5858
const [index, setIndex] = useState(0);
59-
const currentTree = sortedTrees[index];
59+
const currentTree = sortedTrees[Math.min(index, trees.length - 1)];
6060

6161
const length = trees.length;
6262
const hasSibling = length > 1;

0 commit comments

Comments
 (0)