All components

Streaming Markdown

AI

Renders markdown from a string that grows as it streams, with a caret trailing the last glyph. Re-parses the whole string each render into stable, index-keyed blocks so React updates text in place — earlier content never re-mounts, keeping selection and scroll intact while tokens arrive. Unclosed constructs degrade gracefully (an open ``` is already a code block; a dangling ** stays literal until it closes). Hand-written parser, no markdown dependency; monochrome and reduced-motion aware.

Bloom filters

A Bloom filter is a compact, probabilistic set. It answers one question — “have I possibly seen this key?” — with far less memory than storing the keys.

  • Add: hash the key k ways, set those bits to 1
  • Test: if any bit is 0 it's definitely absent
  • Otherwise it's ~probably~ probably present
function mightContain(bits: Uint8Array, key: string) {
  return hashes(key).every((h) => bits[h] === 1);
}
False negatives are impossible; false positives rise as the array fills.

Reach for one as a cheap gate in front of an expensive lookup.

Installation

Terminal
npx shadcn@latest add https://ui.saumyarex.xyz/r/streaming-markdown.json

Props

PropTypeDefaultDescription
textstringThe markdown source. Grow it over time to stream.
isStreamingbooleanfalseShow the blinking caret after the last glyph while tokens are still arriving.
...propsReact.ComponentProps<"div">All native div attributes are forwarded.

Dependencies

clsxtailwind-merge