An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix(artifact): prevent chat overflow on small screens by allowing flex children to shrink and clamping artifact panel width with a non-zero min; add min-w-0/overflow-hidden to layout, add ResizeObserver and chat-min-width-aware clamping
Yoshiki Miura7f9ffdf501cc
diff --git a/app/layout.tsx b/app/layout.tsxindex 1a23b011..769cb5a5 100644--- a/app/layout.tsx+++ b/app/layout.tsx@@ -81,9 +81,9 @@ export default async function RootLayout({><SidebarProvider defaultOpen><AppSidebar />- <div className="flex flex-col flex-1">+ <div className="flex flex-col flex-1 min-w-0"><Header user={user} />- <main className="flex flex-1 min-h-0">+ <main className="flex flex-1 min-h-0 min-w-0 overflow-hidden"><ArtifactRoot>{children}</ArtifactRoot></main></div>diff --git a/components/artifact/chat-artifact-container.tsx b/components/artifact/chat-artifact-container.tsxindex 5d9aabfb..b6e50d8b 100644--- a/components/artifact/chat-artifact-container.tsx+++ b/components/artifact/chat-artifact-container.tsx@@ -12,8 +12,9 @@ import { InspectorPanel } from '@/components/inspector/inspector-panel'import { useArtifact } from './artifact-context'const DEFAULT_WIDTH = 500-const MIN_WIDTH = 400+const MIN_WIDTH = 320const MAX_WIDTH = 800+const CHAT_MIN_WIDTH = 360const RESIZE_OVERLAY_Z_INDEX = 9999export function ChatArtifactContainer({@@ -32,16 +33,43 @@ export function ChatArtifactContainer({const savedWidth = localStorage.getItem('artifactPanelWidth')if (savedWidth) {const parsedWidth = parseInt(savedWidth, 10)- if (- !isNaN(parsedWidth) &&- parsedWidth >= MIN_WIDTH &&- parsedWidth <= MAX_WIDTH- ) {- setWidth(parsedWidth)+ if (!isNaN(parsedWidth) && parsedWidth >= 0 && parsedWidth <= MAX_WIDTH) {+ // Clamp against available space considering chat minimum width+ const containerRect = containerRef.current?.getBoundingClientRect()+ if (containerRect) {+ const available = Math.max(0, containerRect.width - CHAT_MIN_WIDTH)+ const allowedMax = Math.min(MAX_WIDTH, available)+ const allowedMin =+ allowedMax > 0 ? Math.min(MIN_WIDTH, allowedMax) : 0+ const clamped = Math.min(+ Math.max(parsedWidth, allowedMin),+ allowedMax+ )+ setWidth(clamped)+ } else {+ setWidth(parsedWidth)+ }}}}, [])+ // Keep width in bounds when container resizes (e.g., window resize)+ useEffect(() => {+ const el = containerRef.current+ if (!el) return+ const ro = new ResizeObserver(entries => {+ for (const entry of entries) {+ const cr = entry.contentRect+ const available = Math.max(0, cr.width - CHAT_MIN_WIDTH)+ const allowedMax = Math.min(MAX_WIDTH, available)+ const allowedMin = allowedMax > 0 ? Math.min(MIN_WIDTH, allowedMax) : 0+ setWidth(prev => Math.min(Math.max(prev, allowedMin), allowedMax))+ }+ })+ ro.observe(el)+ return () => ro.disconnect()+ }, [])+const startResize = useCallback((e: React.MouseEvent) => {e.preventDefault()setIsResizing(true)@@ -54,7 +82,13 @@ export function ChatArtifactContainer({const containerRect = containerRef.current?.getBoundingClientRect()if (containerRect) {const newWidth = containerRect.right - e.clientX- const clampedWidth = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, newWidth))+ const available = Math.max(0, containerRect.width - CHAT_MIN_WIDTH)+ const allowedMax = Math.min(MAX_WIDTH, available)+ const allowedMin = allowedMax > 0 ? Math.min(MIN_WIDTH, allowedMax) : 0+ const clampedWidth = Math.min(+ Math.max(newWidth, allowedMin),+ allowedMax+ )setWidth(clampedWidth)localStorage.setItem('artifactPanelWidth', clampedWidth.toString())}@@ -74,7 +108,7 @@ export function ChatArtifactContainer({}, [isResizing])return (- <div className="flex-1 min-h-0 h-screen flex">+ <div className="flex-1 min-h-0 min-w-0 h-screen flex"><div className="absolute p-4 z-50 transition-opacity duration-1000">{(!open || isMobileSidebar) && (<SidebarTrigger className="animate-fade-in" showIconLogo />@@ -82,9 +116,12 @@ export function ChatArtifactContainer({</div>{/* Desktop: Independent panels like morphic-studio */}- <div ref={containerRef} className="hidden md:flex flex-1 overflow-hidden">+ <div+ ref={containerRef}+ className="hidden md:flex flex-1 min-w-0 overflow-hidden"+ >{/* Chat Panel - Independent container */}- <div className="flex-1 flex flex-col">{children}</div>+ <div className="flex-1 min-w-0 flex flex-col">{children}</div>{/* Resize Handle */}{state.isOpen && state.part && (