Skip to content

Commit c77f204

Browse files
committed
streamed text change
1 parent b1caeb0 commit c77f204

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/chat-content

apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/chat-content/chat-content.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { type ComponentPropsWithoutRef, useMemo } from 'react'
3+
import { type ComponentPropsWithoutRef, useEffect, useMemo, useRef } from 'react'
44
import { Streamdown } from 'streamdown'
55
import 'streamdown/styles.css'
66
import 'prismjs/components/prism-typescript'
@@ -181,6 +181,18 @@ export function ChatContent({
181181
onOptionSelect,
182182
smoothStreaming = true,
183183
}: ChatContentProps) {
184+
const hydratedStreamingRef = useRef(isStreaming && content.trim().length > 0)
185+
const previousIsStreamingRef = useRef(isStreaming)
186+
187+
useEffect(() => {
188+
if (!previousIsStreamingRef.current && isStreaming && content.trim().length > 0) {
189+
hydratedStreamingRef.current = true
190+
} else if (!isStreaming) {
191+
hydratedStreamingRef.current = false
192+
}
193+
previousIsStreamingRef.current = isStreaming
194+
}, [content, isStreaming])
195+
184196
const rendered = useStreamingText(content, isStreaming && smoothStreaming)
185197

186198
const parsed = useMemo(() => parseSpecialTags(rendered, isStreaming), [rendered, isStreaming])
@@ -216,7 +228,7 @@ export function ChatContent({
216228
<Streamdown
217229
mode={isStreaming ? undefined : 'static'}
218230
isAnimating={isStreaming}
219-
animated={isStreaming}
231+
animated={isStreaming && !hydratedStreamingRef.current}
220232
components={MARKDOWN_COMPONENTS}
221233
>
222234
{rendered}

0 commit comments

Comments
 (0)