Skip to content

Repository files navigation

Streamdown

Headless streaming markdown engine for React β€” render markdown as it arrives

Documents & Playground Β· Changelog Β· Report Bug Β· Request Feature



Table of contents

TOC

✨ Features

  • Smooth reveal β€” character or word granularity with three cadence presets (realtime, balanced, silky).
  • Block cache β€” finished blocks memoize; only the open tail block re-renders on each commit.
  • LaTeX guard β€” unbalanced delimiters stay inert until the stream closes them, so $x^2$ never flashes as raw source.
  • Headless β€” no stylesheet, no component dependencies. Bring your own CSS.

πŸ“¦ Installation

Important

This package is ESM only.

To install Streamdown, run the following command:

$ pnpm add @lobehub/streamdown

react and react-dom ^19 are peer dependencies. The package ships a 'use client' boundary, so it renders from React Server Component frameworks without extra wiring.

πŸš€ Usage

import { Streamdown } from '@lobehub/streamdown';
import rehypeKatex from 'rehype-katex';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';

const Message = ({ content }: { content: string }) => (
  <Streamdown content={content} latexGuard rehypePlugins={[rehypeKatex]} remarkPlugins={[remarkGfm, remarkMath]} />
);

content may be a partial document β€” an unterminated code fence, a half-written table, or a formula missing its closing $. The engine re-lexes only the open tail block, so the cost of a commit grows with the tail, not with the message.

Style the output yourself. The rendered tree is plain markdown HTML plus fade animation classes (STREAMDOWN_ANIMATED_CLASS, STREAM_FADE_DURATION).

🧩 Props

Prop Type Default Description
content string β€” The (partial) markdown to render
smoothing 'realtime' | 'balanced' | 'silky' 'balanced' Reveal pacing preset
granularity 'char' | 'word' 'char' Fade animation unit
latexGuard boolean false Hold the last frame while a trailing formula is incomplete
preprocess (text: string) => string β€” Transform content before rendering
components / remarkPlugins / rehypePlugins β€” β€” Passed through to react-markdown

🧬 Lower-level API

Everything the component is built on is exported for custom pipelines:

  • useSmoothStreamContent / useStreamQueue β€” pacing and block-queue primitives.
  • rehypeStreamAnimated β€” the rehype plugin that tags freshly revealed nodes.
  • CachedMarkdown, findOpenFenceLanguage, STREAM_FADE_DURATION.
  • LaTeX preprocessing: preprocessLaTeX, validateLatexExpressions, isLastFormulaRenderable, and friends.
  • @lobehub/streamdown/profiler β€” StreamdownProfilerProvider and hooks for measuring commit cost.

Limitation: cross-block references

Each top-level block is parsed independently, so a reference whose target sits in another block stays literal: GFM footnotes, reference-style links ([text][ref]) and reference-style images. Inline forms are unaffected. Supply a remark/rehype plugin pair if you need to resolve these out of band.

⌨️ Local Development

You can use Github Codespaces for online development:

Or clone it for local development:

$ git clone https://github.com/lobehub/streamdown.git
$ cd streamdown
$ pnpm install
$ pnpm dev

The remaining scripts:

$ pnpm build        # library β†’ es/
$ pnpm build:site   # site β†’ site/dist
$ pnpm deploy:site  # build + wrangler pages deploy

$ pnpm test         # vitest
$ pnpm type-check   # tsc, library + site
$ pnpm lint

🀝 Contributing

Contributions of all types are more than welcome, if you are interested in contributing code, feel free to check out our GitHub Issues to get stuck in to show us what you’re made of.

Releases are automated with semantic-release from gitmoji-style commit messages on main.

🩷 Sponsor

Every bit counts and your one-time donation sparkles in our galaxy of support! You're a shooting star, making a swift and bright impact on our journey. Thank you for believing in us – your generosity guides us toward our mission, one brilliant flash at a time.

πŸ”— Links

Credits

More Products

  • 🀯 Lobe Chat - An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application.
  • πŸ…°οΈ Lobe Theme - The modern theme for stable diffusion webui, exquisite interface design, highly customizable UI, and efficiency boosting features.
  • 🧸 Lobe Vidol - Experience the magic of virtual idol creation with Lobe Vidol, enjoy the elegance of our Exquisite UI Design, dance along using MMD Dance Support, and engage in Smooth Conversations.

Design Resources

Development Resources

  • 🎀 Lobe TTS - A high-quality & reliable TTS/STT library for Server and Browser
  • 🌏 Lobe i18n - Automation ai tool for the i18n (internationalization) translation process.

More Resources


πŸ“ License

Copyright Β© 2023 LobeHub.
This project is MIT licensed.

About

Headless streaming markdown engine for React: block splitting, smooth reveal, per-char fade animation and LLM output preprocessing

Topics

Resources

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages