import { useRef, useEffect, memo } from 'react'; import { ResizableHandleAlt, ResizablePanel } from '@librechat/client'; import type { ImperativePanelHandle } from 'react-resizable-panels'; const ANIMATION_DURATION = 500; interface ArtifactsPanelProps { artifacts: React.ReactNode | null; currentLayout: number[]; minSizeMain: number; shouldRender: boolean; onRenderChange: (shouldRender: boolean) => void; } /** * ArtifactsPanel component - memoized to prevent unnecessary re-renders * Only re-renders when artifacts visibility or layout changes */ const ArtifactsPanel = memo(function ArtifactsPanel({ artifacts, currentLayout, minSizeMain, shouldRender, onRenderChange, }: ArtifactsPanelProps) { const artifactsPanelRef = useRef(null); const timeoutRef = useRef(null); useEffect(() => { if (artifacts != null) { if (timeoutRef.current) { clearTimeout(timeoutRef.current); timeoutRef.current = null; } onRenderChange(true); requestAnimationFrame(() => { requestAnimationFrame(() => { artifactsPanelRef.current?.expand(); }); }); } else if (shouldRender) { artifactsPanelRef.current?.collapse(); timeoutRef.current = setTimeout(() => { onRenderChange(false); }, ANIMATION_DURATION); } return () => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } }; }, [artifacts, shouldRender, onRenderChange]); if (!shouldRender) { return null; } return ( <> {artifacts != null && ( )}
{artifacts}
); }); ArtifactsPanel.displayName = 'ArtifactsPanel'; export default ArtifactsPanel;