Skip to content

An AI-powered search engine with a generative UI

fix(ui): correctly handle collapsible sections with subsequent content

Yoshiki Miurae8dbd56b3843
diff --git a/components/collapsible-message.tsx b/components/collapsible-message.tsx
index 3e1c2305..325497de 100644
--- a/components/collapsible-message.tsx
+++ b/components/collapsible-message.tsx
@@ -2,7 +2,6 @@ import { ChevronDown } from 'lucide-react'
import { cn } from '@/lib/utils'
-import { CurrentUserAvatar } from './current-user-avatar'
import {
Collapsible,
CollapsibleContent,
@@ -10,6 +9,7 @@ import {
} from './ui/collapsible'
import { IconLogo } from './ui/icons'
import { Separator } from './ui/separator'
+import { CurrentUserAvatar } from './current-user-avatar'
interface CollapsibleMessageProps {
children: React.ReactNode
@@ -68,7 +68,6 @@ export function CollapsibleMessage({
variant === 'default' && !showBorder && 'rounded-lg bg-card',
variant === 'process' && 'rounded-lg border bg-card',
variant === 'process-sub' && 'rounded-md border bg-card/50',
- // Add background highlight when open and no border (grouped sections)
isOpen && !showBorder && 'bg-background'
)}
>
diff --git a/components/reasoning-section.tsx b/components/reasoning-section.tsx
index 388a3373..df7ef538 100644
--- a/components/reasoning-section.tsx
+++ b/components/reasoning-section.tsx
@@ -141,8 +141,8 @@ export function ReasoningSection({
<div className="w-[16px] shrink-0 flex justify-center">
<div
className={cn(
- "w-px bg-border/50 transition-opacity duration-200",
- isOpen ? "opacity-100" : "opacity-0"
+ 'w-px bg-border/50 transition-opacity duration-200',
+ isOpen ? 'opacity-100' : 'opacity-0'
)}
style={{
marginTop: isFirst ? '0' : '-1rem',
diff --git a/components/research-process-section.tsx b/components/research-process-section.tsx
index 09f65ff1..37b1b60c 100644
--- a/components/research-process-section.tsx
+++ b/components/research-process-section.tsx
@@ -77,6 +77,22 @@ export function ResearchProcessSection({
if (segments.length === 0) return null
+ // Check if there are subsequent text parts after this segment
+ const hasSubsequentContent = (segmentIndex: number): boolean => {
+ // Check if there are more segments after this one
+ if (segmentIndex < segments.length - 1) {
+ return true
+ }
+ // Check if there are text parts after the last segment
+ const remainingParts =
+ message.parts?.slice(
+ message.parts.findIndex(
+ p => p === segments[segmentIndex][segments[segmentIndex].length - 1]
+ ) + 1
+ ) || []
+ return remainingParts.some(p => p.type === 'text')
+ }
+
// Handle accordion-style open/close for grouped sections
const handleAccordionChange = (
id: string,
@@ -119,8 +135,11 @@ export function ResearchProcessSection({
const hasNext = pidx < grp.length - 1
if (part.type === 'reasoning') {
const rid = `${messageId}-reasoning-${sidx}-${gidx}-${pidx}`
+ // Check if there's subsequent content (next part in group or next segment/text)
+ const hasSubsequent =
+ hasNext || hasSubsequentContent(sidx)
const isOpen = isSingle
- ? getIsOpen(rid, 'reasoning', hasNext)
+ ? getIsOpen(rid, 'reasoning', hasSubsequent)
: openSectionId === rid
return (
@@ -140,8 +159,11 @@ export function ResearchProcessSection({
if (part.type?.startsWith?.('tool-')) {
const id = part.toolCallId
+ // Check if there's subsequent content (next part in group or next segment/text)
+ const hasSubsequent =
+ hasNext || hasSubsequentContent(sidx)
const isOpen = isSingle
- ? getIsOpen(id, part.type, hasNext)
+ ? getIsOpen(id, part.type, hasSubsequent)
: openSectionId === id
return (
diff --git a/components/search-section.tsx b/components/search-section.tsx
index 41574fb8..df21d5ff 100644
--- a/components/search-section.tsx
+++ b/components/search-section.tsx
@@ -115,8 +115,8 @@ export function SearchSection({
<div className="w-[16px] shrink-0 flex justify-center">
<div
className={cn(
- "w-px bg-border/50 transition-opacity duration-200",
- isOpen ? "opacity-100" : "opacity-0"
+ 'w-px bg-border/50 transition-opacity duration-200',
+ isOpen ? 'opacity-100' : 'opacity-0'
)}
style={{
marginTop: isFirst ? '0' : '-1rem',
diff --git a/components/tool-todo-display.tsx b/components/tool-todo-display.tsx
index bd12be9b..9cdae201 100644
--- a/components/tool-todo-display.tsx
+++ b/components/tool-todo-display.tsx
@@ -135,8 +135,8 @@ export function ToolTodoDisplay({
<div className="w-[16px] shrink-0 flex justify-center">
<div
className={cn(
- "w-px bg-border/50 transition-opacity duration-200",
- isOpen ? "opacity-100" : "opacity-0"
+ 'w-px bg-border/50 transition-opacity duration-200',
+ isOpen ? 'opacity-100' : 'opacity-0'
)}
style={{
marginTop: isFirst ? '0' : '-1rem',