diff --git a/web/app/components/datasets/documents/__tests__/index.spec.tsx b/web/app/components/datasets/documents/__tests__/index.spec.tsx index 092ceaa001..f464c97395 100644 --- a/web/app/components/datasets/documents/__tests__/index.spec.tsx +++ b/web/app/components/datasets/documents/__tests__/index.spec.tsx @@ -313,6 +313,33 @@ describe('Documents', () => { expect(screen.queryByTestId('documents-list')).not.toBeInTheDocument() }) + it('should keep rendering list when loading with existing data', () => { + vi.mocked(useDocumentList).mockReturnValueOnce({ + data: { + data: [ + { + id: 'doc-1', + name: 'Document 1', + indexing_status: 'completed', + data_source_type: 'upload_file', + position: 1, + enabled: true, + }, + ], + total: 1, + page: 1, + limit: 10, + has_more: false, + } as DocumentListResponse, + isLoading: true, + refetch: vi.fn(), + } as unknown as ReturnType) + + render() + expect(screen.getByTestId('documents-list')).toBeInTheDocument() + expect(screen.getByTestId('list-documents-count')).toHaveTextContent('1') + }) + it('should render empty element when no documents exist', () => { vi.mocked(useDocumentList).mockReturnValueOnce({ data: { data: [], total: 0, page: 1, limit: 10, has_more: false }, diff --git a/web/app/components/datasets/documents/index.tsx b/web/app/components/datasets/documents/index.tsx index bb7318c710..764b04227c 100644 --- a/web/app/components/datasets/documents/index.tsx +++ b/web/app/components/datasets/documents/index.tsx @@ -118,7 +118,7 @@ const Documents: FC = ({ datasetId }) => { // Render content based on loading and data state const renderContent = () => { - if (isListLoading) + if (isListLoading && !documentsRes) return if (total > 0) { diff --git a/web/service/knowledge/use-document.ts b/web/service/knowledge/use-document.ts index e387e3a718..4eb2b7d282 100644 --- a/web/service/knowledge/use-document.ts +++ b/web/service/knowledge/use-document.ts @@ -3,6 +3,7 @@ import type { DocumentDownloadResponse, DocumentDownloadZipRequest, MetadataType import type { CommonResponse } from '@/models/common' import type { DocumentDetailResponse, DocumentListResponse, UpdateDocumentBatchParams } from '@/models/datasets' import { + keepPreviousData, useMutation, useQuery, } from '@tanstack/react-query' @@ -45,6 +46,7 @@ export const useDocumentList = (payload: { queryFn: () => get(`/datasets/${datasetId}/documents`, { params, }), + placeholderData: keepPreviousData, refetchInterval, }) }