Skip to content

An AI-powered search engine with a generative UI

Adjust message actions visibility handling

Yoshiki Miuraf198085e04a5
diff --git a/components/message-actions.tsx b/components/message-actions.tsx
index 1f4f921a..ad31814a 100644
--- a/components/message-actions.tsx
+++ b/components/message-actions.tsx
@@ -48,18 +48,16 @@ export function MessageActions({
const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false)
const isLoading = status === 'submitted' || status === 'streaming'
+ // Keep the element mounted during loading to preserve layout; otherwise skip rendering.
+ if (!visible && !isLoading) {
+ return null
+ }
+
const mappedMessage = useMemo(() => {
if (!message) return ''
return processCitations(message, citationMaps || {})
}, [message, citationMaps])
- // Do not render at all when actions should be hidden.
- // Rendering while loading is allowed so previous messages keep their actions
- // visible even during a new message's streaming.
- if (!visible) {
- return null
- }
-
async function handleCopy() {
await navigator.clipboard.writeText(mappedMessage)
toast.success('Message copied to clipboard')
@@ -101,9 +99,12 @@ export function MessageActions({
return (
<div
+ aria-hidden={!visible}
className={cn(
'flex items-center gap-0.5 self-end transition-opacity duration-200',
- 'opacity-100',
+ visible
+ ? 'opacity-100'
+ : 'pointer-events-none opacity-0 invisible',
className
)}
>