yohei0125 4 yıl önce
ebeveyn
işleme
839bfcec5b

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

@@ -25,18 +25,15 @@ const SearchResultContent: FC<Props> = (props: Props) => {
   const contentRef = useRef(null);
 
   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);
     }
-
   }, [isRevisionBodyRendered, contentRef.current]);
 
   const page = props.focusedSearchResultData?.pageData;