From b1c9671a60f43ca2d8a1570a80bd443caaa6d5e9 Mon Sep 17 00:00:00 2001 From: doufa Date: Fri, 31 May 2024 08:07:48 +0000 Subject: [PATCH] fix: status query not stop when leaving document embedding detail page (#4754) --- .../documents/detail/embedding/index.tsx | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/web/app/components/datasets/documents/detail/embedding/index.tsx b/web/app/components/datasets/documents/detail/embedding/index.tsx index bb844e35a4..48e97f0d59 100644 --- a/web/app/components/datasets/documents/detail/embedding/index.tsx +++ b/web/app/components/datasets/documents/detail/embedding/index.tsx @@ -126,17 +126,13 @@ const EmbeddingDetail: FC = ({ detail, stopPosition = 'top', datasetId: d return status } - const [isStopQuery, setIsStopQuery] = useState(false) - const isStopQueryRef = useRef(isStopQuery) - useEffect(() => { - isStopQueryRef.current = isStopQuery - }, [isStopQuery]) - const stopQueryStatus = () => { - setIsStopQuery(true) - } + const isStopQuery = useRef(false) + const stopQueryStatus = useCallback(() => { + isStopQuery.current = true + }, []) - const startQueryStatus = async () => { - if (isStopQueryRef.current) + const startQueryStatus = useCallback(async () => { + if (isStopQuery.current) return try { @@ -146,6 +142,7 @@ const EmbeddingDetail: FC = ({ detail, stopPosition = 'top', datasetId: d detailUpdate() return } + await sleep(2500) await startQueryStatus() } @@ -153,16 +150,15 @@ const EmbeddingDetail: FC = ({ detail, stopPosition = 'top', datasetId: d await sleep(2500) await startQueryStatus() } - } + }, [stopQueryStatus]) useEffect(() => { - setIsStopQuery(false) + isStopQuery.current = false startQueryStatus() return () => { stopQueryStatus() } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) + }, [startQueryStatus, stopQueryStatus]) const { data: indexingEstimateDetail, error: indexingEstimateErr } = useSWR({ action: 'fetchIndexingEstimate',