You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 535b687
Browse filesBrowse the repository at this point in the historyBrowse files
perf(web): streaming replies re-render only their last Markdown block
Every streamed update re-parsed the whole reply and re-rendered every element
in it, so a long reply cost more with each delta. While a reply streams, split
it at blank lines that close every open block and render each block through its
own memoized react-markdown, so finished blocks keep their render. Text with
syntax that spans blocks (definitions, footnotes, raw HTML, container
directives, display math) still renders whole, and so does the finished reply.
The renderer context also rebuilt its file-link maps from the text on every
update; key them by the file links found so streamed text keeps them stable.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
// Whitespace between top-level blocks collapses in the rendered message.
12
+
consthtml=(source: string)=>
13
+
renderToStaticMarkup(
14
+
<ReactMarkdown
15
+
remarkPlugins={CHAT_MARKDOWN_REMARK_PLUGINS}
16
+
rehypePlugins={CHAT_MARKDOWN_REHYPE_PLUGINS}
17
+
>
18
+
{source}
19
+
</ReactMarkdown>,
20
+
)
21
+
.replace(/>\s+</g,"><")
22
+
.trim();
23
+
24
+
describe("splitMarkdownBlocks",()=>{
25
+
it.each([
26
+
"# Title\n\nFirst paragraph with `code` and **bold**.\n\nSecond [link](https://example.com).",
27
+
"- one\n- two\n\n- loose three\n\n continued\n\nAfter the list.",
28
+
"1. first\n\n2. second\n\nText\n\n3) restarted",
29
+
"```ts\nconst a = 1;\n\n\nconst b = 2;\n```\n\nafter\n\n~~~\nx\n\n~~~~\n\ny\n~~~\n\nend",
30
+
"> quote\n\n> another quote\n\n> [!NOTE]\n> alert",
31
+
"| a | b |\n| - | - |\n| 1 | 2 |\n\nAfter the table.",
0 commit comments