From 8ea631a2a03c367e07e12a2f945d6be767e3dcca Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 16 Dec 2024 18:51:45 +0800 Subject: [PATCH] Fix: Every time you switch the page number of a chunk, the PDF document will be reloaded. #4046 (#4047) ### What problem does this PR solve? Fix: Every time you switch the page number of a chunk, the PDF document will be reloaded. #4046 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/hooks/chunk-hooks.ts | 5 ++--- .../components/document-preview/preview.tsx | 9 --------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/web/src/hooks/chunk-hooks.ts b/web/src/hooks/chunk-hooks.ts index 374f1c98335..052f2d17c62 100644 --- a/web/src/hooks/chunk-hooks.ts +++ b/web/src/hooks/chunk-hooks.ts @@ -45,9 +45,8 @@ export const useFetchNextChunkList = (): ResponseGetType<{ debouncedSearchString, available, ], - - initialData: { data: [], total: 0, documentInfo: {} }, - // placeholderData: keepPreviousData, + placeholderData: (previousData) => + previousData ?? { data: [], total: 0, documentInfo: {} }, // https://github.com/TanStack/query/issues/8183 gcTime: 0, queryFn: async () => { const { data } = await kbService.chunk_list({ diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/components/document-preview/preview.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/components/document-preview/preview.tsx index 54b204602d9..6bce02396d5 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/components/document-preview/preview.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/components/document-preview/preview.tsx @@ -32,7 +32,6 @@ const HighlightPopup = ({ // TODO: merge with DocumentPreviewer const Preview = ({ highlights: state, setWidthAndHeight }: IProps) => { const url = useGetDocumentUrl(); - useCatchDocumentError(url); const ref = useRef<(highlight: IHighlight) => void>(() => {}); const error = useCatchDocumentError(url); @@ -119,12 +118,4 @@ const Preview = ({ highlights: state, setWidthAndHeight }: IProps) => { ); }; -const compare = (oldProps: IProps, newProps: IProps) => { - const arePropsEqual = - oldProps.highlights === newProps.highlights || - (oldProps.highlights.length === 0 && newProps.highlights.length === 0); - - return arePropsEqual; -}; - export default memo(Preview);