Skip to content

Commit

Permalink
Fix out of bound index in chat paging (#3480)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
someone13574 authored Jun 16, 2023
1 parent 7885202 commit e1ed96a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion website/src/components/Chat/ChatConversationTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const TreeChildren = ({
} & StrictOmit<ChatMessageEntryProps, "message" | "canRetry">) => {
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;
Expand Down

0 comments on commit e1ed96a

Please sign in to comment.