Description:
Streamdown is a React library that handles the challenges of rendering streaming Markdown content from AI models.
The library addresses the unique problems that arise when Markdown content arrives in real-time chunks, where traditional parsers struggle with incomplete or unterminated blocks.
Unlike standard Markdown parsers that expect complete documents, Streamdown can gracefully handle partial content, incomplete formatting blocks, and unterminated syntax elements while maintaining proper visual presentation.
Features
- 🔄 Streaming-optimized rendering handles incomplete Markdown blocks gracefully during real-time content delivery.
- 🎨 Unterminated block parsing applies proper styling to incomplete bold, italic, code, links, and heading elements.
- 📊 GitHub Flavored Markdown support includes tables, task lists, strikethrough, and other GFM extensions.
- 🔢 Mathematical expression rendering supports LaTeX equations through KaTeX integration.
- 🎯 Syntax-highlighted code blocks uses Shiki for beautiful code presentation with built-in copy functionality.
- 🛡️ Security hardening prevents potential security risks from untrusted Markdown content through origin validation.
- ⚡ Performance optimization implements memoized rendering for efficient updates during streaming.
- 🎨 Built-in typography styles provides Tailwind CSS classes for consistent Markdown component styling.
- 🚀 Functions as a direct replacement for
react-markdown.
Use Cases
- AI chatbot interfaces where responses stream in real-time and need proper Markdown formatting before completion.
- Documentation platforms that generate content dynamically and require progressive rendering capabilities.
- Code review tools that display streaming diff content with syntax highlighting and proper formatting.
- Educational platforms that stream mathematical content requiring LaTeX rendering alongside text formatting.
- Content management systems where editors preview Markdown content as they type with incomplete syntax blocks.
How to Use It
1. Install Streamdown with NPM.
npm install streamdown2. Configure your Tailwind CSS setup to include Streamdown styles in your globals.css file.
@source "../node_modules/streamdown/dist/index.js";3. Import the Streamdown component in your React application and pass Markdown content as children.
import { Streamdown } from 'streamdown';
function MarkdownRenderer() {
const content = "# Documentation\n\nThis **bold text** renders correctly.";
return (
<div>
<Streamdown>{content}</Streamdown>
</div>
);
}4. For AI streaming applications, integrate Streamdown with the AI SDK to handle progressive content rendering.
import { useChat } from '@ai-sdk/react';
import { Streamdown } from 'streamdown';
import { useState } from 'react';
function ChatInterface() {
const { messages, sendMessage, status } = useChat();
const [userInput, setUserInput] = useState('');
const handleSubmit = (event) => {
event.preventDefault();
if (userInput.trim() && status === 'ready') {
sendMessage({ text: userInput });
setUserInput('');
}
};
return (
<div className="chat-container">
<div className="messages">
{messages.map(message => (
<div key={message.id} className="message">
<div className="content">
{message.parts
.filter(part => part.type === 'text')
.map((part, index) => (
<Streamdown key={index}>{part.text}</Streamdown>
))}
</div>
</div>
))}
</div>
<form onSubmit={handleSubmit} className="input-form">
<input
type="text"
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
disabled={status !== 'ready'}
placeholder="Type your message..."
className="message-input"
/>
<button
type="submit"
disabled={status !== 'ready'}
className="send-button"
>
Send Message
</button>
</form>
</div>
);
}5. All available component props.
children: This prop accepts the Markdown content you want to render. It expects a string.parseIncompleteMarkdown: A boolean prop that controls whether Streamdown parses and styles unterminated Markdown blocks. Its default value istrue.className: You can apply custom CSS classes to the container element that wraps the rendered Markdown. Provide a string for this prop.components: Use this object to override default rendering components for specific Markdown elements. For example, you can replace the defaulth1tag with your own custom React component.remarkPlugins: An array of remark plugins to process the Markdown. Streamdown usesremarkGfmandremarkMathby default.rehypePlugins: An array of rehype plugins to process the HTML output.rehypeKatexis included by default for mathematical expressions.allowedImagePrefixes: An array of strings defining allowed URL prefixes for images. This enhances security by preventing images from unexpected sources.allowedLinkPrefixes: An array of strings defining allowed URL prefixes for links. This also helps in security hardening against malicious links.
Related Resources
- React Markdown – The original library that Streamdown replaces, providing standard Markdown rendering for React applications.
- AI SDK – A comprehensive toolkit for building AI applications that integrates seamlessly with Streamdown for streaming responses.
- Remark – The underlying Markdown processor that powers Streamdown’s parsing capabilities.
- KaTeX – The mathematical typesetting library used by Streamdown for rendering LaTeX expressions.
FAQs
Q: Can Streamdown handle large streaming documents without performance issues?
A: Streamdown implements memoized rendering and optimized parsing algorithms to maintain performance even with large streaming content. The library only re-renders changed portions of the document.
Q: Does Streamdown support custom syntax highlighting themes for code blocks?
A: Yes, Streamdown uses Shiki for syntax highlighting, which supports multiple themes. You can configure the theme through the component props or by customizing the CSS classes.
Q: How does Streamdown prevent security risks from untrusted Markdown content?
A: Streamdown includes built-in security hardening that validates image and link URLs against configurable allow-lists, preventing potential security vulnerabilities from malicious content.
Q: Can I use Streamdown with existing react-markdown plugins and extensions?
A: Streamdown accepts the same props as react-markdown, including remarkPlugins and rehypePlugins arrays, so most existing plugins should work without modification.
Q: How does Streamdown handle incomplete Markdown during streaming?
A: Streamdown includes built-in support for parsing and styling unterminated Markdown blocks. This means headings, bold text, italic text, code snippets, and links still appear formatted even when the full Markdown syntax has not yet arrived.
Q: Does Streamdown support advanced Markdown features like tables and task lists?
A: Yes, Streamdown supports GitHub Flavored Markdown (GFM) out of the box. This includes features like tables, task lists, and strikethrough.





