<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: anythic</title>
    <description>The latest articles on DEV Community by anythic (anythic).</description>
    <link>https://dev.to/anythic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F15250%2F2ed2c10b-9702-455a-a50e-d9e79664b54f.png</url>
      <title>DEV Community: anythic</title>
      <link>https://dev.to/anythic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anythic"/>
    <language>en</language>
    <item>
      <title>How we built streaming-safe Markdown for AI chat in React</title>
      <dc:creator>ozoduwdev</dc:creator>
      <pubDate>Sun, 11 Oct 2026 18:58:43 +0000</pubDate>
      <link>https://dev.to/anythic/how-we-built-streaming-safe-markdown-for-ai-chat-in-react-2hdm</link>
      <guid>https://dev.to/anythic/how-we-built-streaming-safe-markdown-for-ai-chat-in-react-2hdm</guid>
      <description>&lt;p&gt;If you've built an AI chat UI, you've seen this: the model streams half a code block, and suddenly your whole reply turns into a giant monospace mess. A &lt;code&gt;**&lt;/code&gt; opens bold and never closes. A link renders as &lt;code&gt;[text](htt&lt;/code&gt;. Then the next token arrives and everything jumps back.&lt;/p&gt;

&lt;p&gt;We hit this so often that we ended up building a component library around it: &lt;strong&gt;&lt;a href="https://github.com/anythic/anythic-ui" rel="noopener noreferrer"&gt;anythic/ui&lt;/a&gt;&lt;/strong&gt;, open-source React components for AI apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: Markdown is not designed to be incomplete
&lt;/h2&gt;

&lt;p&gt;Markdown parsers assume they get the whole document. During streaming, they only get a prefix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Here is the fix:

```ts
function add(a, b) {
  return a +
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code fence is open, so everything after it is treated as code, including text that hasn't arrived yet. With every token, the layout flips back and forth.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: repair the prefix before parsing
&lt;/h2&gt;

&lt;p&gt;Instead of rendering the raw prefix, we "complete" it first: close the open code fence, close unbalanced &lt;code&gt;**&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt; and backticks, and hold back a link until its URL is complete. The parser always sees valid Markdown, so the reply grows smoothly instead of flickering.&lt;/p&gt;

&lt;p&gt;In anythic/ui this happens inside the &lt;code&gt;Markdown&lt;/code&gt; component. You just pass the text as it streams:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Markdown&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@anythic/ui&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Markdown&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;streamingText&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Markdown&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The rest of an AI interface
&lt;/h2&gt;

&lt;p&gt;Once Markdown worked, we kept going with the other pieces every agent UI needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ReasoningBlock&lt;/strong&gt;: collapsible "thinking" that shows how long the model thought&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ToolCall&lt;/strong&gt; and &lt;strong&gt;ToolApproval&lt;/strong&gt;: show what the agent is doing, and ask before dangerous actions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plan&lt;/strong&gt;: a live checklist of the agent's steps&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CodeDiff&lt;/strong&gt;: file changes with an in-house Myers diff&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminal&lt;/strong&gt;: command output with an ANSI color parser and progress bars&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Citation&lt;/strong&gt; and &lt;strong&gt;Sources&lt;/strong&gt;: numbered references that match &lt;code&gt;[1]&lt;/code&gt; in the text&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PromptInput&lt;/strong&gt;, &lt;strong&gt;Conversation&lt;/strong&gt;, &lt;strong&gt;Message&lt;/strong&gt;: the chat shell itself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything is model-agnostic: components take plain props, so they work with the Vercel AI SDK, OpenAI, Anthropic, Gemini or your own backend. Styling uses Tailwind v4 with shadcn-compatible tokens, so it drops into existing shadcn projects and supports dark mode out of the box.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @anythic/ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The repo includes screenshots of every component and a demo app you can run locally with your own Gemini key:&lt;br&gt;
👉 &lt;a href="https://github.com/anythic/anythic-ui" rel="noopener noreferrer"&gt;https://github.com/anythic/anythic-ui&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's MIT licensed. We'd love your feedback: what's the most annoying part of building AI UIs for you, and which component should we build next?**&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu3v6au5rbqa7ji9qr1sp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu3v6au5rbqa7ji9qr1sp.png" alt=" " width="800" height="400"&gt;&lt;/a&gt;**&lt;/p&gt;

</description>
      <category>ai</category>
      <category>react</category>
      <category>opensource</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
