DocsSupportPricing
Roadmap (has updates coming soon)XFigma3.4K
  1. Components
  2. Code Block

Shadcn Code Block: Highlight, Streaming, Diffs, AI Chat and more

View docs

Browse 27 production-ready shadcn code block components for streaming agent responses, AI chat with markdown code fences, diff review, focus walkthroughs, line selection, gutter actions, terminal output, and multi-file patches: a custom ReUI component built on Shiki and composable with Card, Frame, Tabs, and Badge.

Shadcn Code Block: Streaming, Diffs, and AI Chat

ReUI Code Block is a custom shadcn component, not part of the base shadcn/ui library, for rendering source code with syntax highlighting from Shiki. It handles the cases an AI product actually needs: code streaming in token by token, agent-proposed diffs, diagnostics on specific lines, and per-line actions, alongside the ordinary documentation cases.

Eighteen components cover the range: a streaming agent response with a caret and stick-to-bottom scrolling, an AI chat message that renders markdown code fences as they arrive, diff review with added and removed lines, focus walkthroughs, line selection for asking an assistant about a range, terminal output with no highlighting, and multi-file patches in tabs.

The component is composable rather than configured. The root renders the code surface and children supply the chrome, so the same block works bare, inside a shadcn Card, or inside a ReUI Frame without a doubled border.

What is Shadcn Code Block?

ReUI Code Block renders source code as real React elements rather than as an HTML string. Shiki tokenizes the code and the result is normalized into a plain array of lines, which is what makes per-line interaction possible: hover actions in the gutter, click and shift-click line selection, diff markers, and diagnostic backgrounds all attach to elements instead of being baked into markup.

The happy path is one tag. Pass code and a language and you get a complete block with syntax highlighting in both light and dark themes. Everything else, the header, the filename, the language label, the copy button, the wrap toggle and the expand control, is composed as children.

Streaming code and AI chat

When code arrives from a model it grows one chunk at a time. The component re-tokenizes against a deferred value and the highlighter returns the same line objects for lines that did not change, so appending a token re-renders one line rather than the whole file. Lines the highlighter has not caught up to render as plain text, so the newest token is on screen immediately and gains color a frame later.

Most chat UIs hold a markdown message rather than a raw code string. Two helpers cover that: markdownFences splits a message into prose and fenced code and reports a fence whose closing delimiter has not streamed in yet, and markdownCodeProps reads the language and source out of the props react-markdown gives a pre element. An unknown language and a half-finished fence both render as plain text instead of throwing.

Server rendering and bundle cost

The Shiki engine lives in its own module with no client directive, so a React Server Component can call highlightCode and pass the resulting lines down as plain JSON. The browser then never downloads a grammar. The same shape works without React Server Components: return lines from a Remix or TanStack Start loader and pass them to the component.

Highlighting uses Shiki's JavaScript regex engine rather than the WebAssembly one, so installing the component does not force wasm-unsafe-eval into your Content Security Policy. Shiki loads on first highlight and never on import, each language is its own chunk resolved through a static map, and passing pre-highlighted lines or turning highlighting off requests none of it.

Diffs, highlights, and focus

Line state can come from props or from Shiki notation comments. Highlighted lines, highlighted words, added and removed diff lines, focused lines and error, warning or info levels all accept either an array of line numbers or a range string such as 2-4,7. The transformers prop is passed straight to Shiki, so the notation comments from @shikijs/transformers produce the same state without a second code path.

Every piece of state is published as a data attribute on the line, which means restyling any of it is a plain CSS selector and never needs an important flag. Line numbers and diff glyphs are generated content, so they stay out of text selection: selecting code and pasting it gives exact source with no gutter digits.

Frequently Asked Questions

Previous22 Shadcn Checkbox Components
Next10 Shadcn Collapsible Components

Application

  • App Shell
  • Auth
  • Card
  • Chart
  • Dashboard
  • Dialog
  • Empty State
  • Event Calendar
  • Form
  • GanttUpdated 4 blocks
  • Kanban Board
  • List
  • Navbar
  • Onboarding
  • Profile
  • Schedule
  • Settings
  • Sheet
  • Stats
  • Timeline
  • Wizard

Solutions

  • Agents
  • AI Ops
  • Analytics
  • Billing
  • Bookings
  • CRM
  • FilesAdded a new blocks
  • Inventory
  • Users

Templates

  • E-commerce
  • SaaS
  • Dashboard
  • Landing
  • All templates

eCommerce

  • Category Card
  • Checkout
  • Comparison
  • Coupon
  • Filter Sidebar
  • Product Card
  • Product Detail
  • Product Grid
  • Receipt
  • Review
  • Shopping Cart
  • Wishlist

Data Grid

  • Base
  • Columns
  • Drag & Drop
  • Editing
  • Expansion
  • Filtering
  • Grouping
  • Virtualization

Marketing

  • Blog
  • Contact
  • CTA
  • FAQ
  • HeroAddeed new 16 hero blocks

Resources

  • Components
  • Blocks
  • Icons
  • MCP for Agents
  • Docs
  • Support
  • Pricing
  • Roadmap(has updates coming soon)
  • AffiliateSoon

Legal

  • Privacy Policy
  • Terms & Conditions
  • License
  • Refunds
  • Cookies

© 2026 ReUI. All rights reserved.

3.4K

Code block with header, filename, language and copy button.

Headerless block with a pinned copy button and dual-axis scrolling.

Agent writing code in real time with a caret and stick-to-bottom.

Streaming assistant message rendering markdown code fences.

A props-driven diff with added and removed lines and a change summary.

A diff expressed through a shiki transformer instead of props.

Line ranges and word matches highlighted together.

Stepping through regions of a file with the rest dimmed.

Unhighlighted command output with a wrap toggle.

Collapsed at a line budget with an expand control and a line offset.

Error and warning lines with an action button on the active line.

Selecting lines to ask an assistant about them.

Live search marking every match, with a counter that reads the block through useCodeBlockConfig.

A framed file switcher loading one grammar chunk per selected language.

Lines built without shiki, the shape a server component passes down.

Two blocks stacked in a frame for a refactor review.

Long single-line content with a wrap toggle.

A git patch parsed into files with dual old/new gutters, counters and a download.

Syntax colors driven by CSS variables mapped to design tokens.

A block that stays dark in both site themes, with window chrome and every line state.

ANSI-style colored terminal output built from plain lines.

Agent-proposed diff with accept and reject actions.

Fold regions detected from indentation, with nesting and fold-all controls.

A line action scoped to the diagnostic line that applies the patch.

A gutter button that turns lines or a selection into file:line reference badges in a chat composer.

A changed-file list where one shadcn ScrollArea scrolls every block at once.

Agent stdout with SGR colour codes parsed by ansiToLines, retintable via --code-ansi-* variables.