Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🫖 fix: Keep Sidebar Search Results Visible During Refetch (#16411)

lia-by-librechat[bot]f7f7567172d1
diff --git a/client/src/components/Conversations/Conversations.tsx b/client/src/components/Conversations/Conversations.tsx
index dae11862ef..259a55b678 100644
--- a/client/src/components/Conversations/Conversations.tsx
+++ b/client/src/components/Conversations/Conversations.tsx
@@ -284,18 +284,19 @@ const Conversations: FC<ConversationsProps> = ({
[rawConversations],
);
- /** The pinned section above carries pins, so they stay out of these groups — except in
- * the archive, which that section does not cover: an archived pin would otherwise be
- * absent from the sidebar entirely rather than merely further down it. */
+ /** The pinned section carries pins except in the archive or during search, when it is
+ * hidden. Keep matching pins in the Chats results instead of showing an empty list. */
+ const includePinned = isArchivedView || !!search.query;
const datedConversations = useMemo(
() =>
groupConversations(filteredConversations, {
field: sort.field,
direction: sort.direction,
- includePinned: isArchivedView,
+ includePinned,
}),
- [filteredConversations, isArchivedView, sort.direction, sort.field],
+ [filteredConversations, includePinned, sort.direction, sort.field],
);
+ /** The archive keeps its server order, while search still promotes active matches. */
const groupedConversations = useMemo(
() =>
groupConversationsWithRunning(datedConversations, activeJobIds, {
@@ -306,8 +307,8 @@ const Conversations: FC<ConversationsProps> = ({
[datedConversations, activeJobIds, isArchivedView, sort.direction, sort.field],
);
- /* Pins are stripped from the date groups. An all-pin page leaves the
- virtual list with no rows, so onRowsRendered never fires and later
+ /* Outside search, pins are stripped from the date groups. An all-pin page leaves
+ the virtual list with no rows, so onRowsRendered never fires and later
unpinned chats stay unreachable. Ask for another page only when the
conversations input actually changes; a failed fetchNextPage leaves
the same array and must not loop. */
diff --git a/client/src/components/Conversations/__tests__/Conversations.test.tsx b/client/src/components/Conversations/__tests__/Conversations.test.tsx
index 5916901cea..53bdb3a412 100644
--- a/client/src/components/Conversations/__tests__/Conversations.test.tsx
+++ b/client/src/components/Conversations/__tests__/Conversations.test.tsx
@@ -215,8 +215,42 @@ describe('Conversations: pinned chats live in PinnedSection', () => {
);
it('does not render a pinned header inside the chats list', () => {
- const { queryByText } = renderConversations([pinnedConvo]);
+ const { queryByText, queryByTestId } = renderConversations([pinnedConvo]);
expect(queryByText('com_ui_pinned')).not.toBeInTheDocument();
+ expect(queryByTestId('convo')).not.toBeInTheDocument();
+ });
+
+ it('shows pinned search matches in Chats while the Pinned section is hidden', () => {
+ renderConversations([pinnedConvo, pinnedConvo], 'Pinned Chat');
+
+ expect(screen.getAllByTestId('convo')).toHaveLength(1);
+ expect(screen.getByTestId('convo')).toHaveTextContent('Pinned Chat');
+ expect(screen.queryByText('com_ui_no_search_results')).not.toBeInTheDocument();
+ });
+
+ it('keeps running matches promoted when search includes pinned chats', () => {
+ mockActiveJobIds = ['running'];
+ const running = {
+ ...pinnedConvo,
+ conversationId: 'running',
+ title: 'Running match',
+ pinned: false,
+ updatedAt: '2026-01-01T00:00:00.000Z',
+ } as TConversation;
+
+ try {
+ renderConversations([pinnedConvo, running], 'match');
+
+ expect(screen.getAllByTestId('convo').map((row) => row.textContent)).toEqual([
+ 'Running match',
+ 'Pinned Chat',
+ ]);
+ expect(
+ screen.getByRole('heading', { name: 'com_a11y_chats_running_section' }),
+ ).toBeInTheDocument();
+ } finally {
+ mockActiveJobIds = [];
+ }
});
it('does not render a duplicate new chat button in the chats header', () => {
diff --git a/client/src/components/UnifiedSidebar/ConversationsSection.tsx b/client/src/components/UnifiedSidebar/ConversationsSection.tsx
index b00f610516..5ac828a8aa 100644
--- a/client/src/components/UnifiedSidebar/ConversationsSection.tsx
+++ b/client/src/components/UnifiedSidebar/ConversationsSection.tsx
@@ -142,19 +142,9 @@ const ConversationsSection = memo(() => {
void refetch();
}, [refetch]);
- const [isSearchLoading, setIsSearchLoading] = useState(
- !!search.query && (search.isTyping || isLoading || isFetching),
- );
-
- useEffect(() => {
- if (search.isTyping) {
- setIsSearchLoading(true);
- } else if (!isLoading && !isFetching) {
- setIsSearchLoading(false);
- } else if (!!search.query && (isLoading || isFetching)) {
- setIsSearchLoading(true);
- }
- }, [search.query, search.isTyping, isLoading, isFetching]);
+ const isSearchLoading =
+ search.isTyping ||
+ (!!search.query && (isLoading || (isFetching && conversations.length === 0)));
/** Projects, Pinned and Chats share one scroll container so the sidebar scrolls
* as a single surface: the chats list is virtualized against this viewport
diff --git a/client/src/components/UnifiedSidebar/__tests__/ConversationsSection.spec.tsx b/client/src/components/UnifiedSidebar/__tests__/ConversationsSection.spec.tsx
index a6738fec80..0a298fbd80 100644
--- a/client/src/components/UnifiedSidebar/__tests__/ConversationsSection.spec.tsx
+++ b/client/src/components/UnifiedSidebar/__tests__/ConversationsSection.spec.tsx
@@ -1,8 +1,8 @@
import React from 'react';
import { DndProvider } from 'react-dnd';
import { BrowserRouter } from 'react-router-dom';
-import { render, act } from '@testing-library/react';
import { HTML5Backend } from 'react-dnd-html5-backend';
+import { render, act, screen, fireEvent } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { atom, RecoilRoot, useRecoilValue, useSetRecoilState } from 'recoil';
import type { SetterOrUpdater } from 'recoil';
@@ -37,12 +37,15 @@ const mockUseTitleGeneration = jest.fn(() => {
* keeps referential stability mid-stream, which is what the memoized-children
* guarantee below depends on. */
const mockConversationsResult = {
- data: { pages: [{ conversations: [] as unknown[], nextCursor: null }] },
+ data: { pages: [{ conversations: [] as unknown[], nextCursor: null }] } as
+ | { pages: Array<{ conversations: unknown[]; nextCursor: string | null }> }
+ | undefined,
fetchNextPage: jest.fn(),
refetch: jest.fn(),
isFetchingNextPage: false,
isLoading: false,
isFetching: false,
+ isPreviousData: false,
isError: false,
};
@@ -100,9 +103,33 @@ jest.mock('~/hooks/Input/useSelectMention', () => ({
jest.mock('~/components/Conversations', () => {
const { memo } = jest.requireActual('react');
- const ConversationsStub = memo(function ConversationsStub() {
+ const ConversationsStub = memo(function ConversationsStub({
+ conversations,
+ isSearchLoading,
+ isError,
+ onRetry,
+ }: {
+ conversations: Array<{ conversationId: string; title: string }>;
+ isSearchLoading: boolean;
+ isError: boolean;
+ onRetry: () => void;
+ }) {
mockConversationsRender();
- return <div data-testid="conversations-stub" />;
+ const localize: (key: string) => string = jest.requireMock('~/hooks').useLocalize();
+ let body: React.ReactNode = conversations.map((convo) => (
+ <span key={convo.conversationId}>{convo.title}</span>
+ ));
+ if (isError && conversations.length === 0) {
+ body = (
+ <button type="button" onClick={onRetry}>
+ {localize('com_ui_retry')}
+ </button>
+ );
+ }
+ if (isSearchLoading) {
+ body = <div data-testid="search-spinner" />;
+ }
+ return <div data-testid="conversations-stub">{body}</div>;
});
return { __esModule: true, Conversations: ConversationsStub };
});
@@ -139,9 +166,11 @@ import ConversationsSection from '../ConversationsSection';
import store from '~/store';
let setStreamTick: SetterOrUpdater<number>;
+let setSearchState: SetterOrUpdater<SearchState>;
function TickController() {
setStreamTick = useSetRecoilState(streamTickAtom);
+ setSearchState = useSetRecoilState(store.search);
return null;
}
@@ -169,10 +198,22 @@ const settleRenders = async () => {
}
};
-const renderSection = () =>
+const renderSection = (searchQuery = '') =>
render(
<QueryClientProvider client={createQueryClient()}>
- <RecoilRoot>
+ <RecoilRoot
+ initializeState={({ set }) => {
+ if (searchQuery) {
+ set(store.search, {
+ query: searchQuery,
+ debouncedQuery: searchQuery,
+ enabled: true,
+ isTyping: false,
+ isSearching: false,
+ });
+ }
+ }}
+ >
<BrowserRouter>
<DndProvider backend={HTML5Backend}>
<TickController />
@@ -243,6 +284,153 @@ describe('ConversationsSection streaming re-renders', () => {
);
});
+describe('ConversationsSection search refetch', () => {
+ it('does not display old matches as unfiltered chats while clearing the search', async () => {
+ const previousData = mockConversationsResult.data;
+ mockConversationsResult.data = {
+ pages: [
+ {
+ conversations: [{ conversationId: 'chat-1', title: 'Old search match' }],
+ nextCursor: null,
+ },
+ ],
+ };
+
+ try {
+ renderSection('draft');
+ await settleRenders();
+ expect(screen.getByText('Old search match')).toBeInTheDocument();
+
+ act(() => {
+ setSearchState({
+ query: '',
+ debouncedQuery: 'draft',
+ enabled: true,
+ isTyping: true,
+ isSearching: false,
+ });
+ });
+
+ expect(screen.getByTestId('projects-stub')).toBeInTheDocument();
+ expect(screen.queryByText('Old search match')).not.toBeInTheDocument();
+ expect(screen.getByTestId('search-spinner')).toBeInTheDocument();
+ } finally {
+ mockConversationsResult.data = previousData;
+ }
+ });
+
+ it('shows progress while retrying a failed cached search with no results', async () => {
+ const previousData = mockConversationsResult.data;
+ mockConversationsResult.isError = true;
+
+ try {
+ renderSection('draft');
+ await settleRenders();
+ expect(screen.getByRole('button', { name: 'com_ui_retry' })).toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: 'com_ui_retry' }));
+ expect(mockConversationsResult.refetch).toHaveBeenCalledTimes(1);
+
+ act(() => {
+ mockConversationsResult.isFetching = true;
+ setStreamTick((prev) => prev + 1);
+ });
+
+ expect(screen.getByTestId('search-spinner')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'com_ui_retry' })).not.toBeInTheDocument();
+
+ act(() => {
+ mockConversationsResult.isFetching = false;
+ mockConversationsResult.isError = false;
+ mockConversationsResult.data = {
+ pages: [
+ {
+ conversations: [{ conversationId: 'chat-1', title: 'Found match' }],
+ nextCursor: null,
+ },
+ ],
+ };
+ setStreamTick((prev) => prev + 1);
+ });
+
+ expect(screen.getByText('Found match')).toBeInTheDocument();
+ expect(screen.queryByTestId('search-spinner')).not.toBeInTheDocument();
+ } finally {
+ mockConversationsResult.data = previousData;
+ mockConversationsResult.isError = false;
+ mockConversationsResult.isFetching = false;
+ mockConversationsResult.refetch.mockClear();
+ }
+ });
+
+ it('shows loading for an uncached search', async () => {
+ const previousData = mockConversationsResult.data;
+ mockConversationsResult.data = undefined;
+ mockConversationsResult.isLoading = true;
+
+ try {
+ renderSection('draft');
+ await settleRenders();
+ expect(screen.getByTestId('search-spinner')).toBeInTheDocument();
+ } finally {
+ mockConversationsResult.data = previousData;
+ mockConversationsResult.isLoading = false;
+ }
+ });
+
+ it('does not show results from the previous search while the next one loads', async () => {
+ const previousData = mockConversationsResult.data;
+ mockConversationsResult.data = {
+ pages: [
+ {
+ conversations: [{ conversationId: 'chat-1', title: 'Previous match' }],
+ nextCursor: null,
+ },
+ ],
+ };
+ mockConversationsResult.isPreviousData = true;
+
+ try {
+ renderSection('new term');
+ await settleRenders();
+ expect(screen.getByTestId('search-spinner')).toBeInTheDocument();
+ expect(screen.queryByText('Previous match')).not.toBeInTheDocument();
+ } finally {
+ mockConversationsResult.data = previousData;
+ mockConversationsResult.isPreviousData = false;
+ }
+ });
+
+ it('keeps cached results visible when a message triggers a background list refetch', async () => {
+ const previousData = mockConversationsResult.data;
+ mockConversationsResult.data = {
+ pages: [
+ {
+ conversations: [{ conversationId: 'chat-1', title: 'Matching chat' }],
+ nextCursor: null,
+ },
+ ],
+ };
+
+ try {
+ renderSection('draft');
+ await settleRenders();
+ expect(screen.getByText('Matching chat')).toBeInTheDocument();
+
+ act(() => {
+ mockConversationsResult.isFetching = true;
+ setStreamTick((prev) => prev + 1);
+ });
+
+ expect(screen.getByText('Matching chat')).toBeInTheDocument();
+ expect(screen.queryByTestId('search-spinner')).not.toBeInTheDocument();
+ } finally {
+ mockConversationsResult.isFetching = false;
+ mockConversationsResult.data = previousData;
+ }
+ });
+});
+
describe('ConversationsSection shared scroll surface', () => {
/** Searching swaps what the one surface holds — Projects and Pinned leave,
* the chats become results — and a position kept from the previous contents