Skip to content

Commit 6894189

Browse files
Streamdown (#1128)
1 parent 256305d commit 6894189

File tree

6 files changed

+389
-137
lines changed

6 files changed

+389
-137
lines changed

components/code-block.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

components/diffview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { EditorState } from 'prosemirror-state';
1111
import { EditorView } from 'prosemirror-view';
1212
import React, { useEffect, useRef } from 'react';
1313
import { renderToString } from 'react-dom/server';
14-
import ReactMarkdown from 'react-markdown';
14+
import { Streamdown } from 'streamdown';
1515

1616
import { diffEditor, DiffType } from '@/lib/editor/diff';
1717

@@ -60,10 +60,10 @@ export const DiffView = ({ oldContent, newContent }: DiffEditorProps) => {
6060
const parser = DOMParser.fromSchema(diffSchema);
6161

6262
const oldHtmlContent = renderToString(
63-
<ReactMarkdown>{oldContent}</ReactMarkdown>,
63+
<Streamdown>{oldContent}</Streamdown>,
6464
);
6565
const newHtmlContent = renderToString(
66-
<ReactMarkdown>{newContent}</ReactMarkdown>,
66+
<Streamdown>{newContent}</Streamdown>,
6767
);
6868

6969
const oldContainer = document.createElement('div');

components/markdown.tsx

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
11
import Link from 'next/link';
22
import React, { memo } from 'react';
3-
import ReactMarkdown, { type Components } from 'react-markdown';
4-
import remarkGfm from 'remark-gfm';
5-
import { CodeBlock } from './code-block';
3+
import { Streamdown, type StreamdownProps } from 'streamdown';
4+
5+
type Components = StreamdownProps['components'];
66

77
const components: Partial<Components> = {
8-
// @ts-expect-error
9-
code: CodeBlock,
10-
pre: ({ children }) => <>{children}</>,
11-
ol: ({ node, children, ...props }) => {
12-
return (
13-
<ol className="list-decimal list-outside ml-4" {...props}>
14-
{children}
15-
</ol>
16-
);
17-
},
18-
li: ({ node, children, ...props }) => {
19-
return (
20-
<li className="py-1" {...props}>
21-
{children}
22-
</li>
23-
);
24-
},
25-
ul: ({ node, children, ...props }) => {
26-
return (
27-
<ul className="list-decimal list-outside ml-4" {...props}>
28-
{children}
29-
</ul>
30-
);
31-
},
32-
strong: ({ node, children, ...props }) => {
33-
return (
34-
<span className="font-semibold" {...props}>
35-
{children}
36-
</span>
37-
);
38-
},
398
a: ({ node, children, ...props }) => {
409
return (
4110
// @ts-expect-error
@@ -49,59 +18,11 @@ const components: Partial<Components> = {
4918
</Link>
5019
);
5120
},
52-
h1: ({ node, children, ...props }) => {
53-
return (
54-
<h1 className="text-3xl font-semibold mt-6 mb-2" {...props}>
55-
{children}
56-
</h1>
57-
);
58-
},
59-
h2: ({ node, children, ...props }) => {
60-
return (
61-
<h2 className="text-2xl font-semibold mt-6 mb-2" {...props}>
62-
{children}
63-
</h2>
64-
);
65-
},
66-
h3: ({ node, children, ...props }) => {
67-
return (
68-
<h3 className="text-xl font-semibold mt-6 mb-2" {...props}>
69-
{children}
70-
</h3>
71-
);
72-
},
73-
h4: ({ node, children, ...props }) => {
74-
return (
75-
<h4 className="text-lg font-semibold mt-6 mb-2" {...props}>
76-
{children}
77-
</h4>
78-
);
79-
},
80-
h5: ({ node, children, ...props }) => {
81-
return (
82-
<h5 className="text-base font-semibold mt-6 mb-2" {...props}>
83-
{children}
84-
</h5>
85-
);
86-
},
87-
h6: ({ node, children, ...props }) => {
88-
return (
89-
<h6 className="text-sm font-semibold mt-6 mb-2" {...props}>
90-
{children}
91-
</h6>
92-
);
93-
},
9421
};
9522

96-
const remarkPlugins = [remarkGfm];
97-
98-
const NonMemoizedMarkdown = ({ children }: { children: string }) => {
99-
return (
100-
<ReactMarkdown remarkPlugins={remarkPlugins} components={components}>
101-
{children}
102-
</ReactMarkdown>
103-
);
104-
};
23+
const NonMemoizedMarkdown = ({ children }: { children: string }) => (
24+
<Streamdown components={components}>{children}</Streamdown>
25+
);
10526

10627
export const Markdown = memo(
10728
NonMemoizedMarkdown,

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@
7676
"react": "19.0.0-rc-45804af1-20241021",
7777
"react-data-grid": "7.0.0-beta.47",
7878
"react-dom": "19.0.0-rc-45804af1-20241021",
79-
"react-markdown": "^9.0.1",
8079
"react-resizable-panels": "^2.1.7",
8180
"redis": "^5.0.0",
82-
"remark-gfm": "^4.0.0",
8381
"resumable-stream": "^2.0.0",
8482
"server-only": "^0.0.1",
8583
"sonner": "^1.5.0",
84+
"streamdown": "^1.0.11",
8685
"swr": "^2.2.5",
8786
"tailwind-merge": "^2.5.2",
8887
"tailwindcss-animate": "^1.0.7",

0 commit comments

Comments
 (0)