Skip to content

An AI-powered search engine with a generative UI

fix: improve chat message position adjustment for better visibility

Yoshiki Miuradfb7c4a44183
diff --git a/components/chat-messages.tsx b/components/chat-messages.tsx
index 5840401c..95573311 100644
--- a/components/chat-messages.tsx
+++ b/components/chat-messages.tsx
@@ -50,6 +50,7 @@ export function ChatMessages({
// Cache tool counts for performance optimization
const toolCountCacheRef = useRef<Map<string, number>>(new Map())
const isLoading = status === 'submitted' || status === 'streaming'
+ const [offsetHeight, setOffsetHeight] = useState(160) // Dynamic offset for minHeight calculation
// Tool types definition - moved outside function for performance
const toolTypes = [
@@ -67,6 +68,26 @@ export function ChatMessages({
}
}, [isLoading])
+ // Calculate the offset height dynamically based on viewport and UI elements
+ useEffect(() => {
+ const calculateOffset = () => {
+ // Account for:
+ // - Header/navigation (estimated)
+ // - ChatPanel (input area)
+ // - Additional padding and margins
+ const headerHeight = 56 // pt-14 padding top
+ const chatPanelEstimatedHeight = 120 // ChatPanel with input area
+ const additionalPadding = 32 // Safety margin for better visibility
+
+ const totalOffset = headerHeight + chatPanelEstimatedHeight + additionalPadding
+ setOffsetHeight(totalOffset)
+ }
+
+ calculateOffset()
+ window.addEventListener('resize', calculateOffset)
+ return () => window.removeEventListener('resize', calculateOffset)
+ }, [])
+
if (!sections.length) return null
// Check if loading indicator should be shown
@@ -158,7 +179,7 @@ export function ChatMessages({
className="chat-section mb-8"
style={
sectionIndex === sections.length - 1
- ? { minHeight: 'calc(-228px + 100dvh)' }
+ ? { minHeight: `calc(100dvh - ${offsetHeight}px)` }
: {}
}
>