An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix(chat): open chats at the end and smooth the loading skeleton (#1094)
Yoshiki Miuraf53958dc6279
diff --git a/components/chat.tsx b/components/chat.tsxindex 8fb08ffa..b15fa466 100644--- a/components/chat.tsx+++ b/components/chat.tsx@@ -4,6 +4,7 @@ import {useCallback,useEffect,useId,+ useLayoutEffect,useMemo,useRef,useState,@@ -567,6 +568,16 @@ export function Chat({return () => cancelAnimationFrame(frame)}, [messages])+ // History can arrive after mount, so open each saved chat at its end once+ const openedChatIdRef = useRef<string | null>(null)+ useLayoutEffect(() => {+ if (openedChatIdRef.current === chatId || messages.length === 0) return+ openedChatIdRef.current = chatId+ if (entry.createdLocally && !entry.hasServerHistory) return+ const container = scrollContainerRef.current+ if (container) container.scrollTop = container.scrollHeight+ }, [chatId, messages.length, entry])+// Scroll to the section when a new user message is sentuseEffect(() => {// Only scroll if this chat is currently visible in the URLdiff --git a/components/default-skeleton.tsx b/components/default-skeleton.tsxindex 6d7d2024..05166650 100644--- a/components/default-skeleton.tsx+++ b/components/default-skeleton.tsx@@ -1,10 +1,24 @@'use client'+import { useLayoutEffect, useRef } from 'react'+import { Skeleton } from './ui/skeleton'+// Matches Tailwind's animate-pulse duration+const PULSE_MS = 2000+export const DefaultSkeleton = () => {+ // The route loading skeleton is replaced by the chat's own skeleton while+ // history loads; a wall-clock phase keeps the pulse from restarting.+ const ref = useRef<HTMLDivElement>(null)+ useLayoutEffect(() => {+ ref.current?.getAnimations?.({ subtree: true }).forEach(animation => {+ animation.currentTime = Date.now() % PULSE_MS+ })+ }, [])+return (- <div className="flex flex-col gap-2 pb-4 pt-2">+ <div ref={ref} className="flex flex-col gap-2 pb-4 pt-2">{[...Array(2)].map((_, index) => (<Skeleton key={index} className="h-6 w-full" />))}