3 Commits

Author SHA1 Message Date
d85cc205de blog slug scroll 2026-06-18 02:57:36 +02:00
95666e20e9 Merge branch 'chat-scroll-behaiviour' 2026-06-18 02:53:20 +02:00
993137068e chat scroll to bottom by default 2026-06-18 02:53:06 +02:00
3 changed files with 16 additions and 9 deletions

View File

@@ -32,7 +32,7 @@ export default async function BlogPostPage({ params }: Props) {
const date = typeof parsed.data.date === "string" ? parsed.data.date : post.date;
return (
<main className="mx-auto max-w-2xl px-4 py-12">
<main className="mx-auto h-full max-w-2xl overflow-y-auto px-4 py-12">
<header className="mb-8">
<h1 className="text-3xl font-bold">{title}</h1>
{date && (

View File

@@ -6,7 +6,7 @@ export default async function BlogPage() {
const posts = await servTrpc.blog.list();
return (
<main className="mx-auto max-w-2xl px-4 py-12">
<main className="mx-auto h-full max-w-2xl overflow-y-auto px-4 py-12">
<h1 className="mb-8 text-3xl font-bold">Blog</h1>
{posts.length === 0 ? (
<p className="text-muted-foreground">No posts yet.</p>

View File

@@ -1,5 +1,5 @@
'use client'
import { useState, useEffect } from 'react'
import { useState, useEffect, useRef } from 'react'
import { useChat } from '@ai-sdk/react'
import { DefaultChatTransport, type UIMessage } from 'ai'
import { Button } from '~/components/ui/button'
@@ -83,14 +83,21 @@ function AuthenticatedChatInterface({ dbMessages, sessionId }: ChatInterfaceProp
sendMessage({ text })
}
const gsapContext = useGsapContext()
const didInitialScroll = useRef(false)
useEffect(() => {
let scroller = gsapContext?.getScroller()
if (scroller instanceof Window) {
return;
const scroller = gsapContext?.getScroller()
if (!scroller || scroller instanceof Window) {
return
}
console.log(scroller?.scrollHeight)
scroller?.scrollTo({ behavior: 'smooth', top: scroller.scrollHeight })
}, [messages])
// Jump instantly on first open so the chat starts pinned to the bottom;
// animate subsequent updates. Defer a frame so the messages have laid out
// (and any streaming content has grown) before we measure scrollHeight.
const behavior: ScrollBehavior = didInitialScroll.current ? 'smooth' : 'auto'
didInitialScroll.current = true
requestAnimationFrame(() => {
scroller.scrollTo({ behavior, top: scroller.scrollHeight })
})
}, [messages, status])
return (
<div className="flex flex-col h-full">
{messages &&