yohei0125 4 лет назад
Родитель
Сommit
839bfcec5b
1 измененных файлов с 6 добавлено и 9 удалено
  1. 6 9
      packages/app/src/components/SearchPage/SearchResultContent.tsx

+ 6 - 9
packages/app/src/components/SearchPage/SearchResultContent.tsx

@@ -25,18 +25,15 @@ const SearchResultContent: FC<Props> = (props: Props) => {
   const contentRef = useRef(null);
   const contentRef = useRef(null);
 
 
   useEffect(() => {
   useEffect(() => {
-    // reset state
-    if (isRevisionBodyRendered) {
-      const searchResultPageContent = contentRef.current as HTMLElement | null;
-      if (searchResultPageContent !== null) {
-        const highlightedWord = searchResultPageContent?.querySelector('.highlighted-keyword') as HTMLElement | null;
-        if (highlightedWord != null) {
-          smoothScrollIntoView(highlightedWord, SCROLL_OFFSET_TOP, searchResultPageContent);
-        }
+    // if isRevisionBodyRendered is false then do nothing
+    if (isRevisionBodyRendered && contentRef.current != null) {
+      const searchResultPageContent = contentRef.current as HTMLElement;
+      const highlightedWord = searchResultPageContent.querySelector('.highlighted-keyword') as HTMLElement | null;
+      if (highlightedWord != null) {
+        smoothScrollIntoView(highlightedWord, SCROLL_OFFSET_TOP, searchResultPageContent);
       }
       }
       setIsRevisionBodyRendered(false);
       setIsRevisionBodyRendered(false);
     }
     }
-
   }, [isRevisionBodyRendered, contentRef.current]);
   }, [isRevisionBodyRendered, contentRef.current]);
 
 
   const page = props.focusedSearchResultData?.pageData;
   const page = props.focusedSearchResultData?.pageData;