fix: correct chat preview loading in search modal

This commit fixes a bug in the search modal where the chat preview would fail to load for the bottom search results, especially when using tags to filter.

The issue was caused by an incorrect index calculation in the `loadChatPreview` function, which resulted in an out-of-bounds error when accessing the `chatList` array.

This commit resolves the issue by adding a guard clause to the `loadChatPreview` function to ensure that the `selectedChatIdx` is always a valid index. This prevents the out-of-bounds error and ensures that the chat preview is always displayed for the selected chat.
This commit is contained in:
silentoplayz 2025-11-03 19:58:26 -05:00
parent 08bc00ea77
commit 71b86c08ee

View file

@ -56,12 +56,7 @@
}
const loadChatPreview = async (selectedIdx) => {
if (
!chatList ||
chatList.length === 0 ||
selectedIdx === null ||
chatList[selectedIdx] === undefined
) {
if (!chatList || chatList.length === 0 || selectedIdx === null) {
selectedChat = null;
messages = null;
history = null;
@ -70,8 +65,11 @@
}
const selectedChatIdx = selectedIdx - actions.length;
if (selectedChatIdx < 0) {
if (selectedChatIdx < 0 || selectedChatIdx >= chatList.length) {
selectedChat = null;
messages = null;
history = null;
selectedModels = [''];
return;
}