diff --git a/components/sidebar-history.tsx b/components/sidebar-history.tsx index fa6a1518af..cc5ef607b7 100644 --- a/components/sidebar-history.tsx +++ b/components/sidebar-history.tsx @@ -88,13 +88,13 @@ export function getChatHistoryPaginationKey( return `/api/history?limit=${PAGE_SIZE}`; } - const firstChatFromPage = previousPageData.chats.at(-1); + const lastChatFromPage = previousPageData.chats.at(-1); - if (!firstChatFromPage) { + if (!lastChatFromPage) { return null; } - return `/api/history?ending_before=${firstChatFromPage.id}&limit=${PAGE_SIZE}`; + return `/api/history?ending_before=${lastChatFromPage.id}&limit=${PAGE_SIZE}`; } export function SidebarHistory({ user }: { user: User | undefined }) {