
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
react-ai-stream-markdown
Advanced tools
Stream AI/UGC Markdown into React safely with coalescing, callbacks, and auto-scroll. Renders via safe-markdown-react.
Stream AI/UGC Markdown into React safely with coalescing, callbacks, and auto-scroll. Renders via safe-markdown-react.
Perfect for LLM chat UIs: pass a ReadableStream or AsyncIterable and render as the text arrives.
ReadableStream<string|Uint8Array> or AsyncIterable<string>renderIntervalMsonChunk / onComplete callbackssafe-markdown-react (sanitized, link policy, image allowlist)npm i react-ai-stream-markdown safe-markdown-react
# peer deps: react, react-dom >= 18
import { StreamMarkdown } from 'react-ai-stream-markdown';
function ChatMessage({ stream }: { stream: ReadableStream<Uint8Array> }) {
return (
<StreamMarkdown
source={stream}
renderIntervalMs={50}
autoScroll
allowedImageHosts={['images.example.com']}
/>
);
}
import { StreamMarkdown } from 'react-ai-stream-markdown';
async function* toky() {
yield 'Hello'; yield ' '; yield '**world**';
}
<StreamMarkdown source={toky()} />;
type StreamSource =
| ReadableStream<string | Uint8Array>
| AsyncIterable<string | Uint8Array>;
interface StreamMarkdownProps {
source: StreamSource;
initialText?: string;
renderIntervalMs?: number; // default 32ms
autoScroll?: boolean; // default false
onChunk?: (chunk: string, full: string) => void;
onComplete?: (full: string) => void;
// Pass-through to safe-markdown-react
allowedImageHosts?: string[];
allowedSchemes?: string[];
maxHeadingLevel?: 1|2|3|4|5|6;
components?: Record<string, React.ComponentType<any>>;
}
Create app/api/chat/route.ts:
export const runtime = 'edge'; // optional
export async function POST(req: Request) {
const body = await req.json();
const r = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.OPENAI_API_KEY!}`,
},
body: JSON.stringify({
model: 'gpt-4o-mini', // or latest
stream: true,
messages: body.messages,
}),
});
if (!r.ok || !r.body) {
return new Response('Upstream error', { status: 500 });
}
// Pipe the upstream ReadableStream to the client unmodified
// (Optionally, transform SSE → plain text here.)
return new Response(r.body, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache, no-transform',
'Connection': 'keep-alive',
},
});
}
import { StreamMarkdown } from 'react-ai-stream-markdown';
async function startChat(messages) {
const res = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ messages }),
});
if (!res.body) throw new Error('No stream');
return res.body; // ReadableStream<Uint8Array>
}
// in your component
const [stream, setStream] = useState<ReadableStream<Uint8Array> | null>(null);
<button onClick={async () => setStream(await startChat([{ role: 'user', content: 'Hello' }]))}>
Ask
</button>
{stream && <StreamMarkdown source={stream} autoScroll renderIntervalMs={40} />}
If you want Markdown specifically, make sure your system prompt tells the model to reply in Markdown.
Uint8Array chunks, we TextDecoder them as UTF-8.renderIntervalMs (e.g., 50–80ms).MIT
FAQs
Stream AI/UGC Markdown into React safely with coalescing, callbacks, and auto-scroll. Renders via safe-markdown-react.
The npm package react-ai-stream-markdown receives a total of 0 weekly downloads. As such, react-ai-stream-markdown popularity was classified as not popular.
We found that react-ai-stream-markdown demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.