Yidadaa 1 year ago
parent
commit
116e16e30d
2 changed files with 3 additions and 10 deletions
  1. 1 0
      app/components/chat.tsx
  2. 2 10
      app/components/markdown.tsx

+ 1 - 0
app/components/chat.tsx

@@ -725,6 +725,7 @@ export function Chat() {
                     }}
                     fontSize={fontSize}
                     parentRef={scrollRef}
+                    defaultShow={i >= messages.length - 10}
                   />
                 </div>
                 {!isUser && !message.preview && (

+ 2 - 10
app/components/markdown.tsx

@@ -62,11 +62,12 @@ export function Markdown(
     loading?: boolean;
     fontSize?: number;
     parentRef: RefObject<HTMLDivElement>;
+    defaultShow?: boolean;
   } & React.DOMAttributes<HTMLDivElement>,
 ) {
   const mdRef = useRef<HTMLDivElement>(null);
   const renderedHeight = useRef(0);
-  const inView = useRef(false);
+  const inView = useRef(!!props.defaultShow);
 
   const parent = props.parentRef.current;
   const md = mdRef.current;
@@ -90,15 +91,6 @@ export function Markdown(
     }
   };
 
-  useEffect(() => {
-    setTimeout(() => {
-      if (!inView.current) {
-        checkInView();
-      }
-    }, 30);
-    // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, []);
-
   checkInView();
 
   return (