Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: auto-update, auto-scroll to the bottom

Bingxi Zhao (Frank)fba51dc8564a
diff --git a/web/app/(utility)/knowledge/page.tsx b/web/app/(utility)/knowledge/page.tsx
index 205283185..4fe699397 100644
--- a/web/app/(utility)/knowledge/page.tsx
+++ b/web/app/(utility)/knowledge/page.tsx
@@ -1644,7 +1644,6 @@ function KnowledgePageContent() {
ref={createFileRef}
type="file"
multiple
- accept={uploadPolicy.accept || undefined}
className="hidden"
onChange={(event) => {
setNewKbFiles((prev) =>
@@ -1819,7 +1818,6 @@ function KnowledgePageContent() {
ref={uploadFileRef}
type="file"
multiple
- accept={uploadPolicy.accept || undefined}
className="hidden"
onChange={(event) => {
setUploadFiles((prev) =>
diff --git a/web/app/(workspace)/agents/[botId]/chat/page.tsx b/web/app/(workspace)/agents/[botId]/chat/page.tsx
index f36d7b870..a6ba159d9 100644
--- a/web/app/(workspace)/agents/[botId]/chat/page.tsx
+++ b/web/app/(workspace)/agents/[botId]/chat/page.tsx
@@ -37,14 +37,17 @@ export default function BotChatPage() {
const scrollRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLTextAreaElement>(null);
- const scrollToBottom = useCallback(() => {
- requestAnimationFrame(() => {
- scrollRef.current?.scrollTo({
- top: scrollRef.current.scrollHeight,
- behavior: "smooth",
+ const scrollToBottom = useCallback(
+ (behavior: ScrollBehavior = "smooth") => {
+ requestAnimationFrame(() => {
+ scrollRef.current?.scrollTo({
+ top: scrollRef.current.scrollHeight,
+ behavior,
+ });
});
- });
- }, []);
+ },
+ [],
+ );
useEffect(() => {
if (!botId) {
@@ -64,10 +67,17 @@ export default function BotChatPage() {
role: m.role as "user" | "assistant",
content: m.content,
}));
- if (restored.length) setMessages(restored);
+ if (restored.length) {
+ setMessages(restored);
+ // Markdown/KaTeX inside AssistantResponse can grow the container after
+ // the first paint — re-snap a few times so we land at the bottom.
+ requestAnimationFrame(() => scrollToBottom("instant"));
+ window.setTimeout(() => scrollToBottom("instant"), 80);
+ window.setTimeout(() => scrollToBottom("instant"), 250);
+ }
})
.catch(() => {});
- }, [botId]);
+ }, [botId, scrollToBottom]);
useEffect(() => {
if (!botId) {
diff --git a/web/hooks/useChatAutoScroll.ts b/web/hooks/useChatAutoScroll.ts
index 4b09f618c..5b5c01008 100644
--- a/web/hooks/useChatAutoScroll.ts
+++ b/web/hooks/useChatAutoScroll.ts
@@ -90,8 +90,12 @@ export function useChatAutoScroll({
// After streaming ends, dynamically-loaded components (e.g. MathAnimatorViewer
// via next/dynamic) may render and grow the content height. Detect that and
// scroll to bottom so the user can see the full result.
+ // hasMessages is in deps so the observer attaches once the messages
+ // container mounts on session reopen — without it, the container ref is null
+ // on initial mount and the observer is never set up.
useEffect(() => {
if (isStreaming) return;
+ if (!hasMessages) return;
const container = containerRef.current;
if (!container) return;
@@ -118,7 +122,7 @@ export function useChatAutoScroll({
mo.disconnect();
if (rafId) cancelAnimationFrame(rafId);
};
- }, [isStreaming, scrollToBottom]);
+ }, [hasMessages, isStreaming, scrollToBottom]);
const handleScroll = useCallback(() => {
const container = containerRef.current;