yohei0125 пре 4 година
родитељ
комит
c6211d09c4
1 измењених фајлова са 8 додато и 6 уклоњено
  1. 8 6
      packages/app/src/components/SearchPage/SearchResultContent.tsx

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

@@ -25,12 +25,14 @@ const SearchResultContent: FC<Props> = (props: Props) => {
   const contentRef = useRef(null);
 
   useEffect(() => {
-    // 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);
+    // 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);
+        }
       }
       setIsRevisionBodyRendered(false);
     }