@@ -12,23 +12,27 @@ import {
1212 TooltipTrigger ,
1313} from "@/components/ai-ui/tooltip" ;
1414import { cn } from "@/lib/utils" ;
15- import { cjk } from "@streamdown/cjk" ;
16- import { code } from "@streamdown/code" ;
17- import { math } from "@streamdown/math" ;
18- import { mermaid } from "@streamdown/mermaid" ;
1915import type { UIMessage } from "ai" ;
2016import { ChevronLeftIcon , ChevronRightIcon } from "lucide-react" ;
2117import type { ComponentProps , HTMLAttributes , ReactElement } from "react" ;
2218import {
2319 createContext ,
20+ lazy ,
2421 memo ,
22+ Suspense ,
2523 useCallback ,
2624 useContext ,
2725 useEffect ,
2826 useMemo ,
2927 useState ,
3028} from "react" ;
31- import { Streamdown } from "streamdown" ;
29+ import type { Streamdown } from "streamdown" ;
30+
31+ const StreamdownRenderer = lazy ( ( ) =>
32+ import ( "./streamdown-renderer" ) . then ( ( module ) => ( {
33+ default : module . StreamdownRenderer ,
34+ } ) )
35+ ) ;
3236
3337export type MessageProps = HTMLAttributes < HTMLDivElement > & {
3438 from : UIMessage [ "role" ] ;
@@ -321,18 +325,25 @@ export const MessageBranchPage = ({
321325
322326export type MessageResponseProps = ComponentProps < typeof Streamdown > ;
323327
324- const streamdownPlugins = { cjk, code, math, mermaid } ;
325-
326328export const MessageResponse = memo (
327- ( { className, ...props } : MessageResponseProps ) => (
328- < Streamdown
329- className = { cn (
330- "size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0" ,
331- className
332- ) }
333- plugins = { streamdownPlugins }
334- { ...props }
335- />
329+ ( { children, className, ...props } : MessageResponseProps ) => (
330+ < Suspense
331+ fallback = {
332+ < div className = { cn ( "size-full whitespace-pre-wrap" , className ) } >
333+ { children }
334+ </ div >
335+ }
336+ >
337+ < StreamdownRenderer
338+ className = { cn (
339+ "size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0" ,
340+ className
341+ ) }
342+ { ...props }
343+ >
344+ { children }
345+ </ StreamdownRenderer >
346+ </ Suspense >
336347 ) ,
337348 ( prevProps , nextProps ) =>
338349 prevProps . children === nextProps . children &&
0 commit comments