Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): prevent search popover from flashing at top-left on checkbox toggle (#17148)

euvre859006c79afe
diff --git a/web/src/pages/next-search/retrieval-documents/index.tsx b/web/src/pages/next-search/retrieval-documents/index.tsx
index ba0e8604ed..abac65c97d 100644
--- a/web/src/pages/next-search/retrieval-documents/index.tsx
+++ b/web/src/pages/next-search/retrieval-documents/index.tsx
@@ -22,7 +22,7 @@ import {
} from '@/hooks/use-knowledge-request';
import { cn } from '@/lib/utils';
import { CheckIcon, ChevronDown, Files, XIcon } from 'lucide-react';
-import { useEffect, useMemo, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
interface IProps {
@@ -52,10 +52,15 @@ const RetrievalDocuments = ({
}
}, [isTesting, setLoading]);
- const { documents: useDocuments } = {
- documents:
- documentsAll?.length > documents?.length ? documentsAll : documents,
- };
+ const latestDocuments =
+ documentsAll?.length > documents?.length ? documentsAll : documents;
+ // Keep the last non-empty list so the popover anchor is not unmounted
+ // while a new testing request is pending.
+ const documentsRef = useRef(latestDocuments);
+ if (latestDocuments?.length) {
+ documentsRef.current = latestDocuments;
+ }
+ const useDocuments = documentsRef.current;
const [selectedValues, setSelectedValues] =
useState<string[]>(selectedDocumentIds);
@@ -115,7 +120,7 @@ const RetrievalDocuments = ({
return (
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
<PopoverTrigger asChild>
- {useDocuments?.length && (
+ {useDocuments?.length > 0 && (
<Button
onClick={handleTogglePopover}
className={cn(